|
|
|
#define OLC_PGE_APPLICATION
|
|
|
|
#include "pixelGameEngine.h"
|
|
|
|
|
|
|
|
using namespace olc;
|
|
|
|
|
|
|
|
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:
|
|
|
|
Room*CURRENT_ROOM;
|
|
|
|
DoorGame()
|
|
|
|
{
|
|
|
|
sAppName = "Rooms example";
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool OnUserCreate() override
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
DoorGame demo;
|
|
|
|
if (demo.Construct(256, 240, 4, 4))
|
|
|
|
demo.Start();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|