diff --git a/C++ProjectTemplate b/C++ProjectTemplate index b6d212e..fa9b600 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index a9e4841..731beac 100644 --- a/main.cpp +++ b/main.cpp @@ -109,17 +109,25 @@ class Object{ return; } else { if (move.y<0) { - if (objArrElement>0&&OBJECTS[objArrElement-1]->pos.y+OBJECTS[objArrElement-1]->originPoint.y>pos.y+originPoint.y+move.y) { + while (objArrElement>0&&OBJECTS[objArrElement-1]->pos.y+OBJECTS[objArrElement-1]->originPoint.y>pos.y+originPoint.y+move.y) { + //printf("%p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str()); OBJECTS[objArrElement]=OBJECTS[objArrElement-1]; + //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str()); OBJECTS[objArrElement-1]=this; + //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str()); OBJECTS[objArrElement]->objArrElement=objArrElement; + //printf(" %p(%s)(%d)<->%p(%s)(%d)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement]->objArrElement,OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str(),objArrElement-1); objArrElement--; } } else { - if (objArrElementpos.y+OBJECTS[objArrElement+1]->originPoint.ypos.y+OBJECTS[objArrElement+1]->originPoint.y%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str()); OBJECTS[objArrElement]=OBJECTS[objArrElement+1]; + //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str()); OBJECTS[objArrElement+1]=this; + //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str()); OBJECTS[objArrElement]->objArrElement=objArrElement; + //printf(" %p(%s)(%d)<->%p(%s)(%d)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement]->objArrElement,OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str(),objArrElement+1); objArrElement++; } } @@ -526,6 +534,8 @@ goes on a very long time, I hope you can understand this is only for testing pur if (OBJECTS[i]->temp) { delete OBJECTS[i]; OBJECTS.erase(OBJECTS.begin()+i--); + } else { + OBJECTS[i]->objArrElement=i; } } CurrentCutscene->CleanupCutscene(); @@ -622,6 +632,30 @@ goes on a very long time, I hope you can understand this is only for testing pur } } }break; + case GameState::GAME_WORLD:{ + if (PlayerCanMove()) { + if (UpHeld()) { + if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,-1})) { + UpdatePlayerTrail({0,-1}); + } + } + if (DownHeld()) { + if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,1})) { + UpdatePlayerTrail({0,1}); + } + } + if (LeftHeld()) { + if (PARTY_MEMBER_OBJ[0]->SmoothMove({-1,0})) { + UpdatePlayerTrail({-1,0}); + } + } + if (RightHeld()) { + if (PARTY_MEMBER_OBJ[0]->SmoothMove({1,0})) { + UpdatePlayerTrail({1,0}); + } + } + } + }break; case GameState::EDITOR:{ if (TabHeld()) { GAME_STATE=GameState::TILE_SELECT; @@ -775,10 +809,6 @@ goes on a very long time, I hope you can understand this is only for testing pur if (GetKey(F1).bPressed) { ConsoleShow(F1,false); } - if (GetKey(F2).bPressed) { - SaveMap(CURRENT_MAP); - printf("Map Saved\n"); - } switch (GAME_STATE) { case GameState::TILE_SELECT:{ @@ -801,7 +831,19 @@ goes on a very long time, I hope you can understand this is only for testing pur SELECTED_TILE.y=(SELECTED_TILE.y+1)%(TILEMAP_SIZE_Y/32); } }break; + case GameState::GAME_WORLD:{ + if (GetKey(F5).bPressed) { + GAME_STATE=GameState::EDITOR; + } + }break; case GameState::EDITOR:{ + if (GetKey(F2).bPressed) { + SaveMap(CURRENT_MAP); + printf("Map Saved\n"); + } + if (GetKey(F5).bPressed) { + GAME_STATE=GameState::GAME_WORLD; + } if (GetKey(K1).bPressed) { EDITING_LAYER=layer::COLLISION; EnableLayer(layer::COLLISION,true); @@ -834,6 +876,8 @@ goes on a very long time, I hope you can understand this is only for testing pur if (OBJECTS[i]->GetPos()==HIGHLIGHTED_TILE*32) { delete OBJECTS[i]; OBJECTS.erase(OBJECTS.begin()+i--); + } else { + OBJECTS[i]->objArrElement=i; } } } @@ -857,42 +901,11 @@ goes on a very long time, I hope you can understand this is only for testing pur obj->drawn=false; } switch (GAME_STATE) { + case GameState::GAME_WORLD:{ + DrawGameWorld(); + }break; case GameState::EDITOR:{ - for (int y=-1;ydrawn&&obj->GetPos().y+obj->originPoint.y>(y+yTileOffset)*32&&obj->GetPos().y+obj->originPoint.y<=(y+yTileOffset+1)*32) { - obj->drawn=true; - SetDrawTarget(layer::DYNAMIC); - DrawPartialDecal(obj->GetPos()-cameraPos,obj->spr->spr,{(obj->frameIndex%obj->spr->frames)*obj->spr->width,0},{obj->spr->width,obj->spr->spr->sprite->height},obj->GetScale(),obj->color); - } - } - for (int x=-1;x=0&&x+xTileOffset=0&&y+yTileOffsettileX*MAP5[y+yTileOffset][x+xTileOffset]->tileY!=225) { - SetDrawTarget(layer::COLLISION); - DrawPartialSprite({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"]->sprite,{MAP5[y+yTileOffset][x+xTileOffset]->tileX*32,MAP5[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); - } - if(MAP4[y+yTileOffset][x+xTileOffset]->tileX*MAP4[y+yTileOffset][x+xTileOffset]->tileY!=225) { - SetDrawTarget(layer::BACKGROUND); - DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"],{MAP4[y+yTileOffset][x+xTileOffset]->tileX*32,MAP4[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); - } - if(MAP3[y+yTileOffset][x+xTileOffset]->tileX*MAP3[y+yTileOffset][x+xTileOffset]->tileY!=225) { - SetDrawTarget(layer::GROUND); - DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"],{MAP3[y+yTileOffset][x+xTileOffset]->tileX*32,MAP3[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); - } - if(MAP2[y+yTileOffset][x+xTileOffset]->tileX*MAP2[y+yTileOffset][x+xTileOffset]->tileY!=225) { - SetDrawTarget(layer::DYNAMIC); - DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"],{MAP2[y+yTileOffset][x+xTileOffset]->tileX*32,MAP2[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); - } - if(MAP[y+yTileOffset][x+xTileOffset]->tileX*MAP[y+yTileOffset][x+xTileOffset]->tileY!=225) { - SetDrawTarget(layer::HIGH); - DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"],{MAP[y+yTileOffset][x+xTileOffset]->tileX*32,MAP[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); - } - } - } - } + DrawGameWorld(); SetDrawTarget(nullptr); DrawRectDecal((HIGHLIGHTED_TILE)*32-cameraPos,{32,32},YELLOW); /*if (EDITING_LAYER==layer::OBJECT) { @@ -950,6 +963,44 @@ goes on a very long time, I hope you can understand this is only for testing pur FillRectDecal({0,0},{WIDTH,HEIGHT},Pixel(0,0,0,(int)CUTSCENE_FADE_VALUE)); }; + void DrawGameWorld() { + for (int y=-1;ydrawn&&obj->GetPos().y+obj->originPoint.y>(y+yTileOffset)*32&&obj->GetPos().y+obj->originPoint.y<=(y+yTileOffset+1)*32) { + obj->drawn=true; + SetDrawTarget(layer::DYNAMIC); + DrawPartialDecal(obj->GetPos()-cameraPos,obj->spr->spr,{(obj->frameIndex%obj->spr->frames)*obj->spr->width,0},{obj->spr->width,obj->spr->spr->sprite->height},obj->GetScale(),obj->color); + } + } + for (int x=-1;x=0&&x+xTileOffset=0&&y+yTileOffsettileX*MAP5[y+yTileOffset][x+xTileOffset]->tileY!=225) { + SetDrawTarget(layer::COLLISION); + DrawPartialSprite({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"]->sprite,{MAP5[y+yTileOffset][x+xTileOffset]->tileX*32,MAP5[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); + } + if(MAP4[y+yTileOffset][x+xTileOffset]->tileX*MAP4[y+yTileOffset][x+xTileOffset]->tileY!=225) { + SetDrawTarget(layer::BACKGROUND); + DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"],{MAP4[y+yTileOffset][x+xTileOffset]->tileX*32,MAP4[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); + } + if(MAP3[y+yTileOffset][x+xTileOffset]->tileX*MAP3[y+yTileOffset][x+xTileOffset]->tileY!=225) { + SetDrawTarget(layer::GROUND); + DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"],{MAP3[y+yTileOffset][x+xTileOffset]->tileX*32,MAP3[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); + } + if(MAP2[y+yTileOffset][x+xTileOffset]->tileX*MAP2[y+yTileOffset][x+xTileOffset]->tileY!=225) { + SetDrawTarget(layer::DYNAMIC); + DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"],{MAP2[y+yTileOffset][x+xTileOffset]->tileX*32,MAP2[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); + } + if(MAP[y+yTileOffset][x+xTileOffset]->tileX*MAP[y+yTileOffset][x+xTileOffset]->tileY!=225) { + SetDrawTarget(layer::HIGH); + DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES["terrainmap.png"],{MAP[y+yTileOffset][x+xTileOffset]->tileX*32,MAP[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); + } + } + } + } + } + void DrawFancyStringDecal(const olc::vf2d& pos, const std::wstring& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }) { vf2d newpos=pos; for (int i=0;iSetWindowTitle("sTitle"); + platform->SetWindowTitle(sTitle); nFrameCount = 0; } } diff --git a/states.h b/states.h index 978c941..75ebfbd 100644 --- a/states.h +++ b/states.h @@ -3,5 +3,6 @@ namespace GameState{ EDITOR, TILE_SELECT, OBJ_SELECT, + GAME_WORLD, }; } \ No newline at end of file