summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-05-12 23:08:00 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-05-12 23:08:00 +0200
commitf20dfd8240c5cab969b25a3c1e986b28c97f6898 (patch)
tree421171edf089cd50b70f44366cb02ad7fa251be3
parentf194481a520a39a1964348011df8deb108f789b7 (diff)
main menu work
-rw-r--r--.vscode/settings.json3
-rw-r--r--Makefile8
-rw-r--r--data/imgs/ui/menu_screen.pngbin0 -> 8008439 bytes
-rw-r--r--data/imgs/ui/splash2.jfifbin3860975 -> 0 bytes
-rw-r--r--data/imgs/ui/splash2.pngbin0 -> 9277699 bytes
-rw-r--r--data/psd/menu_screen.psdbin0 -> 67199458 bytes
-rw-r--r--data/sounds/Goodnightmare.mp3bin0 -> 7684215 bytes
-rw-r--r--data/sounds/menu_ambient.mp3bin0 -> 1684377 bytes
-rw-r--r--data/sounds/menu_hover.wavbin0 -> 13550 bytes
-rw-r--r--include/asset_defs.h6
-rw-r--r--include/game.h10
-rw-r--r--include/menu.h4
-rw-r--r--main.c18
-rw-r--r--src/asset_defs.c8
-rw-r--r--src/audio.c2
-rw-r--r--src/menu.c120
16 files changed, 173 insertions, 6 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 21cfb64..928ce35 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -5,6 +5,7 @@
"type_traits": "c",
"xutility": "c",
"editor.h": "c",
- "glass_doors.h": "c"
+ "glass_doors.h": "c",
+ "*.rh": "c"
}
} \ No newline at end of file
diff --git a/Makefile b/Makefile
index 8af44db..dd40d32 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,14 @@ main:
cp -a "build/." "C:/Manually installed programs/zombieshooter"
./build/zombies.exe -ip 127.0.0.1 -port 27015
+menu:
+ rm -rf "build/"
+ mkdir -p "build/"
+ cp -a "data/." "build/data"
+ gcc -m64 -g -Wl,--stack,4194304 -DMODE_DEBUG main.c -o build/zombies.exe -lSDL2_mixer -lSDL2
+ cp -a "build/." "C:/Manually installed programs/zombieshooter"
+ ./build/zombies.exe
+
debug_client:
./build/zombies.exe -ip 127.0.0.1 -port 27015 &
gdb --args ./build/zombies.exe -ip 172.29.64.1 -port 27015 \ No newline at end of file
diff --git a/data/imgs/ui/menu_screen.png b/data/imgs/ui/menu_screen.png
new file mode 100644
index 0000000..45dc425
--- /dev/null
+++ b/data/imgs/ui/menu_screen.png
Binary files differ
diff --git a/data/imgs/ui/splash2.jfif b/data/imgs/ui/splash2.jfif
deleted file mode 100644
index df8af3a..0000000
--- a/data/imgs/ui/splash2.jfif
+++ /dev/null
Binary files differ
diff --git a/data/imgs/ui/splash2.png b/data/imgs/ui/splash2.png
new file mode 100644
index 0000000..91fde80
--- /dev/null
+++ b/data/imgs/ui/splash2.png
Binary files differ
diff --git a/data/psd/menu_screen.psd b/data/psd/menu_screen.psd
new file mode 100644
index 0000000..10d4494
--- /dev/null
+++ b/data/psd/menu_screen.psd
Binary files differ
diff --git a/data/sounds/Goodnightmare.mp3 b/data/sounds/Goodnightmare.mp3
new file mode 100644
index 0000000..579f514
--- /dev/null
+++ b/data/sounds/Goodnightmare.mp3
Binary files differ
diff --git a/data/sounds/menu_ambient.mp3 b/data/sounds/menu_ambient.mp3
new file mode 100644
index 0000000..cfcd690
--- /dev/null
+++ b/data/sounds/menu_ambient.mp3
Binary files differ
diff --git a/data/sounds/menu_hover.wav b/data/sounds/menu_hover.wav
new file mode 100644
index 0000000..2eee23b
--- /dev/null
+++ b/data/sounds/menu_hover.wav
Binary files differ
diff --git a/include/asset_defs.h b/include/asset_defs.h
index 9deaf77..b187cda 100644
--- a/include/asset_defs.h
+++ b/include/asset_defs.h
@@ -5,6 +5,12 @@
/////// Loaded at game start.
image* img_splash_art1;
+image* img_splash_art2;
+image* img_menu_screen;
+
+Mix_Music* music_menu;
+
+Mix_Chunk* wav_menu_hover;
font* fnt_52;
font* fnt_48;
diff --git a/include/game.h b/include/game.h
index 60c170c..83c9b3d 100644
--- a/include/game.h
+++ b/include/game.h
@@ -18,6 +18,15 @@ typedef enum t_game_state {
GAMESTATE_PLAYING,
} game_state;
+typedef enum t_scene_state
+{
+ SCENE_MAIN_MENU,
+ SCENE_GAME,
+ SCENE_CREDITS,
+ SCENE_SETTINGS,
+ SCENE_LOBBY,
+} scene_state;
+
typedef struct t_game {
game_state state;
network_state network_state;
@@ -25,6 +34,7 @@ typedef struct t_game {
network_client *client;
} game;
+scene_state global_scene_state = SCENE_MAIN_MENU;
game global_state = {GAMESTATE_IDLE,DISCONNECTED,0,0};
void init_game();
diff --git a/include/menu.h b/include/menu.h
index a00e020..294f87b 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -1,9 +1,13 @@
#ifndef INCLUDE_MENU
#define INCLUDE_MENU
+#include <projectbase/project_base.h>
+
typedef struct t_menu_state
{
} menu_state;
+void update_menu(platform_window* window);
+
#endif \ No newline at end of file
diff --git a/main.c b/main.c
index ab4c64c..710abe6 100644
--- a/main.c
+++ b/main.c
@@ -31,6 +31,7 @@
#include "include/sprite.h"
#include "include/editor.h"
#include "include/glass_doors.h"
+#include "include/menu.h"
#include "src/map.c"
#include "src/players.c"
@@ -55,12 +56,19 @@
#include "src/sprite.c"
#include "src/editor.c"
#include "src/glass_doors.c"
+#include "src/menu.c"
#define CONFIG_DIRECTORY "zombieshooter"
void update_func(platform_window* window) {
renderer->render_clear(window, rgb(0,0,0));
- update_game(window);
+
+ if (global_scene_state == SCENE_GAME) {
+ update_game(window);
+ }
+ else if (global_scene_state == SCENE_MAIN_MENU) {
+ update_menu(window);
+ }
}
@@ -114,15 +122,19 @@ int main(int argc, char **argv)
else {
log_info("Audio failed.");
}
-
+
load_menu_assets();
+ play_music(music_menu);
init_game();
bool did_handle_args = false;
while(platform_keep_running(window)) {
if (global_asset_collection.done_loading_assets && !did_handle_args && global_state.state == GAMESTATE_LOADING_ASSETS) {
- handle_args(argc, argv);
+ if (argc > 1) {
+ handle_args(argc, argv);
+ global_scene_state = SCENE_GAME;
+ }
did_handle_args = true;
}
diff --git a/src/asset_defs.c b/src/asset_defs.c
index 9e29b10..cc7ac6b 100644
--- a/src/asset_defs.c
+++ b/src/asset_defs.c
@@ -4,7 +4,11 @@
#include "../data/fonts/aleo.h"
void load_menu_assets() { // Assets loaded at game start
- img_splash_art1 = assets_load_image_from_file("data/imgs/ui/splash1.png");
+ img_menu_screen = assets_load_image_from_file("data/imgs/ui/menu_screen.png");
+ img_splash_art2 = assets_load_image_from_file("data/imgs/ui/splash2.png");
+
+ wav_menu_hover = Mix_LoadWAV("data/sounds/menu_hover.wav");
+ music_menu = Mix_LoadMUS("data/sounds/menu_ambient.mp3");
fnt_52 = assets_load_font(Aleo_Regular, Aleo_Regular + Aleo_Regular_Size, 52);
fnt_48 = assets_load_font(Aleo_Regular, Aleo_Regular + Aleo_Regular_Size, 48);
@@ -19,6 +23,8 @@ void load_menu_assets() { // Assets loaded at game start
fnt_12 = assets_load_font(Aleo_Regular, Aleo_Regular + Aleo_Regular_Size, 12);
fnt_8 = assets_load_font(Aleo_Regular, Aleo_Regular + Aleo_Regular_Size, 8);
fnt_4 = assets_load_font(Aleo_Regular, Aleo_Regular + Aleo_Regular_Size, 4);
+
+ img_splash_art1 = assets_load_image_from_file("data/imgs/ui/splash1.png");
}
void load_assets() { // Assets loaded at match start.
diff --git a/src/audio.c b/src/audio.c
index 1363fa7..39c3557 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -151,7 +151,7 @@ void play_sound(int channel, Mix_Chunk* wav) {
void play_music(Mix_Music* music) {
Mix_FadeInMusic(music, -1, 2000);
- Mix_VolumeMusic(MIX_MAX_VOLUME/6);
+ Mix_VolumeMusic(MIX_MAX_VOLUME/8);
}
void play_positioned_sound(int channel, Mix_Chunk* wav, vec3f pos, float max_audible_dist) {
diff --git a/src/menu.c b/src/menu.c
new file mode 100644
index 0000000..1173c42
--- /dev/null
+++ b/src/menu.c
@@ -0,0 +1,120 @@
+#include "../include/menu.h"
+
+void draw_background(platform_window* window)
+{
+ image* img = img_splash_art2;
+ int imgw = img->width * (window->height/(float)img->height);
+ int imgh = window->height;
+
+ int imgx = (window->width - imgw) / 2 + _global_camera.x;
+ int imgy = 0 + _global_camera.y;
+ renderer->render_image(img, imgx, imgy, imgw, imgh);
+}
+
+float select_animation_duration = 0.0f;
+static bool draw_menu_option(platform_window* window, int x, int y, int w, int h, char* text, bool is_hovered)
+{
+ color txt = rgb(102, 255, 102);
+ color txt_bg = rgb(90, 176, 90);
+
+ if (is_hovered) {
+ renderer->render_rectangle(x, y, w, h, rgba(245,245,245, 100));
+ //txt = rgb(255,255,255);
+ }
+
+ font* fnt = get_font(window, 1.0f);
+ int offset_x = (w/2) - (renderer->calculate_text_width(fnt, text)/2);
+
+ if (is_hovered && (select_animation_duration*100) < 2*M_PI) offset_x += sin(select_animation_duration*100.0f)*10.0f;
+
+ renderer->render_text(fnt, x+offset_x + 1, y + (h/2) - (fnt->px_h/2) - 1, text, txt_bg);
+ renderer->render_text(fnt, x+offset_x, y + (h/2) - (fnt->px_h/2), text, txt);
+
+ 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;
+}
+
+int selected_menu_option = 0;
+void draw_screen(platform_window* window) {
+ image* img = img_menu_screen;
+ int imgw = img->width * (window->height/(float)img->height);
+ int imgh = window->height;
+
+ int imgx = (window->width - imgw) / 2 + _global_camera.x;
+ int imgy = 0 + _global_camera.y;
+
+ int text_offset_x = imgx + 1540 * (imgw/(float)img->width);
+ int text_offset_y = imgy + 475 * (imgh/(float)img->height);
+
+ int screen_w = 900 * (imgw/(float)img->width);
+ int screen_h = 560 * (imgh/(float)img->height);
+
+ renderer->render_image(img_splash_art2, text_offset_x, text_offset_y, screen_w, screen_h);
+ renderer->render_rectangle(text_offset_x, text_offset_y, screen_w, screen_h, rgba(40,40,40, 200));
+
+ 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 (selected_menu_option != 0) {
+ select_animation_duration = 0.0f;
+ play_sound(-1, wav_menu_hover);
+ }
+ selected_menu_option = 0;
+ }
+
+ 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 (selected_menu_option != 1) {
+ select_animation_duration = 0.0f;
+ play_sound(-1, wav_menu_hover);
+ }
+ 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 (selected_menu_option != 2) {
+ select_animation_duration = 0.0f;
+ play_sound(-1, wav_menu_hover);
+ }
+ selected_menu_option = 2;
+ }
+
+ if (draw_menu_option(window, text_offset_x, text_offset_y + item_h*3, screen_w, item_h, "Settings", 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 (draw_menu_option(window, text_offset_x, text_offset_y + item_h*4, screen_w, item_h, "Credits", 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);
+ }
+ selected_menu_option = 5;
+ }
+
+ renderer->render_image(img, imgx, imgy, imgw, imgh);
+}
+
+void update_menu(platform_window* window)
+{
+ //draw_background(window);
+ draw_screen(window);
+} \ No newline at end of file