Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions games/VentureAdventure/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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());
}

Expand Down
6 changes: 4 additions & 2 deletions games/VentureAdventure/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "boxes.h"
#include "gems.h"
#include "enemy.h"
#include "key_list.h"
#include <vector>

#define SCREEN_WIDTH 512
Expand All @@ -30,9 +31,10 @@ struct game_data
int index[64];
point_2d map_loc;
vector<point_2d> 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<vector<int> > new_level(string file);

Expand Down Expand Up @@ -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();

Expand Down
16 changes: 16 additions & 0 deletions games/VentureAdventure/key_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <splashkit.h>
#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;
57 changes: 47 additions & 10 deletions games/VentureAdventure/program.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "splashkit.h"
#include "game.h"
#include "debugging.h"
#include <cstring>

void load_resources()
{
Expand All @@ -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;
Expand All @@ -32,25 +44,50 @@ 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<string> old_debug_message = { "" };
bool still_waiting = false;

// 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();
Expand All @@ -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);
Expand All @@ -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)))
Expand All @@ -104,7 +141,7 @@ int main()
play_music("intro");
set_music_volume(MUSIC_VOLUME_INTRO);

start_screen();
start_screen(game);

fade_music_out(1000);

Expand All @@ -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);
};
}
}
Expand Down
Loading