feat: separate player/ghost collider sizes, move fruit sprite up 1 pixel, add fruit TTL

This commit is contained in:
Ryan Walters
2025-09-11 14:45:10 -05:00
parent 273385dfe4
commit a887fae00f
6 changed files with 20 additions and 14 deletions

2
Cargo.lock generated
View File

@@ -711,7 +711,7 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]] [[package]]
name = "pacman" name = "pacman"
version = "0.80.2" version = "0.80.3"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bevy_ecs", "bevy_ecs",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "pacman" name = "pacman"
version = "0.80.2" version = "0.80.3"
authors = ["Xevion"] authors = ["Xevion"]
edition = "2021" edition = "2021"
rust-version = "1.86.0" rust-version = "1.86.0"

View File

@@ -53,9 +53,9 @@ pub mod animation {
/// Frightened ghost animation speed (ticks per frame at 60 ticks/sec) /// Frightened ghost animation speed (ticks per frame at 60 ticks/sec)
pub const GHOST_FRIGHTENED_SPEED: u16 = 12; pub const GHOST_FRIGHTENED_SPEED: u16 = 12;
/// Time in ticks for frightened ghosts to return to normal /// 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 /// 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. /// The size of the canvas, in pixels.
@@ -75,13 +75,15 @@ pub const LARGE_CANVAS_SIZE: UVec2 = UVec2::new(
pub mod collider { pub mod collider {
use super::CELL_SIZE; use super::CELL_SIZE;
/// Collider size for player and ghosts (1.375x cell size) /// Collider size for player and ghosts
pub const PLAYER_GHOST_SIZE: f32 = CELL_SIZE as f32 * 1.375; pub const PLAYER_SIZE: f32 = CELL_SIZE as f32 * 1.385;
/// Collider size for pellets (0.4x cell size) /// 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; 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; 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; 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 /// Game initialization constants
pub mod startup { pub mod startup {
/// Number of frames for the startup sequence (3 seconds at 60 FPS) /// 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 /// Game mechanics constants

View File

@@ -381,7 +381,7 @@ impl Game {
directional_animation: player_animation, directional_animation: player_animation,
entity_type: EntityType::Player, entity_type: EntityType::Player,
collider: Collider { collider: Collider {
size: constants::collider::PLAYER_GHOST_SIZE, size: constants::collider::PLAYER_SIZE,
}, },
pacman_collider: PacmanCollider, pacman_collider: PacmanCollider,
} }
@@ -629,7 +629,7 @@ impl Game {
directional_animation: animations, directional_animation: animations,
entity_type: EntityType::Ghost, entity_type: EntityType::Ghost,
collider: Collider { collider: Collider {
size: constants::collider::PLAYER_GHOST_SIZE, size: constants::collider::GHOST_SIZE,
}, },
ghost_collider: GhostCollider, ghost_collider: GhostCollider,
ghost_state: GhostState::Normal, ghost_state: GhostState::Normal,

View File

@@ -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 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 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) Vec2::new((x - CELL_SIZE) as f32, (y + CELL_SIZE) as f32)
} }

View File

@@ -3,12 +3,14 @@ use bevy_ecs::{
observer::Trigger, observer::Trigger,
system::{Commands, NonSendMut, Res}, system::{Commands, NonSendMut, Res},
}; };
use rand::Rng;
use strum_macros::IntoStaticStr; use strum_macros::IntoStaticStr;
use tracing::debug; use tracing::debug;
use crate::{ use crate::{
constants, constants,
map::builder::Map, map::builder::Map,
platform::rng,
systems::{common::bundles::ItemBundle, Collider, Position, Renderable, TimeToLive}, systems::{common::bundles::ItemBundle, Collider, Position, Renderable, TimeToLive},
texture::{ texture::{
sprite::SpriteAtlas, sprite::SpriteAtlas,
@@ -112,7 +114,9 @@ pub fn spawn_fruit_observer(
item_collider: ItemCollider, 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 } => { SpawnTrigger::Bonus { position, value, ttl } => {
let sprite = &atlas let sprite = &atlas