From 135bb9e7c37bbb226d3c676f2d87a67648bf35cb Mon Sep 17 00:00:00 2001 From: tom barrett Date: Tue, 18 Jun 2019 11:19:49 -0500 Subject: got drawing of character --- src/state.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index b659880..f335f49 100644 --- a/src/state.rs +++ b/src/state.rs @@ -25,7 +25,7 @@ impl State { map: Map::new(filesystem::open(context, "/map.tmx")?), tileset: Tileset::new(filesystem::open(context, "/tileset.tsx")?), spritebatch: SpriteBatch::new(image), - camera: Camera::default(), + camera: Camera::new(context), player_position: Point2::new(0.0, 0.0), }) } @@ -48,25 +48,29 @@ impl EventHandler for State { DrawParam::default().dest(self.camera.draw), )?; + self.spritebatch.clear(); + graphics::draw( context, &Text::new("@"), - DrawParam::default().dest(self.player_position), + DrawParam::default().dest(Point2::new( + self.player_position.x + self.camera.draw.x, + self.player_position.y + self.camera.draw.y, + )), )?; - self.spritebatch.clear(); - graphics::present(context)?; Ok(()) } - fn key_down_event(&mut self, _: &mut Context, keycode: KeyCode, _: KeyMods, _: bool) { + 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, _ => (), } } -- cgit v1.2.3