From a887fae00f034889766fbddc27ae7c1d828a940b Mon Sep 17 00:00:00 2001 From: Ryan Walters Date: Thu, 11 Sep 2025 14:45:10 -0500 Subject: [PATCH] feat: separate player/ghost collider sizes, move fruit sprite up 1 pixel, add fruit TTL --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/constants.rs | 18 ++++++++++-------- src/game.rs | 4 ++-- src/systems/hud/fruits.rs | 2 +- src/systems/item.rs | 6 +++++- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6eb0b4..e76374f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -711,7 +711,7 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "pacman" -version = "0.80.2" +version = "0.80.3" dependencies = [ "anyhow", "bevy_ecs", diff --git a/Cargo.toml b/Cargo.toml index 563463f..1dc57da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pacman" -version = "0.80.2" +version = "0.80.3" authors = ["Xevion"] edition = "2021" rust-version = "1.86.0" diff --git a/src/constants.rs b/src/constants.rs index c5c232d..af4cb4b 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -53,9 +53,9 @@ pub mod animation { /// Frightened ghost animation speed (ticks per frame at 60 ticks/sec) pub const GHOST_FRIGHTENED_SPEED: u16 = 12; /// Time in ticks for frightened ghosts to return to normal - pub const GHOST_FRIGHTENED_TICKS: u32 = 300; + pub const GHOST_FRIGHTENED_TICKS: u32 = 5 * 60; /// Time in ticks when frightened ghosts start flashing - pub const GHOST_FRIGHTENED_FLASH_START_TICKS: u32 = GHOST_FRIGHTENED_TICKS - 120; + pub const GHOST_FRIGHTENED_FLASH_START_TICKS: u32 = GHOST_FRIGHTENED_TICKS - 2 * 60; } /// The size of the canvas, in pixels. @@ -75,13 +75,15 @@ pub const LARGE_CANVAS_SIZE: UVec2 = UVec2::new( pub mod collider { use super::CELL_SIZE; - /// Collider size for player and ghosts (1.375x cell size) - pub const PLAYER_GHOST_SIZE: f32 = CELL_SIZE as f32 * 1.375; - /// Collider size for pellets (0.4x cell size) + /// Collider size for player and ghosts + pub const PLAYER_SIZE: f32 = CELL_SIZE as f32 * 1.385; + /// Collider size for ghosts + pub const GHOST_SIZE: f32 = CELL_SIZE as f32 * 1.55; + /// Collider size for pellets pub const PELLET_SIZE: f32 = CELL_SIZE as f32 * 0.4; - /// Collider size for power pellets/energizers (0.95x cell size) + /// Collider size for power pellets/energizers pub const POWER_PELLET_SIZE: f32 = CELL_SIZE as f32 * 0.95; - /// Collider size for fruits (0.8x cell size) + /// Collider size for fruits pub const FRUIT_SIZE: f32 = CELL_SIZE as f32 * 1.375; } @@ -148,7 +150,7 @@ pub const RAW_BOARD: [&str; BOARD_CELL_SIZE.y as usize] = [ /// Game initialization constants pub mod startup { /// Number of frames for the startup sequence (3 seconds at 60 FPS) - pub const STARTUP_FRAMES: u32 = 60 * 3; + pub const STARTUP_FRAMES: u32 = 60 * 4; } /// Game mechanics constants diff --git a/src/game.rs b/src/game.rs index 445a0eb..73f0ed1 100644 --- a/src/game.rs +++ b/src/game.rs @@ -381,7 +381,7 @@ impl Game { directional_animation: player_animation, entity_type: EntityType::Player, collider: Collider { - size: constants::collider::PLAYER_GHOST_SIZE, + size: constants::collider::PLAYER_SIZE, }, pacman_collider: PacmanCollider, } @@ -629,7 +629,7 @@ impl Game { directional_animation: animations, entity_type: EntityType::Ghost, collider: Collider { - size: constants::collider::PLAYER_GHOST_SIZE, + size: constants::collider::GHOST_SIZE, }, ghost_collider: GhostCollider, ghost_state: GhostState::Normal, diff --git a/src/systems/hud/fruits.rs b/src/systems/hud/fruits.rs index 59e3716..97d6915 100644 --- a/src/systems/hud/fruits.rs +++ b/src/systems/hud/fruits.rs @@ -27,7 +27,7 @@ fn calculate_fruit_sprite_position(index: u32) -> Vec2 { let sprite_spacing = CELL_SIZE + CELL_SIZE / 2; // 1.5 cells between sprites let x = start_x - ((index as f32) * (sprite_spacing as f32 * 1.5)).round() as u32; - let y = start_y - CELL_SIZE / 2; + let y = start_y - (1 + CELL_SIZE / 2); Vec2::new((x - CELL_SIZE) as f32, (y + CELL_SIZE) as f32) } diff --git a/src/systems/item.rs b/src/systems/item.rs index 6fc1ec4..1bdf8d8 100644 --- a/src/systems/item.rs +++ b/src/systems/item.rs @@ -3,12 +3,14 @@ use bevy_ecs::{ observer::Trigger, system::{Commands, NonSendMut, Res}, }; +use rand::Rng; use strum_macros::IntoStaticStr; use tracing::debug; use crate::{ constants, map::builder::Map, + platform::rng, systems::{common::bundles::ItemBundle, Collider, Position, Renderable, TimeToLive}, texture::{ sprite::SpriteAtlas, @@ -112,7 +114,9 @@ pub fn spawn_fruit_observer( item_collider: ItemCollider, }; - commands.spawn(bundle) + let lifetime_ticks = (rng().random_range(9f32..10f32) * 60f32).round() as u32; + + commands.spawn((bundle, TimeToLive::new(lifetime_ticks))) } SpawnTrigger::Bonus { position, value, ttl } => { let sprite = &atlas