animations

This commit is contained in:
Rowan 2024-05-24 18:02:52 -04:00
parent 3537cff540
commit 7518ceff39
4 changed files with 145 additions and 63 deletions

63
Cargo.lock generated
View file

@ -310,6 +310,15 @@ version = "0.21.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
[[package]]
name = "benimator"
version = "4.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07ff332b478b24417c1bac8d39bd90454761a4a5b73837cc014a22b78dd905a3"
dependencies = [
"rustc_version",
]
[[package]]
name = "bevy"
version = "0.13.2"
@ -877,7 +886,7 @@ dependencies = [
"quote",
"rustc-hash",
"syn 2.0.64",
"toml_edit",
"toml_edit 0.21.1",
]
[[package]]
@ -1409,12 +1418,14 @@ dependencies = [
name = "brackeys-game"
version = "0.1.0"
dependencies = [
"benimator",
"bevy",
"bevy_asset_loader",
"bevy_ecs_ldtk",
"bevy_editor_pls",
"bevy_xpbd_2d",
"leafwing-input-manager",
"toml",
]
[[package]]
@ -3441,7 +3452,7 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284"
dependencies = [
"toml_edit",
"toml_edit 0.21.1",
]
[[package]]
@ -3759,6 +3770,15 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
dependencies = [
"serde",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
@ -3975,11 +3995,26 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "toml"
version = "0.8.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit 0.22.13",
]
[[package]]
name = "toml_datetime"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
@ -3989,7 +4024,20 @@ checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1"
dependencies = [
"indexmap",
"toml_datetime",
"winnow",
"winnow 0.5.40",
]
[[package]]
name = "toml_edit"
version = "0.22.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow 0.6.8",
]
[[package]]
@ -4795,6 +4843,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "winnow"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d"
dependencies = [
"memchr",
]
[[package]]
name = "x11-dl"
version = "2.21.0"

View file

@ -24,6 +24,8 @@ leafwing-input-manager = "0.13.3"
# Use unstable version for Bevy 0.13 support
bevy_ecs_ldtk = { git = "https://github.com/Trouv/bevy_ecs_ldtk.git" }
bevy_xpbd_2d = "0.4.2"
benimator = "4.1.3"
toml = "0.8.13"
[patch.crates-io]
# Patch unstable version to resolve conflicting dependencies from bevy_ecs_ldtk

View file

@ -966,14 +966,14 @@
"worldDepth": 0,
"pxWid": 624,
"pxHei": 256,
"__bgColor": "#000000",
"bgColor": "#000000",
"__bgColor": "#696A79",
"bgColor": null,
"useAutoIdentifier": true,
"bgRelPath": null,
"bgPos": null,
"bgPivotX": 0.5,
"bgPivotY": 0.5,
"__smartColor": "#737373",
"__smartColor": "#ADADB5",
"__bgPos": null,
"externalRelPath": null,
"fieldInstances": [],
@ -1002,9 +1002,25 @@
"overrideTilesetUid": null,
"gridTiles": [],
"entityInstances": [
{
"__identifier": "Player",
"__grid": [5,8],
"__pivot": [0,0],
"__tags": [],
"__tile": { "tilesetUid": 3, "x": 0, "y": 0, "w": 32, "h": 32 },
"__smartColor": "#BE4A2F",
"iid": "7e842c00-fec0-11ee-a719-3914173281f6",
"width": 16,
"height": 16,
"defUid": 6,
"px": [80,128],
"fieldInstances": [],
"__worldX": 80,
"__worldY": 128
},
{
"__identifier": "Camera",
"__grid": [17,3],
"__grid": [16,2],
"__pivot": [0.5,0.5],
"__tags": [],
"__tile": null,
@ -1013,34 +1029,18 @@
"width": 32,
"height": 32,
"defUid": 31,
"px": [280,56],
"px": [264,40],
"fieldInstances": [{ "__identifier": "Target", "__type": "EntityRef", "__value": {
"entityIid": "f8d0c9b0-fec0-11ee-8a35-b5b194835c7d",
"entityIid": "7e842c00-fec0-11ee-a719-3914173281f6",
"layerIid": "98e95fd0-fec0-11ee-aa65-136eff944257",
"levelIid": "e1f15120-fec0-11ee-aa65-375c6820674f",
"worldIid": "e1f12a10-fec0-11ee-aa65-ef87be1b7c9a"
}, "__tile": null, "defUid": 32, "realEditorValues": [{
"id": "V_String",
"params": ["f8d0c9b0-fec0-11ee-8a35-b5b194835c7d"]
"params": ["7e842c00-fec0-11ee-a719-3914173281f6"]
}] }],
"__worldX": 280,
"__worldY": 56
},
{
"__identifier": "Player",
"__grid": [5,8],
"__pivot": [0,0],
"__tags": [],
"__tile": { "tilesetUid": 3, "x": 0, "y": 0, "w": 32, "h": 32 },
"__smartColor": "#BE4A2F",
"iid": "f8d0c9b0-fec0-11ee-8a35-b5b194835c7d",
"width": 16,
"height": 16,
"defUid": 6,
"px": [80,128],
"fieldInstances": [],
"__worldX": 80,
"__worldY": 128
"__worldX": 264,
"__worldY": 40
}
]
},
@ -1122,46 +1122,46 @@
{ "px": [256,96], "src": [16,0], "f": 0, "t": 1, "d": [60,250], "a": 1 },
{ "px": [272,96], "src": [16,16], "f": 0, "t": 17, "d": [60,251], "a": 1 },
{ "px": [336,128], "src": [16,16], "f": 0, "t": 17, "d": [60,333], "a": 1 },
{ "px": [352,144], "src": [0,16], "f": 0, "t": 16, "d": [60,373], "a": 1 },
{ "px": [352,144], "src": [16,0], "f": 0, "t": 1, "d": [60,373], "a": 1 },
{ "px": [80,176], "src": [16,16], "f": 0, "t": 17, "d": [60,434], "a": 1 },
{ "px": [96,176], "src": [16,16], "f": 0, "t": 17, "d": [60,435], "a": 1 },
{ "px": [544,176], "src": [16,0], "f": 0, "t": 1, "d": [60,463], "a": 1 },
{ "px": [64,192], "src": [0,16], "f": 0, "t": 16, "d": [60,472], "a": 1 },
{ "px": [96,176], "src": [16,0], "f": 0, "t": 1, "d": [60,435], "a": 1 },
{ "px": [544,176], "src": [16,16], "f": 0, "t": 17, "d": [60,463], "a": 1 },
{ "px": [64,192], "src": [16,16], "f": 0, "t": 17, "d": [60,472], "a": 1 },
{ "px": [80,192], "src": [0,16], "f": 0, "t": 16, "d": [60,473], "a": 1 },
{ "px": [96,192], "src": [16,0], "f": 0, "t": 1, "d": [60,474], "a": 1 },
{ "px": [112,192], "src": [0,16], "f": 0, "t": 16, "d": [60,475], "a": 1 },
{ "px": [128,192], "src": [0,16], "f": 0, "t": 16, "d": [60,476], "a": 1 },
{ "px": [544,192], "src": [0,16], "f": 0, "t": 16, "d": [60,502], "a": 1 },
{ "px": [544,192], "src": [16,0], "f": 0, "t": 1, "d": [60,502], "a": 1 },
{ "px": [560,192], "src": [0,16], "f": 0, "t": 16, "d": [60,503], "a": 1 },
{ "px": [144,80], "src": [16,0], "f": 0, "t": 1, "d": [59,204], "a": 1 },
{ "px": [144,80], "src": [0,16], "f": 0, "t": 16, "d": [59,204], "a": 1 },
{ "px": [160,80], "src": [16,0], "f": 1, "t": 1, "d": [59,205], "a": 1 },
{ "px": [80,160], "src": [0,16], "f": 0, "t": 16, "d": [59,395], "a": 1 },
{ "px": [96,160], "src": [16,16], "f": 1, "t": 17, "d": [59,396], "a": 1 },
{ "px": [528,160], "src": [0,16], "f": 0, "t": 16, "d": [59,423], "a": 1 },
{ "px": [544,160], "src": [0,16], "f": 1, "t": 16, "d": [59,424], "a": 1 },
{ "px": [80,160], "src": [16,16], "f": 0, "t": 17, "d": [59,395], "a": 1 },
{ "px": [96,160], "src": [16,0], "f": 1, "t": 1, "d": [59,396], "a": 1 },
{ "px": [528,160], "src": [16,16], "f": 0, "t": 17, "d": [59,423], "a": 1 },
{ "px": [544,160], "src": [16,16], "f": 1, "t": 17, "d": [59,424], "a": 1 },
{ "px": [528,176], "src": [0,16], "f": 0, "t": 16, "d": [59,462], "a": 1 },
{ "px": [48,192], "src": [16,16], "f": 0, "t": 17, "d": [59,471], "a": 1 },
{ "px": [144,192], "src": [16,16], "f": 1, "t": 17, "d": [59,477], "a": 1 },
{ "px": [208,192], "src": [0,16], "f": 0, "t": 16, "d": [59,481], "a": 1 },
{ "px": [224,192], "src": [16,16], "f": 1, "t": 17, "d": [59,482], "a": 1 },
{ "px": [272,192], "src": [16,0], "f": 0, "t": 1, "d": [59,485], "a": 1 },
{ "px": [208,192], "src": [16,0], "f": 0, "t": 1, "d": [59,481], "a": 1 },
{ "px": [224,192], "src": [0,16], "f": 1, "t": 16, "d": [59,482], "a": 1 },
{ "px": [272,192], "src": [0,16], "f": 0, "t": 16, "d": [59,485], "a": 1 },
{ "px": [288,192], "src": [16,0], "f": 1, "t": 1, "d": [59,486], "a": 1 },
{ "px": [528,192], "src": [16,16], "f": 0, "t": 17, "d": [59,501], "a": 1 },
{ "px": [576,192], "src": [0,16], "f": 1, "t": 16, "d": [59,504], "a": 1 },
{ "px": [160,96], "src": [16,0], "f": 0, "t": 1, "d": [58,244], "a": 1 },
{ "px": [160,96], "src": [0,16], "f": 0, "t": 16, "d": [58,244], "a": 1 },
{ "px": [256,112], "src": [16,16], "f": 0, "t": 17, "d": [58,289], "a": 1 },
{ "px": [272,112], "src": [16,16], "f": 0, "t": 17, "d": [58,290], "a": 1 },
{ "px": [272,112], "src": [0,16], "f": 0, "t": 16, "d": [58,290], "a": 1 },
{ "px": [288,112], "src": [16,0], "f": 0, "t": 1, "d": [58,291], "a": 1 },
{ "px": [320,128], "src": [16,16], "f": 0, "t": 17, "d": [58,332], "a": 1 },
{ "px": [368,160], "src": [16,16], "f": 0, "t": 17, "d": [58,413], "a": 1 },
{ "px": [384,160], "src": [16,0], "f": 0, "t": 1, "d": [58,414], "a": 1 },
{ "px": [64,208], "src": [16,0], "f": 0, "t": 1, "d": [58,511], "a": 1 },
{ "px": [384,160], "src": [0,16], "f": 0, "t": 16, "d": [58,414], "a": 1 },
{ "px": [64,208], "src": [0,16], "f": 0, "t": 16, "d": [58,511], "a": 1 },
{ "px": [80,208], "src": [16,0], "f": 0, "t": 1, "d": [58,512], "a": 1 },
{ "px": [96,208], "src": [16,0], "f": 0, "t": 1, "d": [58,513], "a": 1 },
{ "px": [112,208], "src": [16,0], "f": 0, "t": 1, "d": [58,514], "a": 1 },
{ "px": [96,208], "src": [16,16], "f": 0, "t": 17, "d": [58,513], "a": 1 },
{ "px": [112,208], "src": [0,16], "f": 0, "t": 16, "d": [58,514], "a": 1 },
{ "px": [128,208], "src": [16,16], "f": 0, "t": 17, "d": [58,515], "a": 1 },
{ "px": [544,208], "src": [16,16], "f": 0, "t": 17, "d": [58,541], "a": 1 },
{ "px": [560,208], "src": [16,16], "f": 0, "t": 17, "d": [58,542], "a": 1 },
{ "px": [544,208], "src": [16,0], "f": 0, "t": 1, "d": [58,541], "a": 1 },
{ "px": [560,208], "src": [0,16], "f": 0, "t": 16, "d": [58,542], "a": 1 },
{ "px": [176,96], "src": [0,0], "f": 0, "t": 0, "d": [57,245], "a": 1 },
{ "px": [304,112], "src": [0,0], "f": 0, "t": 0, "d": [57,292], "a": 1 },
{ "px": [320,112], "src": [0,0], "f": 0, "t": 0, "d": [57,293], "a": 1 },
@ -1173,20 +1173,20 @@
{ "px": [560,176], "src": [0,0], "f": 0, "t": 0, "d": [57,464], "a": 1 },
{ "px": [144,96], "src": [0,16], "f": 0, "t": 16, "d": [56,243], "a": 1 },
{ "px": [176,112], "src": [0,16], "f": 0, "t": 16, "d": [56,284], "a": 1 },
{ "px": [192,112], "src": [16,0], "f": 1, "t": 1, "d": [56,285], "a": 1 },
{ "px": [192,112], "src": [16,16], "f": 1, "t": 17, "d": [56,285], "a": 1 },
{ "px": [240,112], "src": [0,16], "f": 0, "t": 16, "d": [56,288], "a": 1 },
{ "px": [304,128], "src": [16,0], "f": 0, "t": 1, "d": [56,331], "a": 1 },
{ "px": [336,144], "src": [16,0], "f": 0, "t": 1, "d": [56,372], "a": 1 },
{ "px": [352,160], "src": [0,16], "f": 0, "t": 16, "d": [56,412], "a": 1 },
{ "px": [304,128], "src": [0,16], "f": 0, "t": 16, "d": [56,331], "a": 1 },
{ "px": [336,144], "src": [0,16], "f": 0, "t": 16, "d": [56,372], "a": 1 },
{ "px": [352,160], "src": [16,16], "f": 0, "t": 17, "d": [56,412], "a": 1 },
{ "px": [400,160], "src": [16,16], "f": 1, "t": 17, "d": [56,415], "a": 1 },
{ "px": [48,208], "src": [16,0], "f": 0, "t": 1, "d": [56,510], "a": 1 },
{ "px": [144,208], "src": [16,16], "f": 1, "t": 17, "d": [56,516], "a": 1 },
{ "px": [48,208], "src": [0,16], "f": 0, "t": 16, "d": [56,510], "a": 1 },
{ "px": [144,208], "src": [0,16], "f": 1, "t": 16, "d": [56,516], "a": 1 },
{ "px": [208,208], "src": [16,0], "f": 0, "t": 1, "d": [56,520], "a": 1 },
{ "px": [224,208], "src": [0,16], "f": 1, "t": 16, "d": [56,521], "a": 1 },
{ "px": [224,208], "src": [16,0], "f": 1, "t": 1, "d": [56,521], "a": 1 },
{ "px": [272,208], "src": [0,16], "f": 0, "t": 16, "d": [56,524], "a": 1 },
{ "px": [288,208], "src": [0,16], "f": 1, "t": 16, "d": [56,525], "a": 1 },
{ "px": [528,208], "src": [16,0], "f": 0, "t": 1, "d": [56,540], "a": 1 },
{ "px": [576,208], "src": [16,0], "f": 1, "t": 1, "d": [56,543], "a": 1 },
{ "px": [576,208], "src": [0,16], "f": 1, "t": 16, "d": [56,543], "a": 1 },
{ "px": [144,64], "src": [0,0], "f": 0, "t": 0, "d": [55,165], "a": 1 },
{ "px": [160,64], "src": [0,0], "f": 1, "t": 0, "d": [55,166], "a": 1 },
{ "px": [256,80], "src": [0,0], "f": 0, "t": 0, "d": [55,211], "a": 1 },
@ -1214,7 +1214,7 @@
{ "px": [160,176], "src": [144,0], "f": 0, "t": 9, "d": [69,439], "a": 1 },
{ "px": [192,176], "src": [144,0], "f": 1, "t": 9, "d": [69,441], "a": 1 }
],
"seed": 1402800,
"seed": 7909745,
"overrideTilesetUid": null,
"gridTiles": [],
"entityInstances": []

View file

@ -7,12 +7,17 @@ use bevy_ecs_ldtk::prelude::*;
use leafwing_input_manager::{action_state::ActionState, InputManagerBundle};
use self::{
controller::{
CharacterControllerBundle, CharacterControllerPlugin, Jumping,
},
input::{InputPlugin, PlayerAction}, movement::MovementDirection,
controller::{CharacterControllerBundle, CharacterControllerPlugin, Jumping},
input::{InputPlugin, PlayerAction},
movement::MovementDirection,
};
#[derive(Component, Deref)]
pub struct Animation(benimator::Animation);
#[derive(Default, Component, Deref, DerefMut)]
pub struct AnimationState(benimator::State);
#[derive(Component, Default)]
pub struct Player;
@ -21,6 +26,8 @@ pub struct PlayerBundle {
player: Player,
input_manager_bundle: InputManagerBundle<PlayerAction>,
character_controller_bundle: CharacterControllerBundle,
animation: Animation,
animation_state: AnimationState,
}
impl Default for PlayerBundle {
@ -29,6 +36,11 @@ impl Default for PlayerBundle {
player: Player,
input_manager_bundle: InputManagerBundle::with_map(PlayerAction::default_input_map()),
character_controller_bundle: CharacterControllerBundle::default(),
animation: Animation(benimator::Animation::from_indices(
0..4,
benimator::FrameRate::from_fps(12.),
)),
animation_state: AnimationState::default(),
}
}
}
@ -44,7 +56,7 @@ pub struct PlayerPlugin;
impl Plugin for PlayerPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((InputPlugin, CharacterControllerPlugin))
.add_systems(Update, (apply_movement_input, apply_jumping_input))
.add_systems(Update, (apply_movement_input, apply_jumping_input, animate))
.register_ldtk_entity::<PlayerEntity>("Player");
}
}
@ -70,3 +82,14 @@ fn apply_jumping_input(
}
}
}
fn animate(
time: Res<Time>,
mut query: Query<(&mut AnimationState, &mut TextureAtlas, &Animation)>,
) {
let delta = time.delta();
for (mut state, mut atlas, animation) in query.iter_mut() {
state.update(animation, delta);
atlas.index = state.frame_index();
}
}