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 | |
|---|---|---|---|
| bf8370ef35 |
@@ -83,7 +83,24 @@ impl<'a> AnimatedTexture<'a> {
|
||||
self.render_static(canvas, position, direction, Some(self.current_frame()));
|
||||
self.tick();
|
||||
}
|
||||
|
||||
// Functions like render, but only ticks the animation until the given frame is reached.
|
||||
pub fn render_until(
|
||||
&mut self,
|
||||
canvas: &mut Canvas<Window>,
|
||||
position: (i32, i32),
|
||||
direction: Direction,
|
||||
frame: u32,
|
||||
) {
|
||||
let current = self.current_frame();
|
||||
self.render_static(canvas, position, direction, Some(current));
|
||||
|
||||
if frame != current {
|
||||
self.tick();
|
||||
}
|
||||
}
|
||||
|
||||
// Renders a specific frame of the animation. Defaults to the current frame.
|
||||
pub fn render_static(
|
||||
&mut self,
|
||||
canvas: &mut Canvas<Window>,
|
||||
|
||||
@@ -34,6 +34,11 @@ impl Pacman<'_> {
|
||||
}
|
||||
|
||||
pub fn render(&mut self, canvas: &mut Canvas<Window>) {
|
||||
// When stopped, render the last frame of the animation
|
||||
if self.stopped {
|
||||
self.sprite
|
||||
.render_until(canvas, self.position, self.direction, 2);
|
||||
} else {
|
||||
self.sprite.render(canvas, self.position, self.direction);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user