summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-06-16 12:38:05 -0500
committertom barrett <spalf0@gmail.com>2019-06-16 12:38:05 -0500
commit6162da14c62b1f2e23428dac40ad608bd9bb5e7d (patch)
tree3bb32148741333e9f1b1cb70866933f56489951d /src/main.rs
parent8bb97d08ce435b207419e8c3502ab1fb76a21d2f (diff)
parent02c34c4f2537386fb1087c1fb3528f96011a54e0 (diff)
Merge branch 'master' into feature/tiles
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 953d326..eaafa88 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,5 @@
use ggez::conf::Conf;
-use ggez::event::{self, EventHandler};
+use ggez::event::{self, EventHandler, KeyCode, KeyMods};
use ggez::filesystem;
use ggez::graphics::{self, spritebatch::SpriteBatch, DrawParam, FilterMode, Image};
use ggez::nalgebra::{Point2, Vector2};
@@ -12,6 +12,7 @@ struct State {
map: Map,
tileset: Tileset,
spritebatch: SpriteBatch,
+ camera_point: (f32, f32),
}
impl State {
@@ -23,12 +24,13 @@ impl State {
map: Map::new(filesystem::open(context, "/map.tmx")?),
tileset: Tileset::new(filesystem::open(context, "/tileset.tsx")?),
spritebatch: SpriteBatch::new(image),
+ camera_point: (0.0, 0.0),
})
}
}
impl EventHandler for State {
- fn update(&mut self, _context: &mut Context) -> GameResult {
+ fn update(&mut self, _: &mut Context) -> GameResult {
Ok(())
}
@@ -51,12 +53,25 @@ impl EventHandler for State {
}
}
- graphics::draw(context, &self.spritebatch, DrawParam::default())?;
+ let draw_param =
+ DrawParam::default().dest(Point2::new(self.camera_point.0, self.camera_point.1));
+
+ graphics::draw(context, &self.spritebatch, draw_param)?;
self.spritebatch.clear();
graphics::present(context)?;
Ok(())
}
+
+ fn key_down_event(&mut self, _: &mut Context, keycode: KeyCode, _: KeyMods, _: bool) {
+ match keycode {
+ KeyCode::W => self.camera_point.1 += constants::CAMERA_MOVE,
+ KeyCode::A => self.camera_point.0 += constants::CAMERA_MOVE,
+ KeyCode::S => self.camera_point.1 -= constants::CAMERA_MOVE,
+ KeyCode::D => self.camera_point.0 -= constants::CAMERA_MOVE,
+ _ => (),
+ }
+ }
}
fn main() -> GameResult {