diff --git a/SeasonsOfLoneliness.cpp b/SeasonsOfLoneliness.cpp index 86f6e09..b667fdc 100644 --- a/SeasonsOfLoneliness.cpp +++ b/SeasonsOfLoneliness.cpp @@ -36,6 +36,18 @@ class Object{ std::string name; }; +class Animation{ + public: + olc::Decal*spr; + std::vector frames; + int frame=0; + bool flipped=false; + + olc::vi2d getCurrentFrame() { + return frames[frame]; + } +}; + class SeasonsOfLoneliness : public olc::PixelGameEngine { public: @@ -78,8 +90,22 @@ public: int oxygenQualityLevel=34; int plantState=0b10010110101000101010100110101010; olc::SplashScreen splash; - - olc::Decal*DOME_DECAL,*FOOD_METER_DECAL,*OXYGEN_METER_DECAL,*PLANT_DECAL; + Animation current_playerAnim; + Animation playerAnim; + Animation playerAnimRight; + Animation playerAnimLeft; + Animation playerAnimDown; + Animation playerAnimWalkUp; + Animation playerAnimWalkDown; + Animation playerAnimWalkRight; + Animation playerAnimWalkLeft; + Animation playerAnimPlantUp; + Animation playerAnimPlantDown; + Animation playerAnimPlantRight; + Animation playerAnimPlantLeft; + + olc::Decal*DOME_DECAL,*FOOD_METER_DECAL,*OXYGEN_METER_DECAL,*PLANT_DECAL, + *PLAYER_DECAL; std::map BASE_OBJECTS; bool OnUserCreate() override @@ -93,6 +119,46 @@ public: FOOD_METER_DECAL=new olc::Decal(new olc::Sprite("assets/corn.png")); OXYGEN_METER_DECAL=new olc::Decal(new olc::Sprite("assets/co2.png")); PLANT_DECAL=new olc::Decal(new olc::Sprite("assets/plant.png")); + PLAYER_DECAL=new olc::Decal(new olc::Sprite("assets/player.png")); + + current_playerAnim.spr=PLAYER_DECAL; + playerAnim.spr=PLAYER_DECAL; + playerAnimRight.spr=PLAYER_DECAL; + playerAnimLeft.spr=PLAYER_DECAL; + playerAnimLeft.flipped=true; + playerAnimDown.spr=PLAYER_DECAL; + playerAnimWalkUp.spr=PLAYER_DECAL; + playerAnimWalkDown.spr=PLAYER_DECAL; + playerAnimWalkRight.spr=PLAYER_DECAL; + playerAnimWalkLeft.spr=PLAYER_DECAL; + playerAnimWalkLeft.flipped=true; + playerAnimPlantUp.spr=PLAYER_DECAL; + playerAnimPlantDown.spr=PLAYER_DECAL; + playerAnimPlantRight.spr=PLAYER_DECAL; + playerAnimPlantLeft.spr=PLAYER_DECAL; + playerAnimPlantLeft.flipped=true; + playerAnim.frames.push_back({64,0}); + playerAnimRight.frames.push_back({32,0}); + playerAnimLeft.frames.push_back({32,0}); + playerAnimDown.frames.push_back({0,0}); + playerAnimWalkUp.frames.push_back({0,96}); + playerAnimWalkUp.frames.push_back({32,96}); + playerAnimWalkUp.frames.push_back({64,96}); + playerAnimWalkRight.frames.push_back({0,64}); + playerAnimWalkLeft.frames.push_back({0,64}); + playerAnimWalkRight.frames.push_back({32,64}); + playerAnimWalkLeft.frames.push_back({32,64}); + playerAnimWalkRight.frames.push_back({64,64}); + playerAnimWalkLeft.frames.push_back({64,64}); + playerAnimWalkDown.frames.push_back({0,32}); + playerAnimWalkDown.frames.push_back({32,32}); + playerAnimWalkDown.frames.push_back({64,32}); + playerAnimPlantUp.frames.push_back({64,128}); + playerAnimPlantRight.frames.push_back({32,128}); + playerAnimPlantLeft.frames.push_back({32,128}); + playerAnimPlantDown.frames.push_back({0,128}); + current_playerAnim=playerAnimWalkDown; + BASE_OBJECTS["DOME"]=DOME_DECAL; BASE_OBJECTS["PLANT"]=PLANT_DECAL; BASE_OBJECTS["EXIT"]=NULL; @@ -101,6 +167,10 @@ public: } void GetAnyKeyPress() override { + if (!GetKey(olc::W).bPressed&&!GetKey(olc::A).bPressed&&!GetKey(olc::S).bPressed&&!GetKey(olc::D).bPressed&& + !GetKey(olc::UP).bPressed&&!GetKey(olc::RIGHT).bPressed&&!GetKey(olc::DOWN).bPressed&&!GetKey(olc::LEFT).bPressed) { + ActionButtonPress(); + } if (messageBoxVisible) { if (messageBoxCursor!=messageBoxRefText.length()) { while (messageBoxCursor=8&&PLAYER_COORDS[0]<12&& + PLAYER_COORDS[1]>=2&&PLAYER_COORDS[1]<6) { + cout<<"You are standing over plant "<=current_playerAnim.frames.size())?0:current_playerAnim.frame+1; if (CURRENT_CUTSCENE==NONE&&!messageBoxVisible) { + bool changed=false; if (GetKey(olc::D).bHeld||GetKey(olc::RIGHT).bHeld) { PLAYER_COORDS[0]=clamp(PLAYER_COORDS[0]+MOVE_SPD,0.1,(double)MAP_WIDTH); ConsoleClear(); cout<<"("<>getPlantId(obj)*2&0b11; + int getPlantStatus(int x,int y) { + return plantState>>getPlantId(x,y)*2&0b11; } void DrawDialogBox(const olc::vi2d &pos, const olc::vi2d &size, olc::Pixel p = olc::WHITE, olc::Pixel p2 = olc::DARK_GREY, olc::Pixel p3 = olc::VERY_DARK_GREY) { @@ -531,6 +660,11 @@ public: printf("\n"); } } + + void changeAnimation(Animation anim) { + current_playerAnim=anim; + current_playerAnim.frame=0; + } }; diff --git a/Seasons_of_Loneliness b/Seasons_of_Loneliness index 039c0a7..4cb4748 100755 Binary files a/Seasons_of_Loneliness and b/Seasons_of_Loneliness differ diff --git a/assets/player.png b/assets/player.png index 84af810..0af9ba5 100644 Binary files a/assets/player.png and b/assets/player.png differ diff --git a/pixelGameEngine.h b/pixelGameEngine.h index 57d638f..3e3b890 100644 --- a/pixelGameEngine.h +++ b/pixelGameEngine.h @@ -3442,6 +3442,7 @@ namespace olc // Compare hardware input states from previous frame auto ScanHardware = [&](HWButton* pKeys, bool* pStateOld, bool* pStateNew, uint32_t nKeyCount) { + bool pressed=false; for (uint32_t i = 0; i < nKeyCount; i++) { pKeys[i].bPressed = false; @@ -3450,7 +3451,7 @@ namespace olc { if (pStateNew[i]) { - GetAnyKeyPress(); + pressed=true; pKeys[i].bPressed = !pKeys[i].bHeld; pKeys[i].bHeld = true; } @@ -3463,6 +3464,7 @@ namespace olc } pStateOld[i] = pStateNew[i]; } + if (pressed) {GetAnyKeyPress();} }; ScanHardware(pKeyboardState, pKeyOldState, pKeyNewState, 256);