Made map data xml tag more specific (output width and height as values). Add load level functionality, changes world size.
This commit is contained in:
parent
2ec484206d
commit
d6e9ade54e
@ -133,6 +133,8 @@ bool Crawler::OnUserCreate(){
|
|||||||
,{MonsterName::SLIME_BLUE,{(rand()%20/2.f-5)*24,(rand()%20/2.f-5)*24}}
|
,{MonsterName::SLIME_BLUE,{(rand()%20/2.f-5)*24,(rand()%20/2.f-5)*24}}
|
||||||
}}));
|
}}));
|
||||||
|
|
||||||
|
LoadLevel(CAMPAIGN_1_1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,6 +657,7 @@ void Crawler::RenderWorld(float fElapsedTime){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//DrawDecal({0,0},MAP_TILESETS["assets/maps/"+MAP_DATA[LEVEL1].TilesetData[1].data["source"]]->Decal());
|
||||||
std::vector<Monster>monstersBefore,monstersAfter;
|
std::vector<Monster>monstersBefore,monstersAfter;
|
||||||
Player&pl=player;
|
Player&pl=player;
|
||||||
std::copy_if(MONSTER_LIST.begin(),MONSTER_LIST.end(),std::back_inserter(monstersBefore),[&pl](Monster&m){return m.GetPos().y<pl.GetPos().y;});
|
std::copy_if(MONSTER_LIST.begin(),MONSTER_LIST.end(),std::back_inserter(monstersBefore),[&pl](Monster&m){return m.GetPos().y<pl.GetPos().y;});
|
||||||
@ -771,7 +774,6 @@ void Crawler::RenderHud(){
|
|||||||
DrawStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4 - vf2d{ 0.4,0 }, versionStr, WHITE, { 0.4,0.4 });
|
DrawStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4 - vf2d{ 0.4,0 }, versionStr, WHITE, { 0.4,0.4 });
|
||||||
DrawStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4 - vf2d{ 0,0.4 }, versionStr, WHITE, { 0.4,0.4 });
|
DrawStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4 - vf2d{ 0,0.4 }, versionStr, WHITE, { 0.4,0.4 });
|
||||||
DrawStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4, versionStr, BLACK,{0.4,0.4});
|
DrawStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4, versionStr, BLACK,{0.4,0.4});
|
||||||
DrawDecal({0,0},MAP_TILESETS["assets/maps/"+MAP_DATA[LEVEL1].TilesetData[1].data["source"]]->Decal());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Crawler::AddEffect(Effect foreground,Effect background){
|
void Crawler::AddEffect(Effect foreground,Effect background){
|
||||||
@ -811,6 +813,15 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Crawler::LoadLevel(MapName map){
|
||||||
|
currentLevel=map;
|
||||||
|
WORLD_SIZE={MAP_DATA[map].MapData.width,MAP_DATA[map].MapData.height};
|
||||||
|
}
|
||||||
|
|
||||||
|
vi2d Crawler::GetWorldSize(){
|
||||||
|
return WORLD_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Crawler demo;
|
Crawler demo;
|
||||||
|
@ -27,17 +27,19 @@ class Crawler : public olc::PixelGameEngine
|
|||||||
float lastWorldShakeAdjust=0;
|
float lastWorldShakeAdjust=0;
|
||||||
vf2d worldShakeVel={};
|
vf2d worldShakeVel={};
|
||||||
const float WORLD_SHAKE_ADJUST_MAX_TIME=0.4;
|
const float WORLD_SHAKE_ADJUST_MAX_TIME=0.4;
|
||||||
|
MapName currentLevel=MapName::CAMPAIGN_1_1;
|
||||||
|
vi2d WORLD_SIZE={120,8};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Crawler();
|
Crawler();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const vi2d WORLD_SIZE={120,8};
|
|
||||||
TileTransformedView view;
|
TileTransformedView view;
|
||||||
bool OnUserCreate() override;
|
bool OnUserCreate() override;
|
||||||
bool OnUserUpdate(float fElapsedTime) override;
|
bool OnUserUpdate(float fElapsedTime) override;
|
||||||
void InitializeAnimations();
|
void InitializeAnimations();
|
||||||
void InitializeLevel(std::string mapFile,MapName map);
|
void InitializeLevel(std::string mapFile,MapName map);
|
||||||
|
void LoadLevel(MapName map);
|
||||||
void HandleUserInput(float fElapsedTime);
|
void HandleUserInput(float fElapsedTime);
|
||||||
void UpdateCamera(float fElapsedTime);
|
void UpdateCamera(float fElapsedTime);
|
||||||
void UpdateEffects(float fElapsedTime);
|
void UpdateEffects(float fElapsedTime);
|
||||||
@ -59,4 +61,5 @@ public:
|
|||||||
bool DownReleased();
|
bool DownReleased();
|
||||||
Player&GetPlayer();
|
Player&GetPlayer();
|
||||||
void SetupWorldShake(float duration);
|
void SetupWorldShake(float duration);
|
||||||
|
vi2d GetWorldSize();
|
||||||
};
|
};
|
@ -106,17 +106,17 @@ void Monster::PerformShootAnimation(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Monster::SetX(float x){
|
void Monster::SetX(float x){
|
||||||
if(x-12*size>0&&x+12*size<game->WORLD_SIZE.x*24){
|
if(x-12*size>0&&x+12*size<game->GetWorldSize().x*24){
|
||||||
pos.x=x;
|
pos.x=x;
|
||||||
} else {
|
} else {
|
||||||
pos.x=std::min(game->WORLD_SIZE.x*24-12*size,std::max(12*size,pos.x));
|
pos.x=std::min(game->GetWorldSize().x*24-12*size,std::max(12*size,pos.x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Monster::SetY(float y){
|
void Monster::SetY(float y){
|
||||||
if(y-12*size>0&&y+12*size<game->WORLD_SIZE.y*24){
|
if(y-12*size>0&&y+12*size<game->GetWorldSize().y*24){
|
||||||
pos.y=y;
|
pos.y=y;
|
||||||
} else {
|
} else {
|
||||||
pos.y=std::min(game->WORLD_SIZE.y*24-12*size,std::max(12*size,pos.y));
|
pos.y=std::min(game->GetWorldSize().y*24-12*size,std::max(12*size,pos.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Monster::Update(float fElapsedTime){
|
bool Monster::Update(float fElapsedTime){
|
||||||
@ -187,11 +187,11 @@ bool Monster::Update(float fElapsedTime){
|
|||||||
targetAcquireTimer=1;
|
targetAcquireTimer=1;
|
||||||
if(line.length()<24*6){
|
if(line.length()<24*6){
|
||||||
target=line.upoint(-1.2);
|
target=line.upoint(-1.2);
|
||||||
if(pos.x-12*size>1&&pos.x+12*size<game->WORLD_SIZE.x*24-1&&
|
if(pos.x-12*size>1&&pos.x+12*size<game->GetWorldSize().x*24-1&&
|
||||||
pos.y-12*size>1&&pos.y+12*size<game->WORLD_SIZE.y*24-1){
|
pos.y-12*size>1&&pos.y+12*size<game->GetWorldSize().y*24-1){
|
||||||
state=MOVE_AWAY;
|
state=MOVE_AWAY;
|
||||||
} else
|
} else
|
||||||
if(pos.x-12*size<=1||pos.x+12*size>=game->WORLD_SIZE.x*24-1){
|
if(pos.x-12*size<=1||pos.x+12*size>=game->GetWorldSize().x*24-1){
|
||||||
geom2d::line moveTowardsLine=geom2d::line(pos,target);
|
geom2d::line moveTowardsLine=geom2d::line(pos,target);
|
||||||
if(abs(moveTowardsLine.vector().norm().y)>=0.5){
|
if(abs(moveTowardsLine.vector().norm().y)>=0.5){
|
||||||
state=MOVE_AWAY;
|
state=MOVE_AWAY;
|
||||||
@ -199,7 +199,7 @@ bool Monster::Update(float fElapsedTime){
|
|||||||
state=NORMAL;
|
state=NORMAL;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
if(pos.y-12*size<=1||pos.y+12*size>=game->WORLD_SIZE.y*24-1){
|
if(pos.y-12*size<=1||pos.y+12*size>=game->GetWorldSize().y*24-1){
|
||||||
geom2d::line moveTowardsLine=geom2d::line(pos,target);
|
geom2d::line moveTowardsLine=geom2d::line(pos,target);
|
||||||
if(abs(moveTowardsLine.vector().norm().x)>=0.5){
|
if(abs(moveTowardsLine.vector().norm().x)>=0.5){
|
||||||
state=MOVE_AWAY;
|
state=MOVE_AWAY;
|
||||||
|
@ -221,11 +221,11 @@ void Player::Update(float fElapsedTime){
|
|||||||
vel.y=std::min(0.f,vel.y+friction*fElapsedTime);
|
vel.y=std::min(0.f,vel.y+friction*fElapsedTime);
|
||||||
}
|
}
|
||||||
float newX=pos.x+vel.x*fElapsedTime;
|
float newX=pos.x+vel.x*fElapsedTime;
|
||||||
if(newX-12*size>0&&newX+12*size<game->WORLD_SIZE.x*24){
|
if(newX-12*size>0&&newX+12*size<game->GetWorldSize().x*24){
|
||||||
pos.x=newX;
|
pos.x=newX;
|
||||||
}
|
}
|
||||||
float newY=pos.y+vel.y*fElapsedTime;
|
float newY=pos.y+vel.y*fElapsedTime;
|
||||||
if(newY-12*size>0&&newY+12*size<game->WORLD_SIZE.y*24){
|
if(newY-12*size>0&&newY+12*size<game->GetWorldSize().y*24){
|
||||||
pos.y=newY;
|
pos.y=newY;
|
||||||
}
|
}
|
||||||
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
|
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
|
||||||
|
@ -15,6 +15,11 @@ struct XMLTag{
|
|||||||
bool GetBool(std::string dataTag);
|
bool GetBool(std::string dataTag);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MapTag{
|
||||||
|
int width,height;
|
||||||
|
friend std::ostream& operator << (std::ostream& os, MapTag& rhs);
|
||||||
|
};
|
||||||
|
|
||||||
struct LayerTag{
|
struct LayerTag{
|
||||||
XMLTag tag;
|
XMLTag tag;
|
||||||
std::vector<std::vector<int>> tiles;
|
std::vector<std::vector<int>> tiles;
|
||||||
@ -29,7 +34,7 @@ struct SpawnerTag{
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Map{
|
struct Map{
|
||||||
XMLTag MapData;
|
MapTag MapData;
|
||||||
std::vector<XMLTag> TilesetData;
|
std::vector<XMLTag> TilesetData;
|
||||||
std::vector<LayerTag> LayerData;
|
std::vector<LayerTag> LayerData;
|
||||||
std::vector<SpawnerTag> SpawnerData;
|
std::vector<SpawnerTag> SpawnerData;
|
||||||
@ -66,6 +71,11 @@ class TMXParser{
|
|||||||
rhs.FormatTagData(rhs.data) <<"\n";
|
rhs.FormatTagData(rhs.data) <<"\n";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
std::ostream& operator << (std::ostream& os, MapTag& rhs){
|
||||||
|
os <<
|
||||||
|
"(width:"<<rhs.width<<", height:"<<rhs.height<<")\n";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
int XMLTag::GetInteger(std::string dataTag) {
|
int XMLTag::GetInteger(std::string dataTag) {
|
||||||
return std::stoi(data[dataTag]);
|
return std::stoi(data[dataTag]);
|
||||||
}
|
}
|
||||||
@ -178,7 +188,7 @@ class TMXParser{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newTag.tag=="map") {
|
if (newTag.tag=="map") {
|
||||||
parsedMapInfo.MapData=newTag;
|
parsedMapInfo.MapData={stoi(newTag.data["width"]),stoi(newTag.data["height"])};
|
||||||
} else
|
} else
|
||||||
if (newTag.tag=="tileset") {
|
if (newTag.tag=="tileset") {
|
||||||
parsedMapInfo.TilesetData.push_back(newTag);
|
parsedMapInfo.TilesetData.push_back(newTag);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 0
|
#define VERSION_PATCH 0
|
||||||
#define VERSION_BUILD 135
|
#define VERSION_BUILD 141
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user