summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/game.h2
-rw-r--r--include/menu.h15
-rw-r--r--main.c17
-rw-r--r--src/game.c28
-rw-r--r--src/menu.c178
5 files changed, 214 insertions, 26 deletions
diff --git a/include/game.h b/include/game.h
index 83c9b3d..df9a686 100644
--- a/include/game.h
+++ b/include/game.h
@@ -38,5 +38,7 @@ scene_state global_scene_state = SCENE_MAIN_MENU;
game global_state = {GAMESTATE_IDLE,DISCONNECTED,0,0};
void init_game();
+void start_solo_game();
+void connect_to_game(char* ip, char* port);
#endif \ No newline at end of file
diff --git a/include/menu.h b/include/menu.h
index 5d31256..f2ccb76 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -3,6 +3,21 @@
#include <projectbase/project_base.h>
+extern int current_res_index;
+extern bool is_fullscreen;
+vec2 available_resolutions[] = {
+ (vec2){1366, 769},
+ (vec2){1440, 900},
+ (vec2){1600, 900},
+ (vec2){1920, 1080},
+ (vec2){2560, 1080},
+ (vec2){2560, 1440},
+ (vec2){2560, 1600},
+ (vec2){3440, 1440},
+ (vec2){3840, 2160},
+ (vec2){5120, 1440},
+};
+
void update_menu(platform_window* window);
#endif \ No newline at end of file
diff --git a/main.c b/main.c
index f004750..cb84277 100644
--- a/main.c
+++ b/main.c
@@ -86,17 +86,7 @@ void handle_args(int argc, char **argv) {
}
}
- if (ip && port) {
- if (strcmp(ip, "127.0.0.1") == 0) {
- start_server(port);
- }
- connect_to_server(ip, port);
- }
-
- log_info("STATE: GAMESTATE_PLAYING");
- global_state.state = GAMESTATE_PLAYING;
-
- play_music(music_inside1);
+ connect_to_game(ip, port);
}
int main(int argc, char **argv)
@@ -104,7 +94,10 @@ int main(int argc, char **argv)
platform_init(argc, argv, CONFIG_DIRECTORY);
settings_set_number("USE_GPU", 1);
- platform_window *window = platform_open_window_ex("Zombies!", 1600, 900, 1920, 1080, 500, 500, FLAGS_MINIMIZE, update_func, 0, 0, 0, 0);
+ platform_window *window = platform_open_window_ex("Zombies!",
+ available_resolutions[current_res_index].x,
+ available_resolutions[current_res_index].y,
+ UINT16_MAX, UINT16_MAX, 1366, 768, FLAGS_MINIMIZE, update_func, 0, 0, 0, 0);
platform_toggle_vsync(window, false);
//platform_toggle_fullscreen(window, true);
diff --git a/src/game.c b/src/game.c
index c582ac4..793ea54 100644
--- a/src/game.c
+++ b/src/game.c
@@ -55,6 +55,34 @@ void connect_to_server(char* ip, char* port) {
}
}
+void connect_to_game(char* ip, char* port)
+{
+ if (ip && port) {
+ if (strcmp(ip, "127.0.0.1") == 0) {
+ start_server(port);
+ }
+ connect_to_server(ip, port);
+ }
+
+ log_info("STATE: GAMESTATE_PLAYING");
+ global_state.state = GAMESTATE_PLAYING;
+
+ play_music(music_inside1);
+}
+
+void start_solo_game()
+{
+ char* ip = "127.0.0.1";
+ char* port = "27015";
+ start_server(port);
+ connect_to_server(ip, port);
+
+ log_info("STATE: GAMESTATE_PLAYING");
+ global_state.state = GAMESTATE_PLAYING;
+
+ play_music(music_inside1);
+}
+
void load_map() {
log_info("STATE: GAMESTATE_LOADING_MAP");
global_state.state = GAMESTATE_LOADING_MAP;
diff --git a/src/menu.c b/src/menu.c
index 92ed996..0f6bb0b 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -1,8 +1,15 @@
#include "../include/menu.h"
+#define PROGRAM_VERSION "0.1.0 | "__DATE__
+
+int current_res_index = 0;
+bool is_fullscreen = false;
+
typedef enum t_menu_state {
MENU_STATE_MAIN,
MENU_STATE_LEVEL_SELECT,
+ MENU_STATE_CREDITS,
+ MENU_STATE_SETTINGS,
} menu_state;
menu_state current_menu_state = MENU_STATE_MAIN;
@@ -71,7 +78,7 @@ void draw_screen(platform_window* window) {
select_animation_duration += update_delta;
int item_h = screen_h / 6;
- if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*0, screen_w, item_h, "Play Solo", selected_menu_option == 0)) {
+ if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*0, screen_w, item_h, "Start Game", selected_menu_option == 0)) {
if (selected_menu_option != 0) {
select_animation_duration = 0.0f;
play_sound(-1, wav_menu_hover);
@@ -84,7 +91,7 @@ void draw_screen(platform_window* window) {
}
}
- if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*1, screen_w, item_h, "Host Game", selected_menu_option == 1)) {
+ if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*1, screen_w, item_h, "Join Game", selected_menu_option == 1)) {
if (selected_menu_option != 1) {
select_animation_duration = 0.0f;
play_sound(-1, wav_menu_hover);
@@ -92,36 +99,41 @@ void draw_screen(platform_window* window) {
selected_menu_option = 1;
}
- if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*2, screen_w, item_h, "Join Game", selected_menu_option == 2)) {
+ if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*2, screen_w, item_h, "Settings", selected_menu_option == 2)) {
if (selected_menu_option != 2) {
select_animation_duration = 0.0f;
play_sound(-1, wav_menu_hover);
}
selected_menu_option = 2;
+ if (is_left_clicked()) {
+ play_sound(-1, wav_woosh);
+ current_menu_state = MENU_STATE_SETTINGS;
+ sec_since_state_change = 0.0f;
+ }
}
-
- if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*3, screen_w, item_h, "Settings", selected_menu_option == 3)) {
+
+ if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*3, screen_w, item_h, "Credits", selected_menu_option == 3)) {
if (selected_menu_option != 3) {
select_animation_duration = 0.0f;
play_sound(-1, wav_menu_hover);
}
selected_menu_option = 3;
+ if (is_left_clicked()) {
+ play_sound(-1, wav_woosh);
+ current_menu_state = MENU_STATE_CREDITS;
+ sec_since_state_change = 0.0f;
+ }
}
-
- if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*4, screen_w, item_h, "Credits", selected_menu_option == 4)) {
+
+ if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*4, screen_w, item_h, "Quit", selected_menu_option == 4)) {
if (selected_menu_option != 4) {
select_animation_duration = 0.0f;
play_sound(-1, wav_menu_hover);
}
selected_menu_option = 4;
- }
-
- if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*5, screen_w, item_h, "Quit", selected_menu_option == 5)) {
- if (selected_menu_option != 5) {
- select_animation_duration = 0.0f;
- play_sound(-1, wav_menu_hover);
+ if (is_left_clicked()) {
+ window->is_open = 0;
}
- selected_menu_option = 5;
}
renderer->render_image(img, imgx, imgy, imgw, imgh);
@@ -190,6 +202,7 @@ void draw_level_select(platform_window* window)
level_img_bg = img_splash_art3;
if (is_left_clicked()) {
global_scene_state = SCENE_GAME;
+ start_solo_game();
// start game/go to lobby.
}
}
@@ -201,6 +214,132 @@ void draw_level_select(platform_window* window)
renderable_rec = draw_screen_change_animation(window, 1.0f);
}
+void draw_credits(platform_window* window)
+{
+ color txt = rgb(102, 255, 102);
+
+ int text_x = renderable_rec.x;
+ int text_y = renderable_rec.y + 20;
+
+ renderer->render_image(img_splash_art2, renderable_rec.x, renderable_rec.y, renderable_rec.w, renderable_rec.h);
+ renderer->render_rectangle(renderable_rec.x, renderable_rec.y, renderable_rec.w, renderable_rec.h, rgba(40,40,40, 200));
+
+ #define CREDITS_ADD_LINE(__txt, __fnt) {font* _fnt = get_font(window, __fnt); \
+ renderer->render_text(_fnt, text_x + (renderable_rec.w/2) - (renderer->calculate_text_width(_fnt, __txt)/2), text_y, __txt, txt); \
+ text_y += _fnt->px_h + 10;}
+
+ CREDITS_ADD_LINE("Zombies!", 2.0f);
+ CREDITS_ADD_LINE("", 1.0f);
+ CREDITS_ADD_LINE("A game by:", 0.8f);
+ CREDITS_ADD_LINE("Aldrik Ramaekers", 1.0f);
+ CREDITS_ADD_LINE("", 1.0f);
+ CREDITS_ADD_LINE("Design, code, textures and levels by:", 0.8f);
+ CREDITS_ADD_LINE("Aldrik Ramaekers", 1.0f);
+ CREDITS_ADD_LINE("", 1.0f);
+ CREDITS_ADD_LINE("Sounds and music by numerous artists found at freesound.org", 1.0f);
+ CREDITS_ADD_LINE("", 1.0f);
+ CREDITS_ADD_LINE("Splash art has been created using text2img AI", 1.0f);
+ CREDITS_ADD_LINE("", 1.0f);
+ CREDITS_ADD_LINE("Thanks for playing!", 1.0f);
+
+ renderable_rec = draw_screen_change_animation(window, 1.0f);
+}
+
+static bool draw_settings_btn(platform_window* window, char* txt, int x, int y, int w, int h)
+{
+ font* fnt = get_font(window, 1.0f);
+
+ int pad = 2;
+ renderer->render_rectangle(x, y, w, h, rgb(0,0,0));
+ renderer->render_rectangle(x+pad, y+pad, w-pad*2, h-pad*2, rgb(255,255,255));
+ renderer->render_text(fnt, x+(w/2)-(fnt->px_h/2), y+(h/2)-(fnt->px_h/2), txt, rgb(0,0,0));
+
+ if (_global_mouse.x + _global_camera.x > x &&
+ _global_mouse.x + _global_camera.x < x + w &&
+ _global_mouse.y + _global_camera.y > y &&
+ _global_mouse.y + _global_camera.y < y + h)
+ {
+ return true;
+ }
+
+ return false;
+}
+
+void draw_settings(platform_window* window)
+{
+ color txt = rgb(255,255,255);
+
+ int btn_s = 50;
+ int row_y = renderable_rec.y + 50;
+ int btn_offset = 100;
+
+ renderer->render_image(img_splash_art2, renderable_rec.x, renderable_rec.y, renderable_rec.w, renderable_rec.h);
+ renderer->render_rectangle(renderable_rec.x, renderable_rec.y, renderable_rec.w, renderable_rec.h, rgba(40,40,40, 200));
+ font* fnt = get_font(window, 1.5f);
+
+ { // Resolution.
+ renderer->render_rectangle(renderable_rec.x + btn_offset, row_y, renderable_rec.w - (btn_offset*2), btn_s, rgba(245,245,245, 100));
+
+ if (draw_settings_btn(window, "<", renderable_rec.x + btn_offset, row_y, btn_s, btn_s)) {
+ if (is_left_clicked()) {
+ current_res_index--;
+ if (current_res_index < 0) // Loop around
+ current_res_index = sizeof(available_resolutions)/sizeof(vec2)-1;
+
+ settings_set_number("RES_INDEX", current_res_index);
+ platform_window_set_size(window, available_resolutions[current_res_index].x, available_resolutions[current_res_index].y);
+ }
+ }
+
+ if (draw_settings_btn(window, ">", renderable_rec.x + renderable_rec.w - btn_offset - btn_s, row_y, btn_s, btn_s)) {
+ if (is_left_clicked()) {
+ current_res_index++;
+ if (current_res_index >= sizeof(available_resolutions)/sizeof(vec2)) // Loop around
+ current_res_index = 0;
+
+ settings_set_number("RES_INDEX", current_res_index);
+ platform_window_set_size(window, available_resolutions[current_res_index].x, available_resolutions[current_res_index].y);
+ }
+ }
+
+ // Resolution text.
+ char resolution_txt[50];
+ sprintf(resolution_txt, "%d x %d", available_resolutions[current_res_index].x, available_resolutions[current_res_index].y);
+ int text_w = renderer->calculate_text_width(fnt, resolution_txt);
+ renderer->render_text(fnt, renderable_rec.x + (renderable_rec.w/2) - (text_w/2), row_y + (btn_s/2) - (fnt->px_h/2), resolution_txt, txt);
+ }
+
+ row_y += btn_s + 20;
+
+ { // Fullscreen.
+ renderer->render_rectangle(renderable_rec.x + btn_offset, row_y, renderable_rec.w - (btn_offset*2), btn_s, rgba(245,245,245, 100));
+
+ if (draw_settings_btn(window, "<", renderable_rec.x + btn_offset, row_y, btn_s, btn_s)) {
+ if (is_left_clicked()) {
+ is_fullscreen = !is_fullscreen;
+ settings_set_number("FULLSCRN", is_fullscreen);
+ platform_toggle_fullscreen(window, is_fullscreen);
+ }
+ }
+
+ if (draw_settings_btn(window, ">", renderable_rec.x + renderable_rec.w - btn_offset - btn_s, row_y, btn_s, btn_s)) {
+ if (is_left_clicked()) {
+ is_fullscreen = !is_fullscreen;
+ settings_set_number("FULLSCRN", is_fullscreen);
+ platform_toggle_fullscreen(window, is_fullscreen);
+ }
+ }
+
+ // fullscreen text.
+ char fullscrn_txt[50];
+ sprintf(fullscrn_txt, "%s", is_fullscreen ? "Fullscreen" : "Windowed");
+ int text_w = renderer->calculate_text_width(fnt, fullscrn_txt);
+ renderer->render_text(fnt, renderable_rec.x + (renderable_rec.w/2) - (text_w/2), row_y + (btn_s/2) - (fnt->px_h/2), fullscrn_txt, txt);
+ }
+
+ renderable_rec = draw_screen_change_animation(window, 1.0f);
+}
+
void update_menu(platform_window* window)
{
sec_since_state_change += update_delta;
@@ -211,6 +350,12 @@ void update_menu(platform_window* window)
else if (current_menu_state == MENU_STATE_LEVEL_SELECT) {
draw_level_select(window);
}
+ else if (current_menu_state == MENU_STATE_CREDITS) {
+ draw_credits(window);
+ }
+ else if (current_menu_state == MENU_STATE_SETTINGS) {
+ draw_settings(window);
+ }
if (keyboard_is_key_down(KEY_ESCAPE))
{
@@ -230,6 +375,11 @@ void update_menu(platform_window* window)
draw_screen(window);
}
}
+
+ // Version
+ {
+ renderer->render_text(fnt_16, 10, window->height - fnt_16->px_h - 10, PROGRAM_VERSION, rgb(255,255,255));
+ }
draw_black_overlay(window);
} \ No newline at end of file