mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-10 20:07:53 -06:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 841943e121 |
@@ -18,7 +18,7 @@ pub struct AnimatedTexture<'a> {
|
|||||||
|
|
||||||
impl<'a> AnimatedTexture<'a> {
|
impl<'a> AnimatedTexture<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
texture:Texture<'a>,
|
texture: Texture<'a>,
|
||||||
ticks_per_frame: u32,
|
ticks_per_frame: u32,
|
||||||
frame_count: u32,
|
frame_count: u32,
|
||||||
frame_width: u32,
|
frame_width: u32,
|
||||||
@@ -49,7 +49,7 @@ impl<'a> AnimatedTexture<'a> {
|
|||||||
} else {
|
} else {
|
||||||
self.ticker += 1;
|
self.ticker += 1;
|
||||||
|
|
||||||
if self.ticker > self.ticks_per_frame * self.frame_count {
|
if self.ticker + 1 == self.ticks_per_frame * self.frame_count {
|
||||||
self.reversed = !self.reversed;
|
self.reversed = !self.reversed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,12 @@ impl<'a> AnimatedTexture<'a> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self, canvas: &mut Canvas<Window>, position: (i32, i32), direction: Direction) {
|
pub fn render(
|
||||||
|
&mut self,
|
||||||
|
canvas: &mut Canvas<Window>,
|
||||||
|
position: (i32, i32),
|
||||||
|
direction: Direction,
|
||||||
|
) {
|
||||||
let frame_rect = self.get_frame_rect();
|
let frame_rect = self.get_frame_rect();
|
||||||
let position_rect = Rect::new(position.0, position.1, self.frame_width, self.frame_height);
|
let position_rect = Rect::new(position.0, position.1, self.frame_width, self.frame_height);
|
||||||
|
|
||||||
@@ -76,9 +81,10 @@ impl<'a> AnimatedTexture<'a> {
|
|||||||
direction.angle(),
|
direction.angle(),
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
false
|
false,
|
||||||
).expect("Could not render texture on canvas");
|
)
|
||||||
|
.expect("Could not render texture on canvas");
|
||||||
|
|
||||||
self.next_frame();
|
self.next_frame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user