From fa1f11c6021a04322f3fa36e2b682b0867a1d0ca Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Sat, 23 Nov 2024 21:53:08 +0100 Subject: [PATCH] merge --- src/game/player.rs | 43 ++++++++++++++++++------------------ src/game/player/animation.rs | 43 +++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/game/player.rs b/src/game/player.rs index 3749fc3..bfaa9c6 100644 --- a/src/game/player.rs +++ b/src/game/player.rs @@ -1,6 +1,6 @@ use std::{hash::Hash, time::Duration}; -use animation::AnimBundle; +use animation::{run_animations, AnimBundle, Animation}; use bevy::{ecs::system::SystemId, prelude::*, sprite::MaterialMesh2dBundle, utils::HashMap}; use bevy_rapier2d::prelude::*; @@ -34,8 +34,15 @@ impl FromWorld for PlayerSpawnOneshot { } pub(super) fn player_plugin(app: &mut App) { - app.add_systems(Update, (move_player,)) - .init_resource::(); + app.add_systems( + Update, + ( + move_player, + debug_player_pos, + run_animations::, + ), + ) + .init_resource::(); } #[derive(Component, Hash, PartialEq, Eq, Default)] @@ -47,7 +54,6 @@ enum PlayerAnimations { fn debug_player_pos(query: Query<&Transform, With>) { let trans = query.single(); - dbg!(trans); } fn move_player( kb_input: Res>, @@ -111,27 +117,11 @@ fn add_player( let anims = animation::AnimationManager::default() .insert( PlayerAnimations::Idle, - animation::Animation::new( - TextureAtlas { - layout: layout_idle_handle, - index: 0, - }, - 2, - 4, - tex_idle, - ), + Animation::new(layout_idle_handle.clone(), 2, 4, tex_idle.clone()), ) .insert( PlayerAnimations::Walk, - animation::Animation::new( - TextureAtlas { - layout: layout_walk_handle, - index: 0, - }, - 2, - 4, - tex_walk, - ), + Animation::new(layout_walk_handle.clone(), 4, 10, tex_walk.clone()), ); commands @@ -142,9 +132,18 @@ fn add_player( mgr: anims, }, SpriteBundle { + sprite: Sprite { + custom_size: Some(Vec2::splat(1.)), + ..Default::default() + }, transform: (*player_coords).into(), + texture: tex_idle, ..Default::default() }, + TextureAtlas { + layout: layout_idle_handle, + index: 0, + }, )) .insert(( RigidBody::Dynamic, diff --git a/src/game/player/animation.rs b/src/game/player/animation.rs index a7a70b4..ffeb01b 100644 --- a/src/game/player/animation.rs +++ b/src/game/player/animation.rs @@ -5,6 +5,31 @@ use bevy::utils::HashMap; use std::hash::Hash; +pub fn run_animations( + mut query: Query<(&Tag, &mut AnimationManager, &mut TextureAtlas)>, + time: Res