Read Zone tile data from the map to prepare for special interactions in the game.

pull/28/head
parent d2ab61472a
commit 005c49aa04
  1. 3
      .vscode/settings.json
  2. BIN
      Crawler/Crawler
  3. 1
      Crawler/Crawler.cpp
  4. 14
      Crawler/TMXParser.h
  5. BIN
      Crawler/pixelGameEngine.o

@ -79,6 +79,7 @@
"ios": "cpp", "ios": "cpp",
"locale": "cpp", "locale": "cpp",
"queue": "cpp", "queue": "cpp",
"stack": "cpp" "stack": "cpp",
"span": "cpp"
} }
} }

Binary file not shown.

@ -1003,6 +1003,7 @@ MapName Crawler::GetCurrentLevel(){
int main() int main()
{ {
std::cout<<std::endl<<"============"<<std::endl;
Crawler demo; Crawler demo;
if (demo.Construct(WINDOW_SIZE.x, WINDOW_SIZE.y, 4, 4)) if (demo.Construct(WINDOW_SIZE.x, WINDOW_SIZE.y, 4, 4))
demo.Start(); demo.Start();

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "olcPixelGameEngine.h" #include "olcPixelGameEngine.h"
#include "olcUTIL_Geometry2D.h"
#include <strstream> #include <strstream>
using namespace olc; using namespace olc;
@ -40,6 +41,7 @@ struct Map{
std::vector<XMLTag> TilesetData; std::vector<XMLTag> TilesetData;
std::vector<LayerTag> LayerData; std::vector<LayerTag> LayerData;
std::vector<SpawnerTag> SpawnerData; std::vector<SpawnerTag> SpawnerData;
std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
std::string FormatLayerData(std::ostream& os, std::vector<LayerTag>tiles); std::string FormatLayerData(std::ostream& os, std::vector<LayerTag>tiles);
std::string FormatSpawnerData(std::ostream& os, std::vector<SpawnerTag>tiles); std::string FormatSpawnerData(std::ostream& os, std::vector<SpawnerTag>tiles);
friend std::ostream& operator << (std::ostream& os, Map& rhs); friend std::ostream& operator << (std::ostream& os, Map& rhs);
@ -57,7 +59,6 @@ class TMXParser{
public: public:
TMXParser(std::string file); TMXParser(std::string file);
}; };
#ifdef TMX_PARSER_SETUP #ifdef TMX_PARSER_SETUP
#undef TMX_PARSER_SETUP #undef TMX_PARSER_SETUP
const std::string XMLTag::FormatTagData(std::map<std::string,std::string>tiles){ const std::string XMLTag::FormatTagData(std::map<std::string,std::string>tiles){
@ -213,6 +214,17 @@ class TMXParser{
if (newTag.tag=="object"&&newTag.data["type"]=="PlayerSpawnLocation") { if (newTag.tag=="object"&&newTag.data["type"]=="PlayerSpawnLocation") {
parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2}; parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2};
} else } else
if (newTag.tag=="object"&&newTag.data.find("type")!=newTag.data.end()){
//This is an object with a type that doesn't fit into other categories, we can add it to ZoneData.
if(parsedMapInfo.ZoneData.find(newTag.data["type"])!=parsedMapInfo.ZoneData.end()){
std::vector<geom2d::rect<int>>&zones=parsedMapInfo.ZoneData[newTag.data["type"]];
zones.push_back({{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}});
} else {
std::vector<geom2d::rect<int>>zones;
zones.push_back({{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}});
parsedMapInfo.ZoneData[newTag.data["type"]]=zones;
}
}
if (newTag.tag=="property"&&buildingSpawner) { if (newTag.tag=="property"&&buildingSpawner) {
if(newTag.data["propertytype"]=="MonsterName"){ if(newTag.data["propertytype"]=="MonsterName"){
obj.properties.push_back(newTag); obj.properties.push_back(newTag);

Binary file not shown.
Loading…
Cancel
Save