From b4072b110df8886089d807bcd78891430ea7f974 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Wed, 19 Jun 2019 07:49:33 -0500 Subject: can now move in angles --- src/state.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index d63a763..299ecc9 100644 --- a/src/state.rs +++ b/src/state.rs @@ -3,7 +3,6 @@ use ggez::graphics::{self, spritebatch::SpriteBatch, DrawParam, FilterMode, Imag use ggez::{filesystem, Context, GameResult}; use crate::camera::Camera; -use crate::constants; use crate::map::Map; use crate::player::Player; use crate::tileset::Tileset; @@ -36,6 +35,7 @@ impl State { impl EventHandler for State { fn update(&mut self, _: &mut Context) -> GameResult { + self.player.update(); self.camera.give_center(self.player.position); Ok(()) } @@ -59,14 +59,22 @@ impl EventHandler for State { Ok(()) } - fn key_down_event(&mut self, context: &mut Context, keycode: KeyCode, _: KeyMods, _: bool) { - match keycode { - KeyCode::W => self.player.position.y -= constants::PLAYER_SPEED, - KeyCode::A => self.player.position.x -= constants::PLAYER_SPEED, - KeyCode::S => self.player.position.y += constants::PLAYER_SPEED, - KeyCode::D => self.player.position.x += constants::PLAYER_SPEED, - KeyCode::Q => context.continuing = false, - _ => (), + fn key_down_event( + &mut self, + context: &mut Context, + keycode: KeyCode, + _: KeyMods, + repeat: bool, + ) { + if !repeat { + match keycode { + KeyCode::Q => context.continuing = false, + _ => self.player.give_key_down(keycode), + } } } + + fn key_up_event(&mut self, _: &mut Context, keycode: KeyCode, _: KeyMods) { + self.player.give_key_up(keycode) + } } -- cgit v1.2.3