Skip to content

Commit

Permalink
Bevy 0.15 progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldom-SE committed Dec 16, 2024
1 parent f8877c9 commit 38bbf2e
Show file tree
Hide file tree
Showing 33 changed files with 711 additions and 950 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ anyhow = "1.0"
event-listener = "5.3"
serde = "1.0"
line_drawing = { version = "1.0", optional = true }
seldom_singleton = "0.2.0"
seldom_singleton = "0.3.0"
bevy_turborand = { version = "0.9.0", optional = true }
seldom_map_nav = { version = "0.7.0", optional = true }
seldom_pixel_macros = { version = "0.2.0-dev", path = "macros" }
seldom_state = { version = "0.11.0", optional = true }

[dependencies.bevy]
version = "0.14.0"
version = "0.15.0"
default-features = false
features = ["bevy_asset", "bevy_core_pipeline", "bevy_render", "bevy_sprite"]

[dev-dependencies]
bevy = { version = "0.14.0", features = ["png"] }
leafwing-input-manager = "0.14.0"
bevy = "0.15.0"
# leafwing-input-manager = "0.14.0"
rand = "0.8.5"
seldom_state = { version = "0.11.0", features = ["leafwing_input"] }
# seldom_state = { version = "0.11.0", features = ["leafwing_input"] }

[[example]]
name = "line"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ need improvement, feel free to submit an issue or pr!

## Philosophies

- Assets are created through images
- Assets are normal images

All assets, including filters, are loaded from images. `seldom_pixel`'s scope is limited
to rendered things, so this doesn't apply to things like levels and sounds. I recommend
Expand All @@ -41,7 +41,7 @@ about [Aseprite](https://github.com/aseprite/aseprite/), which you can use for f
can compile it. I've only used this plugin on `.png` files, so I recommend using that format,
but feel free to try it on other lossless formats.

- It is what it looks like
- What you see is what you get

This crate's position component, `PxPosition`, uses an `IVec2` (2-dimensional `i32` vector)
to store positions. This means that entities are located at exact pixel positions.
Expand All @@ -52,7 +52,7 @@ which I recommend using when possible. I also recommend resetting the `SubPxPosi
to `PxPosition`'s value when it stops moving, so moving objects feel consistent to the player.
This is less of a concern for games with smaller pixels.

- Sacrifice versatility for productivity
- Trade versatility for productivity

If you are already interested in making a limited color palette pixel art game,
this is an easy win for you. Filters in `seldom_pixel` are just maps from each color
Expand Down
33 changes: 15 additions & 18 deletions examples/anchors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,27 @@ fn main() {
}

fn init(assets: Res<AssetServer>, mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

// Centered
commands.spawn(PxSpriteBundle::<Layer> {
sprite: assets.load("sprite/mage.px_sprite.png"),
position: IVec2::new(8, 16).into(),
..default()
});
commands.spawn((
PxSprite(assets.load("sprite/mage.px_sprite.png")),
PxPosition(IVec2::new(8, 16)),
));

// Bottom Left
commands.spawn(PxSpriteBundle::<Layer> {
sprite: assets.load("sprite/mage.px_sprite.png"),
position: IVec2::splat(16).into(),
anchor: PxAnchor::BottomLeft,
..default()
});
commands.spawn((
PxSprite(assets.load("sprite/mage.px_sprite.png")),
PxPosition(IVec2::splat(16)),
PxAnchor::BottomLeft,
));

// Custom. Values range from 0 to 1, with the origin at the bottom left corner.
commands.spawn(PxSpriteBundle::<Layer> {
sprite: assets.load("sprite/mage.px_sprite.png"),
position: IVec2::new(24, 16).into(),
anchor: Vec2::new(0.2, 0.8).into(),
..default()
});
commands.spawn((
PxSprite(assets.load("sprite/mage.px_sprite.png")),
PxPosition(IVec2::new(24, 16)),
PxAnchor::Custom(Vec2::new(0.2, 0.8)),
));
}

#[px_layer]
Expand Down
87 changes: 31 additions & 56 deletions examples/animated_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,68 +21,55 @@ fn main() {
}

fn init(assets: Res<AssetServer>, mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let mage = assets.load("sprite/mage.px_sprite.png");

// Spawn a bunch of sprites on different layers
for layer in 0..8 {
commands.spawn(PxSpriteBundle {
sprite: mage.clone(),
position: IVec2::new(layer % 4 * 13, layer / 4 * 18).into(),
anchor: PxAnchor::BottomLeft,
layer: Layer(layer),
..default()
});
commands.spawn((
PxSprite(mage.clone()),
PxPosition(IVec2::new(layer % 4 * 13, layer / 4 * 18)),
PxAnchor::BottomLeft,
Layer(layer),
));
}

// Load the filter
let fade_to_black = assets.load("filter/fade_to_black.px_filter.png");

// Despawn at the end
commands.spawn((
PxFilterBundle {
filter: fade_to_black.clone(),
layers: PxFilterLayers::single_clip(Layer(0)),
..default()
},
PxAnimationBundle::default(),
PxFilter(fade_to_black.clone()),
PxFilterLayers::single_clip(Layer(0)),
PxAnimation::default(),
));

// Add the `PxAnimationFinished` component at the end
commands.spawn((
PxFilterBundle {
filter: fade_to_black.clone(),
layers: PxFilterLayers::single_clip(Layer(1)),
..default()
},
PxAnimationBundle {
PxFilter(fade_to_black.clone()),
PxFilterLayers::single_clip(Layer(1)),
PxAnimation {
on_finish: PxAnimationFinishBehavior::Mark,
..default()
},
));

// Loop
commands.spawn((
PxFilterBundle {
filter: fade_to_black.clone(),
layers: PxFilterLayers::single_clip(Layer(2)),
..default()
},
PxAnimationBundle {
PxFilter(fade_to_black.clone()),
PxFilterLayers::single_clip(Layer(2)),
PxAnimation {
on_finish: PxAnimationFinishBehavior::Loop,
..default()
},
));

// Backward
commands.spawn((
PxFilterBundle {
filter: fade_to_black.clone(),
layers: PxFilterLayers::single_clip(Layer(3)),
..default()
},
PxAnimationBundle {
PxFilter(fade_to_black.clone()),
PxFilterLayers::single_clip(Layer(3)),
PxAnimation {
direction: PxAnimationDirection::Backward,
on_finish: PxAnimationFinishBehavior::Loop,
..default()
Expand All @@ -91,12 +78,9 @@ fn init(assets: Res<AssetServer>, mut commands: Commands) {

// Faster
commands.spawn((
PxFilterBundle {
filter: fade_to_black.clone(),
layers: PxFilterLayers::single_clip(Layer(5)),
..default()
},
PxAnimationBundle {
PxFilter(fade_to_black.clone()),
PxFilterLayers::single_clip(Layer(5)),
PxAnimation {
duration: PxAnimationDuration::millis_per_animation(500),
on_finish: PxAnimationFinishBehavior::Loop,
..default()
Expand All @@ -105,12 +89,9 @@ fn init(assets: Res<AssetServer>, mut commands: Commands) {

// Slower
commands.spawn((
PxFilterBundle {
filter: fade_to_black.clone(),
layers: PxFilterLayers::single_clip(Layer(4)),
..default()
},
PxAnimationBundle {
PxFilter(fade_to_black.clone()),
PxFilterLayers::single_clip(Layer(4)),
PxAnimation {
duration: PxAnimationDuration::millis_per_animation(2000),
on_finish: PxAnimationFinishBehavior::Loop,
..default()
Expand All @@ -119,12 +100,9 @@ fn init(assets: Res<AssetServer>, mut commands: Commands) {

// Duration per frame
commands.spawn((
PxFilterBundle {
filter: fade_to_black.clone(),
layers: PxFilterLayers::single_clip(Layer(6)),
..default()
},
PxAnimationBundle {
PxFilter(fade_to_black.clone()),
PxFilterLayers::single_clip(Layer(6)),
PxAnimation {
duration: PxAnimationDuration::millis_per_frame(1000),
on_finish: PxAnimationFinishBehavior::Loop,
..default()
Expand All @@ -133,12 +111,9 @@ fn init(assets: Res<AssetServer>, mut commands: Commands) {

// Dither between frames
commands.spawn((
PxFilterBundle {
filter: fade_to_black,
layers: PxFilterLayers::single_clip(Layer(7)),
..default()
},
PxAnimationBundle {
PxFilter(fade_to_black),
PxFilterLayers::single_clip(Layer(7)),
PxAnimation {
on_finish: PxAnimationFinishBehavior::Loop,
frame_transition: PxAnimationFrameTransition::Dither,
..default()
Expand Down
88 changes: 32 additions & 56 deletions examples/animated_sprites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,46 @@ fn main() {
}

fn init(assets: Res<AssetServer>, mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

// Load an animated sprite with `add_animated`
let runner = assets.load("sprite/runner.px_sprite.png");

// Despawn at the end
commands.spawn((
PxSpriteBundle::<Layer> {
sprite: runner.clone(),
anchor: PxAnchor::BottomLeft,
..default()
},
PxAnimationBundle::default(),
PxSprite(runner.clone()),
PxAnchor::BottomLeft,
PxAnimation::default(),
));

// Add the `PxAnimationFinished` component at the end
commands.spawn((
PxSpriteBundle::<Layer> {
sprite: runner.clone(),
position: IVec2::new(13, 0).into(),
anchor: PxAnchor::BottomLeft,
..default()
},
PxAnimationBundle {
PxSprite(runner.clone()),
PxPosition(IVec2::new(13, 0)),
PxAnchor::BottomLeft,
PxAnimation {
on_finish: PxAnimationFinishBehavior::Mark,
..default()
},
));

// Loop
commands.spawn((
PxSpriteBundle::<Layer> {
sprite: runner.clone(),
position: IVec2::new(26, 0).into(),
anchor: PxAnchor::BottomLeft,
..default()
},
PxAnimationBundle {
PxSprite(runner.clone()),
PxPosition(IVec2::new(26, 0)),
PxAnchor::BottomLeft,
PxAnimation {
on_finish: PxAnimationFinishBehavior::Loop,
..default()
},
));

// Backward
commands.spawn((
PxSpriteBundle::<Layer> {
sprite: runner.clone(),
position: IVec2::new(39, 0).into(),
anchor: PxAnchor::BottomLeft,
..default()
},
PxAnimationBundle {
PxSprite(runner.clone()),
PxPosition(IVec2::new(39, 0)),
PxAnchor::BottomLeft,
PxAnimation {
direction: PxAnimationDirection::Backward,
on_finish: PxAnimationFinishBehavior::Loop,
..default()
Expand All @@ -81,13 +69,10 @@ fn init(assets: Res<AssetServer>, mut commands: Commands) {

// Faster
commands.spawn((
PxSpriteBundle::<Layer> {
sprite: runner.clone(),
position: IVec2::new(13, 18).into(),
anchor: PxAnchor::BottomLeft,
..default()
},
PxAnimationBundle {
PxSprite(runner.clone()),
PxPosition(IVec2::new(13, 18)),
PxAnchor::BottomLeft,
PxAnimation {
duration: PxAnimationDuration::millis_per_animation(500),
on_finish: PxAnimationFinishBehavior::Loop,
..default()
Expand All @@ -96,13 +81,10 @@ fn init(assets: Res<AssetServer>, mut commands: Commands) {

// Slower
commands.spawn((
PxSpriteBundle::<Layer> {
sprite: runner.clone(),
position: IVec2::new(0, 18).into(),
anchor: PxAnchor::BottomLeft,
..default()
},
PxAnimationBundle {
PxSprite(runner.clone()),
PxPosition(IVec2::new(0, 18)),
PxAnchor::BottomLeft,
PxAnimation {
duration: PxAnimationDuration::millis_per_animation(2000),
on_finish: PxAnimationFinishBehavior::Loop,
..default()
Expand All @@ -111,13 +93,10 @@ fn init(assets: Res<AssetServer>, mut commands: Commands) {

// Duration per frame
commands.spawn((
PxSpriteBundle::<Layer> {
sprite: runner.clone(),
position: IVec2::new(26, 18).into(),
anchor: PxAnchor::BottomLeft,
..default()
},
PxAnimationBundle {
PxSprite(runner.clone()),
PxPosition(IVec2::new(26, 18)),
PxAnchor::BottomLeft,
PxAnimation {
duration: PxAnimationDuration::millis_per_frame(1000),
on_finish: PxAnimationFinishBehavior::Loop,
..default()
Expand All @@ -126,13 +105,10 @@ fn init(assets: Res<AssetServer>, mut commands: Commands) {

// Dither between frames
commands.spawn((
PxSpriteBundle::<Layer> {
sprite: runner,
position: IVec2::new(39, 18).into(),
anchor: PxAnchor::BottomLeft,
..default()
},
PxAnimationBundle {
PxSprite(runner),
PxPosition(IVec2::new(39, 18)),
PxAnchor::BottomLeft,
PxAnimation {
on_finish: PxAnimationFinishBehavior::Loop,
frame_transition: PxAnimationFrameTransition::Dither,
..default()
Expand Down
Loading

0 comments on commit 38bbf2e

Please sign in to comment.