use std::{collections::HashMap, error::Error, fmt::Debug, hash::Hash, marker::PhantomData}; use bevy::prelude::*; use bevy_input_actionmap::InputMap; use bevy_rapier2d::{na::UnitComplex, prelude::*}; use bevy_tts::Tts; use derive_more::{Deref, DerefMut}; use crate::{ core::{Angle, CardinalDirection, Player, PointLike}, error::error_handler, exploration::{ExplorationFocused, Exploring}, map::{ITileType, Map}, pathfinding::Destination, }; #[derive(Clone, Copy, Debug, Deref, DerefMut, Reflect)] #[reflect(Component)] pub struct MaxSpeed(pub f32); impl Default for MaxSpeed { fn default() -> Self { MaxSpeed(2.) } } #[derive(Clone, Copy, Debug, Deref, DerefMut, Reflect)] #[reflect(Component)] pub struct RotationSpeed(pub Angle); impl Default for RotationSpeed { fn default() -> Self { Self(Angle::Radians(0.)) } } #[derive(Clone, Copy, Debug, Default, Deref, DerefMut, Reflect)] #[reflect(Component)] pub struct Speed(pub f32); #[derive(Clone, Copy, Debug, Default, Reflect)] #[reflect(Component)] pub struct Sprinting; fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added>) { for (map_entity, map) in maps.iter() { let rigid_body_entity = commands .entity(map_entity) .insert_bundle(RigidBodyBundle { body_type: RigidBodyType::Static, ..Default::default() }) .id(); for x in 0..map.width() { for y in 0..map.height() { let tile = map.base.at(x, y); if tile.blocks_motion() { let collider = ColliderBundle { shape: ColliderShape::cuboid(0.5, 0.5), ..Default::default() }; let collider_parent = ColliderParent { handle: rigid_body_entity.handle(), pos_wrt_parent: Vec2::new(x as f32 + 0.5, y as f32 + 0.5).into(), }; commands .spawn() .insert_bundle(collider) .insert(collider_parent); } } } } } fn movement_controls( mut commands: Commands, config: Res>, input: Res>, time: Res