use std::{any::Any, hash::Hash, time::Duration}; use animation::{run_animations, AnimBundle, Animation}; use bevy::{ecs::system::SystemId, prelude::*, sprite::MaterialMesh2dBundle, utils::HashMap}; use bevy_rapier2d::prelude::*; use crate::{AppState, METER}; use super::{ scene::{PlayerCoords, WorldInfo}, set::IngameSet, PLAYER_DEPTH, }; mod animation; #[derive(Event)] enum PlayerDeathEvent { Void, Spikes, } #[derive(Event)] struct RespawnPointSetEvent; #[derive(Component)] struct Player { move_cooldown: Timer, } impl Default for Player { fn default() -> Self { Self { move_cooldown: Timer::from_seconds(0.01, TimerMode::Repeating), } } } #[derive(Resource)] pub struct PlayerSpawnOneshot(pub SystemId); impl FromWorld for PlayerSpawnOneshot { fn from_world(world: &mut World) -> Self { Self(world.register_system(add_player)) } } pub(super) fn player_plugin(app: &mut App) { app.add_systems( Update, ( move_player, debug_player_pos, run_animations::, ), ) .init_resource::(); } #[derive(Component, Hash, PartialEq, Eq, Default)] enum PlayerAnimations { #[default] Idle, Walk, } fn debug_player_pos(query: Query<&Transform, With>) { let trans = query.single(); } fn move_player( mut commands: Commands, kb_input: Res>, mut query: Query<( &mut Velocity, &mut Transform, &mut Player, &mut KinematicCharacterController, &mut Sprite, &mut PlayerAnimations, )>, mut camera_query: Query<&mut Transform, (With, Without)>, phys: Query<&KinematicCharacterControllerOutput>, player_coords: Res, world_info: Res, time: Res