getting all changes off laptop

main
BraydonKains 6 years ago
parent 2173fa2825
commit eb3f1163aa

@ -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<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")));
//sprites.insert(pair<string, ALLEGRO_BITMAP*>("Title", al_load_bitmap("logo.bmp")));
//al_reserve_samples(4);
//samples.insert(pair<string, ALLEGRO_SAMPLE*>("Theme", al_load_sample("rasputin.wav")));
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();
}
@ -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<string, ALLEGRO_BITMAP*>::iterator it;

@ -11,6 +11,7 @@
#include <map>
#include "enums.h"
#include "screen.h"
//Game state machine, contains data global to game
class Game {

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

@ -0,0 +1,42 @@
#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include <allegro5/allegro_color.h>
#include <allegro5/allegro_font.h>
#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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

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

@ -8,9 +8,7 @@ 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("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;

Binary file not shown.
Loading…
Cancel
Save