diff options
author | tom barrett <spalf0@gmail.com> | 2019-06-19 07:49:33 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-06-19 07:49:33 -0500 |
commit | b4072b110df8886089d807bcd78891430ea7f974 (patch) | |
tree | 6ebd974fa52b308f21a0f3c95c74ff98290e7afb /src/state.rs | |
parent | 8693a266c2c9a8448b70d87d487ed211c439cbc4 (diff) |
can now move in angles
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 26 |
1 files changed, 17 insertions, 9 deletions
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) + } } |