summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-06-16 12:26:06 -0500
committertom barrett <spalf0@gmail.com>2019-06-16 12:26:06 -0500
commit02c34c4f2537386fb1087c1fb3528f96011a54e0 (patch)
treeca64b493288c889d6845210ac761f89afbad41c0 /src/main.rs
parent49b07a29ab42b2d550becfd0de8da4231341b706 (diff)
movement of camera
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 {