This commit is contained in:
0m.ax 2025-07-18 23:48:41 +02:00
parent 08874882ec
commit 24492eb158

View file

@ -51,6 +51,12 @@ struct BouncingImage {
rate: u32,
}
trait Drawable {
// Associated function signature; `Self` refers to the implementor type.
fn draw_and_move(&mut self, display: &mut Display);
}
impl BouncingImage {
/// Initializes a new BouncingImage.
fn new(img_file: &str, move_x: i32, move_y: i32, rate: u32, start_x: i32, start_y: i32) -> Self {
@ -75,7 +81,8 @@ impl BouncingImage {
}
bb
}
}
impl Drawable for BouncingImage {
/// Draws the image and updates its position.
fn draw_and_move(&mut self, display: &mut Display) {
display.draw_png(&self.img, self.x, self.y);