summaryrefslogtreecommitdiff
path: root/src/state.rs
diff options
context:
space:
mode:
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,
_ => (),
}
}