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