diff --git a/Assignment3Project/Assignment3Project/game.cpp b/Assignment3Project/Assignment3Project/game.cpp index ce9d1eb..30b7390 100644 --- a/Assignment3Project/Assignment3Project/game.cpp +++ b/Assignment3Project/Assignment3Project/game.cpp @@ -1,7 +1,6 @@ #include "game.h" #include "start_screen.h" #include "game_screen.h" -#include "result_screen.h" using std::string; using std::map; @@ -14,31 +13,12 @@ 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("BigMrManager.bmp"))); - sprites.insert(pair("Mr. ManagerSad", al_load_bitmap("mrmanagersad.bmp"))); - sprites.insert(pair("Mr. ManagerHappy", al_load_bitmap("mrmanagerhappy.bmp"))); - sprites.insert(pair("KeyUp", al_load_bitmap("small_key_up.bmp"))); - sprites.insert(pair("Spacebar", al_load_bitmap("spacebar.bmp"))); - sprites.insert(pair("Employee", al_load_bitmap("employee.bmp"))); - sprites.insert(pair("EmployeeHappy", al_load_bitmap("employee_happy.bmp"))); - sprites.insert(pair("EmployeeSad", al_load_bitmap("employee_sad.bmp"))); - sprites.insert(pair("Conveyor", al_load_bitmap("conveyor.bmp"))); - sprites.insert(pair("KeyCtrl", al_load_bitmap("small_key_ctrl.bmp"))); - sprites.insert(pair("KeyH", al_load_bitmap("small_key_h.bmp"))); - sprites.insert(pair("KeyM", al_load_bitmap("small_key_m.bmp"))); - sprites.insert(pair("KeyEsc", al_load_bitmap("small_key_esc.bmp"))); - sprites.insert(pair("MusicOn", al_load_bitmap("music_on.bmp"))); - sprites.insert(pair("MusicOff", al_load_bitmap("music_off.bmp"))); + //sprites.insert(pair("Title", al_load_bitmap("logo.bmp"))); + + + //al_reserve_samples(4); + //samples.insert(pair("Theme", al_load_sample("rasputin.wav"))); - al_reserve_samples(4); - samples.insert(pair("Theme", al_load_sample("rasputin.wav"))); - samples.insert(pair("Move", al_load_sample("move.wav"))); - samples.insert(pair("Catch", al_load_sample("catch.wav"))); - samples.insert(pair("Fall", al_load_sample("fall.wav"))); - samples.insert(pair("Place", al_load_sample("place.wav"))); - samples.insert(pair("LevelUp", al_load_sample("level.wav"))); font = al_create_builtin_font(); } @@ -50,56 +30,7 @@ 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::iterator it; diff --git a/Assignment3Project/Assignment3Project/game.h b/Assignment3Project/Assignment3Project/game.h index 7e37d30..da5eda2 100644 --- a/Assignment3Project/Assignment3Project/game.h +++ b/Assignment3Project/Assignment3Project/game.h @@ -11,6 +11,7 @@ #include #include "enums.h" +#include "screen.h" //Game state machine, contains data global to game class Game { diff --git a/Assignment3Project/Assignment3Project/game_screen.cpp b/Assignment3Project/Assignment3Project/game_screen.cpp index 5668a14..6554a5d 100644 --- a/Assignment3Project/Assignment3Project/game_screen.cpp +++ b/Assignment3Project/Assignment3Project/game_screen.cpp @@ -60,7 +60,7 @@ void GameScreen::run(ALLEGRO_FONT* font) { for (int i = 0; i < ALLEGRO_KEY_MAX; i++) keys[i] = false; al_start_timer(timer); - bool exit_screen; + bool exit_screen = false; while (!exit_screen) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); @@ -118,6 +118,7 @@ void GameScreen::run(ALLEGRO_FONT* font) { case ALLEGRO_KEY_RCTRL: keys[KEYCTRL] = false; break; + } } //Global refresh al_clear_to_color(al_map_rgb(0, 0, 0)); diff --git a/Assignment3Project/Assignment3Project/main.cpp b/Assignment3Project/Assignment3Project/main.cpp index e69de29..36bd308 100644 --- a/Assignment3Project/Assignment3Project/main.cpp +++ b/Assignment3Project/Assignment3Project/main.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "game.h" + +int main() { + if (!al_init()) { + fprintf(stderr, "Could not initialize Allegro!"); + } + if (!al_init_image_addon()) { + fprintf(stderr, "Could not initialize image addon!"); + } + if (!al_init_acodec_addon()) { + fprintf(stderr, "Could not initialize audio codec addon!"); + } + if (!al_install_audio()) { + fprintf(stderr, "Could not install audio!"); + } + if (!al_init_font_addon()) { + fprintf(stderr, "Could not initialize font addon!"); + } + if (!al_install_keyboard()) { + fprintf(stderr, "Could not install keyboard!"); + } + + ALLEGRO_DISPLAY* display = NULL; + display = al_create_display(SCREEN_W, SCREEN_H); + + Game main_game; + main_game.init(); + main_game.run(); + + al_uninstall_keyboard(); + al_uninstall_audio(); + + return 0; +} \ No newline at end of file diff --git a/Assignment3Project/Assignment3Project/placeholder.bmp b/Assignment3Project/Assignment3Project/placeholder.bmp new file mode 100644 index 0000000..a8e1408 Binary files /dev/null and b/Assignment3Project/Assignment3Project/placeholder.bmp differ diff --git a/Assignment3Project/Assignment3Project/screen.h b/Assignment3Project/Assignment3Project/screen.h index f235019..427be60 100644 --- a/Assignment3Project/Assignment3Project/screen.h +++ b/Assignment3Project/Assignment3Project/screen.h @@ -7,6 +7,9 @@ #include "enums.h" +#define SCREEN_W 640 +#define SCREEN_H 480 + //Screen base class, implemented by every game screen class Screen { public: diff --git a/Assignment3Project/Assignment3Project/start_screen.cpp b/Assignment3Project/Assignment3Project/start_screen.cpp index b82bc19..c018add 100644 --- a/Assignment3Project/Assignment3Project/start_screen.cpp +++ b/Assignment3Project/Assignment3Project/start_screen.cpp @@ -8,9 +8,7 @@ using std::string; StartScreen::StartScreen(std::map _sprites) { vector menu_options; - menu_options.push_back("Easy"); //Select Difficulty - menu_options.push_back("Medium"); - menu_options.push_back("Hard"); + menu_options.push_back("Start"); //Start game menu_options.push_back("Quit"); //Quit game menu.activate(menu_options); @@ -44,13 +42,8 @@ void StartScreen::run(ALLEGRO_FONT * font) { 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 - } - + //Select item + cont(); exit_screen = true; break; case ALLEGRO_KEY_ESCAPE: @@ -58,19 +51,10 @@ void StartScreen::run(ALLEGRO_FONT * font) { 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 @@ -78,12 +62,8 @@ void StartScreen::run(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["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 - } - + //al_draw_bitmap(sprites["Title"], SCREEN_W / 2 - 240, 20, NULL); //logo + //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"); @@ -121,14 +101,8 @@ void StartScreen::back() { } 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; + if (menu.get_selected() == "Start") { + next_state = Gameplay; } else { next_state = Exit; diff --git a/Untitled.xcf b/Untitled.xcf new file mode 100644 index 0000000..75c20dd Binary files /dev/null and b/Untitled.xcf differ