commit ee1fd511
Now spawns player at the player spawn
Changed files
| M | src/sagotmx/tmx_struct.h before |
| M | src/saland/Game.cpp before |
diff --git a/src/sagotmx/tmx_struct.h b/src/sagotmx/tmx_struct.h
index c090a2a..39cbff3 100644
--- a/src/sagotmx/tmx_struct.h
+++ b/src/sagotmx/tmx_struct.h
@@ -470,6 +470,9 @@ inline void xml_add_objectgroup(std::iostream& io, const TileMap& m, size_t obje
if (to.name.length() > 0) {
io << " name=\"" << to.name << "\"";
}
+ if (to.type.length() > 0) {
+ io << " type=\"" << to.type << "\"";
+ }
io << " x=\"" << to.x << "\" y=\"" << to.y << "\" width=\"" << to.width << "\" height=\"" << to.height << "\"";
io << ">\n";
if (to.isEllipse) {
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp
index fa01467..35d70a9 100644
--- a/src/saland/Game.cpp
+++ b/src/saland/Game.cpp
@@ -42,6 +42,7 @@ https://github.com/sago007/saland
int32 velocityIterations = 6;
int32 positionIterations = 2;
+typedef std::pair<float,float> SpawnPoint;
/**
* This sort method sorts the elements from furthest to screen to closest to screen, so that elemnets closer to the screen will be drawn last
@@ -79,8 +80,19 @@ struct Game::GameImpl {
sago::SagoTextField bottomField;
};
-static std::pair<float,float> GetSpawnpoint(const sago::tiled::TileMap& tm) {
- std::pair<float,float> ret(tm.width/2.0f, tm.height/2.0f);
+static SpawnPoint GetSpawnpoint(const sago::tiled::TileMap& tm) {
+ SpawnPoint ret(tm.width/2.0f, tm.height/2.0f);
+ std::vector<SpawnPoint> points;
+ for (const sago::tiled::TileObjectGroup& og : tm.object_groups) {
+ for (const sago::tiled::TileObject& o : og.objects) {
+ if (o.type == "playerStart") {
+ points.push_back(SpawnPoint(o.x/32.0f, o.y/32.0f));
+ }
+ }
+ }
+ if (points.size() > 0) {
+ ret = points[rand()%points.size()];
+ }
return ret;
}