drawable
This commit is contained in:
parent
08874882ec
commit
24492eb158
1 changed files with 8 additions and 1 deletions
|
@ -51,6 +51,12 @@ struct BouncingImage {
|
||||||
rate: u32,
|
rate: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait Drawable {
|
||||||
|
// Associated function signature; `Self` refers to the implementor type.
|
||||||
|
|
||||||
|
fn draw_and_move(&mut self, display: &mut Display);
|
||||||
|
|
||||||
|
}
|
||||||
impl BouncingImage {
|
impl BouncingImage {
|
||||||
/// Initializes a new 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 {
|
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
|
bb
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
impl Drawable for BouncingImage {
|
||||||
/// Draws the image and updates its position.
|
/// Draws the image and updates its position.
|
||||||
fn draw_and_move(&mut self, display: &mut Display) {
|
fn draw_and_move(&mut self, display: &mut Display) {
|
||||||
display.draw_png(&self.img, self.x, self.y);
|
display.draw_png(&self.img, self.x, self.y);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue