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}}
|
||||
}}));
|
||||
|
||||
LoadLevel(CAMPAIGN_1_1);
|
||||
|
||||
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;
|
||||
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;});
|
||||
@ -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,0.4 }, versionStr, WHITE, { 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){
|
||||
@ -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()
|
||||
{
|
||||
Crawler demo;
|
||||
|
@ -27,17 +27,19 @@ class Crawler : public olc::PixelGameEngine
|
||||
float lastWorldShakeAdjust=0;
|
||||
vf2d worldShakeVel={};
|
||||
const float WORLD_SHAKE_ADJUST_MAX_TIME=0.4;
|
||||
MapName currentLevel=MapName::CAMPAIGN_1_1;
|
||||
vi2d WORLD_SIZE={120,8};
|
||||
|
||||
public:
|
||||
Crawler();
|
||||
|
||||
public:
|
||||
const vi2d WORLD_SIZE={120,8};
|
||||
TileTransformedView view;
|
||||
bool OnUserCreate() override;
|
||||
bool OnUserUpdate(float fElapsedTime) override;
|
||||
void InitializeAnimations();
|
||||
void InitializeLevel(std::string mapFile,MapName map);
|
||||
void LoadLevel(MapName map);
|
||||
void HandleUserInput(float fElapsedTime);
|
||||
void UpdateCamera(float fElapsedTime);
|
||||
void UpdateEffects(float fElapsedTime);
|
||||
@ -59,4 +61,5 @@ public:
|
||||
bool DownReleased();
|
||||
Player&GetPlayer();
|
||||
void SetupWorldShake(float duration);
|
||||
vi2d GetWorldSize();
|
||||
};
|
@ -106,17 +106,17 @@ void Monster::PerformShootAnimation(){
|
||||
}
|
||||
}
|
||||
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;
|
||||
} 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){
|
||||
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;
|
||||
} 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){
|
||||
@ -187,11 +187,11 @@ bool Monster::Update(float fElapsedTime){
|
||||
targetAcquireTimer=1;
|
||||
if(line.length()<24*6){
|
||||
target=line.upoint(-1.2);
|
||||
if(pos.x-12*size>1&&pos.x+12*size<game->WORLD_SIZE.x*24-1&&
|
||||
pos.y-12*size>1&&pos.y+12*size<game->WORLD_SIZE.y*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->GetWorldSize().y*24-1){
|
||||
state=MOVE_AWAY;
|
||||
} 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);
|
||||
if(abs(moveTowardsLine.vector().norm().y)>=0.5){
|
||||
state=MOVE_AWAY;
|
||||
@ -199,7 +199,7 @@ bool Monster::Update(float fElapsedTime){
|
||||
state=NORMAL;
|
||||
}
|
||||
} 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);
|
||||
if(abs(moveTowardsLine.vector().norm().x)>=0.5){
|
||||
state=MOVE_AWAY;
|
||||
|
@ -221,11 +221,11 @@ void Player::Update(float fElapsedTime){
|
||||
vel.y=std::min(0.f,vel.y+friction*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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
|
||||
|
@ -15,6 +15,11 @@ struct XMLTag{
|
||||
bool GetBool(std::string dataTag);
|
||||
};
|
||||
|
||||
struct MapTag{
|
||||
int width,height;
|
||||
friend std::ostream& operator << (std::ostream& os, MapTag& rhs);
|
||||
};
|
||||
|
||||
struct LayerTag{
|
||||
XMLTag tag;
|
||||
std::vector<std::vector<int>> tiles;
|
||||
@ -29,7 +34,7 @@ struct SpawnerTag{
|
||||
};
|
||||
|
||||
struct Map{
|
||||
XMLTag MapData;
|
||||
MapTag MapData;
|
||||
std::vector<XMLTag> TilesetData;
|
||||
std::vector<LayerTag> LayerData;
|
||||
std::vector<SpawnerTag> SpawnerData;
|
||||
@ -66,6 +71,11 @@ class TMXParser{
|
||||
rhs.FormatTagData(rhs.data) <<"\n";
|
||||
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) {
|
||||
return std::stoi(data[dataTag]);
|
||||
}
|
||||
@ -178,7 +188,7 @@ class TMXParser{
|
||||
}
|
||||
|
||||
if (newTag.tag=="map") {
|
||||
parsedMapInfo.MapData=newTag;
|
||||
parsedMapInfo.MapData={stoi(newTag.data["width"]),stoi(newTag.data["height"])};
|
||||
} else
|
||||
if (newTag.tag=="tileset") {
|
||||
parsedMapInfo.TilesetData.push_back(newTag);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 135
|
||||
#define VERSION_BUILD 141
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Loading…
x
Reference in New Issue
Block a user