|
|
|
@ -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,24 +208,26 @@ public: |
|
|
|
|
if (TabHeld()) { |
|
|
|
|
GAME_STATE=GameState::TILE_SELECT; |
|
|
|
|
} |
|
|
|
|
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; |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (GetKey(K).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; |
|
|
|
|
if (GetKey(K).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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (GetKey(J).bHeld) { |
|
|
|
|
if (!Collision({OBJECTS[0]->pos.x-1+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+OBJECTS[0]->originPoint.y})) { |
|
|
|
|
OBJECTS[0]->pos.x-=1; |
|
|
|
|
if (GetKey(J).bHeld) { |
|
|
|
|
if (!Collision({OBJECTS[0]->pos.x-1+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+OBJECTS[0]->originPoint.y})) { |
|
|
|
|
OBJECTS[0]->pos.x-=1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (GetKey(L).bHeld) { |
|
|
|
|
if (!Collision({OBJECTS[0]->pos.x+1+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+OBJECTS[0]->originPoint.y})) { |
|
|
|
|
OBJECTS[0]->pos.x+=1; |
|
|
|
|
if (GetKey(L).bHeld) { |
|
|
|
|
if (!Collision({OBJECTS[0]->pos.x+1+OBJECTS[0]->originPoint.x,OBJECTS[0]->pos.y+OBJECTS[0]->originPoint.y})) { |
|
|
|
|
OBJECTS[0]->pos.x+=1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
int selectedTileX=(GetMouseX()+cameraPos.x)/32; |
|
|
|
@ -483,9 +492,22 @@ public: |
|
|
|
|
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());
|
|
|
|
|
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 Loaded.\n",OBJ_INFO[id]->name.c_str()); |
|
|
|
|
} else { |
|
|
|
|
std::vector<TILE*> tiles; |
|
|
|
|
printf("%s\n",data.c_str()); |
|
|
|
@ -501,143 +523,47 @@ 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; |
|
|
|
|
tileX=data[i]-'0'; |
|
|
|
|
tileY=data[i+1]-'0'; |
|
|
|
|
tiles.push_back(new TILE(tileX,tileY)); |
|
|
|
|
} |
|
|
|
|
MAP2.push_back(tiles); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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; |
|
|
|
|
tileX=data[i]-'0'; |
|
|
|
|
tileY=data[i+1]-'0'; |
|
|
|
|
tiles.push_back(new TILE(tileX,tileY)); |
|
|
|
|
} |
|
|
|
|
MAP3.push_back(tiles); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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; |
|
|
|
|
tileX=data[i]-'0'; |
|
|
|
|
tileY=data[i+1]-'0'; |
|
|
|
|
tiles.push_back(new TILE(tileX,tileY)); |
|
|
|
|
} |
|
|
|
|
MAP4.push_back(tiles); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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; |
|
|
|
|
tileX=data[i]-'0'; |
|
|
|
|
tileY=data[i+1]-'0'; |
|
|
|
|
tiles.push_back(new TILE(tileX,tileY)); |
|
|
|
|
} |
|
|
|
|
MAP5.push_back(tiles); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
printf("Loaded map %s.\n",map->filename.c_str()); |
|
|
|
|
f.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() { |
|
|
|
|