Adding project

main
BraydonKains 6 years ago
parent e4a5f6b5a9
commit 2173fa2825

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2050
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Assignment3Project", "Assignment3Project\Assignment3Project.vcxproj", "{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}"
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
{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}.Debug|x64.ActiveCfg = Debug|x64
{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}.Debug|x64.Build.0 = Debug|x64
{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}.Debug|x86.ActiveCfg = Debug|Win32
{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}.Debug|x86.Build.0 = Debug|Win32
{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}.Release|x64.ActiveCfg = Release|x64
{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}.Release|x64.Build.0 = Release|x64
{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}.Release|x86.ActiveCfg = Release|Win32
{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {31EA9156-58D8-4051-BF47-8493A2F999B2}
EndGlobalSection
EndGlobal

@ -0,0 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{8A067FEB-7D3A-45FB-BED3-77A1965E41D8}</ProjectGuid>
<RootNamespace>Assignment3Project</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|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_AddonFont>true</Allegro_AddonFont>
<Allegro_AddonColor>true</Allegro_AddonColor>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="cursor.h" />
<ClInclude Include="enums.h" />
<ClInclude Include="game.h" />
<ClInclude Include="game_screen.h" />
<ClInclude Include="screen.h" />
<ClInclude Include="start_screen.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="cursor.cpp" />
<ClCompile Include="game.cpp" />
<ClCompile Include="game_screen.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="start_screen.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<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.4.0\build\native\Allegro.targets" Condition="Exists('..\packages\Allegro.5.2.4.0\build\native\Allegro.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<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>
</PropertyGroup>
<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.4.0\build\native\Allegro.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Allegro.5.2.4.0\build\native\Allegro.targets'))" />
</Target>
</Project>

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Header Files\Engine">
<UniqueIdentifier>{b3cfe90b-396f-4928-8b95-6b453c9cdee6}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Screens">
<UniqueIdentifier>{079f6f25-ed43-4671-bb66-1a1c580b5f6b}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Assignment3">
<UniqueIdentifier>{e9904f71-fa80-4ab4-a0ee-7fc1c8c3f92e}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\EngineImplement">
<UniqueIdentifier>{60b0cc02-34f3-4b2f-a55d-aae1f622f730}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\ScreensImplement">
<UniqueIdentifier>{df34ca78-eaef-42da-84e1-e081ee065499}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Assignment3Implement">
<UniqueIdentifier>{d177d104-1e60-4cd4-81d4-232c379ac302}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cursor.h">
<Filter>Header Files\Engine</Filter>
</ClInclude>
<ClInclude Include="game.h">
<Filter>Header Files\Engine</Filter>
</ClInclude>
<ClInclude Include="game_screen.h">
<Filter>Header Files\Screens</Filter>
</ClInclude>
<ClInclude Include="screen.h">
<Filter>Header Files\Engine</Filter>
</ClInclude>
<ClInclude Include="enums.h">
<Filter>Header Files\Assignment3</Filter>
</ClInclude>
<ClInclude Include="start_screen.h">
<Filter>Header Files\Screens</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="game_screen.cpp">
<Filter>Source Files\ScreensImplement</Filter>
</ClCompile>
<ClCompile Include="cursor.cpp">
<Filter>Source Files\EngineImplement</Filter>
</ClCompile>
<ClCompile Include="game.cpp">
<Filter>Source Files\EngineImplement</Filter>
</ClCompile>
<ClCompile Include="start_screen.cpp">
<Filter>Source Files\ScreensImplement</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

@ -0,0 +1,109 @@
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_primitives.h>
#include <string>
#include "cursor.h"
using std::string;
using std::vector;
template<class T>
Cursor<T>::Cursor()
{
active = false;
}
//Give items to the cursor, and set the selected item to be the first
template<class T>
void Cursor<T>::activate(std::vector<T> _items)
{
items = _items;
selected = 0;
active = true;
}
//Functionality that was not used for this game, may be used in future projects.
template<class T>
void Cursor<T>::deactivate()
{
active = false;
}
//Draw the menu options on the screen based on the x and y coordinates for the menu to start at
template<class T>
void Cursor<T>::draw(float _x_start, float _y_start, float _y_offset, ALLEGRO_FONT* _font) {
vector<string> items_text = get_item_strings();
x_start = _x_start;
y_start = _y_start;
y_offset = _y_offset;
font = _font;
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());
}
update_selector();
}
//Change the selection of the cursor
template<class T>
void Cursor<T>::down()
{
if (selected < items.size() - 1) {
selected++;
redraw();
}
}
template<class T>
void Cursor<T>::up()
{
if (selected > 0) {
selected--;
redraw();
}
}
template<class T>
T Cursor<T>::get_selected() {
return items.at(selected);
}
//Clear screen before drawing menu
template<class T>
void Cursor<T>::redraw()
{
al_clear_to_color(al_map_rgb(0, 0, 0));
draw(x_start, y_start, y_offset, font);
}
//Draw selector to highlight proper selected item
template<class T>
void Cursor<T>::update_selector() {
ALLEGRO_COLOR white = al_map_rgb(255, 255, 255);
float offset = y_offset * selected;
float x1 = x_start - 5;
float y1 = y_start + offset;
float x2 = x_start - 5;
float y2 = y_start + 5 + offset;
float x3 = x_start - 1;
float y3 = y_start + 2.5 + offset;
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.
template Cursor<string>::Cursor();
template void Cursor<string>::activate(std::vector<string> _options);
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>::redraw();
template void Cursor<string>::up();
template void Cursor<string>::down();
template string Cursor<string>::get_selected();
template void Cursor<string>::update_selector();
vector<string> Cursor<string>::get_item_strings() {
return items;
}

@ -0,0 +1,32 @@
#pragma once
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <vector>
//Default object used for menues
template <class T>
class Cursor {
public:
std::vector<T> items;
unsigned int selected;
bool active;
Cursor();
void activate(std::vector<T> _items);
void deactivate();
void draw(float _x_start, float _y_start, float _y_offset, ALLEGRO_FONT* _font);
void up();
void down();
T get_selected();
private:
float x_start;
float y_start;
float y_offset;
ALLEGRO_FONT* font;
std::vector<std::string> get_item_strings();
void update_selector();
void redraw();
};

@ -0,0 +1,8 @@
#pragma once
enum State {
Start,
Gameplay,
End,
Exit
};

@ -0,0 +1,113 @@
#include "game.h"
#include "start_screen.h"
#include "game_screen.h"
#include "result_screen.h"
using std::string;
using std::map;
using std::pair;
Game::Game() {
}
//Load all global data for the game: sprites, audio, and font.
void Game::init() {
score = 0;
state = Start;
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. 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*>("Spacebar", al_load_bitmap("spacebar.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*>("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*>("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")));
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")));
al_reserve_samples(4);
samples.insert(pair<string, ALLEGRO_SAMPLE*>("Theme", al_load_sample("rasputin.wav")));
samples.insert(pair<string, ALLEGRO_SAMPLE*>("Move", al_load_sample("move.wav")));
samples.insert(pair<string, ALLEGRO_SAMPLE*>("Catch", al_load_sample("catch.wav")));
samples.insert(pair<string, ALLEGRO_SAMPLE*>("Fall", al_load_sample("fall.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")));
font = al_create_builtin_font();
}
//Was not used in this project
void Game::reset() {
}
//Run the game state machine
void Game::run() {
//Load screens
int difficulty = 1; //Difficulty to run
bool EXTREME_ON = false; //Flag for EXTREME easter egg
while (state != Exit) {
al_clear_to_color(al_map_rgb(0, 0, 0));
switch (state) {
case Start:
start_screen.run(font);
if (start_screen.next_state == EXTREME) {
EXTREME_ON = true;
state = Hard;
}
else {
state = start_screen.next_state;
}
break;
//The same set of code will be run for any difficulty state
case Easy:
case Medium:
case Hard:
//But we need to check once here whether the difficulty value needs to be adjusted
switch (state) {
case Medium:
difficulty = 3;
result_screen.prev_state = Medium;
break;
case Hard:
difficulty = 5;
result_screen.prev_state = Hard;
break;
}
if (EXTREME_ON) {
game_screen.reset(5, 5, difficulty); //If the EXTREME easter egg is enabled, the game will be run with 5 lines on hard mode
}
else {
game_screen.reset(3, 5, difficulty);
}
EXTREME_ON = false;
game_screen.run(font);
state = game_screen.next_state;
break;
case End:
//Send proper finishing values for this game to the result screen
result_screen.score = game_screen.score;
result_screen.difficulty = game_screen.difficulty;
result_screen.run(font);
state = result_screen.next_state;
break;
}
}
//Garbage collection
map<string, ALLEGRO_BITMAP*>::iterator it;
for (it = sprites.begin(); it != sprites.end(); it++) {
al_destroy_bitmap(it->second);
}
map<string, ALLEGRO_SAMPLE*>::iterator it2;
for (it2 = samples.begin(); it2 != samples.end(); it2++) {
al_destroy_sample(it2->second);
}
}

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

@ -0,0 +1,148 @@
#pragma once
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <ctime>
#include "game_screen.h"
#define FPS 60
using std::vector;
using std::string;
using std::ostringstream;
using std::map;
using std::pair;
enum KEYS {
KEYUP, KEYDOWN, KEYSPACE, KEYCTRL, KEYH, KEYM, KEYESC
};
GameScreen::GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, std::map<std::string, ALLEGRO_SAMPLE*> _samples) {
sprites = _sprites;
samples = _samples;
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
void GameScreen::reset(int _lines, int _max_catchers, int _difficulty) {
}
//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.
//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) {
if (al_get_sample_instance_playing(x)) {
al_stop_sample_instance(x);
}
al_play_sample_instance(x);
}
void GameScreen::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());
ALLEGRO_TIMER* timer = NULL;
timer = al_create_timer(1.0 / FPS); //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));
redraw(font);
al_flip_display();
bool keys[ALLEGRO_KEY_MAX];
for (int i = 0; i < ALLEGRO_KEY_MAX; i++) keys[i] = false;
al_start_timer(timer);
bool exit_screen;
while (!exit_screen) {
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);
if (ev.type == ALLEGRO_EVENT_TIMER) {
if (keys[KEYUP]) {
//Up is pressed!
}
}
if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
switch (ev.keyboard.keycode) {
case ALLEGRO_KEY_DOWN:
keys[KEYDOWN] = true;
break;
case ALLEGRO_KEY_UP:
keys[KEYUP] = true;
break;
case ALLEGRO_KEY_SPACE:
keys[KEYSPACE] = true;
break;
case ALLEGRO_KEY_M:
keys[KEYM] = true;
break;
case ALLEGRO_KEY_H:
keys[KEYH] = true;
break;
case ALLEGRO_KEY_ESCAPE:
keys[KEYESC] = true;
break;
case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL:
keys[KEYCTRL] = true;
break;
}
if (ev.type == ALLEGRO_EVENT_KEY_UP) {
switch (ev.keyboard.keycode) {
case ALLEGRO_KEY_DOWN:
keys[KEYDOWN] = false;
break;
case ALLEGRO_KEY_UP:
keys[KEYUP] = false;
break;
case ALLEGRO_KEY_SPACE:
keys[KEYSPACE] = false;
break;
case ALLEGRO_KEY_M:
keys[KEYM] = false;
break;
case ALLEGRO_KEY_H:
keys[KEYH] = false;
break;
case ALLEGRO_KEY_ESCAPE:
keys[KEYESC] = false;
break;
case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL:
keys[KEYCTRL] = false;
break;
}
//Global refresh
al_clear_to_color(al_map_rgb(0, 0, 0));
redraw(font);
al_flip_display();
}
}
if (next_state != Exit) { //If the game loop was exited naturally rather than forced by Esc
cont();
}
//Garbage collection
al_destroy_event_queue(event_queue);
al_destroy_timer(timer);
}
//Redraw all elements of the screen
void GameScreen::redraw(ALLEGRO_FONT* font) {
}
void GameScreen::back() {
next_state = Exit;
}
void GameScreen::cont() {
next_state = End;
}

@ -0,0 +1,25 @@
#pragma once
#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include "screen.h"
//Main screen for gameplay
class GameScreen : public Screen {
public:
std::map<std::string, ALLEGRO_BITMAP*> sprites;
std::map<std::string, ALLEGRO_SAMPLE*> samples;
unsigned int selected;
int max_catchers;
int catchers;
int score;
int difficulty;
bool music;
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 run(ALLEGRO_FONT* font);
void redraw(ALLEGRO_FONT* font);
void back();
void cont();
};

@ -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>

@ -0,0 +1,20 @@
#pragma once
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <vector>
#include <string>
#include <map>
#include "enums.h"
//Screen base class, implemented by every game screen
class Screen {
public:
State next_state;
std::map<std::string, ALLEGRO_BITMAP*> sprites;
virtual void run(ALLEGRO_FONT* font) = 0;
virtual void redraw(ALLEGRO_FONT* font) = 0;
virtual void back() = 0;
virtual void cont() = 0;
};

@ -0,0 +1,136 @@
#include "start_screen.h"
#include <vector>
#include <string>
using std::vector;
using std::string;
StartScreen::StartScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites) {
vector<string> menu_options;
menu_options.push_back("Easy"); //Select Difficulty
menu_options.push_back("Medium");
menu_options.push_back("Hard");
menu_options.push_back("Quit"); //Quit game
menu.activate(menu_options);
sprites = _sprites;
}
//Run screen
void StartScreen::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);
menu.draw(300.0, 400.0, 20.0, font);
al_flip_display();
bool ctrl = false;
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:
//Move cursor up
menu.up();
break;
case ALLEGRO_KEY_DOWN:
//Move cursor down
menu.down();
break;
case ALLEGRO_KEY_SPACE:
if (ctrl) { //If the ctrl key is held regardless of option, they will enter EXTREME easter egg mode
next_state = EXTREME;
}
else {
cont(); //Otherwise select the menu item
}
exit_screen = true;
break;
case ALLEGRO_KEY_ESCAPE:
//Force quit game
back();
exit_screen = true;
break;
case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL:
ctrl = true; //ctrl is held down
break;
}
redraw(font);
al_flip_display();
}
if (ev.type == ALLEGRO_EVENT_KEY_UP) {
if (ev.keyboard.keycode == ALLEGRO_KEY_LCTRL || ev.keyboard.keycode == ALLEGRO_KEY_RCTRL) {
ctrl = false; //ctrl is released
}
}
}
//Garbage collection
al_destroy_event_queue(event_queue);
}
void StartScreen::redraw(ALLEGRO_FONT* font) {
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
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
}
//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 + 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 + 40, ALLEGRO_ALIGN_CENTER, "Try to catch enough to help the team bond!");
//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 + 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 - ");
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_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_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");
al_draw_text(font, al_map_rgb(255, 255, 255), 0, SCREEN_H - 10, ALLEGRO_ALIGN_LEFT, "Copyright 2019 Braydon Kains");
}
void StartScreen::back() {
next_state = Exit;
}
void StartScreen::cont() {
if (menu.get_selected() == "Easy") {
next_state = Easy;
}
else if (menu.get_selected() == "Medium") {
next_state = Medium;
}
else if (menu.get_selected() == "Hard") {
next_state = Hard;
}
else {
next_state = Exit;
}
}

@ -0,0 +1,17 @@
#pragma once
#include "screen.h"
#include "cursor.h"
//Starting menu
class StartScreen : public Screen {
public:
Cursor<std::string> menu;
std::map<std::string, ALLEGRO_BITMAP*> sprites;
StartScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites);
void run(ALLEGRO_FONT* font);
void redraw(ALLEGRO_FONT* font);
void back();
void cont();
};
Loading…
Cancel
Save