diff --git a/C++ProjectTemplate b/C++ProjectTemplate index c6ef6f0..ff8f73f 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index b23f577..7091ef9 100644 --- a/main.cpp +++ b/main.cpp @@ -120,6 +120,7 @@ public: int OBJ_DISPLAY_OFFSET = 0; bool GAME_FLAGS[128]={}; Object* PLAYER_OBJ; + bool messageBoxVisible=false; bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things. @@ -198,8 +199,6 @@ public: } } - std::cout << Collision(GetMousePos()); - switch (GAME_STATE) { case GameState::TILE_SELECT:{ if (!TabHeld()) { @@ -217,26 +216,18 @@ public: if (TabHeld()) { GAME_STATE=GameState::TILE_SELECT; } - if (OBJECTS.size()>0) { + if (PlayerCanMove()) { if (GetKey(I).bHeld) { - if (!Collision({PLAYER_OBJ->pos.x+PLAYER_OBJ->originPoint.x,PLAYER_OBJ->pos.y-1+PLAYER_OBJ->originPoint.y})) { - Move(PLAYER_OBJ,{0,-1}); - } + SmoothMove(PLAYER_OBJ,{0,-1}); } if (GetKey(K).bHeld) { - if (!Collision({PLAYER_OBJ->pos.x+PLAYER_OBJ->originPoint.x,PLAYER_OBJ->pos.y+1+PLAYER_OBJ->originPoint.y})) { - Move(PLAYER_OBJ,{0,1}); - } + SmoothMove(PLAYER_OBJ,{0,1}); } if (GetKey(J).bHeld) { - if (!Collision({PLAYER_OBJ->pos.x-1+PLAYER_OBJ->originPoint.x,PLAYER_OBJ->pos.y+PLAYER_OBJ->originPoint.y})) { - Move(PLAYER_OBJ,{-1,0}); - } + SmoothMove(PLAYER_OBJ,{-1,0}); } if (GetKey(L).bHeld) { - if (!Collision({PLAYER_OBJ->pos.x+1+PLAYER_OBJ->originPoint.x,PLAYER_OBJ->pos.y+PLAYER_OBJ->originPoint.y})) { - Move(PLAYER_OBJ,{1,0}); - } + SmoothMove(PLAYER_OBJ,{1,0}); } } int selectedTileX=(GetMouseX()+cameraPos.x)/32; @@ -909,6 +900,79 @@ public: } } + void SmoothMove(Object*obj,vd2d move) { + const int wiggleRoom=3; + vd2d originPos = {obj->pos.x+obj->originPoint.x,obj->pos.y-1+obj->originPoint.y}; + if (!Collision(originPos+move)) { + Move(PLAYER_OBJ,move); + return; + } else + if (move.x>0) { + for (int i=0;i0) { + for (int i=0;i::const_iterator it = OBJECTS.begin(); if (obj->id==PLAYER) { @@ -983,6 +1047,10 @@ public: bool RightReleased(){ return GetKey(D).bReleased||GetKey(RIGHT).bReleased||GetKey(NP6).bReleased||MOUSE_RELEASED&&GetMouseX()<=128&&GetMouseX()>=96&&GetMouseY()>=HEIGHT-128; } + + bool PlayerCanMove(){ + return !messageBoxVisible&&PLAYER_OBJ!=nullptr; + } };