Skip to content

Allow custom sprites, introduce collider files, collider_creator example #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,32 @@ approach.
`MyGameState` is any user-defined struct type that will be passed to the logic functions each frame.
- `GameState` has been renamed to `EngineState` so that user's custom game state can be referred to
as `GameState` instead.
- `GameState::add_actor` has been renamed to `EngineState::add_sprite`
- `GameState::add_text_actor` has been renamed to `EngineState::add_text`
- `Game` now implements `Deref` and `DerefMut` for `EngineState`, so you can easily access
`EngineState`'s methods from `Game` in `main.rs` for your game setup. `Game::game_state_mut` has
been removed (if it had stayed it would have been renamed `engine_state_mut`, but with the deref
implementations it's not needed at all).
- `GameState.screen_dimensions`, which was set at startup and never updated, has been replaced by `EngineState.window_dimensions`, which is updated every frame so resizing the window can be handled in your game logic.
- Multiple logic functions can now be run. Pass them to `Game::run` in the order you would like them
run. Return `false` to abort running any later functions during the frame.
- Logic functions now need to fit the signature
`fn somename(engine_state: &mut EngineState, game_state: &mut GameState) -> bool`, where `GameState`
is the user-defined struct passed to `rusty_engine::init!()`, or `()` if nothing was passed in.
- Logic functions now need to fit the signature `fn somename(engine_state: &mut EngineState, game_state: &mut GameState) -> bool`, where `GameState` is the user-defined struct passed to `rusty_engine::init!()`, or `()` if nothing was passed in.
- `.play_sfx()` now takes a volume level from `0.0` to `1.0` as a second argument, e.g. `.play_sfx(SfxPreset::Congratulations, 1.0)`
- `Actor` has been renamed to `Sprite` to eliminate the confusing "actor" terminalogy.
- `Actor::build` has been replaced by `Sprite::new`, which _must_ be used to create a `Sprite` instead of defining a struct literal (enforced via private phantom data). The `Default` implementation has been removed because of the previous restriction.
- `Actor.preset` has been removed
- `Actor.filename` (a `String`) has been replaced with `Sprite.filepath` (a `PathBuf`)
- The builder methods `Actor::set_collision` and `Actor::set_collider` have been removed since we never ended up adopting a builder pattern.
- `Sprite.collider_filepath` has been added
- `Sprite::write_collider` has been added (see note below about changes to colliders)
- `TextActor` has been renamed to `Text` to eliminate the confusing "actor" terminology.
`TextActor::text` is now `Text::value` for similar reasons.
- `TextActor.text` is now `Text.value` for similar reasons.
- `Sprite`s may now be created with either a `SpritePreset` or the path to an image file via both `Sprite::new` or `EngineState::add_sprite`
- `SpritePreset::build_from_name` and `SpritePreset::build` have been removed (see note above about the new, more flexible way to create sprites)
- `SpritePreset::collider()` has been removed since colliders are no longer hard-coded features of presets (see note below about changes to colliders)
- `SpritePreset::filename -> String` has been replaced by `SpritePreset::filepath -> PathBuf`, which powers the `impl From<SpritePreset> for PathBuf` implementation.
- Colliders are now loaded from collider files. Collider files use the [Rusty Object Notation (RON)](https://github.com/ron-rs/ron) format. The easiest way to create a collider is to run the `collider_creator` example by cloning the `rusty_engine` repository and running `cargo run --release --example collider_creator relative/path/to/my/image.png`. The image needs to be somewhere inside the `assets/` directory. You could also create the collider programmatically, set it on the `Sprite` struct, and call the sprite's `write_collider()` method. Or you could copy an existing collider file, name it the same as your image file (but with the `.collider` extension) and change it to match your image. Collider coordinates need to define a convex polygon with points going in clockwise order. Coordinates are floating point values relative to the center of the image, with the center of the image being (0.0, 0.0).
- All sprites' colliders in the asset pack have been recreated more cleanly using the new `collider_creator` example.

### Other Changes

Expand All @@ -37,8 +50,12 @@ through `EngineState:audio_manager`)
a `.ttf` or `.otf` file stored in `assets/fonts`
- Custom sounds may now be played via `AudioManager::play_music` and `AudioManager::play_sfx` by
specifying a path to a sound file relative to `assets/audio`.

- `Collider` now implements `PartialEq`, `Serialize`, and `Deserialize`
- `Collider::is_convex` was added to make it easier to tell if you have a convex collider.
- The `collider_creator` example was added to make it easy to load a sprite and make a collider file for it. Place your image file (let's call it `my_image.png`) anywhere inside your local clone of the Rusty Engine `assets/` directory and then run the example: `cargo run --release --example collider_creator -- assets/my_image.png`. Afterwards, copy the image file and the new collider file `my_image.collider` file over to the assets directory of your own project.
- You can now toggle debug rendering of colliders by setting `EngineState.debug_sprite_colliders` to `true`. The `collision` example will now toggle that value when you press the `C` key.
- (meta) Improved CI times by using sccache together with GitHub Actions caching
- Circular colliders no longer have duplicate starting and ending coordinates

## [2.0.1] - 2021-11-15

Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ bevy_kira_audio = { version = "0.6.0", features = [
"ogg",
"wav",
] }
bevy_prototype_debug_lines = "0.3"
lazy_static = "1.4"
log = "0.4"
ron = "0.7"
serde = { version = "1.0", features = [ "derive" ] }

[dev-dependencies]
env_logger = "0.9"
Expand Down
18 changes: 18 additions & 0 deletions assets/sprite/racing/barrel_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Poly([
(28, 0),
(25.868626, 10.715136),
(19.79899, 19.79899),
(10.715136, 25.868626),
(0, 28),
(-10.715136, 25.868626),
(-19.79899, 19.79899),
(-25.868626, 10.715136),
(-28, 0),
(-25.868626, -10.715136),
(-19.79899, -19.79899),
(-10.715136, -25.868626),
(0, -28),
(10.715136, -25.868626),
(19.79899, -19.79899),
(25.868626, -10.715136),
])
18 changes: 18 additions & 0 deletions assets/sprite/racing/barrel_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Poly([
(28, 0),
(25.868626, 10.715136),
(19.79899, 19.79899),
(10.715136, 25.868626),
(0, 28),
(-10.715136, 25.868626),
(-19.79899, 19.79899),
(-25.868626, 10.715136),
(-28, 0),
(-25.868626, -10.715136),
(-19.79899, -19.79899),
(-10.715136, -25.868626),
(0, -28),
(10.715136, -25.868626),
(19.79899, -19.79899),
(25.868626, -10.715136),
])
10 changes: 10 additions & 0 deletions assets/sprite/racing/barrier_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-105, -29),
(-105, 28),
(-102, 31),
(102, 31),
(105, 28),
(105, -29),
(103, -31),
(-103, -31),
])
10 changes: 10 additions & 0 deletions assets/sprite/racing/barrier_white.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-105, -29),
(-105, 28),
(-102, 31),
(102, 31),
(105, 28),
(105, -29),
(103, -31),
(-103, -31),
])
19 changes: 19 additions & 0 deletions assets/sprite/racing/car_black.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Poly([
(-45, 33.5),
(38.5, 33.5),
(50, 29.5),
(57, 22.5),
(59, 18),
(59, -13),
(57, -23),
(51, -29),
(45, -32),
(37, -34),
(-43, -34),
(-50, -32),
(-57, -26.5),
(-60, -19),
(-60, 19),
(-58, 24.5),
(-52, 30.5),
])
19 changes: 19 additions & 0 deletions assets/sprite/racing/car_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Poly([
(-45, 33.5),
(38.5, 33.5),
(50, 29.5),
(57, 22.5),
(59, 18),
(59, -13),
(57, -23),
(51, -29),
(45, -32),
(37, -34),
(-43, -34),
(-50, -32),
(-57, -26.5),
(-60, -19),
(-60, 19),
(-58, 24.5),
(-52, 30.5),
])
19 changes: 19 additions & 0 deletions assets/sprite/racing/car_green.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Poly([
(-45, 33.5),
(38.5, 33.5),
(50, 29.5),
(57, 22.5),
(59, 18),
(59, -13),
(57, -23),
(51, -29),
(45, -32),
(37, -34),
(-43, -34),
(-50, -32),
(-57, -26.5),
(-60, -19),
(-60, 19),
(-58, 24.5),
(-52, 30.5),
])
19 changes: 19 additions & 0 deletions assets/sprite/racing/car_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Poly([
(-45, 33.5),
(38.5, 33.5),
(50, 29.5),
(57, 22.5),
(59, 18),
(59, -13),
(57, -23),
(51, -29),
(45, -32),
(37, -34),
(-43, -34),
(-50, -32),
(-57, -26.5),
(-60, -19),
(-60, 19),
(-58, 24.5),
(-52, 30.5),
])
19 changes: 19 additions & 0 deletions assets/sprite/racing/car_yellow.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Poly([
(-45, 33.5),
(38.5, 33.5),
(50, 29.5),
(57, 22.5),
(59, 18),
(59, -13),
(57, -23),
(51, -29),
(45, -32),
(37, -34),
(-43, -34),
(-50, -32),
(-57, -26.5),
(-60, -19),
(-60, 19),
(-58, 24.5),
(-52, 30.5),
])
10 changes: 10 additions & 0 deletions assets/sprite/racing/cone_straight.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-22, 16),
(-16, 22),
(16, 22),
(22, 16),
(22, -16),
(16, -22),
(-16, -22),
(-22, -16),
])
18 changes: 18 additions & 0 deletions assets/sprite/rolling/ball_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Poly([
(16.5, 0),
(15.244012, 6.3142767),
(11.667262, 11.667262),
(6.3142767, 15.244012),
(0, 16.5),
(-6.3142767, 15.244012),
(-11.667262, 11.667262),
(-15.244012, 6.3142767),
(-16.5, 0),
(-15.244012, -6.3142767),
(-11.667262, -11.667262),
(-6.3142767, -15.244012),
(0, -16.5),
(6.3142767, -15.244012),
(11.667262, -11.667262),
(15.244012, -6.3142767),
])
18 changes: 18 additions & 0 deletions assets/sprite/rolling/ball_blue_alt.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Poly([
(16.5, 0),
(15.244012, 6.3142767),
(11.667262, 11.667262),
(6.3142767, 15.244012),
(0, 16.5),
(-6.3142767, 15.244012),
(-11.667262, 11.667262),
(-15.244012, 6.3142767),
(-16.5, 0),
(-15.244012, -6.3142767),
(-11.667262, -11.667262),
(-6.3142767, -15.244012),
(0, -16.5),
(6.3142767, -15.244012),
(11.667262, -11.667262),
(15.244012, -6.3142767),
])
18 changes: 18 additions & 0 deletions assets/sprite/rolling/ball_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Poly([
(16.5, 0),
(15.244012, 6.3142767),
(11.667262, 11.667262),
(6.3142767, 15.244012),
(0, 16.5),
(-6.3142767, 15.244012),
(-11.667262, 11.667262),
(-15.244012, 6.3142767),
(-16.5, 0),
(-15.244012, -6.3142767),
(-11.667262, -11.667262),
(-6.3142767, -15.244012),
(0, -16.5),
(6.3142767, -15.244012),
(11.667262, -11.667262),
(15.244012, -6.3142767),
])
18 changes: 18 additions & 0 deletions assets/sprite/rolling/ball_red_alt.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Poly([
(16.5, 0),
(15.244012, 6.3142767),
(11.667262, 11.667262),
(6.3142767, 15.244012),
(0, 16.5),
(-6.3142767, 15.244012),
(-11.667262, 11.667262),
(-15.244012, 6.3142767),
(-16.5, 0),
(-15.244012, -6.3142767),
(-11.667262, -11.667262),
(-6.3142767, -15.244012),
(0, -16.5),
(6.3142767, -15.244012),
(11.667262, -11.667262),
(15.244012, -6.3142767),
])
10 changes: 10 additions & 0 deletions assets/sprite/rolling/block_corner.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-64, 59),
(-59, 64),
(-49, 64),
(64, -49),
(64, -59),
(59, -64),
(-59, -64),
(-64, -59),
])
10 changes: 10 additions & 0 deletions assets/sprite/rolling/block_narrow.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-64, 11),
(-59, 16),
(59, 16),
(64, 11),
(64, -11),
(59, -16),
(-59, -16),
(-64, -11),
])
10 changes: 10 additions & 0 deletions assets/sprite/rolling/block_small.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-16, 11),
(-11, 16),
(11, 16),
(16, 11),
(16, -11),
(11, -16),
(-11, -16),
(-16, -11),
])
10 changes: 10 additions & 0 deletions assets/sprite/rolling/block_square.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-32, 27),
(-27, 32),
(27, 32),
(32, 27),
(32, -27),
(27, -32),
(-27, -32),
(-32, -27),
])
18 changes: 18 additions & 0 deletions assets/sprite/rolling/hole_end.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Poly([
(18.5, 0),
(17.09177, 7.0796432),
(13.081475, 13.081475),
(7.0796432, 17.09177),
(0, 18.5),
(-7.0796432, 17.09177),
(-13.081475, 13.081475),
(-17.09177, 7.0796432),
(-18.5, 0),
(-17.09177, -7.0796432),
(-13.081475, -13.081475),
(-7.0796432, -17.09177),
(0, -18.5),
(7.0796432, -17.09177),
(13.081475, -13.081475),
(17.09177, -7.0796432),
])
18 changes: 18 additions & 0 deletions assets/sprite/rolling/hole_start.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Poly([
(24.5, 0),
(22.635048, 9.375744),
(17.324116, 17.324116),
(9.375744, 22.635048),
(0, 24.5),
(-9.375744, 22.635048),
(-17.324116, 17.324116),
(-22.635048, 9.375744),
(-24.5, 0),
(-22.635048, -9.375744),
(-17.324116, -17.324116),
(-9.375744, -22.635048),
(0, -24.5),
(9.375744, -22.635048),
(17.324116, -17.324116),
(22.635048, -9.375744),
])
Loading