From a82a4d23f7e76f6899919fda31e7c29e68d319bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Sun, 17 Jan 2021 16:16:06 +0100 Subject: [PATCH] No need for mutable references --- src/core/app.rs | 8 ++++---- src/core/game.rs | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/core/app.rs b/src/core/app.rs index be546c1..cac2a37 100644 --- a/src/core/app.rs +++ b/src/core/app.rs @@ -246,10 +246,10 @@ impl App { } pub trait AppState { - fn enter(&mut self, ctrl_man: &mut ControllerManager); + fn enter(&mut self, ctrl_man: &ControllerManager); fn leave(&mut self); fn update(&mut self, dt: Duration); - fn render(&mut self, canvas: &mut Canvas, sprites: &mut SpriteManager); + fn render(&mut self, canvas: &mut Canvas, sprites: &SpriteManager); fn handle_event(&mut self, event: Event); } @@ -299,7 +299,7 @@ impl ActiveState { } impl AppState for ActiveState { - fn enter(&mut self, _ctrl_man: &mut ControllerManager) {} + fn enter(&mut self, _ctrl_man: &ControllerManager) {} fn update(&mut self, dt: Duration) { for b in &mut self.bolls { @@ -313,7 +313,7 @@ impl AppState for ActiveState { } } - fn render(&mut self, canvas: &mut Canvas, sprites: &mut SpriteManager) { + fn render(&mut self, canvas: &mut Canvas, sprites: &SpriteManager) { /* draw square of blocks */ { let blocks = 20; let size = 32; diff --git a/src/core/game.rs b/src/core/game.rs index 80e1e36..e335798 100644 --- a/src/core/game.rs +++ b/src/core/game.rs @@ -28,7 +28,7 @@ impl GameState { } impl AppState for GameState { - fn enter(&mut self, ctrl_man: &mut ControllerManager) { + fn enter(&mut self, ctrl_man: &ControllerManager) { if let Some(ctrl) = ctrl_man.controllers.get(&0) { self.world.add(Box::new(Character::new(ctrl.clone()))); } @@ -40,7 +40,7 @@ impl AppState for GameState { self.world.update(dt); } - fn render(&mut self, canvas: &mut Canvas, sprites: &mut SpriteManager) { + fn render(&mut self, canvas: &mut Canvas, sprites: &SpriteManager) { self.world.render(canvas, sprites); } @@ -80,7 +80,7 @@ impl World { } } - pub fn render(&mut self, canvas: &mut Canvas, sprites: &mut SpriteManager) { + pub fn render(&mut self, canvas: &mut Canvas, sprites: &SpriteManager) { self.level.render(canvas, sprites); for o in &mut self.objects { o.render(canvas, sprites); @@ -101,7 +101,7 @@ pub struct Level { } impl Level { - pub fn render(&mut self, canvas: &mut Canvas, _sprites: &mut SpriteManager) { + pub fn render(&mut self, canvas: &mut Canvas, _sprites: &SpriteManager) { let w = canvas.viewport().width() as i32; for i in 1..11 { let y = (i * i - 1) as i32 + self.ground as i32; @@ -117,7 +117,7 @@ type Objects = Vec>; pub trait Object { fn update(&mut self, objects: &mut Objects, lvl: &Level, dt: Duration) -> ObjectState; - fn render(&self, _canvas: &mut Canvas, _sprites: &mut SpriteManager) {} + fn render(&self, _canvas: &mut Canvas, _sprites: &SpriteManager) {} } #[derive(PartialEq)] @@ -185,7 +185,7 @@ impl Object for Character { Alive } - fn render(&self, canvas: &mut Canvas, sprites: &mut SpriteManager) { + fn render(&self, canvas: &mut Canvas, sprites: &SpriteManager) { let block = sprites.get("mario"); let size = 32; canvas.copy(block, None, Rect::new(self.pos.x as i32 - size as i32 / 2, self.pos.y as i32 - size as i32, size, size)).unwrap(); @@ -216,6 +216,8 @@ fn draw_cross(canvas: &mut Canvas, p: (i32, i32)) { canvas.draw_line((p.0, p.1 - 5), (p.0, p.1 + 5)).unwrap(); } +////////// BOLL //////////////////////////////////////////////////////////////// + pub struct Boll { pos: Point2D, vel: Point2D, @@ -240,7 +242,7 @@ impl Object for Boll { Alive } - fn render(&self, canvas: &mut Canvas, _sprites: &mut SpriteManager) { + fn render(&self, canvas: &mut Canvas, _sprites: &SpriteManager) { let block = _sprites.get("block"); let size = 4 + self.bounces * 6; canvas.copy(block, None, Rect::new(self.pos.x as i32 - size as i32 / 2, self.pos.y as i32 - size as i32 / 2, size as u32, size as u32)).unwrap(); -- 2.11.0