summaryrefslogtreecommitdiff
path: root/src/entity.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-07-02 04:23:33 -0500
committertom barrett <spalf0@gmail.com>2019-07-02 04:23:33 -0500
commit6bf9e96140c91340d6ae643b6e0896aa734d8605 (patch)
treeea5fba741326bd952b7808d402c4bbaf572d170d /src/entity.rs
parent1b5f06e902b9e5c5b0d5897fc981eeaa6dc39b37 (diff)
entities now spawn on points
Diffstat (limited to 'src/entity.rs')
-rw-r--r--src/entity.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/entity.rs b/src/entity.rs
new file mode 100644
index 0000000..bd29a84
--- /dev/null
+++ b/src/entity.rs
@@ -0,0 +1,45 @@
+use ggez::graphics::{spritebatch::SpriteBatch, DrawParam, Rect};
+use ggez::nalgebra::{Point2, Vector2};
+
+use crate::constants;
+use crate::map::Map;
+use crate::tileset::Tileset;
+
+#[derive(Clone)]
+pub struct Entity {
+ position: Point2<f32>,
+ source: Rect,
+ spawn: Point2<f32>,
+}
+
+impl Entity {
+ pub fn new(tileset: &Tileset, spawn: Point2<f32>) -> Entity {
+ let mut source = tileset.get_tile_by_entity_keyframe("player-top", 0);
+ source.h += tileset.get_tile_by_entity_keyframe("player-bottom", 0).h;
+
+ Entity {
+ position: spawn,
+ source,
+ spawn,
+ }
+ }
+
+ pub fn draw(&self, spritebatch: &mut SpriteBatch) {
+ let draw_param = DrawParam::default()
+ .src(self.source)
+ .dest(self.position)
+ .scale(Vector2::new(constants::TILE_SCALE, constants::TILE_SCALE));
+
+ spritebatch.add(draw_param);
+ }
+
+ pub fn build_entities(tileset: &Tileset, map: &Map) -> Vec<Entity> {
+ let mut entities = Vec::new();
+
+ for (_name, position) in map.get_spawns() {
+ entities.push(Entity::new(tileset, position));
+ }
+
+ entities
+ }
+}