Ver código fonte

Add physics

master
Noelle 4 anos atrás
pai
commit
2c872a1591
2 arquivos alterados com 31 adições e 0 exclusões
  1. 1
    0
      src/main.rs
  2. 30
    0
      src/physics.rs

+ 1
- 0
src/main.rs Ver arquivo

@@ -1,4 +1,5 @@
mod components;
mod physics;

use sdl2::pixels::Color;
use sdl2::event::Event;

+ 30
- 0
src/physics.rs Ver arquivo

@@ -0,0 +1,30 @@
use specs::prelude::*;

use crate::components::*;

struct Physics;

impl<'a> System<'a> for Physics {
type SystemData = (WriteStorage<'a, Position>, ReadStorage<'a, Velocity>);

fn run(&mut self, mut data: Self::SystemData) {
use self::Direction::*;

for (pos, vel) in (&mut data.0, &data.1).join() {
match vel.direction {
Left => {
pos.0 = pos.0.offset(-vel.speed, 0);
},
Right => {
pos.0 = pos.0.offset(vel.speed, 0);
},
Up => {
pos.0 = pos.0.offset(0, -vel.speed);
},
Down => {
pos.0 = pos.0.offset(0, vel.speed);
},
}
}
}
}

Carregando…
Cancelar
Salvar