basically the whole game tbh without sound

windows
Braydon Kains 6 years ago
parent 2bb2c77c8f
commit 1575312454

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

@ -87,6 +87,16 @@
<Allegro_AddonFont>true</Allegro_AddonFont> <Allegro_AddonFont>true</Allegro_AddonFont>
<Allegro_AddonColor>true</Allegro_AddonColor> <Allegro_AddonColor>true</Allegro_AddonColor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Allegro_AddonImage>true</Allegro_AddonImage>
<Allegro_AddonTTF>true</Allegro_AddonTTF>
<Allegro_AddonPrimitives>true</Allegro_AddonPrimitives>
<Allegro_AddonAudio>true</Allegro_AddonAudio>
<Allegro_AddonAcodec>true</Allegro_AddonAcodec>
<Allegro_AddonMemfile>true</Allegro_AddonMemfile>
<Allegro_AddonFont>true</Allegro_AddonFont>
<Allegro_AddonColor>true</Allegro_AddonColor>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
@ -138,19 +148,25 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="catcher.cpp" />
<ClCompile Include="cursor.cpp" /> <ClCompile Include="cursor.cpp" />
<ClCompile Include="employee.cpp" />
<ClCompile Include="game.cpp" /> <ClCompile Include="game.cpp" />
<ClCompile Include="game_screen.cpp" /> <ClCompile Include="game_screen.cpp" />
<ClCompile Include="line.cpp" /> <ClCompile Include="line.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="result_screen.cpp" />
<ClCompile Include="start_screen.cpp" /> <ClCompile Include="start_screen.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="catcher.h" />
<ClInclude Include="cursor.h" /> <ClInclude Include="cursor.h" />
<ClInclude Include="employee.h" />
<ClInclude Include="enums.h" /> <ClInclude Include="enums.h" />
<ClInclude Include="game.h" /> <ClInclude Include="game.h" />
<ClInclude Include="game_screen.h" /> <ClInclude Include="game_screen.h" />
<ClInclude Include="line.h" /> <ClInclude Include="line.h" />
<ClInclude Include="result_screen.h" />
<ClInclude Include="screen.h" /> <ClInclude Include="screen.h" />
<ClInclude Include="start_screen.h" /> <ClInclude Include="start_screen.h" />
</ItemGroup> </ItemGroup>

@ -54,6 +54,15 @@
<ClCompile Include="line.cpp"> <ClCompile Include="line.cpp">
<Filter>Source Files\TrustFallImplement</Filter> <Filter>Source Files\TrustFallImplement</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="catcher.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="employee.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="result_screen.cpp">
<Filter>Source Files\ScreensImplement</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="cursor.h"> <ClInclude Include="cursor.h">
@ -77,5 +86,14 @@
<ClInclude Include="line.h"> <ClInclude Include="line.h">
<Filter>Header Files\TrustFall</Filter> <Filter>Header Files\TrustFall</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="catcher.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="employee.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="result_screen.h">
<Filter>Header Files\Screens</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,4 +1,6 @@
#pragma once #pragma once
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <vector> #include <vector>
template <class T> template <class T>

@ -1,6 +1,7 @@
#include "game.h" #include "game.h"
#include "start_screen.h" #include "start_screen.h"
#include "game_screen.h" #include "game_screen.h"
#include "result_screen.h"
using std::string; using std::string;
using std::map; using std::map;
@ -15,12 +16,18 @@ void Game::init() {
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Title", al_load_bitmap("logo.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("Title", al_load_bitmap("logo.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Mr. Man", al_load_bitmap("MrMan.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("Mr. Man", al_load_bitmap("MrMan.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Mr. Manager", al_load_bitmap("BigMrManager.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("Mr. Manager", al_load_bitmap("BigMrManager.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Mr. ManagerSad", al_load_bitmap("mrmanagersad.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Mr. ManagerHappy", al_load_bitmap("mrmanagerhappy.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("KeyUp", al_load_bitmap("small_key_up.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("KeyUp", al_load_bitmap("small_key_up.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Spacebar", al_load_bitmap("spacebar.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("Spacebar", al_load_bitmap("spacebar.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Employee", al_load_bitmap("employee.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("Employee", al_load_bitmap("employee.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("EmployeeHappy", al_load_bitmap("employee_happy.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("EmployeeHappy", al_load_bitmap("employee_happy.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("EmployeeSad", al_load_bitmap("employee_sad.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("EmployeeSad", al_load_bitmap("employee_sad.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Conveyor", al_load_bitmap("conveyor.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("Conveyor", al_load_bitmap("conveyor.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("KeyCtrl", al_load_bitmap("small_key_ctrl.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("KeyH", al_load_bitmap("small_key_h.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("KeyM", al_load_bitmap("small_key_m.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("KeyEsc", al_load_bitmap("small_key_esc.bmp")));
font = al_create_builtin_font(); font = al_create_builtin_font();
} }
@ -31,8 +38,9 @@ void Game::reset() {
} }
void Game::run() { void Game::run() {
GameScreen game_screen(sprites);
StartScreen start_screen(sprites); StartScreen start_screen(sprites);
GameScreen game_screen(sprites, 3); ResultScreen result_screen(sprites, 0, 0);
while (state != Exit) { while (state != Exit) {
al_clear_to_color(al_map_rgb(0, 0, 0)); al_clear_to_color(al_map_rgb(0, 0, 0));
switch (state) { switch (state) {
@ -41,9 +49,16 @@ void Game::run() {
state = start_screen.next_state; state = start_screen.next_state;
break; break;
case Gameplay: case Gameplay:
game_screen.reset(3, 5, 3);
game_screen.run(font); game_screen.run(font);
state = game_screen.next_state; state = game_screen.next_state;
break; break;
case End:
result_screen.score = game_screen.score;
result_screen.difficulty = game_screen.difficulty;
result_screen.run(font);
state = result_screen.next_state;
break;
} }
} }
} }

@ -2,6 +2,8 @@
#include <allegro5/allegro_image.h> #include <allegro5/allegro_image.h>
#include <vector> #include <vector>
#include <string> #include <string>
#include <sstream>
#include <map>
#include "game_screen.h" #include "game_screen.h"
@ -9,48 +11,86 @@
using std::vector; using std::vector;
using std::string; using std::string;
using std::ostringstream;
using std::map;
using std::pair;
GameScreen::GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, int _lines) { GameScreen::GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites) {
sprites = _sprites; sprites = _sprites;
}
void GameScreen::reset(int _lines, int _max_catchers, int _difficulty) {
if (!lines.empty()) {
lines.erase(lines.begin(), lines.begin() + _lines);
}
for (int i = 0; i < _lines; i++) { for (int i = 0; i < _lines; i++) {
Line new_line(SCREEN_W/2, SCREEN_H/_lines * i, sprites); Line new_line(SCREEN_W / 2, SCREEN_H / _lines * i, sprites);
lines.push_back(new_line); lines.push_back(new_line);
} }
selected = 0; selected = 0;
max_catchers = _max_catchers;
catchers = 0;
score = 0;
difficulty = _difficulty;
} }
void GameScreen::run(ALLEGRO_FONT * font) { void GameScreen::run(ALLEGRO_FONT* font) {
bool music = true; bool music = true;
bool help = false;
map<int, double> difficulty_map;
difficulty_map.insert(pair<int, int>(1, 15));
difficulty_map.insert(pair<int, int>(2, 12));
difficulty_map.insert(pair<int, int>(3, 10));
difficulty_map.insert(pair<int, int>(4, 8));
difficulty_map.insert(pair<int, int>(5, 5));
ALLEGRO_EVENT_QUEUE* event_queue = NULL; ALLEGRO_EVENT_QUEUE* event_queue = NULL;
event_queue = al_create_event_queue(); event_queue = al_create_event_queue();
al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_keyboard_event_source());
ALLEGRO_TIMER* timer = NULL; ALLEGRO_TIMER* timer = NULL;
timer = al_create_timer(1.5); timer = al_create_timer(0.1);
al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_timer_event_source(timer));
redraw(font); redraw(font);
al_flip_display(); al_flip_display();
int ticks = 0;
bool exit_screen = false; bool exit_screen = false;
bool ctrl = false;
al_start_timer(timer); al_start_timer(timer);
while (!exit_screen) { while (!exit_screen) {
ALLEGRO_EVENT ev; ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev); al_wait_for_event(event_queue, &ev);
if (ev.type == ALLEGRO_EVENT_TIMER) { if (ev.type == ALLEGRO_EVENT_TIMER) {
int add_to = rand() % (lines.size()+1); if (ticks == difficulty_map[difficulty]) {
for (int i = 0; i < lines.size(); i++) { int add_to = rand() % (lines.size() + 1);
if (i == add_to) { for (unsigned int i = 0; i < lines.size(); i++) {
lines.at(i).add_employee(); if (i == add_to) {
lines.at(i).add_employee();
}
lines.at(i).move();
if (lines.at(i).fall) {
exit_screen = true;
}
else if (lines.at(i).caught) {
catchers--;
score++;
if ((score == 10 || score == 20 || score == 30 || score == 40 || score == 50) && difficulty < 5) {
difficulty++;
}
}
} }
lines.at(i).move(); al_clear_to_color(al_map_rgb(0, 0, 0));
redraw(font);
al_flip_display();
ticks = 0;
}
else {
ticks++;
} }
al_clear_to_color(al_map_rgb(0, 0, 0));
redraw(font);
al_flip_display();
} }
if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
switch (ev.keyboard.keycode) { switch (ev.keyboard.keycode) {
@ -61,37 +101,98 @@ void GameScreen::run(ALLEGRO_FONT * font) {
if (selected > 0) selected--; if (selected > 0) selected--;
break; break;
case ALLEGRO_KEY_SPACE: case ALLEGRO_KEY_SPACE:
lines.at(selected).add_catcher(); if (catchers < max_catchers) {
lines.at(selected).add_catcher();
catchers++;
}
break; break;
case ALLEGRO_KEY_M: case ALLEGRO_KEY_M:
if (ev.keyboard.modifiers == ALLEGRO_KEYMOD_CTRL) { if (ev.keyboard.modifiers == ALLEGRO_KEYMOD_CTRL) {
music = false; music = !music;
} }
break; break;
case ALLEGRO_KEY_H: case ALLEGRO_KEY_H:
if (ev.keyboard.modifiers == ALLEGRO_KEYMOD_CTRL) { if (ctrl) {
music = music; //INCOMPLETE help = true;
al_clear_to_color(al_map_rgb(0, 0, 0));
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 20, ALLEGRO_ALIGN_CENTER, "Place catchers at the ends of the conveyors");
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 30, ALLEGRO_ALIGN_CENTER, "You can place 3 catchers per conveyor");
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 40, ALLEGRO_ALIGN_CENTER, "Make sure to keep track of how many catchers you have left");
al_draw_bitmap(sprites["KeyUp"], SCREEN_W / 8, SCREEN_H / 2 + 60, NULL);
al_draw_bitmap(sprites["KeyUp"], SCREEN_W / 8 + 34, SCREEN_H / 2 + 60, ALLEGRO_FLIP_VERTICAL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 68, SCREEN_H / 1.5 - 10, ALLEGRO_ALIGN_LEFT, "Up and down - Move cursor");
al_draw_bitmap(sprites["Spacebar"], SCREEN_W / 8 + 20, SCREEN_H / 2 + 100, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 68, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Spacebar - Place employee");
al_draw_bitmap(sprites["KeyEsc"], SCREEN_W / 2 + 58, SCREEN_H / 2 + 60, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2 + 113, SCREEN_H / 1.5 - 10, ALLEGRO_ALIGN_LEFT, "Close menu");
al_draw_bitmap(sprites["KeyCtrl"], SCREEN_W / 2 + 40, SCREEN_H / 2 + 100, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2 + 70, SCREEN_H / 2 + 110, ALLEGRO_ALIGN_LEFT, "+");
al_draw_bitmap(sprites["KeyM"], SCREEN_W / 2 + 78, SCREEN_H / 2 + 100, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2 + 113, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Toggle Music");
al_flip_display();
while (help) {
ALLEGRO_EVENT unhelp;
al_wait_for_event(event_queue, &unhelp);
if (unhelp.type == ALLEGRO_EVENT_KEY_DOWN) {
if (unhelp.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
help = false;
}
}
}
} }
break; break;
case ALLEGRO_KEY_ESCAPE: case ALLEGRO_KEY_ESCAPE:
next_state = Exit; back();
exit_screen = true; exit_screen = true;
break; break;
case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL:
ctrl = true;
break;
}
if (ev.type == ALLEGRO_EVENT_KEY_UP) {
if (ev.keyboard.keycode == ALLEGRO_KEY_LCTRL || ev.keyboard.keycode == ALLEGRO_KEY_RCTRL) {
ctrl = false;
}
} }
al_clear_to_color(al_map_rgb(0, 0, 0)); al_clear_to_color(al_map_rgb(0, 0, 0));
redraw(font); redraw(font);
al_flip_display(); al_flip_display();
} }
} }
if (next_state != Exit) {
cont();
}
al_rest(2.0);
} }
void GameScreen::redraw(ALLEGRO_FONT* font) { void GameScreen::redraw(ALLEGRO_FONT* font) {
al_draw_bitmap(sprites["Mr. Manager"], 10, 0 + (SCREEN_H / lines.size() * selected), NULL); al_draw_bitmap(sprites["Mr. Manager"], 80, 0 + (SCREEN_H / lines.size() * selected), NULL);
for (int i = 0; i < lines.size(); i++) { for (unsigned int i = 0; i < lines.size(); i++) {
lines.at(i).draw(); lines.at(i).draw();
} }
ostringstream score_msg;
score_msg << "Score: " << score;
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W - 90, 0, ALLEGRO_ALIGN_LEFT, score_msg.str().c_str());
al_draw_bitmap(sprites["Mr. Man"], SCREEN_W - 90, 20, NULL);
ostringstream catcher_msg;
catcher_msg << " x " << max_catchers - catchers;
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W - 50, 30, ALLEGRO_ALIGN_LEFT, catcher_msg.str().c_str());
ostringstream difficulty_msg;
difficulty_msg << "Level: " << difficulty;
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W - 90, 75, ALLEGRO_ALIGN_LEFT, difficulty_msg.str().c_str());
} }
void GameScreen::back() { void GameScreen::back() {

@ -7,9 +7,14 @@ public:
std::map<std::string, ALLEGRO_BITMAP*> sprites; std::map<std::string, ALLEGRO_BITMAP*> sprites;
std::vector<Line> lines; std::vector<Line> lines;
int selected; int selected;
int max_catchers;
int catchers;
int score;
int difficulty;
GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, int _lines); GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites);
void reset(int _lines, int _max_catchers, int _difficulty);
void run(ALLEGRO_FONT* font); void run(ALLEGRO_FONT* font);
void redraw(ALLEGRO_FONT* font); void redraw(ALLEGRO_FONT* font);
void back(); void back();

@ -21,23 +21,27 @@ Line::Line(int _start_x, int _start_y, map<string, ALLEGRO_BITMAP*> _sprites) {
} }
void Line::move() { void Line::move() {
if (caught) {
caught = false;
catchers[0] = catchers[1];
catchers[1] = catchers[2];
catchers[2] = 0;
}
for (int i = 0; i < 5; i++) {
employees[i] = employees[i + 1];
}
employees[5] = (queued) ? 1 : 0;
queued = false;
if (employees[0]) { if (employees[0]) {
if (catchers[0]) { if (catchers[0]) {
caught = true; caught = true;
catchers[0] = catchers[1];
catchers[1] = catchers[0];
catchers[2] = 0;
} }
else { else {
fall = true; fall = true;
} }
} }
for (int i = 0; i < 4; i++) {
employees[i] = employees[i + 1];
}
employees[4] = (queued) ? 1 : 0;
queued = false;
} }
void Line::add_employee() { void Line::add_employee() {
@ -45,7 +49,7 @@ void Line::add_employee() {
} }
void Line::add_catcher() { void Line::add_catcher() {
for (int i = 2; i > -1; i--) { for (int i = 0; i < 3; i++) {
if (!catchers[i]) { if (!catchers[i]) {
catchers[i] = 1; catchers[i] = 1;
break; break;
@ -56,31 +60,23 @@ void Line::add_catcher() {
void Line::draw() { void Line::draw() {
al_draw_bitmap(sprites["Conveyor"], start_x, start_y, NULL); al_draw_bitmap(sprites["Conveyor"], start_x, start_y, NULL);
for (int i = 0; i < 5; i++) { for (int i = 1; i < 6; i++) {
if (employees[i]) { if (employees[i]) {
al_draw_bitmap(sprites["Employee"], start_x + (40 * i), start_y, NULL); al_draw_bitmap(sprites["Employee"], start_x + (40 * (i-1)), start_y, NULL);
} }
} }
for (int i = 2; i > -1; i--) { for (int i = 2; i > -1; i--) {
if (i = 0) { if (i == 0) {
if (caught) { if (caught) {
al_draw_bitmap(sprites["EmployeeHappy"], start_x - 40, start_y, NULL); al_draw_bitmap(sprites["EmployeeHappy"], start_x - 40, start_y, NULL);
caught = false;
} }
else if (fall) { else if (fall) {
al_draw_bitmap(sprites["EmployeeSad"], start_x - 40, start_y - 55, ALLEGRO_FLIP_VERTICAL); al_draw_bitmap(sprites["EmployeeSad"], start_x - 40, start_y + 55, ALLEGRO_FLIP_VERTICAL);
}
else {
if (catchers[i]) {
al_draw_bitmap(sprites["Mr. Man"], start_x - 40, start_y - 40, NULL);
}
} }
} }
else { if (catchers[i]) {
if (catchers[i]) { al_draw_bitmap(sprites["Mr. Man"], start_x - 40 - (50*(i)), start_y + 40, NULL);
al_draw_bitmap(sprites["Mr. Man"], start_x - 40 - (50*(i)), start_y + 40, NULL);
}
} }
} }
} }

@ -15,7 +15,7 @@ public:
std::map<std::string, ALLEGRO_BITMAP*> sprites; std::map<std::string, ALLEGRO_BITMAP*> sprites;
int catchers[3]; int catchers[3];
int employees[5]; int employees[6];
bool queued; bool queued;
bool fall; bool fall;

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

@ -0,0 +1,88 @@
#include <vector>
#include <sstream>
#include "result_screen.h"
using std::string;
using std::vector;
using std::ostringstream;
ResultScreen::ResultScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, int _score, int _difficulty) {
score = _score;
difficulty = _difficulty;
vector<string> menu_options;
menu_options.push_back("Retry");
menu_options.push_back("To Main Menu");
menu_options.push_back("Exit");
menu.activate(menu_options);
sprites = _sprites;
}
void ResultScreen::run(ALLEGRO_FONT* font) {
ALLEGRO_EVENT_QUEUE* event_queue = NULL;
event_queue = al_create_event_queue();
al_register_event_source(event_queue, al_get_keyboard_event_source());
redraw(font);
al_flip_display();
bool exit_screen = false;
while (!exit_screen) {
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);
if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
switch (ev.keyboard.keycode) {
case ALLEGRO_KEY_UP:
menu.up();
break;
case ALLEGRO_KEY_DOWN:
menu.down();
break;
case ALLEGRO_KEY_ENTER:
cont();
exit_screen = true;
break;
case ALLEGRO_KEY_ESCAPE:
back();
exit_screen = true;
break;
}
redraw(font);
al_flip_display();
}
}
}
void ResultScreen::redraw(ALLEGRO_FONT * font) {
string manager_sprite = (score > 29) ? "Mr. ManagerHappy" : "Mr. ManagerSad";
string result_text = (score > 29) ? "Great job! You helped Mr. Manager's team feel more close together!" : "You didn't catch a lot of employees. Try to catch more next time!";
al_draw_bitmap(sprites[manager_sprite], SCREEN_W / 2 - 120, SCREEN_H / 2 - 40, NULL);
menu.draw(SCREEN_W / 2, SCREEN_H / 2 - 30, 20.0, font);
ostringstream score_msg;
score_msg << "Final Score: " << score;
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 - 90, ALLEGRO_ALIGN_CENTER, score_msg.str().c_str());
ostringstream difficulty_msg;
difficulty_msg << "Level: " << difficulty;
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 - 75, ALLEGRO_ALIGN_CENTER, difficulty_msg.str().c_str());
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 - 60, ALLEGRO_ALIGN_CENTER, result_text.c_str());
}
void ResultScreen::back() {
next_state = Exit;
}
void ResultScreen::cont() {
string result = menu.get_selected();
if(result == "Retry") {
next_state = Gameplay;
}
else if (result == "To Main Menu") {
next_state = Start;
}
else {
next_state = Exit;
}
}

@ -0,0 +1,18 @@
#pragma once
#include "cursor.h"
#include "screen.h"
class ResultScreen : public Screen {
public:
int score;
int difficulty;
Cursor<std::string> menu;
std::map<std::string, ALLEGRO_BITMAP*> sprites;
ResultScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, int _score, int _difficulty);
void run(ALLEGRO_FONT* font);
void redraw(ALLEGRO_FONT* font);
void back();
void cont();
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@ -63,12 +63,22 @@ void StartScreen::redraw(ALLEGRO_FONT* font) {
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 30, ALLEGRO_ALIGN_CENTER, "Help Mr.Manager place his employees at the end of his"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 30, ALLEGRO_ALIGN_CENTER, "Help Mr.Manager place his employees at the end of his");
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 40, ALLEGRO_ALIGN_CENTER, "conveyor belts to make sure no other employees fall off."); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 40, ALLEGRO_ALIGN_CENTER, "conveyor belts to make sure no other employees fall off.");
al_draw_bitmap(sprites["KeyUp"], SCREEN_W / 3, SCREEN_H / 2 + 60, NULL); al_draw_bitmap(sprites["KeyUp"], SCREEN_W / 8, SCREEN_H / 2 + 60, NULL);
al_draw_bitmap(sprites["KeyUp"], SCREEN_W / 3 + 34, SCREEN_H / 2 + 60, ALLEGRO_FLIP_VERTICAL); al_draw_bitmap(sprites["KeyUp"], SCREEN_W / 8 + 34, SCREEN_H / 2 + 60, ALLEGRO_FLIP_VERTICAL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 1.5 - 10, ALLEGRO_ALIGN_LEFT, "Up and down - Move cursor"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 68, SCREEN_H / 1.5 - 10, ALLEGRO_ALIGN_LEFT, "Up and down - Move cursor");
al_draw_bitmap(sprites["Spacebar"], SCREEN_W / 3 + 20, SCREEN_H / 2 + 100, NULL); al_draw_bitmap(sprites["Spacebar"], SCREEN_W / 8 + 20, SCREEN_H / 2 + 100, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Spacebar - Place employee"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 68, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Spacebar - Place employee");
al_draw_bitmap(sprites["KeyCtrl"], SCREEN_W / 2 + 40, SCREEN_H / 2 + 60, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2 + 70, SCREEN_H / 1.5 - 10, ALLEGRO_ALIGN_LEFT, "+");
al_draw_bitmap(sprites["KeyH"], SCREEN_W / 2 + 78, SCREEN_H / 2 + 60, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2 + 113, SCREEN_H / 1.5 - 10, ALLEGRO_ALIGN_LEFT, "Help menu");
al_draw_bitmap(sprites["KeyCtrl"], SCREEN_W / 2 + 40, SCREEN_H / 2 + 100, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2 + 70, SCREEN_H / 2 + 110, ALLEGRO_ALIGN_LEFT, "+");
al_draw_bitmap(sprites["KeyM"], SCREEN_W / 2 + 78, SCREEN_H / 2 + 100, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2 + 113, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Toggle Music");
} }
void StartScreen::back() { void StartScreen::back() {

Loading…
Cancel
Save