more animatoin hell
This commit is contained in:
parent
ebff0ac8ac
commit
c897a77e8d
2 changed files with 26 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
use std::{hash::Hash, time::Duration};
|
use std::{hash::Hash, time::Duration};
|
||||||
|
|
||||||
|
use animation::AnimBundle;
|
||||||
use bevy::{prelude::*, sprite::MaterialMesh2dBundle, utils::HashMap};
|
use bevy::{prelude::*, sprite::MaterialMesh2dBundle, utils::HashMap};
|
||||||
|
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
|
@ -11,13 +12,13 @@ use super::set::IngameSet;
|
||||||
mod animation;
|
mod animation;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Player {}
|
struct Player;
|
||||||
|
|
||||||
pub(super) fn player_plugin(app: &mut App) {
|
pub(super) fn player_plugin(app: &mut App) {
|
||||||
app.add_systems(OnEnter(AppState::InGame), add_player.in_set(IngameSet));
|
app.add_systems(OnEnter(AppState::InGame), add_player.in_set(IngameSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Hash, PartialEq, Eq, Default)]
|
#[derive(Component, Hash, PartialEq, Eq, Default)]
|
||||||
enum PlayerAnimations {
|
enum PlayerAnimations {
|
||||||
#[default]
|
#[default]
|
||||||
Idle,
|
Idle,
|
||||||
|
@ -64,4 +65,16 @@ pub fn add_player(
|
||||||
tex_walk,
|
tex_walk,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
commands.spawn((
|
||||||
|
Player,
|
||||||
|
AnimBundle {
|
||||||
|
tag: PlayerAnimations::Idle,
|
||||||
|
mgr: anims,
|
||||||
|
},
|
||||||
|
SpriteBundle {
|
||||||
|
transform: Transform::from_scale(Vec3::splat(50.)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,19 @@ use bevy::utils::HashMap;
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Bundle)]
|
||||||
pub(crate) struct AnimationManager<Anim: Hash + Eq> {
|
pub struct AnimBundle<Tag: Hash + Eq + Component> {
|
||||||
animations: HashMap<Anim, Animation>,
|
pub tag: Tag,
|
||||||
|
pub mgr: AnimationManager<Tag>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Anim: Hash + Eq> AnimationManager<Anim> {
|
#[derive(Default, Component)]
|
||||||
pub fn insert(mut self, which: Anim, anim: Animation) -> Self {
|
pub(crate) struct AnimationManager<Tag: Hash + Eq> {
|
||||||
|
animations: HashMap<Tag, Animation>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Tag: Hash + Eq> AnimationManager<Tag> {
|
||||||
|
pub fn insert(mut self, which: Tag, anim: Animation) -> Self {
|
||||||
self.animations.insert(which, anim);
|
self.animations.insert(which, anim);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue