Compare commits

..

2 Commits

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Before

Width:  |  Height:  |  Size: 306 B

After

Width:  |  Height:  |  Size: 306 B

Before

Width:  |  Height:  |  Size: 211 KiB

After

Width:  |  Height:  |  Size: 211 KiB

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

@ -22,32 +22,32 @@
<VCProjectVersion>15.0</VCProjectVersion> <VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{C6900ECF-254F-4751-A968-DDA699CCD5A6}</ProjectGuid> <ProjectGuid>{C6900ECF-254F-4751-A968-DDA699CCD5A6}</ProjectGuid>
<RootNamespace>TrustFall</RootNamespace> <RootNamespace>TrustFall</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
@ -144,6 +144,9 @@
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="cursor.cpp" /> <ClCompile Include="cursor.cpp" />
<ClCompile Include="game.cpp" /> <ClCompile Include="game.cpp" />
@ -163,19 +166,16 @@
<ClInclude Include="screen.h" /> <ClInclude Include="screen.h" />
<ClInclude Include="start_screen.h" /> <ClInclude Include="start_screen.h" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\AllegroDeps.1.12.0\build\native\AllegroDeps.targets" Condition="Exists('..\packages\AllegroDeps.1.12.0\build\native\AllegroDeps.targets')" /> <Import Project="..\packages\AllegroDeps.1.7.0.0\build\native\AllegroDeps.targets" Condition="Exists('..\packages\AllegroDeps.1.7.0.0\build\native\AllegroDeps.targets')" />
<Import Project="..\packages\Allegro.5.2.7\build\native\Allegro.targets" Condition="Exists('..\packages\Allegro.5.2.7\build\native\Allegro.targets')" /> <Import Project="..\packages\Allegro.5.2.4.0\build\native\Allegro.targets" Condition="Exists('..\packages\Allegro.5.2.4.0\build\native\Allegro.targets')" />
</ImportGroup> </ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\AllegroDeps.1.12.0\build\native\AllegroDeps.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\AllegroDeps.1.12.0\build\native\AllegroDeps.targets'))" /> <Error Condition="!Exists('..\packages\AllegroDeps.1.7.0.0\build\native\AllegroDeps.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\AllegroDeps.1.7.0.0\build\native\AllegroDeps.targets'))" />
<Error Condition="!Exists('..\packages\Allegro.5.2.7\build\native\Allegro.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Allegro.5.2.7\build\native\Allegro.targets'))" /> <Error Condition="!Exists('..\packages\Allegro.5.2.4.0\build\native\Allegro.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Allegro.5.2.4.0\build\native\Allegro.targets'))" />
</Target> </Target>
</Project> </Project>

@ -32,6 +32,9 @@
<UniqueIdentifier>{b26b82a2-f4cd-444a-923f-82aad7c96345}</UniqueIdentifier> <UniqueIdentifier>{b26b82a2-f4cd-444a-923f-82aad7c96345}</UniqueIdentifier>
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
@ -81,7 +84,4 @@
<Filter>Header Files\Screens</Filter> <Filter>Header Files\Screens</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project> </Project>

@ -1,31 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2042
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrustFall", "TrustFall\TrustFall.vcxproj", "{C6900ECF-254F-4751-A968-DDA699CCD5A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C6900ECF-254F-4751-A968-DDA699CCD5A6}.Debug|x64.ActiveCfg = Debug|x64
{C6900ECF-254F-4751-A968-DDA699CCD5A6}.Debug|x64.Build.0 = Debug|x64
{C6900ECF-254F-4751-A968-DDA699CCD5A6}.Debug|x86.ActiveCfg = Debug|Win32
{C6900ECF-254F-4751-A968-DDA699CCD5A6}.Debug|x86.Build.0 = Debug|Win32
{C6900ECF-254F-4751-A968-DDA699CCD5A6}.Release|x64.ActiveCfg = Release|x64
{C6900ECF-254F-4751-A968-DDA699CCD5A6}.Release|x64.Build.0 = Release|x64
{C6900ECF-254F-4751-A968-DDA699CCD5A6}.Release|x86.ActiveCfg = Release|Win32
{C6900ECF-254F-4751-A968-DDA699CCD5A6}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {33B495B4-3A19-4588-AA7F-6E664C8E0C19}
EndGlobalSection
EndGlobal

Binary file not shown.

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Allegro" version="5.2.7" targetFramework="native" />
<package id="AllegroDeps" version="1.12.0" targetFramework="native" />
</packages>

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

@ -9,102 +9,102 @@
using std::string; using std::string;
using std::vector; using std::vector;
template<class T> template<class T>
Cursor<T>::Cursor() Cursor<T>::Cursor()
{ {
active = false; active = false;
} }
//Give items to the cursor, and set the selected item to be the first //Give items to the cursor, and set the selected item to be the first
template<class T> template<class T>
void Cursor<T>::activate(std::vector<T> _items) void Cursor<T>::activate(std::vector<T> _items)
{ {
items = _items; items = _items;
selected = 0; selected = 0;
active = true; active = true;
} }
//Functionality that was not used for this game, may be used in future projects. //Functionality that was not used for this game, may be used in future projects.
template<class T> template<class T>
void Cursor<T>::deactivate() void Cursor<T>::deactivate()
{ {
active = false; active = false;
} }
//Draw the menu options on the screen based on the x and y coordinates for the menu to start at //Draw the menu options on the screen based on the x and y coordinates for the menu to start at
template<class T> template<class T>
void Cursor<T>::draw(float _x_start, float _y_start, float _y_offset, ALLEGRO_FONT* _font) { void Cursor<T>::draw(float _x_start, float _y_start, float _y_offset, ALLEGRO_FONT* _font) {
vector<string> items_text = get_item_strings(); vector<string> items_text = get_item_strings();
x_start = _x_start; x_start = _x_start;
y_start = _y_start; y_start = _y_start;
y_offset = _y_offset; y_offset = _y_offset;
font = _font; font = _font;
for (unsigned int i = 0; i < items_text.size(); i++) { for (unsigned int i = 0; i < items_text.size(); i++) {
al_draw_text(font, al_map_rgb(255, 255, 255), x_start, y_start + (y_offset*i), ALLEGRO_ALIGN_LEFT, items_text.at(i).c_str()); al_draw_text(font, al_map_rgb(255, 255, 255), x_start, y_start + (y_offset*i), ALLEGRO_ALIGN_LEFT, items_text.at(i).c_str());
} }
update_selector(); update_selector();
} }
//Change the selection of the cursor //Change the selection of the cursor
template<class T> template<class T>
void Cursor<T>::down() void Cursor<T>::down()
{ {
if (selected < items.size() - 1) { if (selected < items.size() - 1) {
selected++; selected++;
redraw(); redraw();
} }
} }
template<class T> template<class T>
void Cursor<T>::up() void Cursor<T>::up()
{ {
if (selected > 0) { if (selected > 0) {
selected--; selected--;
redraw(); redraw();
} }
} }
template<class T> template<class T>
T Cursor<T>::get_selected() { T Cursor<T>::get_selected() {
return items.at(selected); return items.at(selected);
} }
//Clear screen before drawing menu //Clear screen before drawing menu
template<class T> template<class T>
void Cursor<T>::redraw() void Cursor<T>::redraw()
{ {
al_clear_to_color(al_map_rgb(0, 0, 0)); al_clear_to_color(al_map_rgb(0, 0, 0));
draw(x_start, y_start, y_offset, font); draw(x_start, y_start, y_offset, font);
} }
//Draw selector to highlight proper selected item //Draw selector to highlight proper selected item
template<class T> template<class T>
void Cursor<T>::update_selector() { void Cursor<T>::update_selector() {
ALLEGRO_COLOR white = al_map_rgb(255, 255, 255); ALLEGRO_COLOR white = al_map_rgb(255, 255, 255);
float offset = y_offset * selected; float offset = y_offset * selected;
float x1 = x_start - 5; float x1 = x_start - 5;
float y1 = y_start + offset; float y1 = y_start + offset;
float x2 = x_start - 5; float x2 = x_start - 5;
float y2 = y_start + 5 + offset; float y2 = y_start + 5 + offset;
float x3 = x_start - 1; float x3 = x_start - 1;
float y3 = y_start + 2.5 + offset; float y3 = y_start + 2.5 + offset;
al_draw_filled_triangle(x1, y1, x2, y2, x3, y3, white); al_draw_filled_triangle(x1, y1, x2, y2, x3, y3, white);
} }
//Define how the template will function when given various types. Only string was needed for this project. //Define how the template will function when given various types. Only string was needed for this project.
template Cursor<string>::Cursor(); template Cursor<string>::Cursor();
template void Cursor<string>::activate(std::vector<string> _options); template void Cursor<string>::activate(std::vector<string> _options);
template void Cursor<string>::deactivate(); template void Cursor<string>::deactivate();
template void Cursor<string>::draw(float x_start, float y_start, float _y_offset, ALLEGRO_FONT* font); template void Cursor<string>::draw(float x_start, float y_start, float _y_offset, ALLEGRO_FONT* font);
template void Cursor<string>::redraw(); template void Cursor<string>::redraw();
template void Cursor<string>::up(); template void Cursor<string>::up();
template void Cursor<string>::down(); template void Cursor<string>::down();
template string Cursor<string>::get_selected(); template string Cursor<string>::get_selected();
template void Cursor<string>::update_selector(); template void Cursor<string>::update_selector();
vector<string> Cursor<string>::get_item_strings() { vector<string> Cursor<string>::get_item_strings() {
return items; return items;
} }

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

@ -11,49 +11,46 @@ Game::Game() {
} }
//Load all global data for the game: sprites, audio, and font. //Load all global data for the game: sprites, audio, and font.
void Game::init() { void Game::init() {
score = 0; score = 0;
state = Start; state = Start;
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. 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*>("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*>("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*>("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*>("KeyM", al_load_bitmap("small_key_m.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("KeyEsc", al_load_bitmap("small_key_esc.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("KeyEsc", al_load_bitmap("small_key_esc.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("MusicOn", al_load_bitmap("music_on.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("MusicOn", al_load_bitmap("music_on.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("MusicOff", al_load_bitmap("music_off.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("MusicOff", al_load_bitmap("music_off.bmp")));
al_reserve_samples(4); al_reserve_samples(4);
samples.insert(pair<string, ALLEGRO_SAMPLE*>("Move", al_load_sample("move.wav"))); samples.insert(pair<string, ALLEGRO_SAMPLE*>("Theme", al_load_sample("rasputin.wav")));
samples.insert(pair<string, ALLEGRO_SAMPLE*>("Catch", al_load_sample("catch.wav"))); samples.insert(pair<string, ALLEGRO_SAMPLE*>("Move", al_load_sample("move.wav")));
samples.insert(pair<string, ALLEGRO_SAMPLE*>("Fall", al_load_sample("fall.wav"))); samples.insert(pair<string, ALLEGRO_SAMPLE*>("Catch", al_load_sample("catch.wav")));
samples.insert(pair<string, ALLEGRO_SAMPLE*>("Place", al_load_sample("place.wav"))); samples.insert(pair<string, ALLEGRO_SAMPLE*>("Fall", al_load_sample("fall.wav")));
samples.insert(pair<string, ALLEGRO_SAMPLE*>("LevelUp", al_load_sample("level.wav"))); samples.insert(pair<string, ALLEGRO_SAMPLE*>("Place", al_load_sample("place.wav")));
samples.insert(pair<string, ALLEGRO_SAMPLE*>("LevelUp", al_load_sample("level.wav")));
themes.insert(pair<string, ALLEGRO_SAMPLE*>("Rasputin", al_load_sample("rasputin.wav")));
themes.insert(pair<string, ALLEGRO_SAMPLE*>("Guile", al_load_sample("guile.wav"))); font = al_create_builtin_font();
themes.insert(pair<string, ALLEGRO_SAMPLE*>("Mine", al_load_sample("customtheme.wav"))); }
font = al_create_builtin_font(); //Was not used in this project
} void Game::reset() {
}
//Was not used in this project
void Game::reset() {
}
//Run the game state machine //Run the game state machine
void Game::run() { void Game::run() {
//Load screens //Load screens
GameScreen game_screen(sprites, samples, themes); GameScreen game_screen(sprites, samples);
StartScreen start_screen(sprites); StartScreen start_screen(sprites);
ResultScreen result_screen(sprites, 0, 0, Easy); ResultScreen result_screen(sprites, 0, 0, Easy);
int difficulty = 1; //Difficulty to run int difficulty = 1; //Difficulty to run
@ -115,8 +112,4 @@ void Game::run() {
for (it2 = samples.begin(); it2 != samples.end(); it2++) { for (it2 = samples.begin(); it2 != samples.end(); it2++) {
al_destroy_sample(it2->second); al_destroy_sample(it2->second);
} }
map<string, ALLEGRO_SAMPLE*>::iterator it3; }
for (it3 = themes.begin(); it3 != themes.end(); it3++) {
al_destroy_sample(it3->second);
}
}

@ -1,37 +1,36 @@
#pragma once #pragma once
#include <allegro5/allegro.h> #include <allegro5/allegro.h>
#include <allegro5/allegro_font.h> #include <allegro5/allegro_font.h>
#include <allegro5/allegro_image.h> #include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h> #include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_audio.h> #include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h> #include <allegro5/allegro_acodec.h>
#include <vector> #include <vector>
#include <string> #include <string>
#include <map> #include <map>
#include "enums.h" #include "enums.h"
//Game state machine, contains data global to game //Game state machine, contains data global to game
class Game { class Game {
public: public:
//Allegro elements //Allegro elements
ALLEGRO_FONT* font; ALLEGRO_FONT* font;
//Game elements //Game elements
State state; State state;
int score; int score;
std::map<std::string, ALLEGRO_BITMAP*> sprites; std::map<std::string, ALLEGRO_BITMAP*> sprites;
std::map<std::string, ALLEGRO_SAMPLE*> samples; std::map<std::string, ALLEGRO_SAMPLE*> samples;
std::map<std::string, ALLEGRO_SAMPLE*> themes;
Game();
Game();
void init();
void init(); void run();
void run();
private:
private: void reset();
void reset(); };
};

@ -1,284 +1,275 @@
#include <allegro5/allegro.h> #include <allegro5/allegro.h>
#include <allegro5/allegro_image.h> #include <allegro5/allegro_image.h>
#include <allegro5/allegro_audio.h> #include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h> #include <allegro5/allegro_acodec.h>
#include <vector> #include <vector>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <map> #include <map>
#include <ctime> #include <ctime>
#include "game_screen.h" #include "game_screen.h"
#define FPS 60 #define FPS 60
using std::vector; using std::vector;
using std::string; using std::string;
using std::ostringstream; using std::ostringstream;
using std::map; using std::map;
using std::pair; using std::pair;
GameScreen::GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, std::map<std::string, ALLEGRO_SAMPLE*> _samples, std::map<std::string, ALLEGRO_SAMPLE*> _themes) { GameScreen::GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, std::map<std::string, ALLEGRO_SAMPLE*> _samples) {
sprites = _sprites; sprites = _sprites;
samples = _samples; samples = _samples;
themes = _themes; srand(time(NULL)); //Seed random number generator with current time so sequence is unique each run
srand(time(NULL)); //Seed random number generator with current time so sequence is unique each run }
}
//Resets game to default values, and uses new given values
//Resets game to default values, and uses new given values void GameScreen::reset(int _lines, int _max_catchers, int _difficulty) {
void GameScreen::reset(int _lines, int _max_catchers, int _difficulty) { lines.clear();
lines.clear(); 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;
max_catchers = _max_catchers; catchers = 0;
catchers = 0; score = 0;
score = 0; difficulty = _difficulty;
difficulty = _difficulty; music = true;
music = true; }
}
//If a sample needs to be played while it is still being played, it will be stopped first.
//If a sample needs to be played while it is still being played, it will be stopped first. //Admittedly this was a hack solution to the fact that my sound effect samples are too long.
//Admittedly this was a hack solution to the fact that my sound effect samples are too long. //In future projects I will use a better program for sound effect creation that does not have a large minimum length for audio export.
//In future projects I will use a better program for sound effect creation that does not have a large minimum length for audio export. void play(ALLEGRO_SAMPLE_INSTANCE* x) {
void play(ALLEGRO_SAMPLE_INSTANCE* x) { if (al_get_sample_instance_playing(x)) {
if (al_get_sample_instance_playing(x)) { al_stop_sample_instance(x);
al_stop_sample_instance(x); }
} al_play_sample_instance(x);
al_play_sample_instance(x); }
}
void GameScreen::run(ALLEGRO_FONT* font) {
void GameScreen::run(ALLEGRO_FONT* font) { //Map that represents difficulty scale
//Map that represents difficulty scale map<int, double> difficulty_map;
map<int, double> difficulty_map; difficulty_map.insert(pair<int, int>(1, 15));
difficulty_map.insert(pair<int, int>(1, 15)); difficulty_map.insert(pair<int, int>(2, 12));
difficulty_map.insert(pair<int, int>(2, 12)); difficulty_map.insert(pair<int, int>(3, 10));
difficulty_map.insert(pair<int, int>(3, 10)); difficulty_map.insert(pair<int, int>(4, 8));
difficulty_map.insert(pair<int, int>(4, 8)); difficulty_map.insert(pair<int, int>(5, 5));
difficulty_map.insert(pair<int, int>(5, 5)); difficulty_map.insert(pair<int, int>(6, 3));
difficulty_map.insert(pair<int, int>(6, 3)); difficulty_map.insert(pair<int, int>(7, 2));
difficulty_map.insert(pair<int, int>(7, 2));
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(0.1); //Universally a "tick" in the context of the game is 1/10 of a second.
timer = al_create_timer(0.1); //Universally a "tick" in the context of the game is 1/10 of a second. 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();
//Create map of sample instances. This is more memory efficient than play samples over and over again individually,
//Create map of sample instances. This is more memory efficient than play samples over and over again individually, //and allows the anti-overlap functionality implemented above.
//and allows the anti-overlap functionality implemented above. map<string, ALLEGRO_SAMPLE_INSTANCE*> instances;
map<string, ALLEGRO_SAMPLE_INSTANCE*> instances; map<string, ALLEGRO_SAMPLE*>::iterator it;
map<string, ALLEGRO_SAMPLE_INSTANCE*> theme_instances; for (it = samples.begin(); it != samples.end(); it++) {
map<string, ALLEGRO_SAMPLE*>::iterator it; instances.insert(pair<string, ALLEGRO_SAMPLE_INSTANCE*>(it->first, al_create_sample_instance(it->second)));
for (it = samples.begin(); it != samples.end(); it++) { al_attach_sample_instance_to_mixer(instances[it->first], al_get_default_mixer());
instances.insert(pair<string, ALLEGRO_SAMPLE_INSTANCE*>(it->first, al_create_sample_instance(it->second))); }
al_attach_sample_instance_to_mixer(instances[it->first], al_get_default_mixer());
} al_set_sample_instance_playmode(instances["Theme"], ALLEGRO_PLAYMODE_LOOP);
for (it = themes.begin(); it != themes.end(); it++) { play(instances["Theme"]);
theme_instances.insert(pair<string, ALLEGRO_SAMPLE_INSTANCE*>(it->first, al_create_sample_instance(it->second)));
al_attach_sample_instance_to_mixer(theme_instances[it->first], al_get_default_mixer()); int ticks = 0; //Counts the number of ticks, this is used to determine when to move the lines
} bool exit_screen = false;
bool ctrl = false; //whether ctrl key is currently held
map<string, ALLEGRO_SAMPLE_INSTANCE*>::iterator theme_it = theme_instances.begin(); bool help = false; //whether help screen is currently displayed
std::advance(theme_it, rand() % (theme_instances.size()));
al_set_sample_instance_playmode(theme_it->second, ALLEGRO_PLAYMODE_LOOP); al_start_timer(timer);
play(theme_it->second); while (!exit_screen) {
ALLEGRO_EVENT ev;
int ticks = 0; //Counts the number of ticks, this is used to determine when to move the lines al_wait_for_event(event_queue, &ev);
bool exit_screen = false; if (ev.type == ALLEGRO_EVENT_TIMER) {
bool ctrl = false; //whether ctrl key is currently held if (ticks == difficulty_map[difficulty]) { //If at the current difficulty level, the lines are due to move
bool help = false; //whether help screen is currently displayed int add_to = rand() % (lines.size() + 1); //Randomly decide which line to add to, with a 1/lines.size() chance of not adding
for (unsigned int i = 0; i < lines.size(); i++) {
al_start_timer(timer); if (i == add_to) {
while (!exit_screen) { lines.at(i).add_employee();
ALLEGRO_EVENT ev; }
al_wait_for_event(event_queue, &ev); lines.at(i).move(); //Every line will move regardless of any factors
if (ev.type == ALLEGRO_EVENT_TIMER) { if (lines.at(i).fall) { //If an employee has fallen, the game is over
if (ticks == difficulty_map[difficulty]) { //If at the current difficulty level, the lines are due to move map<string, ALLEGRO_SAMPLE_INSTANCE*>::iterator in_it;
int add_to = rand() % (lines.size() + 1); //Randomly decide which line to add to, with a 1/lines.size() chance of not adding for (in_it = instances.begin(); in_it != instances.end(); in_it++) {
for (unsigned int i = 0; i < lines.size(); i++) { al_stop_sample_instance(in_it->second);
if (i == add_to) { }
lines.at(i).add_employee(); al_play_sample_instance(instances["Fall"]);
} exit_screen = true;
lines.at(i).move(); //Every line will move regardless of any factors al_clear_to_color(al_map_rgb(0, 0, 0));
if (lines.at(i).fall) { //If an employee has fallen, the game is over redraw(font);
map<string, ALLEGRO_SAMPLE_INSTANCE*>::iterator in_it; al_flip_display();
for (in_it = instances.begin(); in_it != instances.end(); in_it++) { al_rest(2.0);
al_stop_sample_instance(in_it->second); }
} else if (lines.at(i).caught) { //If an employee is caught, add to the score and then check if difficulty should be adjusted
al_stop_sample_instance(theme_it->second); play(instances["Catch"]);
al_play_sample_instance(instances["Fall"]); catchers--;
exit_screen = true; score++;
al_clear_to_color(al_map_rgb(0, 0, 0)); if ((score == 10 || score == 20 || score == 30 || score == 40 || score == 50 || score == 75 || score == 100) && difficulty < 7) {
redraw(font); play(instances["LevelUp"]);
al_flip_display(); difficulty++;
al_rest(2.0); }
} }
else if (lines.at(i).caught) { //If an employee is caught, add to the score and then check if difficulty should be adjusted }
play(instances["Catch"]); //Refresh screen
catchers--; al_clear_to_color(al_map_rgb(0, 0, 0));
score++; redraw(font);
if ((score == 10 || score == 20 || score == 30 || score == 40 || score == 50 || score == 75 || score == 100) && difficulty < 7) { al_flip_display();
play(instances["LevelUp"]); ticks = 0; //reset ticks
difficulty++; }
} else {
} //if not time to move, add to ticks
} ticks++;
//Refresh screen }
al_clear_to_color(al_map_rgb(0, 0, 0)); }
redraw(font); if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
al_flip_display(); switch (ev.keyboard.keycode) {
ticks = 0; //reset ticks case ALLEGRO_KEY_DOWN:
} play(instances["Move"]);
else { if (selected < lines.size() - 1) selected++;
//if not time to move, add to ticks break;
ticks++; case ALLEGRO_KEY_UP:
} play(instances["Move"]);
} if (selected > 0) selected--;
if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { break;
switch (ev.keyboard.keycode) { case ALLEGRO_KEY_SPACE:
case ALLEGRO_KEY_DOWN: if (catchers < max_catchers) {
play(instances["Move"]); if (!lines.at(selected).catchers[2]) {
if (selected < lines.size() - 1) selected++; play(instances["Place"]);
break; lines.at(selected).add_catcher();
case ALLEGRO_KEY_UP: catchers++;
play(instances["Move"]); }
if (selected > 0) selected--; }
break; break;
case ALLEGRO_KEY_SPACE: case ALLEGRO_KEY_M:
if (catchers < max_catchers) { //Toggle music
if (!lines.at(selected).catchers[2]) { if (ctrl) {
play(instances["Place"]); if (music) {
lines.at(selected).add_catcher(); al_stop_sample_instance(instances["Theme"]);
catchers++; }
} else {
} al_play_sample_instance(instances["Theme"]);
break; }
case ALLEGRO_KEY_M: music = !music;
//Toggle music }
if (ctrl) { break;
if (music) { case ALLEGRO_KEY_H:
al_stop_sample_instance(theme_it->second); if (ctrl) {
} help = true; //help screen is up
else {
al_play_sample_instance(theme_it->second); //Draw the help screen
} al_clear_to_color(al_map_rgb(0, 0, 0));
music = !music;
}
break;
case ALLEGRO_KEY_H:
if (ctrl) {
help = true; //help screen is up
//Draw the help screen
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 + 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 + 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_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, SCREEN_H / 2 + 60, NULL);
al_draw_bitmap(sprites["KeyUp"], SCREEN_W / 8 + 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 / 8 + 68, 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 / 8 + 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 / 8 + 68, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Spacebar - "); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 68, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Spacebar - ");
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 150, SCREEN_H / 1.3 - 15, ALLEGRO_ALIGN_LEFT, "Place Employee"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 150, SCREEN_H / 1.3 - 15, ALLEGRO_ALIGN_LEFT, "Place Employee");
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 150, SCREEN_H / 1.3 - 25, ALLEGRO_ALIGN_LEFT, "Select Menu Item"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 150, SCREEN_H / 1.3 - 25, ALLEGRO_ALIGN_LEFT, "Select Menu Item");
al_draw_bitmap(sprites["KeyEsc"], SCREEN_W / 2 + 58, SCREEN_H / 2 + 60, NULL); 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_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_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_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_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_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(); al_flip_display();
while (help) { //While the help screen is still down while (help) { //While the help screen is still down
ALLEGRO_EVENT unhelp; ALLEGRO_EVENT unhelp;
al_wait_for_event(event_queue, &unhelp); al_wait_for_event(event_queue, &unhelp);
if (unhelp.type == ALLEGRO_EVENT_KEY_DOWN) { if (unhelp.type == ALLEGRO_EVENT_KEY_DOWN) {
if (unhelp.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { if (unhelp.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
help = false; //Take the help screen down help = false; //Take the help screen down
} }
} }
} }
} }
break; break;
case ALLEGRO_KEY_ESCAPE: case ALLEGRO_KEY_ESCAPE:
//Force quit game //Force quit game
back(); back();
exit_screen = true; exit_screen = true;
break; break;
case ALLEGRO_KEY_LCTRL: case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL: case ALLEGRO_KEY_RCTRL:
ctrl = true; //ctrl is held ctrl = true; //ctrl is held
break; break;
} }
if (ev.type == ALLEGRO_EVENT_KEY_UP) { if (ev.type == ALLEGRO_EVENT_KEY_UP) {
if (ev.keyboard.keycode == ALLEGRO_KEY_LCTRL || ev.keyboard.keycode == ALLEGRO_KEY_RCTRL) { if (ev.keyboard.keycode == ALLEGRO_KEY_LCTRL || ev.keyboard.keycode == ALLEGRO_KEY_RCTRL) {
ctrl = false; //ctrl is released ctrl = false; //ctrl is released
} }
} }
//Global refresh //Global refresh
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) { //If the game loop was exited naturally rather than forced by Esc if (next_state != Exit) { //If the game loop was exited naturally rather than forced by Esc
cont(); cont();
} }
//Garbage collection //Garbage collection
al_destroy_event_queue(event_queue); al_destroy_event_queue(event_queue);
al_destroy_timer(timer); al_destroy_timer(timer);
map<string, ALLEGRO_SAMPLE_INSTANCE*>::iterator it2; map<string, ALLEGRO_SAMPLE_INSTANCE*>::iterator it2;
for (it2 = instances.begin(); it2 != instances.end(); it2++) { for (it2 = instances.begin(); it2 != instances.end(); it2++) {
al_destroy_sample_instance(it2->second); al_destroy_sample_instance(it2->second);
} }
} }
//Redraw all elements of the screen //Redraw all elements of the screen
void GameScreen::redraw(ALLEGRO_FONT* font) { void GameScreen::redraw(ALLEGRO_FONT* font) {
al_draw_bitmap(sprites["Mr. Manager"], 80, 0 + (SCREEN_H / lines.size() * selected), NULL); //Draw the manager based on which line is selected al_draw_bitmap(sprites["Mr. Manager"], 80, 0 + (SCREEN_H / lines.size() * selected), NULL); //Draw the manager based on which line is selected
for (unsigned int i = 0; i < lines.size(); i++) { //Draw each line for (unsigned int i = 0; i < lines.size(); i++) { //Draw each line
lines.at(i).draw(); lines.at(i).draw();
} }
//Display score, number of catchers, current difficulty level, and whether the music is on or off //Display score, number of catchers, current difficulty level, and whether the music is on or off
ostringstream score_msg; ostringstream score_msg;
score_msg << "Score: " << score; 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_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); al_draw_bitmap(sprites["Mr. Man"], SCREEN_W - 90, 20, NULL);
ostringstream catcher_msg; ostringstream catcher_msg;
catcher_msg << " x " << max_catchers - catchers; 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()); 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; ostringstream difficulty_msg;
difficulty_msg << "Level: " << difficulty; 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()); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W - 90, 75, ALLEGRO_ALIGN_LEFT, difficulty_msg.str().c_str());
string music_img = (music) ? "MusicOn" : "MusicOff"; string music_img = (music) ? "MusicOn" : "MusicOff";
al_draw_bitmap(sprites[music_img], SCREEN_W - 60, 90, NULL); al_draw_bitmap(sprites[music_img], SCREEN_W - 60, 90, NULL);
} }
void GameScreen::back() { void GameScreen::back() {
next_state = Exit; next_state = Exit;
} }
void GameScreen::cont() { void GameScreen::cont() {
next_state = End; next_state = End;
} }

@ -7,7 +7,6 @@ class GameScreen : public Screen {
public: public:
std::map<std::string, ALLEGRO_BITMAP*> sprites; std::map<std::string, ALLEGRO_BITMAP*> sprites;
std::map<std::string, ALLEGRO_SAMPLE*> samples; std::map<std::string, ALLEGRO_SAMPLE*> samples;
std::map<std::string, ALLEGRO_SAMPLE*> themes;
std::vector<Line> lines; std::vector<Line> lines;
unsigned int selected; unsigned int selected;
int max_catchers; int max_catchers;
@ -16,7 +15,7 @@ public:
int difficulty; int difficulty;
bool music; bool music;
GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, std::map<std::string, ALLEGRO_SAMPLE*> _samples, std::map<std::string, ALLEGRO_SAMPLE*> _themes); GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, std::map<std::string, ALLEGRO_SAMPLE*> _samples);
void reset(int _lines, int _max_catchers, int _difficulty); void reset(int _lines, int _max_catchers, int _difficulty);
void run(ALLEGRO_FONT* font); void run(ALLEGRO_FONT* font);

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 141 KiB

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Allegro" version="5.2.4.0" targetFramework="native" />
<package id="AllegroDeps" version="1.7.0.0" targetFramework="native" />
</packages>

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

@ -1,136 +1,136 @@
#include "start_screen.h" #include "start_screen.h"
#include <vector> #include <vector>
#include <string> #include <string>
using std::vector; using std::vector;
using std::string; using std::string;
StartScreen::StartScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites) { StartScreen::StartScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites) {
vector<string> menu_options; vector<string> menu_options;
menu_options.push_back("Easy"); //Select Difficulty menu_options.push_back("Easy"); //Select Difficulty
menu_options.push_back("Medium"); menu_options.push_back("Medium");
menu_options.push_back("Hard"); menu_options.push_back("Hard");
menu_options.push_back("Quit"); //Quit game menu_options.push_back("Quit"); //Quit game
menu.activate(menu_options); menu.activate(menu_options);
sprites = _sprites; sprites = _sprites;
} }
//Run screen //Run screen
void StartScreen::run(ALLEGRO_FONT * font) { void StartScreen::run(ALLEGRO_FONT * font) {
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());
redraw(font); redraw(font);
menu.draw(300.0, 400.0, 20.0, font); menu.draw(300.0, 400.0, 20.0, font);
al_flip_display(); al_flip_display();
bool ctrl = false; bool ctrl = false;
bool exit_screen = false; bool exit_screen = false;
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_KEY_DOWN) { if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
switch (ev.keyboard.keycode) { switch (ev.keyboard.keycode) {
case ALLEGRO_KEY_UP: case ALLEGRO_KEY_UP:
//Move cursor up //Move cursor up
menu.up(); menu.up();
break; break;
case ALLEGRO_KEY_DOWN: case ALLEGRO_KEY_DOWN:
//Move cursor down //Move cursor down
menu.down(); menu.down();
break; break;
case ALLEGRO_KEY_SPACE: case ALLEGRO_KEY_SPACE:
if (ctrl) { //If the ctrl key is held regardless of option, they will enter EXTREME easter egg mode if (ctrl) { //If the ctrl key is held regardless of option, they will enter EXTREME easter egg mode
next_state = EXTREME; next_state = EXTREME;
} }
else { else {
cont(); //Otherwise select the menu item cont(); //Otherwise select the menu item
} }
exit_screen = true; exit_screen = true;
break; break;
case ALLEGRO_KEY_ESCAPE: case ALLEGRO_KEY_ESCAPE:
//Force quit game //Force quit game
back(); back();
exit_screen = true; exit_screen = true;
break; break;
case ALLEGRO_KEY_LCTRL: case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL: case ALLEGRO_KEY_RCTRL:
ctrl = true; //ctrl is held down ctrl = true; //ctrl is held down
break; break;
} }
redraw(font); redraw(font);
al_flip_display(); al_flip_display();
} }
if (ev.type == ALLEGRO_EVENT_KEY_UP) { if (ev.type == ALLEGRO_EVENT_KEY_UP) {
if (ev.keyboard.keycode == ALLEGRO_KEY_LCTRL || ev.keyboard.keycode == ALLEGRO_KEY_RCTRL) { if (ev.keyboard.keycode == ALLEGRO_KEY_LCTRL || ev.keyboard.keycode == ALLEGRO_KEY_RCTRL) {
ctrl = false; //ctrl is released ctrl = false; //ctrl is released
} }
} }
} }
//Garbage collection //Garbage collection
al_destroy_event_queue(event_queue); al_destroy_event_queue(event_queue);
} }
void StartScreen::redraw(ALLEGRO_FONT* font) { void StartScreen::redraw(ALLEGRO_FONT* font) {
al_draw_bitmap(sprites["Title"], SCREEN_W/2 - 240, 20, NULL); //logo al_draw_bitmap(sprites["Title"], SCREEN_W/2 - 240, 20, NULL); //logo
al_draw_bitmap(sprites["Mr. Manager"], SCREEN_W / 2 - 40, 120, NULL); //manager al_draw_bitmap(sprites["Mr. Manager"], SCREEN_W / 2 - 40, 120, NULL); //manager
for (int i = 1; i < 7; i++) { for (int i = 1; i < 7; i++) {
al_draw_bitmap(sprites["Mr. Man"], SCREEN_W / 8 * i + 14, SCREEN_H / 2 - 30, NULL); //army of catchers al_draw_bitmap(sprites["Mr. Man"], SCREEN_W / 8 * i + 14, SCREEN_H / 2 - 30, NULL); //army of catchers
} }
//Instructions //Instructions
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 10, ALLEGRO_ALIGN_CENTER, "Mr. Manager wants to run a teambuilding exercise for his employees."); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 10, ALLEGRO_ALIGN_CENTER, "Mr. Manager wants to run a teambuilding exercise for his employees.");
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 20, ALLEGRO_ALIGN_CENTER, "Help Mr.Manager place his 5 catchers at the end of his"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 20, ALLEGRO_ALIGN_CENTER, "Help Mr.Manager place his 5 catchers 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, "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 + 30, 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, "Try to catch enough to help the team bond!"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 40, ALLEGRO_ALIGN_CENTER, "Try to catch enough to help the team bond!");
//Keys and their associated functions //Keys and their associated functions
al_draw_bitmap(sprites["KeyUp"], SCREEN_W / 8, 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 / 8 + 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 / 8 + 68, 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 / 8 + 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 / 8 + 68, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Spacebar - "); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 68, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Spacebar - ");
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 150, SCREEN_H / 1.3 - 15, ALLEGRO_ALIGN_LEFT, "Place Employee"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 150, SCREEN_H / 1.3 - 15, ALLEGRO_ALIGN_LEFT, "Place Employee");
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 150, SCREEN_H / 1.3 - 25, ALLEGRO_ALIGN_LEFT, "Select Menu Item"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 150, SCREEN_H / 1.3 - 25, ALLEGRO_ALIGN_LEFT, "Select Menu Item");
al_draw_bitmap(sprites["KeyEsc"], SCREEN_W / 8 + 20, SCREEN_H / 2 + 140, NULL); al_draw_bitmap(sprites["KeyEsc"], SCREEN_W / 8 + 20, SCREEN_H / 2 + 140, NULL);
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 68, SCREEN_H / 2 + 150, ALLEGRO_ALIGN_LEFT, "Exit Game"); al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 8 + 68, SCREEN_H / 2 + 150, ALLEGRO_ALIGN_LEFT, "Exit Game");
al_draw_bitmap(sprites["KeyCtrl"], SCREEN_W / 2 + 40, SCREEN_H / 2 + 60, NULL); 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_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_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_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_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_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_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_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2 + 113, SCREEN_H / 1.3 - 20, ALLEGRO_ALIGN_LEFT, "Toggle Music");
al_draw_text(font, al_map_rgb(255, 255, 255), 0, SCREEN_H - 10, ALLEGRO_ALIGN_LEFT, "Copyright 2019 Braydon Kains"); al_draw_text(font, al_map_rgb(255, 255, 255), 0, SCREEN_H - 10, ALLEGRO_ALIGN_LEFT, "Copyright 2019 Braydon Kains");
} }
void StartScreen::back() { void StartScreen::back() {
next_state = Exit; next_state = Exit;
} }
void StartScreen::cont() { void StartScreen::cont() {
if (menu.get_selected() == "Easy") { if (menu.get_selected() == "Easy") {
next_state = Easy; next_state = Easy;
} }
else if (menu.get_selected() == "Medium") { else if (menu.get_selected() == "Medium") {
next_state = Medium; next_state = Medium;
} }
else if (menu.get_selected() == "Hard") { else if (menu.get_selected() == "Hard") {
next_state = Hard; next_state = Hard;
} }
else { else {
next_state = Exit; next_state = Exit;
} }
} }
Loading…
Cancel
Save