-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
65 lines (54 loc) · 1.64 KB
/
Game.cpp
File metadata and controls
65 lines (54 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "Game.h"
#include <raylib.h>
Game::Game()
{
this->Init();
}
Game::~Game() {}
void Game::Init()
{
handler = new CommandHandler;
player = new Player;
Room* bridge = new Room("Bridge", "This is the bridge.");
Room* cic = new Room("Combat Information Center", "This is the combat information center.");
bridge->ConnectRooms(cic, "south");
cic->ConnectRooms(bridge, "north");
Location* spaceship = new Location("Spaceship", "This is the spaceship.");
spaceship->AddRoom(bridge);
spaceship->AddRoom(cic);
player->SetLocation(spaceship);
player->SetRoom(bridge);
}
void Game::AddLocation(Location* location)
{
locations.push_back(location);
}
void Game::Update()
{
handler->UpdateInput(player);
}
void Game::Draw()
{
BeginDrawing();
ClearBackground(BLACK);
//Description Area
DrawText((player->GetLocation()->GetName() + " | " + player->GetRoom()->GetName()).c_str(), 20, 20, 20, WHITE);
//Input Area
if (handler->GetInputActive() == true)
{
//DrawText(("> " + handler->GetInput()).c_str(), 20, GetScreenHeight() - 30, 20, WHITE);
int inputStartX = 20;
if (MeasureText(("> " + handler->GetInput()).c_str(), 20) > GetScreenWidth() - 40)
{
inputStartX -= MeasureText(("> " + handler->GetInput()).c_str(), 20) - (GetScreenWidth() - 40);
}
std::string displayInput = handler->GetInput();
if (displayInput.length() > GetScreenWidth() - 20)
{
displayInput = displayInput.substr(displayInput.length() - GetScreenWidth() - 20);
}
DrawText(("> " + displayInput).c_str(), inputStartX, GetScreenHeight() - 30, 20, WHITE);
}
else DrawText("Press 'Enter' to continue.", 20, GetScreenHeight() - 30, 20, WHITE);
EndDrawing();
}