diff --git a/TrustFall/TrustFall.sln b/TrustFall/TrustFall.sln new file mode 100644 index 0000000..caf1981 --- /dev/null +++ b/TrustFall/TrustFall.sln @@ -0,0 +1,31 @@ + +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 diff --git a/TrustFall/TrustFall/Assets/MrMan.bmp b/TrustFall/TrustFall/Assets/MrMan.bmp new file mode 100644 index 0000000..b2765ed Binary files /dev/null and b/TrustFall/TrustFall/Assets/MrMan.bmp differ diff --git a/TrustFall/TrustFall/Assets/MrMan2.bmp b/TrustFall/TrustFall/Assets/MrMan2.bmp new file mode 100644 index 0000000..afc0be1 Binary files /dev/null and b/TrustFall/TrustFall/Assets/MrMan2.bmp differ diff --git a/TrustFall/TrustFall/Assets/MrMcPlaceholder.bmp b/TrustFall/TrustFall/Assets/MrMcPlaceholder.bmp new file mode 100644 index 0000000..2d5683f Binary files /dev/null and b/TrustFall/TrustFall/Assets/MrMcPlaceholder.bmp differ diff --git a/TrustFall/TrustFall/Assets/logo.bmp b/TrustFall/TrustFall/Assets/logo.bmp new file mode 100644 index 0000000..fff965d Binary files /dev/null and b/TrustFall/TrustFall/Assets/logo.bmp differ diff --git a/TrustFall/TrustFall/MrMan.bmp b/TrustFall/TrustFall/MrMan.bmp new file mode 100644 index 0000000..afc0be1 Binary files /dev/null and b/TrustFall/TrustFall/MrMan.bmp differ diff --git a/TrustFall/TrustFall/MrManager.bmp b/TrustFall/TrustFall/MrManager.bmp new file mode 100644 index 0000000..af46ac5 Binary files /dev/null and b/TrustFall/TrustFall/MrManager.bmp differ diff --git a/TrustFall/TrustFall/TrustFall.vcxproj b/TrustFall/TrustFall/TrustFall.vcxproj new file mode 100644 index 0000000..fc3ad9b --- /dev/null +++ b/TrustFall/TrustFall/TrustFall.vcxproj @@ -0,0 +1,156 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {C6900ECF-254F-4751-A968-DDA699CCD5A6} + TrustFall + 10.0.17134.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + true + true + true + true + true + true + true + + + + Level3 + Disabled + true + true + + + Windows + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + 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}. + + + + + \ No newline at end of file diff --git a/TrustFall/TrustFall/TrustFall.vcxproj.filters b/TrustFall/TrustFall/TrustFall.vcxproj.filters new file mode 100644 index 0000000..b9d8f93 --- /dev/null +++ b/TrustFall/TrustFall/TrustFall.vcxproj.filters @@ -0,0 +1,66 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {208c3bdc-70a1-468f-abb5-27de77aca6f5} + + + {39102eef-101d-459c-91bd-eb99f53a680c} + + + {9584aa99-4970-43df-9c74-abb55fe47b48} + + + {c35524f9-e2af-4389-8842-332f6f7a1048} + + + {bc95f981-5965-4a34-8f2e-afba2627bb4b} + + + + + + + + Source Files + + + Source Files\EngineImplement + + + Source Files\EngineImplement + + + Source Files\ScreensImplement + + + + + Header Files\Engine + + + Header Files\TrustFall + + + Header Files\Engine + + + Header Files\Engine + + + Header Files\Screens + + + \ No newline at end of file diff --git a/TrustFall/TrustFall/cursor.cpp b/TrustFall/TrustFall/cursor.cpp new file mode 100644 index 0000000..160d131 --- /dev/null +++ b/TrustFall/TrustFall/cursor.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include + +#include "cursor.h" + +using std::string; +using std::vector; + +template +Cursor::Cursor() +{ + active = false; +} + +template +void Cursor::activate(std::vector _items) +{ + items = _items; + selected = 0; + active = true; +} + +template +void Cursor::deactivate() +{ + active = false; +} + +template +void Cursor::draw(float _x_start, float _y_start, float _y_offset, ALLEGRO_FONT* _font) { + vector items_text = get_item_strings(); + + x_start = _x_start; + y_start = _y_start; + y_offset = _y_offset; + font = _font; + + for (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(); +} + +template +void Cursor::down() +{ + if (selected < items.size() - 1) { + selected++; + redraw(); + } +} + +template +void Cursor::up() +{ + if (selected > 0) { + selected--; + redraw(); + } +} + +template +T Cursor::get_selected() { + return items.at(selected); +} + +template +void Cursor::redraw() +{ + al_clear_to_color(al_map_rgb(0, 0, 0)); + draw(x_start, y_start, y_offset, font); +} + +template +void Cursor::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); +} + +template Cursor::Cursor(); +template void Cursor::activate(std::vector _options); +template void Cursor::deactivate(); +template void Cursor::draw(float x_start, float y_start, float _y_offset, ALLEGRO_FONT* font); +template void Cursor::redraw(); +template void Cursor::up(); +template void Cursor::down(); +template string Cursor::get_selected(); +template void Cursor::update_selector(); +vector Cursor::get_item_strings() { + return items; +} diff --git a/TrustFall/TrustFall/cursor.h b/TrustFall/TrustFall/cursor.h new file mode 100644 index 0000000..8409560 --- /dev/null +++ b/TrustFall/TrustFall/cursor.h @@ -0,0 +1,29 @@ +#pragma once +#include + +template +class Cursor { +public: + std::vector items; + int selected; + bool active; + + Cursor(); + + void activate(std::vector _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 get_item_strings(); + void update_selector(); + void redraw(); +}; \ No newline at end of file diff --git a/TrustFall/TrustFall/enums.h b/TrustFall/TrustFall/enums.h new file mode 100644 index 0000000..bccad62 --- /dev/null +++ b/TrustFall/TrustFall/enums.h @@ -0,0 +1,12 @@ +#pragma once + +#define SCREEN_W 640 +#define SCREEN_H 480 + +enum State { + Start, + Gameplay, + Help, + End, + Exit +}; \ No newline at end of file diff --git a/TrustFall/TrustFall/game.cpp b/TrustFall/TrustFall/game.cpp new file mode 100644 index 0000000..1c9e89a --- /dev/null +++ b/TrustFall/TrustFall/game.cpp @@ -0,0 +1,38 @@ +#include "game.h" +#include "start_screen.h" + +using std::string; +using std::map; +using std::pair; + +Game::Game() { +} + +void Game::init() { + score = 0; + state = Start; + sprites.insert(pair("Title", al_load_bitmap("logo.bmp"))); + sprites.insert(pair("Mr. Man", al_load_bitmap("MrMan.bmp"))); + sprites.insert(pair("Mr. Manager", al_load_bitmap("MrManager.bmp"))); + sprites.insert(pair("KeyUp", al_load_bitmap("small_key_up.bmp"))); + sprites.insert(pair("Spacebar", al_load_bitmap("spacebar.bmp"))); + + font = al_create_builtin_font(); +} + +void Game::reset() { + score = 0; + state = Start; +} + +void Game::run() { + while (state != Exit) { + switch (state) { + case Start: + StartScreen start_screen(sprites); + start_screen.run(font); + state = start_screen.next_state; + break; + } + } +} \ No newline at end of file diff --git a/TrustFall/TrustFall/game.h b/TrustFall/TrustFall/game.h new file mode 100644 index 0000000..b9acaac --- /dev/null +++ b/TrustFall/TrustFall/game.h @@ -0,0 +1,31 @@ +#pragma once +#include +#include +#include + +#include +#include +#include + +#include "enums.h" + +class Game { +public: + //Allegro elements + ALLEGRO_FONT* font; + + //Game elements + State state; + + int score; + + std::map sprites; + + Game(); + + void init(); + void run(); + +private: + void reset(); +}; \ No newline at end of file diff --git a/TrustFall/TrustFall/game_screen.cpp b/TrustFall/TrustFall/game_screen.cpp new file mode 100644 index 0000000..59c318e --- /dev/null +++ b/TrustFall/TrustFall/game_screen.cpp @@ -0,0 +1,42 @@ +#include "game_screen.h" + +#include +#include + +using std::vector; +using std::string; + +GameScreen::GameScreen(std::map _sprites) { + sprites = _sprites; +} + +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()); + + 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) { + + } + } +} + +void GameScreen::redraw(ALLEGRO_FONT* font) { + +} + +void GameScreen::back() { + next_state = Exit; +} + +void GameScreen::cont() { + next_state = End; +} \ No newline at end of file diff --git a/TrustFall/TrustFall/game_screen.h b/TrustFall/TrustFall/game_screen.h new file mode 100644 index 0000000..ece3708 --- /dev/null +++ b/TrustFall/TrustFall/game_screen.h @@ -0,0 +1,15 @@ +#pragma once +#include "screen.h" +#include "cursor.h" + +class GameScreen : public Screen { +public: + std::map sprites; + + GameScreen(std::map _sprites); + + void run(ALLEGRO_FONT* font); + void redraw(ALLEGRO_FONT* font); + void back(); + void cont(); +}; \ No newline at end of file diff --git a/TrustFall/TrustFall/key_up.bmp b/TrustFall/TrustFall/key_up.bmp new file mode 100644 index 0000000..b97a2c1 Binary files /dev/null and b/TrustFall/TrustFall/key_up.bmp differ diff --git a/TrustFall/TrustFall/logo.bmp b/TrustFall/TrustFall/logo.bmp new file mode 100644 index 0000000..fff965d Binary files /dev/null and b/TrustFall/TrustFall/logo.bmp differ diff --git a/TrustFall/TrustFall/main.cpp b/TrustFall/TrustFall/main.cpp new file mode 100644 index 0000000..2d0c430 --- /dev/null +++ b/TrustFall/TrustFall/main.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "game.h" + +using std::string; + +int main() +{ + //Allegro setup + if (!al_init()) { + fprintf(stderr, "failed to initialize allegro!\n"); + return -1; + } + if (!al_init_font_addon()) { + fprintf(stderr, "failed to initialize font!\n"); + return -1; + } + if (!al_init_primitives_addon()) { + fprintf(stderr, "failed to initialize primitives!\n"); + return -1; + } + if (!al_init_image_addon()) { + fprintf(stderr, "failed to initialize image addon!\n"); + return -1; + } + if (!al_install_audio()) { + fprintf(stderr, "failed to initialize audio!\n"); + return -1; + } + if (!al_init_acodec_addon()) { + fprintf(stderr, "failed to initialize audio codecs!\n"); + return -1; + } + if (!al_install_keyboard()) { + fprintf(stderr, "failed to initialize allegro!\n"); + return -1; + } + if (!al_reserve_samples(1)) { + fprintf(stderr, "failed to reserve samples!\n"); + return -1; + } + + ALLEGRO_DISPLAY* display = al_create_display(SCREEN_W, SCREEN_H); + al_clear_to_color(al_map_rgb(0, 0, 0)); + + Game main_game; + main_game.init(); + main_game.run(); + + al_destroy_display(display); + + return 0; +} \ No newline at end of file diff --git a/TrustFall/TrustFall/packages.config b/TrustFall/TrustFall/packages.config new file mode 100644 index 0000000..0c6bbd7 --- /dev/null +++ b/TrustFall/TrustFall/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/TrustFall/TrustFall/screen.h b/TrustFall/TrustFall/screen.h new file mode 100644 index 0000000..0a0c2eb --- /dev/null +++ b/TrustFall/TrustFall/screen.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include +#include +#include + +#include "enums.h" + +class Screen { +public: + State next_state; + std::map sprites; + + virtual void run(ALLEGRO_FONT* font) = 0; + virtual void redraw(ALLEGRO_FONT* font) = 0; + virtual void back() = 0; + virtual void cont() = 0; +}; \ No newline at end of file diff --git a/TrustFall/TrustFall/small_key_up.bmp b/TrustFall/TrustFall/small_key_up.bmp new file mode 100644 index 0000000..a885e66 Binary files /dev/null and b/TrustFall/TrustFall/small_key_up.bmp differ diff --git a/TrustFall/TrustFall/spacebar.bmp b/TrustFall/TrustFall/spacebar.bmp new file mode 100644 index 0000000..66bb9fe Binary files /dev/null and b/TrustFall/TrustFall/spacebar.bmp differ diff --git a/TrustFall/TrustFall/start_screen.cpp b/TrustFall/TrustFall/start_screen.cpp new file mode 100644 index 0000000..9d5f3b7 --- /dev/null +++ b/TrustFall/TrustFall/start_screen.cpp @@ -0,0 +1,85 @@ +#include "start_screen.h" + +#include +#include + +using std::vector; +using std::string; + +StartScreen::StartScreen(std::map _sprites) { + vector menu_options; + menu_options.push_back("Start"); + menu_options.push_back("Quit"); + menu.activate(menu_options); + + sprites = _sprites; +} + +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 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_BACKSPACE: + back(); + exit_screen = true; + break; + } + redraw(font); + al_flip_display(); + } + } +} + +void StartScreen::redraw(ALLEGRO_FONT* font) { + al_draw_bitmap(sprites["Title"], 0, 20, NULL); + al_draw_bitmap(sprites["Mr. Manager"], SCREEN_W / 2 - 24, 150, NULL); + for (int i = 1; i < 7; i++) { + al_draw_bitmap(sprites["Mr. Man"], SCREEN_W / 8 * i + 14, SCREEN_H / 2 - 40, NULL); + } + + al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 20, 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 + 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_bitmap(sprites["KeyUp"], SCREEN_W / 3, SCREEN_H / 2 + 60, NULL); + al_draw_bitmap(sprites["KeyUp"], SCREEN_W / 3 + 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_bitmap(sprites["Spacebar"], SCREEN_W / 3 + 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"); +} + +void StartScreen::back() { + next_state = Exit; +} + +void StartScreen::cont() { + if (menu.get_selected() == "Start") { + next_state = Gameplay; + } + else { + next_state = Exit; + } +} \ No newline at end of file diff --git a/TrustFall/TrustFall/start_screen.h b/TrustFall/TrustFall/start_screen.h new file mode 100644 index 0000000..e417fe1 --- /dev/null +++ b/TrustFall/TrustFall/start_screen.h @@ -0,0 +1,16 @@ +#pragma once +#include "screen.h" +#include "cursor.h" + +class StartScreen : public Screen { +public: + Cursor menu; + std::map sprites; + + StartScreen(std::map _sprites); + + void run(ALLEGRO_FONT* font); + void redraw(ALLEGRO_FONT* font); + void back(); + void cont(); +}; \ No newline at end of file