diff --git a/games/VentureAdventure/game.cpp b/games/VentureAdventure/game.cpp index b7eab728..0549631f 100644 --- a/games/VentureAdventure/game.cpp +++ b/games/VentureAdventure/game.cpp @@ -8,10 +8,12 @@ // make this 'true' to enable easier level completion, will cause only 1 gem to generate. bool debugeasymode = false; -game_data new_game(string map) +game_data new_game(string map, key_list_t& required_key_list) { game_data new_game; + new_game.key_list = required_key_list; + // use new_level function to load the map to new_game.map_array new_game.map_array = new_level(map); @@ -422,7 +424,7 @@ void handle_input(game_data &game) game.player.x_id = game.player.x_pos/TILESIZE; game.player.stopped = false; - if(key_down(W_KEY) && game.player.walking == false) + if(key_down(game.key_list.MOVE_UP) && game.player.walking == false) { // checks for collision between box and enemy. specific based on player moving up (W key). stops box moving into enemy. // In future this could do possibly be changed to do something else, like destroy the enemy? @@ -484,7 +486,7 @@ void handle_input(game_data &game) } } - if(key_down(S_KEY) && game.player.walking == false) + if(key_down(game.key_list.MOVE_DOWN) && game.player.walking == false) { // checks for collision between box and enemy. specific based on player moving up (W key). stops box moving into enemy update_enemy_position(game); @@ -547,7 +549,7 @@ void handle_input(game_data &game) } } - if(key_down(A_KEY) && game.player.walking == false) + if(key_down(game.key_list.MOVE_LEFT) && game.player.walking == false) { // checks for collision between box and enemy. specific based on player moving left (A key). stops box moving into enemy update_enemy_position(game); @@ -610,7 +612,7 @@ void handle_input(game_data &game) } } - if(key_down(D_KEY) && game.player.walking == false ) + if(key_down(game.key_list.MOVE_RIGHT) && game.player.walking == false ) { // checks for collision between box and enemy. specific based on player moving right (D key). stops box moving into enemy update_enemy_position(game); @@ -1012,12 +1014,12 @@ int check_lives(game_data game) return game.lives; } -void start_screen() +void start_screen(game_data& game) { int ven = 500; int adv = 542; - while( not key_down(RETURN_KEY) && not quit_requested() && not key_down(ESCAPE_KEY)) + while( not key_down(game.key_list.START_KEY) && not quit_requested() && not key_down(game.key_list.EXIT_KEY)) { process_events(); @@ -1030,7 +1032,10 @@ void start_screen() if(ven == SCREEN_HEIGHT/2-150) { - draw_text("PRESS ENTER KEY TO START", COLOR_BLANCHED_ALMOND, "font.ttf", 20, SCREEN_WIDTH/2 - 50, SCREEN_HEIGHT-50, option_to_screen()); + std::string start_key_text = "START"; + if(game.key_list.START_KEY == RETURN_KEY) + start_key_text = "ENTER"; + draw_text("PRESS " + start_key_text + " KEY TO START", COLOR_BLANCHED_ALMOND, "font.ttf", 20, SCREEN_WIDTH/2 - 50, SCREEN_HEIGHT-50, option_to_screen()); draw_text("By Anthony George", COLOR_BLANCHED_ALMOND, "font.ttf", 10, SCREEN_WIDTH/2+20, SCREEN_HEIGHT/2-50, option_to_screen()); } diff --git a/games/VentureAdventure/game.h b/games/VentureAdventure/game.h index 639a0894..6be545d3 100644 --- a/games/VentureAdventure/game.h +++ b/games/VentureAdventure/game.h @@ -6,6 +6,7 @@ #include "boxes.h" #include "gems.h" #include "enemy.h" +#include "key_list.h" #include #define SCREEN_WIDTH 512 @@ -30,9 +31,10 @@ struct game_data int index[64]; point_2d map_loc; vector solid; + key_list_t key_list; }; -game_data new_game(string map); +game_data new_game(string map, key_list_t& required_key_list); vector > new_level(string file); @@ -85,7 +87,7 @@ int check_lives(game_data game); void attack(game_data &game); -void start_screen(); +void start_screen(game_data& game); void win_screen(); diff --git a/games/VentureAdventure/key_list.h b/games/VentureAdventure/key_list.h new file mode 100644 index 00000000..f56e3648 --- /dev/null +++ b/games/VentureAdventure/key_list.h @@ -0,0 +1,16 @@ +#pragma once +#include +#define P1_B1_KEY LEFT_CTRL_KEY +#define P1_B2_KEY LEFT_ALT_KEY +#define P1_START_KEY NUM_1_KEY + +typedef struct key_list +{ + key_code MOVE_UP; + key_code MOVE_DOWN; + key_code MOVE_LEFT; + key_code MOVE_RIGHT; + key_code RESET_LEVEL; + key_code START_KEY; + key_code EXIT_KEY; +} key_list_t; \ No newline at end of file diff --git a/games/VentureAdventure/program.cpp b/games/VentureAdventure/program.cpp index a672fa95..605ab41c 100644 --- a/games/VentureAdventure/program.cpp +++ b/games/VentureAdventure/program.cpp @@ -1,6 +1,7 @@ #include "splashkit.h" #include "game.h" #include "debugging.h" +#include void load_resources() { @@ -10,8 +11,19 @@ void load_resources() open_audio(); } -int main() +int main(int argc, char** argv) { + bool running_in_arcade_controller = false; + if(argc > 1) + { + for(int i = 1; i < argc; i++) + { + if(std::strcmp(argv[i],"--arcade-controller-required") == 0) + { + running_in_arcade_controller = true; + } + } + } const string WINDOW_NAME = "VentureAdventure"; const int WINDOW_WIDTH = 672; const int WINDOW_HEIGHT = SCREEN_HEIGHT; @@ -32,8 +44,33 @@ int main() string level_map = "Resources/levels/level1.txt"; bool is_level_completed = false; + + key_list_t required_keylist = + { + W_KEY, + S_KEY, + A_KEY, + D_KEY, + R_KEY, + RETURN_KEY, + ESCAPE_KEY + }; + if(running_in_arcade_controller) + { + required_keylist = + { + UP_KEY, + DOWN_KEY, + LEFT_KEY, + RIGHT_KEY, + P1_B1_KEY, + P1_START_KEY, + ESCAPE_KEY + }; + } + game_data game; - game = new_game(level_map); + game = new_game(level_map, required_keylist); bool is_debugging_output_enabled = false; // Change this to toggle the debugging output on/off vector old_debug_message = { "" }; @@ -41,16 +78,16 @@ int main() // process start screen. could be expanded in future to be a main menu. no way to return to this screen unless game is lost or won, but there's currently no need to go back anyway // could also have a proper controls menu/button in future to view controls during the game rather than displayed in the hud (see game.cpp file for hud) - while (!quit_requested() && !key_down(ESCAPE_KEY)) + while (!quit_requested() && !key_down(game.key_list.EXIT_KEY)) { play_music("intro"); set_music_volume(MUSIC_VOLUME_INTRO); - start_screen(); + start_screen(game); fade_music_out(1000); // processes game/levels - while (!quit_requested() && !key_down(ESCAPE_KEY)) + while (!quit_requested() && !key_down(game.key_list.EXIT_KEY)) { process_events(); clear_screen(); @@ -73,9 +110,9 @@ int main() } // Intended for use when soft-locked/trapped by boxes without needing to restart game. Will reset gems and player on current level, but won't reset lives - if (key_down(R_KEY)) + if (key_down(game.key_list.RESET_LEVEL)) { - game = new_game(level_map); + game = new_game(level_map, required_keylist); } refresh_screen(60); @@ -89,7 +126,7 @@ int main() set_music_volume(0.025); write_line(level_map); - game = new_game(level_map); + game = new_game(level_map, required_keylist); } // If last level is won or game is lost, returns to main menu. Gamer over sounds and message call are currently within the game.cpp file else if ((is_level_completed && level_id >= TOTAL_LEVELS) || (check_gameover(game))) @@ -104,7 +141,7 @@ int main() play_music("intro"); set_music_volume(MUSIC_VOLUME_INTRO); - start_screen(); + start_screen(game); fade_music_out(1000); @@ -117,7 +154,7 @@ int main() level_map = "Resources/levels/level" + std::to_string(level_id) + ".txt"; write_line(level_map); - game = new_game(level_map); + game = new_game(level_map, required_keylist); }; } }