diff --git a/C++ProjectTemplate b/C++ProjectTemplate index ac186db..52f02d9 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 395b95d..c7b56fb 100644 --- a/main.cpp +++ b/main.cpp @@ -79,7 +79,7 @@ class Object{ this->scale=scale; this->color=color; this->animationSpd=animationSpd; - this->originPoint={spr->spr->sprite->width/2,spr->spr->sprite->height-4}; + this->originPoint={spr->width/2,spr->spr->sprite->height-4}; } }; @@ -152,7 +152,11 @@ public: SetDrawTarget(nullptr); Clear(BLANK); SetDrawTarget(layer::COLLISION); - Clear(BLANK); + if (EDITING_LAYER!=layer::COLLISION) { + Clear(MAGENTA); + } else { + Clear(BLANK); + } SetDrawTarget(layer::HIGH); Clear(BLANK); SetDrawTarget(layer::DYNAMIC); @@ -173,9 +177,8 @@ public: obj->frameIndex++; } } - SetDrawTarget(layer::COLLISION); - Pixel collisionData = GetDrawTarget()->GetPixel((int)OBJECTS[0]->pos.x-cameraPos.x,(int)OBJECTS[0]->pos.y-cameraPos.y); + std::cout << Collision(GetMousePos()); switch (GAME_STATE) { case state::TILE_SELECT:{ @@ -194,29 +197,25 @@ public: if (TabHeld()) { GAME_STATE=state::TILE_SELECT; } - if (UpHeld()) { - cameraPos.y-=CAMERA_MOVESPD; - } - if (RightHeld()) { - cameraPos.x+=CAMERA_MOVESPD; - } - if (LeftHeld()) { - cameraPos.x-=CAMERA_MOVESPD; - } - if (DownHeld()) { - cameraPos.y+=CAMERA_MOVESPD; - } 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) { - 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(J).bHeld) { - OBJECTS[0]->pos.x-=1; + 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) { - OBJECTS[0]->pos.x+=1; + 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; int selectedTileY=(GetMouseY()+cameraPos.y)/32; @@ -276,11 +275,42 @@ public: }break; } } + }break; } + + //CAMERA UPDATES MUST BE LAST!!! COLLISIONS RELY ON THE GAME POSITION STATES REMAINING THE SAME! + cameraUpdate(); + } + + //CAMERA UPDATES MUST BE LAST!!! COLLISIONS RELY ON THE GAME POSITION STATES REMAINING THE SAME! + void cameraUpdate() { + + switch (GAME_STATE) { + case state::EDITOR:{ + //CAMERA MOVEMENTS MUST BE LAST!!! + if (UpHeld()) { + cameraPos.y-=CAMERA_MOVESPD; + } + if (RightHeld()) { + cameraPos.x+=CAMERA_MOVESPD; + } + if (LeftHeld()) { + cameraPos.x-=CAMERA_MOVESPD; + } + if (DownHeld()) { + cameraPos.y+=CAMERA_MOVESPD; + } + }break; + } } void keyUpdates() { + + if (GetKey(F1).bPressed) { + ConsoleShow(F1,false); + } + switch (GAME_STATE) { case state::TILE_SELECT:{ if (UpPressed()) { @@ -623,6 +653,11 @@ public: OBJ_INFO[PLAYER]=new Object("player",{0,0},ANIMATIONS[PLAYER]); } + bool Collision(vd2d pos) { + SetDrawTarget(layer::COLLISION); + Pixel collisionData = GetDrawTarget()->GetPixel((int)pos.x-cameraPos.x,(int)pos.y-cameraPos.y); + return collisionData!=MAGENTA; + } bool TabHeld(){