mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-06 15:15:48 -06:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c90f221c73 |
@@ -1,11 +1,15 @@
|
|||||||
use sdl2::{render::{Canvas, Texture}, video::Window};
|
use sdl2::{
|
||||||
|
render::{Canvas, Texture},
|
||||||
|
video::Window,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{direction::Direction, entity::Entity, animation::AnimatedTexture};
|
use crate::{animation::AnimatedTexture, direction::Direction, entity::Entity};
|
||||||
|
|
||||||
pub struct Pacman<'a> {
|
pub struct Pacman<'a> {
|
||||||
// Absolute position on the board (precise)
|
// Absolute position on the board (precise)
|
||||||
pub position: (i32, i32),
|
pub position: (i32, i32),
|
||||||
pub direction: Direction,
|
pub direction: Direction,
|
||||||
|
speed: u32,
|
||||||
sprite: AnimatedTexture<'a>,
|
sprite: AnimatedTexture<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,6 +18,7 @@ impl Pacman<'_> {
|
|||||||
Pacman {
|
Pacman {
|
||||||
position: starting_position.unwrap_or((0i32, 0i32)),
|
position: starting_position.unwrap_or((0i32, 0i32)),
|
||||||
direction: Direction::Right,
|
direction: Direction::Right,
|
||||||
|
speed: 2,
|
||||||
sprite: AnimatedTexture::new(atlas, 4, 3, 32, 32),
|
sprite: AnimatedTexture::new(atlas, 4, 3, 32, 32),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,18 +45,19 @@ impl Entity for Pacman<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tick(&mut self) {
|
fn tick(&mut self) {
|
||||||
|
let speed = self.speed as i32;
|
||||||
match self.direction {
|
match self.direction {
|
||||||
Direction::Right => {
|
Direction::Right => {
|
||||||
self.position.0 += 1;
|
self.position.0 += speed;
|
||||||
}
|
}
|
||||||
Direction::Left => {
|
Direction::Left => {
|
||||||
self.position.0 -= 1;
|
self.position.0 -= speed;
|
||||||
}
|
}
|
||||||
Direction::Up => {
|
Direction::Up => {
|
||||||
self.position.1 -= 1;
|
self.position.1 -= speed;
|
||||||
}
|
}
|
||||||
Direction::Down => {
|
Direction::Down => {
|
||||||
self.position.1 += 1;
|
self.position.1 += speed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user