summaryrefslogtreecommitdiff
path: root/src/state.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-06-18 11:19:49 -0500
committertom barrett <spalf0@gmail.com>2019-06-18 11:19:49 -0500
commit135bb9e7c37bbb226d3c676f2d87a67648bf35cb (patch)
treebebd562b897e1923668802bcad2eb322cf090ee5 /src/state.rs
parentc510d4a406218c38e1146503473e9e10c282a56d (diff)
got drawing of character
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs14
1 files changed, 9 insertions, 5 deletions
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,
_ => (),
}
}