summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--resources/map.tmx2
-rw-r--r--resources/tileset.pngbin10036 -> 10257 bytes
-rw-r--r--resources/tileset.tsx6
-rw-r--r--src/animations.rs18
-rw-r--r--src/constants.rs2
-rw-r--r--src/map.rs13
-rw-r--r--src/npc.rs4
-rw-r--r--src/player.rs4
-rw-r--r--src/state.rs9
-rw-r--r--src/tileset.rs20
10 files changed, 53 insertions, 25 deletions
diff --git a/resources/map.tmx b/resources/map.tmx
index de8221e..7845c4d 100644
--- a/resources/map.tmx
+++ b/resources/map.tmx
@@ -87,7 +87,7 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
diff --git a/resources/tileset.png b/resources/tileset.png
index 8a32cbf..7051fff 100644
--- a/resources/tileset.png
+++ b/resources/tileset.png
Binary files differ
diff --git a/resources/tileset.tsx b/resources/tileset.tsx
index d5a44dd..44b6778 100644
--- a/resources/tileset.tsx
+++ b/resources/tileset.tsx
@@ -8,6 +8,12 @@
<property name="keyframe" type="int" value="0"/>
</properties>
</tile>
+ <tile id="15">
+ <properties>
+ <property name="spawn" value="player"/>
+ <property name="visible" type="bool" value="false"/>
+ </properties>
+ </tile>
<tile id="24">
<properties>
<property name="delay" type="int" value="100"/>
diff --git a/src/animations.rs b/src/animations.rs
index 43f4326..58b6bf2 100644
--- a/src/animations.rs
+++ b/src/animations.rs
@@ -43,14 +43,16 @@ impl Animation {
}
pub fn draw(&self, spritebatch: &mut SpriteBatch, position: Point2<f32>) {
- spritebatch.add(
- DrawParam::default()
- .src(self.current.source)
- .rotation(self.current.properties.rotation)
- .offset(Point2::new(0.5, 0.5))
- .dest(position)
- .scale(Vector2::new(constants::TILE_SCALE, constants::TILE_SCALE)),
- );
+ if self.current.properties.visible.is_none() {
+ spritebatch.add(
+ DrawParam::default()
+ .src(self.current.source)
+ .rotation(self.current.properties.rotation)
+ .offset(Point2::new(0.5, 0.5))
+ .dest(position)
+ .scale(Vector2::new(constants::TILE_SCALE, constants::TILE_SCALE)),
+ );
+ }
}
}
diff --git a/src/constants.rs b/src/constants.rs
index a1dd0eb..35ddda7 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -7,6 +7,8 @@ pub const ENTITY_SPEED: f32 = 2.5;
pub const WANDER_DISTANCE: f32 = 150.0;
pub const GOAL_DISTANCE: f32 = 6.0;
+pub const FLOAT_PRECISION: f32 = 0.001;
+
pub const FLIP_H: usize = 0x8000_0000;
pub const FLIP_V: usize = 0x4000_0000;
pub const FLIP_D: usize = 0x2000_0000;
diff --git a/src/map.rs b/src/map.rs
index 8ef6f4e..124125a 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -61,7 +61,7 @@ impl Map {
})
.collect();
- let spawns = Map::get_spawn_points(&layers, tileset.get_spawn_tiles());
+ let spawns = Map::find_spawn_points(&layers, tileset.get_spawn_tiles());
Map {
layers,
@@ -70,7 +70,7 @@ impl Map {
}
}
- fn get_spawn_points(
+ fn find_spawn_points(
layers: &[Layer],
spawn_tiles: HashMap<usize, Tile>,
) -> Vec<(String, Point2<f32>)> {
@@ -90,8 +90,13 @@ impl Map {
spawn_points
}
- pub fn get_spawns(&self) -> Vec<(String, Point2<f32>)> {
- self.spawns.clone()
+ pub fn get_spawn_points(&self, name: &str) -> Vec<Point2<f32>> {
+ self.spawns
+ .clone()
+ .into_iter()
+ .filter(|s| s.0 == name)
+ .map(|s| s.1)
+ .collect()
}
pub fn get_dimensions(&self) -> (f32, f32) {
diff --git a/src/npc.rs b/src/npc.rs
index c31f305..316908b 100644
--- a/src/npc.rs
+++ b/src/npc.rs
@@ -72,8 +72,8 @@ impl NPC {
pub fn build_npcs(tileset: &Tileset, map: &Map) -> Vec<NPC> {
let mut npcs = Vec::new();
- for (_name, position) in map.get_spawns() {
- npcs.push(NPC::new(tileset, position, map.get_dimensions()));
+ for point in map.get_spawn_points("peasant") {
+ npcs.push(NPC::new(tileset, point, map.get_dimensions()));
}
npcs
diff --git a/src/player.rs b/src/player.rs
index 5993d21..025056c 100644
--- a/src/player.rs
+++ b/src/player.rs
@@ -23,9 +23,9 @@ impl Operable for Player {
}
impl Player {
- pub fn new(tileset: &Tileset, dimensions: (f32, f32)) -> Player {
+ pub fn new(tileset: &Tileset, spawn: Point2<f32>, map_dimensions: (f32, f32)) -> Player {
Player {
- entity: Entity::new(Point2::new(0.0, 0.0), dimensions),
+ entity: Entity::new(spawn, map_dimensions),
animations: Animations::new(tileset),
}
}
diff --git a/src/state.rs b/src/state.rs
index db72d10..98ad422 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -26,13 +26,16 @@ impl State {
let tileset = Tileset::new(filesystem::open(context, "/tileset.tsx")?);
let map = Map::new(filesystem::open(context, "/map.tmx")?, &tileset);
- let map_dimensions = map.get_dimensions();
Ok(State {
map: map.clone(),
spritebatch: SpriteBatch::new(image),
- camera: Camera::new(context, map_dimensions),
- player: Player::new(&tileset, map_dimensions),
+ camera: Camera::new(context, map.get_dimensions()),
+ player: Player::new(
+ &tileset,
+ map.get_spawn_points("player")[0],
+ map.get_dimensions(),
+ ),
npcs: NPC::build_npcs(&tileset, &map),
})
}
diff --git a/src/tileset.rs b/src/tileset.rs
index 6a7ca42..effba3b 100644
--- a/src/tileset.rs
+++ b/src/tileset.rs
@@ -65,8 +65,8 @@ impl Tileset {
for i in 1..8 {
let (new_id, new_tile) = match i {
1 => ((id | FLIP_H), flip(tile.clone())),
- 2 => ((id | FLIP_V), tile.clone()),
- 3 => ((id | FLIP_D), tile.clone()),
+ //2 => ((id | FLIP_V), tile.clone()),
+ //3 => ((id | FLIP_D), tile.clone()),
4 => ((id | FLIP_D | FLIP_H), rotate(tile.clone(), 90.0)),
5 => ((id | FLIP_D | FLIP_V), rotate(tile.clone(), 270.0)),
6 => ((id | FLIP_H | FLIP_V), rotate(tile.clone(), 180.0)),
@@ -95,7 +95,9 @@ impl Tileset {
let first_tile = self
.tiles
.iter()
- .find(|(id, _)| id == &&tile_id)
+ .find(
+ |(id, _)| id == &&tile_id
+ )
.unwrap()
.1
.clone();
@@ -105,8 +107,13 @@ impl Tileset {
self.tiles
.values()
.cloned()
- .filter(|t| t.properties.entity == first_tile.properties.entity)
- .collect(),
+ .filter(|t| {
+ t.properties.entity == first_tile.properties.entity
+ && (t.properties.rotation - first_tile.properties.rotation) < constants::FLOAT_PRECISION
+ && t.source.x.is_sign_positive() == first_tile.source.x.is_sign_positive()
+ && t.source.y.is_sign_positive() == first_tile.source.y.is_sign_positive()
+ })
+ .collect()
)
} else {
Animation::new(vec![first_tile])
@@ -119,6 +126,9 @@ impl Tileset {
.find(|t| {
t.properties.entity == Some(entity.to_string())
&& Some(keyframe) == t.properties.keyframe
+ && t.properties.rotation == 0.0
+ && t.source.x > 0.0
+ && t.source.y > 0.0
})
.unwrap()
.clone()