diff --git a/C++/scripts/md5 b/C++/scripts/md5 index 3e77b3f..7cf8083 100644 --- a/C++/scripts/md5 +++ b/C++/scripts/md5 @@ -1,3 +1,3 @@ build.sh:530634457ea9041267c05d4ced95eee1 - commit.sh:d03a46e721060c22ccb146e19d27e70a - -web.sh:241ce74055952325f82f009b494df250 - +web.sh:3dcc2fe7e036359eedd257a864e9a1e1 - diff --git a/C++ProjectTemplate b/C++ProjectTemplate index dc59e7a..2820b7e 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 05849a6..8b0d5c8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,36 +1,130 @@ #define OLC_PGE_APPLICATION #include "pixelGameEngine.h" -using namespace std; +using namespace olc; -class Example : public olc::PixelGameEngine +class Room{ + public: + Room*DoorS=nullptr; + Room*DoorE=nullptr; + Room*DoorW=nullptr; + Room*DoorN=nullptr; + std::string roomName; + Room(){}; + Room(std::string name):roomName(name){}; +}; + +class DoorGame : public olc::PixelGameEngine { public: - Example() + Room*CURRENT_ROOM; + DoorGame() { - sAppName = "Example"; + sAppName = "Rooms example"; } public: bool OnUserCreate() override { - SetPixelMode(olc::Pixel::ALPHA); - ConsoleCaptureStdOut(true); - // Called once at the start, so create things here - for (int x = 0; x < ScreenWidth(); x++) - for (int y = 0; y < ScreenHeight(); y++) - Draw(x, y, olc::Pixel(rand() % 255, rand() % 255, rand()% 255)); - for (int x=0;x<50;x++) { - for (int y=0;y<50;y++) { - Draw(x, y, olc::Pixel(255, 0, 0, 128)); - } - } + Room*WEST_ROOM=new Room("West Room"); + Room*MAIN_HANGAR=new Room("Main Hangar"); + Room*NORTH_ROOM=new Room("North Room"); + Room*SOUTH_ROOM=new Room("South Room"); + Room*EAST_HALLWAY=new Room("East Hallway"); + Room*EAST_EXIT=new Room("East Exit"); + + //West Room has an east door leading to Main Hangar. + WEST_ROOM->DoorE=MAIN_HANGAR; + + //The Main hangar has 4 doors each leading to other places... + MAIN_HANGAR->DoorW=WEST_ROOM; + MAIN_HANGAR->DoorS=SOUTH_ROOM; + MAIN_HANGAR->DoorE=EAST_HALLWAY; + MAIN_HANGAR->DoorN=NORTH_ROOM; + + //The North room has a south door leading to Main Hangar. + NORTH_ROOM->DoorS=MAIN_HANGAR; + + //The South room has a north door leading to Main Hangar. + SOUTH_ROOM->DoorN=MAIN_HANGAR; + + //The East Hallway has a west door leading to Main Hangar and an east door leading to the exit. + EAST_HALLWAY->DoorW=MAIN_HANGAR; + EAST_HALLWAY->DoorE=EAST_EXIT; + + //The East Exit has a west door leading to the East Hallway. + EAST_EXIT->DoorW=EAST_HALLWAY; + + CURRENT_ROOM=MAIN_HANGAR; //Let's start in the Main Hangar. + TextEntryEnable(true); return true; } + void OnTextEntryComplete(const std::string&str)override{ + if (str.compare("north")==0&&CURRENT_ROOM->DoorN!=nullptr) { + CURRENT_ROOM=CURRENT_ROOM->DoorN; + } + if (str.compare("east")==0&&CURRENT_ROOM->DoorE!=nullptr) { + CURRENT_ROOM=CURRENT_ROOM->DoorE; + } + if (str.compare("west")==0&&CURRENT_ROOM->DoorW!=nullptr) { + CURRENT_ROOM=CURRENT_ROOM->DoorW; + } + if (str.compare("south")==0&&CURRENT_ROOM->DoorS!=nullptr) { + CURRENT_ROOM=CURRENT_ROOM->DoorS; + } + } + bool OnUserUpdate(float fElapsedTime) override { - // called once per frame + if (!IsTextEntryEnabled()) { + TextEntryEnable(true); + } + + DrawStringDecal({0,0},"You are in the "+CURRENT_ROOM->roomName+"."); + + vi2d doorTextOffset={0,24}; + vi2d mapCenterPos={256/2-16,240-64}; + for (int i=0;i<4;i++) { + switch (i) { + case 0:{ + if (CURRENT_ROOM->DoorN!=nullptr) { //See if there's a door to the north. + DrawStringDecal(doorTextOffset,"You see a door to your North."); + vi2d northSquarePos={0,-16}; + FillRectDecal(mapCenterPos+northSquarePos,{16,16},BLUE); + doorTextOffset.y+=16; + } + }break; + case 1:{ + if (CURRENT_ROOM->DoorE!=nullptr) { //See if there's a door to the east. + DrawStringDecal(doorTextOffset,"You see a door to the East."); + vi2d eastSquarePos={16,0}; + FillRectDecal(mapCenterPos+eastSquarePos,{16,16},GREEN); + doorTextOffset.y+=16; + } + }break; + case 2:{ + if (CURRENT_ROOM->DoorS!=nullptr) { //See if there's a door to the south. + DrawStringDecal(doorTextOffset,"You see a door South of you."); + vi2d southSquarePos={0,16}; + FillRectDecal(mapCenterPos+southSquarePos,{16,16},RED); + doorTextOffset.y+=16; + } + }break; + case 3:{ + if (CURRENT_ROOM->DoorW!=nullptr) { //See if there's a door to the west. + DrawStringDecal(doorTextOffset,"You see a door on the West side."); + vi2d westSquarePos={-16,0}; + FillRectDecal(mapCenterPos+westSquarePos,{16,16},YELLOW); + doorTextOffset.y+=16; + } + }break; + } + } + + FillRect(mapCenterPos,{16,16}); + + DrawStringDecal({2,240-10},"Action: "+TextEntryGetString()); return true; } }; @@ -38,7 +132,7 @@ public: int main() { - Example demo; + DoorGame demo; if (demo.Construct(256, 240, 4, 4)) demo.Start();