mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-06 03:15:48 -06:00
chore: remove unused code, resolve simple stuff
This commit is contained in:
@@ -87,7 +87,7 @@ impl Ghost {
|
||||
GhostType::Inky => "inky",
|
||||
GhostType::Clyde => "clyde",
|
||||
};
|
||||
let get = |dir: &str, suffix: &str| get_atlas_tile(&atlas, &format!("ghost/{}/{}_{}.png", name, dir, suffix));
|
||||
let get = |dir: &str, suffix: &str| get_atlas_tile(&atlas, &format!("ghost/{name}/{dir}_{suffix}.png"));
|
||||
|
||||
let texture = DirectionalAnimatedTexture::new(
|
||||
vec![get("up", "a"), get("up", "b")],
|
||||
@@ -109,7 +109,7 @@ impl Ghost {
|
||||
15,
|
||||
);
|
||||
|
||||
let eyes_get = |dir: &str| get_atlas_tile(&atlas, &format!("ghost/eyes/{}.png", dir));
|
||||
let eyes_get = |dir: &str| get_atlas_tile(&atlas, &format!("ghost/eyes/{dir}.png"));
|
||||
|
||||
let eyes_texture = DirectionalAnimatedTexture::new(
|
||||
vec![eyes_get("up")],
|
||||
@@ -334,12 +334,12 @@ impl Renderable for Ghost {
|
||||
self.frightened_texture.render(canvas, dest)
|
||||
}
|
||||
GhostMode::Eyes => {
|
||||
let tile = self.eyes_texture.up.get(0).unwrap();
|
||||
let tile = self.eyes_texture.up.first().unwrap();
|
||||
let dest = sdl2::rect::Rect::new(pos.x - 4, pos.y - 4, tile.size.x as u32, tile.size.y as u32);
|
||||
self.eyes_texture.render(canvas, dest, dir)
|
||||
}
|
||||
_ => {
|
||||
let tile = self.texture.up.get(0).unwrap();
|
||||
let tile = self.texture.up.first().unwrap();
|
||||
let dest = sdl2::rect::Rect::new(pos.x - 4, pos.y - 4, tile.size.x as u32, tile.size.y as u32);
|
||||
self.texture.render(canvas, dest, dir)
|
||||
}
|
||||
|
||||
@@ -126,17 +126,15 @@ impl Entity for MovableEntity {
|
||||
|
||||
impl Moving for MovableEntity {
|
||||
fn tick_movement(&mut self) {
|
||||
if self.speed.next() {
|
||||
if !self.is_wall_ahead(None) {
|
||||
match self.direction {
|
||||
Direction::Right => self.base.pixel_position.x += 1,
|
||||
Direction::Left => self.base.pixel_position.x -= 1,
|
||||
Direction::Up => self.base.pixel_position.y -= 1,
|
||||
Direction::Down => self.base.pixel_position.y += 1,
|
||||
}
|
||||
if self.is_grid_aligned() {
|
||||
self.update_cell_position();
|
||||
}
|
||||
if self.speed.next() && !self.is_wall_ahead(None) {
|
||||
match self.direction {
|
||||
Direction::Right => self.base.pixel_position.x += 1,
|
||||
Direction::Left => self.base.pixel_position.x -= 1,
|
||||
Direction::Up => self.base.pixel_position.y -= 1,
|
||||
Direction::Down => self.base.pixel_position.y += 1,
|
||||
}
|
||||
if self.is_grid_aligned() {
|
||||
self.update_cell_position();
|
||||
}
|
||||
}
|
||||
if self.is_grid_aligned() {
|
||||
|
||||
@@ -105,7 +105,7 @@ impl Pacman {
|
||||
),
|
||||
death_animation: AnimatedTexture::new(
|
||||
(0..=10)
|
||||
.map(|i| get_atlas_tile(&atlas, &format!("pacman/death/{}.png", i)))
|
||||
.map(|i| get_atlas_tile(&atlas, &format!("pacman/death/{i}.png")))
|
||||
.collect(),
|
||||
5,
|
||||
),
|
||||
@@ -138,6 +138,6 @@ impl Renderable for Pacman {
|
||||
} else {
|
||||
self.texture.render(canvas, dest, dir)?;
|
||||
}
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ impl Game {
|
||||
/// Creates a new `Game` instance.
|
||||
pub fn new(
|
||||
texture_creator: &TextureCreator<WindowContext>,
|
||||
ttf_context: &sdl2::ttf::Sdl2TtfContext,
|
||||
_ttf_context: &sdl2::ttf::Sdl2TtfContext,
|
||||
_audio_subsystem: &sdl2::AudioSubsystem,
|
||||
) -> Game {
|
||||
let map = Rc::new(RefCell::new(Map::new(RAW_BOARD)));
|
||||
@@ -313,13 +313,11 @@ impl Game {
|
||||
canvas,
|
||||
&format!("{lives}UP HIGH SCORE "),
|
||||
UVec2::new(8 * lives_offset as u32 + x_offset, y_offset),
|
||||
Color::WHITE,
|
||||
);
|
||||
let _ = self.text_texture.render(
|
||||
canvas,
|
||||
&score_text,
|
||||
UVec2::new(8 * score_offset as u32 + x_offset, 8 + y_offset),
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
// Display FPS information in top-left corner
|
||||
|
||||
12
src/main.rs
12
src/main.rs
@@ -134,10 +134,10 @@ pub fn main() {
|
||||
|
||||
// Initial draw and tick
|
||||
if let Err(e) = game.draw(&mut canvas, &mut backbuffer) {
|
||||
eprintln!("Initial draw failed: {}", e);
|
||||
eprintln!("Initial draw failed: {e}");
|
||||
}
|
||||
if let Err(e) = game.present_backbuffer(&mut canvas, &backbuffer) {
|
||||
eprintln!("Initial present failed: {}", e);
|
||||
eprintln!("Initial present failed: {e}");
|
||||
}
|
||||
game.tick();
|
||||
|
||||
@@ -145,8 +145,6 @@ pub fn main() {
|
||||
let loop_time = Duration::from_secs(1) / 60;
|
||||
|
||||
let mut paused = false;
|
||||
// Whether the window is currently shown.
|
||||
let mut shown = false;
|
||||
|
||||
// FPS tracking
|
||||
let mut frame_times_1s = Vec::new();
|
||||
@@ -205,11 +203,9 @@ pub fn main() {
|
||||
Event::Window { win_event, .. } => match win_event {
|
||||
WindowEvent::Hidden => {
|
||||
event!(tracing::Level::DEBUG, "Window hidden");
|
||||
shown = false;
|
||||
}
|
||||
WindowEvent::Shown => {
|
||||
event!(tracing::Level::DEBUG, "Window shown");
|
||||
shown = true;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
@@ -241,10 +237,10 @@ pub fn main() {
|
||||
if !paused {
|
||||
game.tick();
|
||||
if let Err(e) = game.draw(&mut canvas, &mut backbuffer) {
|
||||
eprintln!("Failed to draw game: {}", e);
|
||||
eprintln!("Failed to draw game: {e}");
|
||||
}
|
||||
if let Err(e) = game.present_backbuffer(&mut canvas, &backbuffer) {
|
||||
eprintln!("Failed to present backbuffer: {}", e);
|
||||
eprintln!("Failed to present backbuffer: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,5 +10,5 @@ pub mod sprite;
|
||||
pub mod text;
|
||||
|
||||
pub fn get_atlas_tile(atlas: &Rc<RefCell<SpriteAtlas>>, name: &str) -> AtlasTile {
|
||||
SpriteAtlas::get_tile(atlas, name).unwrap_or_else(|| panic!("Could not find tile {}", name))
|
||||
SpriteAtlas::get_tile(atlas, name).unwrap_or_else(|| panic!("Could not find tile {name}"))
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
use anyhow::Result;
|
||||
use glam::UVec2;
|
||||
use sdl2::pixels::Color;
|
||||
|
||||
use sdl2::render::{Canvas, RenderTarget};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
@@ -89,9 +89,9 @@ impl TextTexture {
|
||||
fn char_to_tile_name(&self, c: char) -> Option<String> {
|
||||
let name = match c {
|
||||
// Letters A-Z
|
||||
'A'..='Z' => format!("text/{}.png", c),
|
||||
'A'..='Z' => format!("text/{c}.png"),
|
||||
// Numbers 0-9
|
||||
'0'..='9' => format!("text/{}.png", c),
|
||||
'0'..='9' => format!("text/{c}.png"),
|
||||
// Special characters
|
||||
'!' => "text/!.png".to_string(),
|
||||
'-' => "text/-.png".to_string(),
|
||||
@@ -108,7 +108,7 @@ impl TextTexture {
|
||||
}
|
||||
|
||||
/// Renders a string of text at the given position.
|
||||
pub fn render<C: RenderTarget>(&mut self, canvas: &mut Canvas<C>, text: &str, position: UVec2, color: Color) -> Result<()> {
|
||||
pub fn render<C: RenderTarget>(&mut self, canvas: &mut Canvas<C>, text: &str, position: UVec2) -> Result<()> {
|
||||
let mut x_offset = 0;
|
||||
let char_width = (8.0 * self.scale) as u32;
|
||||
let char_height = (8.0 * self.scale) as u32;
|
||||
|
||||
Reference in New Issue
Block a user