|
|
@ -61,6 +61,7 @@ class Animation{ |
|
|
|
|
|
|
|
|
|
|
|
class Object{ |
|
|
|
class Object{ |
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
int id; |
|
|
|
Animation*spr; |
|
|
|
Animation*spr; |
|
|
|
vd2d pos; |
|
|
|
vd2d pos; |
|
|
|
int frameIndex=0; |
|
|
|
int frameIndex=0; |
|
|
@ -72,9 +73,10 @@ class Object{ |
|
|
|
vd2d originPoint={0,0}; |
|
|
|
vd2d originPoint={0,0}; |
|
|
|
bool drawn=false; |
|
|
|
bool drawn=false; |
|
|
|
//animationSpd is how long to wait before switching frames.
|
|
|
|
//animationSpd is how long to wait before switching frames.
|
|
|
|
Object(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; |
|
|
|
this->pos=pos; |
|
|
|
this->pos=pos; |
|
|
|
|
|
|
|
this->id=id; |
|
|
|
this->name=name; |
|
|
|
this->name=name; |
|
|
|
this->scale=scale; |
|
|
|
this->scale=scale; |
|
|
|
this->color=color; |
|
|
|
this->color=color; |
|
|
@ -101,7 +103,7 @@ public: |
|
|
|
Map*CURRENT_MAP; |
|
|
|
Map*CURRENT_MAP; |
|
|
|
Map*MAP_ONETT; |
|
|
|
Map*MAP_ONETT; |
|
|
|
vd2d cameraPos = {0,0}; |
|
|
|
vd2d cameraPos = {0,0}; |
|
|
|
state::GameState GAME_STATE = state::EDITOR; |
|
|
|
GameState GAME_STATE = GameState::EDITOR; |
|
|
|
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; |
|
|
@ -135,8 +137,10 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
//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; |
|
|
|
} |
|
|
|
} |
|
|
@ -181,9 +185,9 @@ public: |
|
|
|
std::cout << Collision(GetMousePos()); |
|
|
|
std::cout << Collision(GetMousePos()); |
|
|
|
|
|
|
|
|
|
|
|
switch (GAME_STATE) { |
|
|
|
switch (GAME_STATE) { |
|
|
|
case state::TILE_SELECT:{ |
|
|
|
case GameState::TILE_SELECT:{ |
|
|
|
if (!TabHeld()) { |
|
|
|
if (!TabHeld()) { |
|
|
|
GAME_STATE=state::EDITOR; |
|
|
|
GAME_STATE=GameState::EDITOR; |
|
|
|
} |
|
|
|
} |
|
|
|
if (GetMouse(0).bHeld) { |
|
|
|
if (GetMouse(0).bHeld) { |
|
|
|
int selectedTileX=GetMouseX()/TILEMAP_EDITOR_TILESIZE; |
|
|
|
int selectedTileX=GetMouseX()/TILEMAP_EDITOR_TILESIZE; |
|
|
@ -193,9 +197,9 @@ public: |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case state::EDITOR:{ |
|
|
|
case GameState::EDITOR:{ |
|
|
|
if (TabHeld()) { |
|
|
|
if (TabHeld()) { |
|
|
|
GAME_STATE=state::TILE_SELECT; |
|
|
|
GAME_STATE=GameState::TILE_SELECT; |
|
|
|
} |
|
|
|
} |
|
|
|
if (GetKey(I).bHeld) { |
|
|
|
if (GetKey(I).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})) { |
|
|
@ -287,7 +291,7 @@ public: |
|
|
|
void cameraUpdate() { |
|
|
|
void cameraUpdate() { |
|
|
|
|
|
|
|
|
|
|
|
switch (GAME_STATE) { |
|
|
|
switch (GAME_STATE) { |
|
|
|
case state::EDITOR:{ |
|
|
|
case GameState::EDITOR:{ |
|
|
|
//CAMERA MOVEMENTS MUST BE LAST!!!
|
|
|
|
//CAMERA MOVEMENTS MUST BE LAST!!!
|
|
|
|
if (UpHeld()) { |
|
|
|
if (UpHeld()) { |
|
|
|
cameraPos.y-=CAMERA_MOVESPD; |
|
|
|
cameraPos.y-=CAMERA_MOVESPD; |
|
|
@ -310,9 +314,13 @@ public: |
|
|
|
if (GetKey(F1).bPressed) { |
|
|
|
if (GetKey(F1).bPressed) { |
|
|
|
ConsoleShow(F1,false); |
|
|
|
ConsoleShow(F1,false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (GetKey(F2).bPressed) { |
|
|
|
|
|
|
|
SaveMap(CURRENT_MAP); |
|
|
|
|
|
|
|
printf("Map Saved\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (GAME_STATE) { |
|
|
|
switch (GAME_STATE) { |
|
|
|
case state::TILE_SELECT:{ |
|
|
|
case GameState::TILE_SELECT:{ |
|
|
|
if (UpPressed()) { |
|
|
|
if (UpPressed()) { |
|
|
|
SELECTED_TILE.y=SELECTED_TILE.y-1; |
|
|
|
SELECTED_TILE.y=SELECTED_TILE.y-1; |
|
|
|
if (SELECTED_TILE.y<0) { |
|
|
|
if (SELECTED_TILE.y<0) { |
|
|
@ -332,7 +340,7 @@ public: |
|
|
|
SELECTED_TILE.y=(SELECTED_TILE.y+1)%(TILEMAP_SIZE_Y/32); |
|
|
|
SELECTED_TILE.y=(SELECTED_TILE.y+1)%(TILEMAP_SIZE_Y/32); |
|
|
|
} |
|
|
|
} |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case state::EDITOR:{ |
|
|
|
case GameState::EDITOR:{ |
|
|
|
if (GetKey(K1).bPressed) { |
|
|
|
if (GetKey(K1).bPressed) { |
|
|
|
EDITING_LAYER=layer::COLLISION; |
|
|
|
EDITING_LAYER=layer::COLLISION; |
|
|
|
EnableLayer(layer::COLLISION,true); |
|
|
|
EnableLayer(layer::COLLISION,true); |
|
|
@ -363,7 +371,7 @@ public: |
|
|
|
obj->drawn=false; |
|
|
|
obj->drawn=false; |
|
|
|
} |
|
|
|
} |
|
|
|
switch (GAME_STATE) { |
|
|
|
switch (GAME_STATE) { |
|
|
|
case state::EDITOR:{ |
|
|
|
case GameState::EDITOR:{ |
|
|
|
for (int y=-1;y<HEIGHT/32+2;y++) { |
|
|
|
for (int y=-1;y<HEIGHT/32+2;y++) { |
|
|
|
int yTileOffset = cameraPos.y/32; |
|
|
|
int yTileOffset = cameraPos.y/32; |
|
|
|
for (auto&obj:OBJECTS) { |
|
|
|
for (auto&obj:OBJECTS) { |
|
|
@ -403,7 +411,7 @@ public: |
|
|
|
DrawRectDecal((HIGHLIGHTED_TILE)*32-cameraPos,{32,32},YELLOW); |
|
|
|
DrawRectDecal((HIGHLIGHTED_TILE)*32-cameraPos,{32,32},YELLOW); |
|
|
|
DrawStringPropDecal({2,2},"Editing Layer "+std::to_string(EDITING_LAYER)); |
|
|
|
DrawStringPropDecal({2,2},"Editing Layer "+std::to_string(EDITING_LAYER)); |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case state::TILE_SELECT:{ |
|
|
|
case GameState::TILE_SELECT:{ |
|
|
|
//14x14 pixels per tile.
|
|
|
|
//14x14 pixels per tile.
|
|
|
|
DrawDecal({0,0},SPRITES[TILESET1],{TILEMAP_EDITOR_DRAW_MULT,TILEMAP_EDITOR_DRAW_MULT}); |
|
|
|
DrawDecal({0,0},SPRITES[TILESET1],{TILEMAP_EDITOR_DRAW_MULT,TILEMAP_EDITOR_DRAW_MULT}); |
|
|
|
DrawRectDecal(SELECTED_TILE*(TILEMAP_EDITOR_TILESIZE),{TILEMAP_EDITOR_TILESIZE,TILEMAP_EDITOR_TILESIZE},RED); |
|
|
|
DrawRectDecal(SELECTED_TILE*(TILEMAP_EDITOR_TILESIZE),{TILEMAP_EDITOR_TILESIZE,TILEMAP_EDITOR_TILESIZE},RED); |
|
|
@ -454,7 +462,7 @@ public: |
|
|
|
while (f.good()) { |
|
|
|
while (f.good()) { |
|
|
|
f>>data; |
|
|
|
f>>data; |
|
|
|
if (MAP_WIDTH==-1) { |
|
|
|
if (MAP_WIDTH==-1) { |
|
|
|
MAP_WIDTH=data.length(); |
|
|
|
MAP_WIDTH=data.length()/2; |
|
|
|
printf("Map Width: %d\n",MAP_WIDTH); |
|
|
|
printf("Map Width: %d\n",MAP_WIDTH); |
|
|
|
} |
|
|
|
} |
|
|
|
if (data.find("OBJECT")!=std::string::npos) { |
|
|
|
if (data.find("OBJECT")!=std::string::npos) { |
|
|
@ -475,7 +483,7 @@ public: |
|
|
|
int id; |
|
|
|
int id; |
|
|
|
split3>>id; |
|
|
|
split3>>id; |
|
|
|
|
|
|
|
|
|
|
|
Object*newObj = new Object(OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -512,7 +520,7 @@ public: |
|
|
|
int id; |
|
|
|
int id; |
|
|
|
split3>>id; |
|
|
|
split3>>id; |
|
|
|
|
|
|
|
|
|
|
|
Object*newObj = new Object(OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -547,7 +555,7 @@ public: |
|
|
|
int id; |
|
|
|
int id; |
|
|
|
split3>>id; |
|
|
|
split3>>id; |
|
|
|
|
|
|
|
|
|
|
|
Object*newObj = new Object(OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -582,7 +590,7 @@ public: |
|
|
|
int id; |
|
|
|
int id; |
|
|
|
split3>>id; |
|
|
|
split3>>id; |
|
|
|
|
|
|
|
|
|
|
|
Object*newObj = new Object(OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -617,7 +625,7 @@ public: |
|
|
|
int id; |
|
|
|
int id; |
|
|
|
split3>>id; |
|
|
|
split3>>id; |
|
|
|
|
|
|
|
|
|
|
|
Object*newObj = new Object(OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
Object*newObj = new Object(id,OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
OBJECTS.push_back(newObj); |
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
|
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -639,6 +647,46 @@ public: |
|
|
|
f5.close(); |
|
|
|
f5.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SaveMap(Map*map) { |
|
|
|
|
|
|
|
std::ofstream f("assets/maps/"+map->filename,std::ios::binary); |
|
|
|
|
|
|
|
std::ofstream f2("assets/maps/"+map->l2filename,std::ios::binary); |
|
|
|
|
|
|
|
std::ofstream f3("assets/maps/"+map->l3filename,std::ios::binary); |
|
|
|
|
|
|
|
std::ofstream f4("assets/maps/"+map->l4filename,std::ios::binary); |
|
|
|
|
|
|
|
std::ofstream f5("assets/maps/"+map->l5filename,std::ios::binary); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Map width: %d, Map Height: %d::\n",MAP_WIDTH,MAP_HEIGHT); |
|
|
|
|
|
|
|
for (int y=0;y<MAP_HEIGHT;y++) { |
|
|
|
|
|
|
|
for (int x=0;x<MAP_WIDTH;x++) { |
|
|
|
|
|
|
|
f.put(MAP[y][x]->tileX+'0');f.put(MAP[y][x]->tileY+'0'); |
|
|
|
|
|
|
|
f2.put(MAP2[y][x]->tileX+'0');f2.put(MAP2[y][x]->tileY+'0'); |
|
|
|
|
|
|
|
f3.put(MAP3[y][x]->tileX+'0');f3.put(MAP3[y][x]->tileY+'0'); |
|
|
|
|
|
|
|
f4.put(MAP4[y][x]->tileX+'0');f4.put(MAP4[y][x]->tileY+'0'); |
|
|
|
|
|
|
|
f5.put(MAP5[y][x]->tileX+'0');f5.put(MAP5[y][x]->tileY+'0'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (y!=MAP_HEIGHT-1) { |
|
|
|
|
|
|
|
f.put('\n'); |
|
|
|
|
|
|
|
f2.put('\n'); |
|
|
|
|
|
|
|
f3.put('\n'); |
|
|
|
|
|
|
|
f4.put('\n'); |
|
|
|
|
|
|
|
f5.put('\n'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<OBJECTS.size();i++) { |
|
|
|
|
|
|
|
f.put('\n'); |
|
|
|
|
|
|
|
const std::string obj="OBJECT"+std::to_string(OBJECTS[i]->pos.x)+";"+std::to_string(OBJECTS[i]->pos.y)+";"+std::to_string(OBJECTS[i]->id); |
|
|
|
|
|
|
|
for (int i=0;i<obj.length();i++) { |
|
|
|
|
|
|
|
f.put(obj[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f.close(); |
|
|
|
|
|
|
|
f2.close(); |
|
|
|
|
|
|
|
f3.close(); |
|
|
|
|
|
|
|
f4.close(); |
|
|
|
|
|
|
|
f5.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Decal*CreateSprite(std::string spriteName) { |
|
|
|
Decal*CreateSprite(std::string spriteName) { |
|
|
|
return new Decal(new Sprite("assets/"+spriteName)); |
|
|
|
return new Decal(new Sprite("assets/"+spriteName)); |
|
|
|
} |
|
|
|
} |
|
|
@ -649,8 +697,12 @@ public: |
|
|
|
SPRITES[TILESET1] = CreateSprite("terrainmap.png"); |
|
|
|
SPRITES[TILESET1] = CreateSprite("terrainmap.png"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object*CreateObject(Reference ref,std::string name,vd2d pos) { |
|
|
|
|
|
|
|
return new Object(ref,name,pos,ANIMATIONS[ref]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SetupObjectInfo() { |
|
|
|
void SetupObjectInfo() { |
|
|
|
OBJ_INFO[PLAYER]=new Object("player",{0,0},ANIMATIONS[PLAYER]); |
|
|
|
OBJ_INFO[PLAYER]=CreateObject(PLAYER,"player",{0,0}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Collision(vd2d pos) { |
|
|
|
bool Collision(vd2d pos) { |
|
|
|