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,
|
||||||
|
};
|
||||||
|
}
|
219
main.cpp
219
main.cpp
@ -7,6 +7,7 @@
|
|||||||
#include "tiles.h"
|
#include "tiles.h"
|
||||||
#include "references.h"
|
#include "references.h"
|
||||||
#include "states.h"
|
#include "states.h"
|
||||||
|
#include "flags.h"
|
||||||
|
|
||||||
#define WIDTH 256
|
#define WIDTH 256
|
||||||
#define HEIGHT 224
|
#define HEIGHT 224
|
||||||
@ -72,6 +73,8 @@ class Object{
|
|||||||
Pixel color=WHITE;
|
Pixel color=WHITE;
|
||||||
vd2d originPoint={0,0};
|
vd2d originPoint={0,0};
|
||||||
bool drawn=false;
|
bool drawn=false;
|
||||||
|
int disableFlag;
|
||||||
|
int enableFlag;
|
||||||
//animationSpd is how long to wait before switching frames.
|
//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) {
|
Object(int id,std::string name,vi2d pos,Animation*spr,vi2d scale={1,1},Pixel color=WHITE,int animationSpd=1) {
|
||||||
this->spr=spr;
|
this->spr=spr;
|
||||||
@ -107,6 +110,7 @@ public:
|
|||||||
vi2d SELECTED_TILE={0,0};
|
vi2d SELECTED_TILE={0,0};
|
||||||
vi2d HIGHLIGHTED_TILE={0,0};
|
vi2d HIGHLIGHTED_TILE={0,0};
|
||||||
int EDITING_LAYER=layer::DYNAMIC;
|
int EDITING_LAYER=layer::DYNAMIC;
|
||||||
|
bool GAME_FLAGS[128]={};
|
||||||
|
|
||||||
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
|
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
|
||||||
|
|
||||||
@ -135,12 +139,15 @@ public:
|
|||||||
SetupAnimations();
|
SetupAnimations();
|
||||||
SetupObjectInfo();
|
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]);
|
MAP_ONETT=new Map("map0","map0_2","map0_3","map0_4","map0_5",SPRITES[TILESET1]);
|
||||||
|
|
||||||
CURRENT_MAP=MAP_ONETT;
|
CURRENT_MAP=MAP_ONETT;
|
||||||
//OBJ_INFO["PLAYER"]=PLAYER_ANIMATION;
|
//OBJ_INFO["PLAYER"]=PLAYER_ANIMATION;
|
||||||
LoadMap(MAP_ONETT);
|
LoadMap(MAP_ONETT);
|
||||||
OBJECTS[0]->pos.x=0;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -201,24 +208,26 @@ public:
|
|||||||
if (TabHeld()) {
|
if (TabHeld()) {
|
||||||
GAME_STATE=GameState::TILE_SELECT;
|
GAME_STATE=GameState::TILE_SELECT;
|
||||||
}
|
}
|
||||||
if (GetKey(I).bHeld) {
|
if (OBJECTS.size()>0) {
|
||||||
if (!Collision({OBJECTS[0]->pos.x+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y-1+OBJECTS[0]->originPoint.y})) {
|
if (GetKey(I).bHeld) {
|
||||||
OBJECTS[0]->pos.y-=1;
|
if (!Collision({OBJECTS[0]->pos.x+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y-1+OBJECTS[0]->originPoint.y})) {
|
||||||
|
OBJECTS[0]->pos.y-=1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (GetKey(K).bHeld) {
|
||||||
if (GetKey(K).bHeld) {
|
if (!Collision({OBJECTS[0]->pos.x+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+1+OBJECTS[0]->originPoint.y})) {
|
||||||
if (!Collision({OBJECTS[0]->pos.x+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+1+OBJECTS[0]->originPoint.y})) {
|
OBJECTS[0]->pos.y+=1;
|
||||||
OBJECTS[0]->pos.y+=1;
|
}
|
||||||
}
|
}
|
||||||
}
|
if (GetKey(J).bHeld) {
|
||||||
if (GetKey(J).bHeld) {
|
if (!Collision({OBJECTS[0]->pos.x-1+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+OBJECTS[0]->originPoint.y})) {
|
||||||
if (!Collision({OBJECTS[0]->pos.x-1+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+OBJECTS[0]->originPoint.y})) {
|
OBJECTS[0]->pos.x-=1;
|
||||||
OBJECTS[0]->pos.x-=1;
|
}
|
||||||
}
|
}
|
||||||
}
|
if (GetKey(L).bHeld) {
|
||||||
if (GetKey(L).bHeld) {
|
if (!Collision({OBJECTS[0]->pos.x+1+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+OBJECTS[0]->originPoint.y})) {
|
||||||
if (!Collision({OBJECTS[0]->pos.x+1+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+OBJECTS[0]->originPoint.y})) {
|
OBJECTS[0]->pos.x+=1;
|
||||||
OBJECTS[0]->pos.x+=1;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int selectedTileX=(GetMouseX()+cameraPos.x)/32;
|
int selectedTileX=(GetMouseX()+cameraPos.x)/32;
|
||||||
@ -483,9 +492,22 @@ public:
|
|||||||
int id;
|
int id;
|
||||||
split3>>id;
|
split3>>id;
|
||||||
|
|
||||||
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr);
|
bool enabled=true;
|
||||||
OBJECTS.push_back(newObj);
|
if (OBJ_INFO[id]->disableFlag!=Flag::NONE) {
|
||||||
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
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 Loaded.\n",OBJ_INFO[id]->name.c_str());
|
||||||
} else {
|
} else {
|
||||||
std::vector<TILE*> tiles;
|
std::vector<TILE*> tiles;
|
||||||
printf("%s\n",data.c_str());
|
printf("%s\n",data.c_str());
|
||||||
@ -501,143 +523,47 @@ public:
|
|||||||
}
|
}
|
||||||
while (f2.good()) {
|
while (f2.good()) {
|
||||||
f2>>data;
|
f2>>data;
|
||||||
if (data.find("OBJECT")!=std::string::npos) {
|
std::vector<TILE*> tiles;
|
||||||
int marker=data.find_first_of(';');
|
for (int i=0;i<data.length();i+=2) {
|
||||||
int lastMarker=marker;
|
unsigned char tileX,tileY;
|
||||||
std::stringstream split1(data.substr(6,marker-6));
|
tileX=data[i]-'0';
|
||||||
marker=data.find_first_of(';',marker+1);
|
tileY=data[i+1]-'0';
|
||||||
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
|
tiles.push_back(new TILE(tileX,tileY));
|
||||||
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;
|
|
||||||
tileX=data[i]-'0';
|
|
||||||
tileY=data[i+1]-'0';
|
|
||||||
tiles.push_back(new TILE(tileX,tileY));
|
|
||||||
}
|
|
||||||
MAP2.push_back(tiles);
|
|
||||||
}
|
}
|
||||||
|
MAP2.push_back(tiles);
|
||||||
}
|
}
|
||||||
while (f3.good()) {
|
while (f3.good()) {
|
||||||
f3>>data;
|
f3>>data;
|
||||||
if (data.find("OBJECT")!=std::string::npos) {
|
std::vector<TILE*> tiles;
|
||||||
int marker=data.find_first_of(';');
|
for (int i=0;i<data.length();i+=2) {
|
||||||
int lastMarker=marker;
|
unsigned char tileX,tileY;
|
||||||
std::stringstream split1(data.substr(6,marker-6));
|
tileX=data[i]-'0';
|
||||||
marker=data.find_first_of(';',marker+1);
|
tileY=data[i+1]-'0';
|
||||||
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
|
tiles.push_back(new TILE(tileX,tileY));
|
||||||
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;
|
|
||||||
tileX=data[i]-'0';
|
|
||||||
tileY=data[i+1]-'0';
|
|
||||||
tiles.push_back(new TILE(tileX,tileY));
|
|
||||||
}
|
|
||||||
MAP3.push_back(tiles);
|
|
||||||
}
|
}
|
||||||
|
MAP3.push_back(tiles);
|
||||||
}
|
}
|
||||||
while (f4.good()) {
|
while (f4.good()) {
|
||||||
f4>>data;
|
f4>>data;
|
||||||
if (data.find("OBJECT")!=std::string::npos) {
|
std::vector<TILE*> tiles;
|
||||||
int marker=data.find_first_of(';');
|
for (int i=0;i<data.length();i+=2) {
|
||||||
int lastMarker=marker;
|
unsigned char tileX,tileY;
|
||||||
std::stringstream split1(data.substr(6,marker-6));
|
tileX=data[i]-'0';
|
||||||
marker=data.find_first_of(';',marker+1);
|
tileY=data[i+1]-'0';
|
||||||
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
|
tiles.push_back(new TILE(tileX,tileY));
|
||||||
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;
|
|
||||||
tileX=data[i]-'0';
|
|
||||||
tileY=data[i+1]-'0';
|
|
||||||
tiles.push_back(new TILE(tileX,tileY));
|
|
||||||
}
|
|
||||||
MAP4.push_back(tiles);
|
|
||||||
}
|
}
|
||||||
|
MAP4.push_back(tiles);
|
||||||
}
|
}
|
||||||
while (f5.good()) {
|
while (f5.good()) {
|
||||||
f5>>data;
|
f5>>data;
|
||||||
if (data.find("OBJECT")!=std::string::npos) {
|
std::vector<TILE*> tiles;
|
||||||
int marker=data.find_first_of(';');
|
for (int i=0;i<data.length();i+=2) {
|
||||||
int lastMarker=marker;
|
unsigned char tileX,tileY;
|
||||||
std::stringstream split1(data.substr(6,marker-6));
|
tileX=data[i]-'0';
|
||||||
marker=data.find_first_of(';',marker+1);
|
tileY=data[i+1]-'0';
|
||||||
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
|
tiles.push_back(new TILE(tileX,tileY));
|
||||||
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;
|
|
||||||
tileX=data[i]-'0';
|
|
||||||
tileY=data[i+1]-'0';
|
|
||||||
tiles.push_back(new TILE(tileX,tileY));
|
|
||||||
}
|
|
||||||
MAP5.push_back(tiles);
|
|
||||||
}
|
}
|
||||||
|
MAP5.push_back(tiles);
|
||||||
}
|
}
|
||||||
printf("Loaded map %s.\n",map->filename.c_str());
|
printf("Loaded map %s.\n",map->filename.c_str());
|
||||||
f.close();
|
f.close();
|
||||||
@ -697,8 +623,11 @@ public:
|
|||||||
SPRITES[TILESET1] = CreateSprite("terrainmap.png");
|
SPRITES[TILESET1] = CreateSprite("terrainmap.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
Object*CreateObject(Reference ref,std::string name,vd2d pos) {
|
Object*CreateObject(Reference ref,std::string name,vd2d pos,int enableFlag=Flag::NONE,int disableFlag=Flag::NONE) {
|
||||||
return new Object(ref,name,pos,ANIMATIONS[ref]);
|
Object*newObj = new Object(ref,name,pos,ANIMATIONS[ref]);
|
||||||
|
newObj->disableFlag=disableFlag;
|
||||||
|
newObj->enableFlag=enableFlag;
|
||||||
|
return newObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupObjectInfo() {
|
void SetupObjectInfo() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user