feat: sprite frame pinning, conditional on stopped PacMan

This commit is contained in:
2023-09-11 02:40:47 -05:00
parent c71b6d69ab
commit e69f5b8378
2 changed files with 22 additions and 0 deletions

View File

@@ -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>,

View File

@@ -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);
}