aboutsummaryrefslogtreecommitdiff
path: root/src/game_loop
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_loop')
-rw-r--r--src/game_loop/high_score.c104
-rw-r--r--src/game_loop/high_score.h29
-rw-r--r--src/game_loop/shop.c4
-rw-r--r--src/game_loop/shop.h3
4 files changed, 136 insertions, 4 deletions
diff --git a/src/game_loop/high_score.c b/src/game_loop/high_score.c
new file mode 100644
index 0000000..51f3d48
--- /dev/null
+++ b/src/game_loop/high_score.c
@@ -0,0 +1,104 @@
+#include "high_score.h"
+
+#include <string.h>
+
+#define HH_KB_MAX_X 9
+#define HH_KB_MAX_Y 4
+
+void hh_high_score(hh_e_game_state* hh_game_state) {
+ static hh_e_score_states hh_e_score = hh_e_score_show;
+ // static uint8_t selected[HH_KB_MAX_X][HH_KB_MAX_Y] = {0};
+ static char* name = "";
+ static hh_s_controller_exp con1;
+ static uint8_t selected_x = 0,
+ selected_y = 0;
+
+ hh_update_controller_exp(&con1);
+
+ switch (hh_e_score)
+ {
+ case hh_e_score_show:
+ hh_clear_screen();
+ hh_clear_sprite();
+ name = "";
+ if (!hh_controller_exp_pressed(con1)){
+ hh_e_score = hh_e_score_main;
+ }
+ break;
+ case hh_e_score_main:
+ if (con1.rising.dpad_left || con1.rising.dpad_right){
+ hh_shift_selected(&selected_x,con1.pressed.dpad_right,0,HH_KB_MAX_X-1);
+ }
+ if (con1.rising.dpad_up || con1.rising.dpad_down){
+ hh_shift_selected(&selected_y,con1.pressed.dpad_down,0,HH_KB_MAX_Y-1);
+ }
+ if (con1.rising.button_primary) {
+ int str_idx = selected_x + selected_y*HH_KB_MAX_X;
+ int len = strlen(name);
+ if (str_idx < 10) {
+ name[len] = str_idx + '0';
+ } else {
+ name[len] = str_idx + 'a';
+ }
+ name[len+1] = '\0';
+ }
+ int idx = 37;
+ hh_ui_show_char(&idx,name,(vec2){16,16});
+ hh_kb_display(selected_x + selected_y*HH_KB_MAX_X);
+
+
+ break;
+ case hh_e_score_end:
+ hh_e_score = hh_e_score_show;
+ *hh_game_state = hh_e_state_gameplay;
+ break;
+ default:
+ hh_e_score = hh_e_score_show;
+ break;
+ }
+
+}
+
+bool hh_controller_exp_pressed(hh_s_controller_exp con1) {
+ return (con1.pressed.button_primary || con1.pressed.button_secondary || con1.pressed.dpad_down || con1.pressed.dpad_up || con1.pressed.dpad_left || con1.pressed.dpad_right);
+}
+
+void hh_update_controller_exp(hh_s_controller_exp* in) {
+
+ in->falling.button_primary = (in->pressed.button_primary && !g_hh_controller_p1.button_primary);
+ in->falling.button_secondary = (in->pressed.button_secondary && !g_hh_controller_p1.button_secondary);
+ in->falling.dpad_right = (in->pressed.dpad_right && !g_hh_controller_p1.dpad_right);
+ in->falling.dpad_left = (in->pressed.dpad_left && !g_hh_controller_p1.dpad_left);
+ in->falling.dpad_down = (in->pressed.dpad_down && !g_hh_controller_p1.dpad_down);
+ in->falling.dpad_up = (in->pressed.dpad_up && !g_hh_controller_p1.dpad_up);
+
+ in->rising.button_primary = (!in->pressed.button_primary && g_hh_controller_p1.button_primary);
+ in->rising.button_secondary = (!in->pressed.button_secondary && g_hh_controller_p1.button_secondary);
+ in->rising.dpad_right = (!in->pressed.dpad_right && g_hh_controller_p1.dpad_right);
+ in->rising.dpad_left = (!in->pressed.dpad_left && g_hh_controller_p1.dpad_left);
+ in->rising.dpad_down = (!in->pressed.dpad_down && g_hh_controller_p1.dpad_down);
+ in->rising.dpad_up = (!in->pressed.dpad_up && g_hh_controller_p1.dpad_up);
+
+ in->pressed = g_hh_controller_p1;
+}
+
+void hh_kb_display(uint8_t sel) {
+ const vec_cor start = {(320-16*HH_KB_MAX_X)/2,120};
+ const uint8_t space = 16;
+ int counter = 0;
+ for (int y = 0; y < HH_KB_MAX_Y; y++) {
+ for (int x = 0; x < HH_KB_MAX_X; x++) {
+ hh_ppu_update_foreground(counter++,
+ (hh_s_ppu_loc_fam_entry){
+ .horizontal_flip = false, .vertical_flip = false,
+ .position_x = x*space+start.x,
+ .position_y = y*space+start.y,
+ .palette_index = (counter == sel ? 6 : 4),
+ .tilemap_index = HH_TM_FONT_OFFSET + counter
+ });
+ }
+
+ }
+
+}
+
diff --git a/src/game_loop/high_score.h b/src/game_loop/high_score.h
new file mode 100644
index 0000000..1af350a
--- /dev/null
+++ b/src/game_loop/high_score.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include "input.h"
+#include "engine/draw_screen.h"
+#include "engine/maths.h"
+#include "ppu/ppu.h"
+
+#include "game_loop/ui.h"
+
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef enum {
+ hh_e_score_show,
+ hh_e_score_main,
+ hh_e_score_end,
+} hh_e_score_states;
+
+typedef struct {
+ hh_s_gamepad pressed, rising, falling;
+} hh_s_controller_exp;
+
+void hh_high_score(hh_e_game_state* hh_game_state);
+
+bool hh_controller_exp_pressed(hh_s_controller_exp con1);
+
+void hh_update_controller_exp(hh_s_controller_exp* in);
+
+void hh_kb_display(uint8_t sel);
diff --git a/src/game_loop/shop.c b/src/game_loop/shop.c
index c8dcfe5..14d96e2 100644
--- a/src/game_loop/shop.c
+++ b/src/game_loop/shop.c
@@ -1,8 +1,4 @@
#include "shop.h"
-#include "engine/maths.h"
-#include "ppu/ppu.h"
-
-#include "game_loop/ui.h"
hh_e_upgrades hh_shop(hh_e_game_state* hh_game_state, hh_g_all_levels* levels, int rng_seed){
static hh_e_shop_states hh_e_shop = hh_e_shop_show;
diff --git a/src/game_loop/shop.h b/src/game_loop/shop.h
index c4f3ced..8c2f5b2 100644
--- a/src/game_loop/shop.h
+++ b/src/game_loop/shop.h
@@ -4,7 +4,10 @@
#include "engine/draw_screen.h"
#include "engine/level_const.h"
#include "engine/sprite_controller.h"
+#include "engine/maths.h"
+#include "ppu/ppu.h"
+#include "game_loop/ui.h"
#include <stdint.h>
#include <stdbool.h>