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]]
name = "pacman"
version = "0.80.2"
version = "0.80.3"
dependencies = [
"anyhow",
"bevy_ecs",

View File

@@ -1,6 +1,6 @@
[package]
name = "pacman"
version = "0.80.2"
version = "0.80.3"
authors = ["Xevion"]
edition = "2021"
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)
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

View File

@@ -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,

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 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)
}

View File

@@ -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