}
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<Window>, sprites: &mut SpriteManager);
+ fn render(&mut self, canvas: &mut Canvas<Window>, sprites: &SpriteManager);
fn handle_event(&mut self, event: Event);
}
}
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 {
}
}
- fn render(&mut self, canvas: &mut Canvas<Window>, sprites: &mut SpriteManager) {
+ fn render(&mut self, canvas: &mut Canvas<Window>, sprites: &SpriteManager) {
/* draw square of blocks */ {
let blocks = 20;
let size = 32;
}
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())));
}
self.world.update(dt);
}
- fn render(&mut self, canvas: &mut Canvas<Window>, sprites: &mut SpriteManager) {
+ fn render(&mut self, canvas: &mut Canvas<Window>, sprites: &SpriteManager) {
self.world.render(canvas, sprites);
}
}
}
- pub fn render(&mut self, canvas: &mut Canvas<Window>, sprites: &mut SpriteManager) {
+ pub fn render(&mut self, canvas: &mut Canvas<Window>, sprites: &SpriteManager) {
self.level.render(canvas, sprites);
for o in &mut self.objects {
o.render(canvas, sprites);
}
impl Level {
- pub fn render(&mut self, canvas: &mut Canvas<Window>, _sprites: &mut SpriteManager) {
+ pub fn render(&mut self, canvas: &mut Canvas<Window>, _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;
pub trait Object {
fn update(&mut self, objects: &mut Objects, lvl: &Level, dt: Duration) -> ObjectState;
- fn render(&self, _canvas: &mut Canvas<Window>, _sprites: &mut SpriteManager) {}
+ fn render(&self, _canvas: &mut Canvas<Window>, _sprites: &SpriteManager) {}
}
#[derive(PartialEq)]
Alive
}
- fn render(&self, canvas: &mut Canvas<Window>, sprites: &mut SpriteManager) {
+ fn render(&self, canvas: &mut Canvas<Window>, 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();
canvas.draw_line((p.0, p.1 - 5), (p.0, p.1 + 5)).unwrap();
}
+////////// BOLL ////////////////////////////////////////////////////////////////
+
pub struct Boll {
pos: Point2D<f64>,
vel: Point2D<f64>,
Alive
}
- fn render(&self, canvas: &mut Canvas<Window>, _sprites: &mut SpriteManager) {
+ fn render(&self, canvas: &mut Canvas<Window>, _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();