12345678910111213141516171819202122232425262728 |
- use crate::components::{Movable, Position};
- use sdl2::keyboard as sdl;
- pub struct Move {
- pub keycode: sdl::Keycode,
- }
- impl<'a> specs::System<'a> for Move {
- type SystemData = (
- specs::ReadStorage<'a, Movable>,
- specs::WriteStorage<'a, Position>,
- );
- fn run(&mut self, (movable, mut position): Self::SystemData) {
- use specs::Join;
- for (_, pos) in (&movable, &mut position).join() {
- match self.keycode {
- sdl::Keycode::W => pos.y -= 1.0,
- sdl::Keycode::A => pos.x -= 1.0,
- sdl::Keycode::S => pos.y += 1.0,
- sdl::Keycode::D => pos.x += 1.0,
- _ => (),
- }
- }
- }
- }
|