generated from sigonasr2/CPlusPlusProjectTemplate
Enable and disable flags are implemented
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
d34f7cc044
commit
b8e480c8ca
Binary file not shown.
8
flags.h
Normal file
8
flags.h
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Flag{
|
||||
enum{
|
||||
TEST_FLAG1,
|
||||
TEST_FLAG2,
|
||||
TEST_FLAG3,
|
||||
NONE,
|
||||
};
|
||||
}
|
129
main.cpp
129
main.cpp
@ -7,6 +7,7 @@
|
||||
#include "tiles.h"
|
||||
#include "references.h"
|
||||
#include "states.h"
|
||||
#include "flags.h"
|
||||
|
||||
#define WIDTH 256
|
||||
#define HEIGHT 224
|
||||
@ -72,6 +73,8 @@ class Object{
|
||||
Pixel color=WHITE;
|
||||
vd2d originPoint={0,0};
|
||||
bool drawn=false;
|
||||
int disableFlag;
|
||||
int enableFlag;
|
||||
//animationSpd is how long to wait before switching frames.
|
||||
Object(int id,std::string name,vi2d pos,Animation*spr,vi2d scale={1,1},Pixel color=WHITE,int animationSpd=1) {
|
||||
this->spr=spr;
|
||||
@ -107,6 +110,7 @@ public:
|
||||
vi2d SELECTED_TILE={0,0};
|
||||
vi2d HIGHLIGHTED_TILE={0,0};
|
||||
int EDITING_LAYER=layer::DYNAMIC;
|
||||
bool GAME_FLAGS[128]={};
|
||||
|
||||
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
|
||||
|
||||
@ -135,12 +139,15 @@ public:
|
||||
SetupAnimations();
|
||||
SetupObjectInfo();
|
||||
|
||||
GAME_FLAGS[Flag::TEST_FLAG1]=true;
|
||||
GAME_FLAGS[Flag::TEST_FLAG2]=false;
|
||||
GAME_FLAGS[Flag::TEST_FLAG3]=true;
|
||||
|
||||
MAP_ONETT=new Map("map0","map0_2","map0_3","map0_4","map0_5",SPRITES[TILESET1]);
|
||||
|
||||
CURRENT_MAP=MAP_ONETT;
|
||||
//OBJ_INFO["PLAYER"]=PLAYER_ANIMATION;
|
||||
LoadMap(MAP_ONETT);
|
||||
OBJECTS[0]->pos.x=0;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -201,6 +208,7 @@ public:
|
||||
if (TabHeld()) {
|
||||
GAME_STATE=GameState::TILE_SELECT;
|
||||
}
|
||||
if (OBJECTS.size()>0) {
|
||||
if (GetKey(I).bHeld) {
|
||||
if (!Collision({OBJECTS[0]->pos.x+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y-1+OBJECTS[0]->originPoint.y})) {
|
||||
OBJECTS[0]->pos.y-=1;
|
||||
@ -221,6 +229,7 @@ public:
|
||||
OBJECTS[0]->pos.x+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
int selectedTileX=(GetMouseX()+cameraPos.x)/32;
|
||||
int selectedTileY=(GetMouseY()+cameraPos.y)/32;
|
||||
if (selectedTileX<MAP_WIDTH&&selectedTileY<MAP_HEIGHT&&selectedTileX>=0&&selectedTileY>=0) {
|
||||
@ -483,9 +492,22 @@ public:
|
||||
int id;
|
||||
split3>>id;
|
||||
|
||||
bool enabled=true;
|
||||
if (OBJ_INFO[id]->disableFlag!=Flag::NONE) {
|
||||
if (GAME_FLAGS[OBJ_INFO[id]->disableFlag]) {
|
||||
enabled=false;
|
||||
}
|
||||
}
|
||||
if (OBJ_INFO[id]->enableFlag!=Flag::NONE) {
|
||||
if (!GAME_FLAGS[OBJ_INFO[id]->enableFlag]) {
|
||||
enabled=false;
|
||||
}
|
||||
}
|
||||
if (enabled) {
|
||||
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr);
|
||||
OBJECTS.push_back(newObj);
|
||||
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
||||
}
|
||||
printf("Object %s Loaded.\n",OBJ_INFO[id]->name.c_str());
|
||||
} else {
|
||||
std::vector<TILE*> tiles;
|
||||
printf("%s\n",data.c_str());
|
||||
@ -501,29 +523,6 @@ public:
|
||||
}
|
||||
while (f2.good()) {
|
||||
f2>>data;
|
||||
if (data.find("OBJECT")!=std::string::npos) {
|
||||
int marker=data.find_first_of(';');
|
||||
int lastMarker=marker;
|
||||
std::stringstream split1(data.substr(6,marker-6));
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split3(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
|
||||
double x,y;
|
||||
|
||||
split1>>x;
|
||||
split2>>y;
|
||||
|
||||
int id;
|
||||
split3>>id;
|
||||
|
||||
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr);
|
||||
OBJECTS.push_back(newObj);
|
||||
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
||||
} else {
|
||||
std::vector<TILE*> tiles;
|
||||
for (int i=0;i<data.length();i+=2) {
|
||||
unsigned char tileX,tileY;
|
||||
@ -533,32 +532,8 @@ public:
|
||||
}
|
||||
MAP2.push_back(tiles);
|
||||
}
|
||||
}
|
||||
while (f3.good()) {
|
||||
f3>>data;
|
||||
if (data.find("OBJECT")!=std::string::npos) {
|
||||
int marker=data.find_first_of(';');
|
||||
int lastMarker=marker;
|
||||
std::stringstream split1(data.substr(6,marker-6));
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split3(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
|
||||
double x,y;
|
||||
|
||||
split1>>x;
|
||||
split2>>y;
|
||||
|
||||
int id;
|
||||
split3>>id;
|
||||
|
||||
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr);
|
||||
OBJECTS.push_back(newObj);
|
||||
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
||||
} else {
|
||||
std::vector<TILE*> tiles;
|
||||
for (int i=0;i<data.length();i+=2) {
|
||||
unsigned char tileX,tileY;
|
||||
@ -568,32 +543,8 @@ public:
|
||||
}
|
||||
MAP3.push_back(tiles);
|
||||
}
|
||||
}
|
||||
while (f4.good()) {
|
||||
f4>>data;
|
||||
if (data.find("OBJECT")!=std::string::npos) {
|
||||
int marker=data.find_first_of(';');
|
||||
int lastMarker=marker;
|
||||
std::stringstream split1(data.substr(6,marker-6));
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split3(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
|
||||
double x,y;
|
||||
|
||||
split1>>x;
|
||||
split2>>y;
|
||||
|
||||
int id;
|
||||
split3>>id;
|
||||
|
||||
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr);
|
||||
OBJECTS.push_back(newObj);
|
||||
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
||||
} else {
|
||||
std::vector<TILE*> tiles;
|
||||
for (int i=0;i<data.length();i+=2) {
|
||||
unsigned char tileX,tileY;
|
||||
@ -603,32 +554,8 @@ public:
|
||||
}
|
||||
MAP4.push_back(tiles);
|
||||
}
|
||||
}
|
||||
while (f5.good()) {
|
||||
f5>>data;
|
||||
if (data.find("OBJECT")!=std::string::npos) {
|
||||
int marker=data.find_first_of(';');
|
||||
int lastMarker=marker;
|
||||
std::stringstream split1(data.substr(6,marker-6));
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split3(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
|
||||
double x,y;
|
||||
|
||||
split1>>x;
|
||||
split2>>y;
|
||||
|
||||
int id;
|
||||
split3>>id;
|
||||
|
||||
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr);
|
||||
OBJECTS.push_back(newObj);
|
||||
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
||||
} else {
|
||||
std::vector<TILE*> tiles;
|
||||
for (int i=0;i<data.length();i+=2) {
|
||||
unsigned char tileX,tileY;
|
||||
@ -638,7 +565,6 @@ public:
|
||||
}
|
||||
MAP5.push_back(tiles);
|
||||
}
|
||||
}
|
||||
printf("Loaded map %s.\n",map->filename.c_str());
|
||||
f.close();
|
||||
f2.close();
|
||||
@ -697,8 +623,11 @@ public:
|
||||
SPRITES[TILESET1] = CreateSprite("terrainmap.png");
|
||||
}
|
||||
|
||||
Object*CreateObject(Reference ref,std::string name,vd2d pos) {
|
||||
return new Object(ref,name,pos,ANIMATIONS[ref]);
|
||||
Object*CreateObject(Reference ref,std::string name,vd2d pos,int enableFlag=Flag::NONE,int disableFlag=Flag::NONE) {
|
||||
Object*newObj = new Object(ref,name,pos,ANIMATIONS[ref]);
|
||||
newObj->disableFlag=disableFlag;
|
||||
newObj->enableFlag=enableFlag;
|
||||
return newObj;
|
||||
}
|
||||
|
||||
void SetupObjectInfo() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user