feat: ghosts system

This commit is contained in:
2025-08-15 20:38:18 -05:00
parent e0a15c1ca8
commit 3d0bc66e40
5 changed files with 271 additions and 3 deletions

View File

@@ -11,6 +11,65 @@ use crate::{
#[derive(Default, Component)]
pub struct PlayerControlled;
/// The four classic ghost types.
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq)]
pub enum GhostType {
Blinky,
Pinky,
Inky,
Clyde,
}
impl GhostType {
/// Returns the ghost type name for atlas lookups.
pub fn as_str(self) -> &'static str {
match self {
GhostType::Blinky => "blinky",
GhostType::Pinky => "pinky",
GhostType::Inky => "inky",
GhostType::Clyde => "clyde",
}
}
/// Returns the base movement speed for this ghost type.
pub fn base_speed(self) -> f32 {
match self {
GhostType::Blinky => 1.0,
GhostType::Pinky => 0.95,
GhostType::Inky => 0.9,
GhostType::Clyde => 0.85,
}
}
/// Returns the ghost's color for debug rendering.
pub fn debug_color(&self) -> sdl2::pixels::Color {
match self {
GhostType::Blinky => sdl2::pixels::Color::RGB(255, 0, 0), // Red
GhostType::Pinky => sdl2::pixels::Color::RGB(255, 182, 255), // Pink
GhostType::Inky => sdl2::pixels::Color::RGB(0, 255, 255), // Cyan
GhostType::Clyde => sdl2::pixels::Color::RGB(255, 182, 85), // Orange
}
}
}
/// Ghost AI behavior component - controls randomized movement decisions.
#[derive(Component)]
pub struct GhostBehavior {
/// Timer for making new direction decisions
pub decision_timer: f32,
/// Interval between direction decisions (in seconds)
pub decision_interval: f32,
}
impl Default for GhostBehavior {
fn default() -> Self {
Self {
decision_timer: 0.0,
decision_interval: 0.5, // Make decisions every half second
}
}
}
/// A tag component denoting the type of entity.
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EntityType {
@@ -94,6 +153,20 @@ pub struct ItemBundle {
pub item_collider: ItemCollider,
}
#[derive(Bundle)]
pub struct GhostBundle {
pub ghost_type: GhostType,
pub ghost_behavior: GhostBehavior,
pub position: Position,
pub movement_state: MovementState,
pub movable: Movable,
pub sprite: Renderable,
pub directional_animated: DirectionalAnimated,
pub entity_type: EntityType,
pub collider: Collider,
pub ghost_collider: GhostCollider,
}
#[derive(Resource)]
pub struct GlobalState {
pub exit: bool,