123456789101112131415161718192021222324252627282930313233343536373839404142 |
- use crate::com::{Controlled, Velocity};
- use crate::game::MyGame;
- use crate::res::KeySet;
- use sdl2::keyboard as sdl;
- use specs::RunNow;
- pub struct Move;
- impl<'a> specs::System<'a> for Move {
- type SystemData = (
- specs::ReadStorage<'a, Controlled>,
- specs::WriteStorage<'a, Velocity>,
- specs::Read<'a, KeySet>,
- );
- fn run(&mut self, (movable, mut velocity, keys): Self::SystemData) {
- use specs::Join;
- for (_, vel) in (&movable, &mut velocity).join() {
- vel.dx = 0.0;
- vel.dy = 0.0;
- if keys.contains(&sdl::Keycode::W) {
- vel.dy -= 2.0;
- }
- if keys.contains(&sdl::Keycode::A) {
- vel.dx -= 2.0;
- }
- if keys.contains(&sdl::Keycode::S) {
- vel.dy += 2.0;
- }
- if keys.contains(&sdl::Keycode::D) {
- vel.dx += 2.0;
- }
- }
- }
- }
- pub fn systems(game: &mut MyGame) {
- Move.run_now(&game.world.res);
- }
|