aboutsummaryrefslogtreecommitdiff
path: root/src/GameLoop
diff options
context:
space:
mode:
authorUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2023-04-03 11:39:08 +0200
committerGitHub <noreply@github.com>2023-04-03 11:39:08 +0200
commit68862666219c07ee62c9e59dd6866c1c7b26cc00 (patch)
treeb0224b1516a362c27903efd4797f9bdf1a7eabc6 /src/GameLoop
parentcc23564547b736125fe7e7869de277ea4d4455ab (diff)
parentf761624a95de538bb2be8f9449ed0edb8ae067ad (diff)
Merge pull request #49 from UnavailableDev/dev
Game stuff
Diffstat (limited to 'src/GameLoop')
-rw-r--r--src/GameLoop/shop.c78
-rw-r--r--src/GameLoop/shop.h32
-rw-r--r--src/GameLoop/startingScreen.c32
-rw-r--r--src/GameLoop/startingScreen.h14
4 files changed, 156 insertions, 0 deletions
diff --git a/src/GameLoop/shop.c b/src/GameLoop/shop.c
new file mode 100644
index 0000000..fb7ef4c
--- /dev/null
+++ b/src/GameLoop/shop.c
@@ -0,0 +1,78 @@
+#include "shop.h"
+#include "engine/maths.h"
+#include "ppu/ppu.h"
+
+bool hh_show_Shop(){
+ static hh_e_ShopStates hh_e_Shop = hh_e_shop_init;
+ static hh_e_upgrades upgrades[HH_SHOP_UPG_DISPLAY] = {0};
+ static uint8_t selected = 0;
+
+ switch (hh_e_Shop)
+ {
+ case hh_e_shop_init:
+ hh_clear_screen();
+ hh_clear_sprite();
+
+ //TODO: render shop bg from level file here
+ //hh_setup_shop();
+ hh_shop_init(&upgrades);
+ selected = HH_SHOP_UPG_DISPLAY/2;
+ hh_shop_display(selected, &upgrades);
+ hh_e_Shop = hh_e_shop_main;
+ return false;
+ break;
+ case hh_e_shop_main:
+ if(g_hh_controller_p1.dpad_left || g_hh_controller_p1.dpad_right){
+ hh_shift_selected(&selected,(g_hh_controller_p1.dpad_right?1:0),0,HH_SHOP_UPG_DISPLAY);
+ hh_shop_display(selected, &upgrades);
+ }
+ if(g_hh_controller_p1.button_primary){
+ //apply selected upgrade
+ hh_e_Shop = hh_e_shop_end;
+ }
+ if(g_hh_controller_p1.button_secondary){
+ hh_e_Shop = hh_e_shop_end;
+ }
+ break;
+ case hh_e_shop_end:
+ hh_e_Shop = hh_e_shop_init;
+ return true;
+ break;
+ default:
+ hh_e_Shop = hh_e_shop_init;
+ break;
+ }
+ return false;
+}
+
+void hh_shop_init(hh_e_upgrades* in) {
+ for (int i = 0; i < HH_SHOP_UPG_DISPLAY; i++) {
+ in[i] = i%HH_SHOP_UPG_COUNT;
+ }
+}
+
+void hh_shop_display(uint8_t selected, hh_e_upgrades* upgrades) {
+ const vec_cor start = {48,16};
+ const uint8_t up = 8,
+ space = 24+8;
+
+ for (int i = 0; i < HH_SHOP_UPG_DISPLAY; i++) {
+ hh_ppu_update_foreground(i+16,
+ (hh_s_ppu_loc_fam_entry){
+ .horizontal_flip = false, .vertical_flip = false,
+ .position_x = i*space+start.x, .position_y = start.y + (i==selected?up:0),
+ .palette_index = 7,
+ .tilemap_index = i
+ });
+ }
+}
+
+void hh_shift_selected(uint8_t* pos, bool dir, uint8_t min, uint8_t max) {
+ if (dir) {
+ pos = CLAMP(++pos,min,max);
+ } else {
+ if (pos > 0) {
+ pos--;
+ }
+ }
+}
diff --git a/src/GameLoop/shop.h b/src/GameLoop/shop.h
new file mode 100644
index 0000000..5cd6b53
--- /dev/null
+++ b/src/GameLoop/shop.h
@@ -0,0 +1,32 @@
+#include "input.h"
+#include "engine/draw_screen.h"
+
+
+
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef enum {
+ hh_e_shop_init,
+ hh_e_shop_main,
+ hh_e_shop_end
+} hh_e_ShopStates;
+
+/** @brief amount of upgrade types */
+#define HH_SHOP_UPG_COUNT 2
+/** @brief count of visible upgrades in shop */
+#define HH_SHOP_UPG_DISPLAY 4
+/** @brief all possible upgrades */
+typedef enum {
+ hh_e_UPG_JUMP,
+ hh_e_UPG_HEALTH
+} hh_e_upgrades;
+
+/** @brief init */
+void hh_shop_init(hh_e_upgrades* in);
+/** @brief deals with displayed entity rendering */
+void hh_shop_display(uint8_t selected, hh_e_upgrades* upgrades);
+/** @brief moves 'cursor' through selection field */
+void hh_shift_selected(uint8_t* pos, bool dir, uint8_t min, uint8_t max);
+
+bool hh_show_Shop();
diff --git a/src/GameLoop/startingScreen.c b/src/GameLoop/startingScreen.c
new file mode 100644
index 0000000..4fc5af9
--- /dev/null
+++ b/src/GameLoop/startingScreen.c
@@ -0,0 +1,32 @@
+#include "startingScreen.h"
+#include "input.h"
+#include "engine/title_screen.h"
+#include "engine/draw_screen.h"
+// #include "engine/player_controller.h"
+
+bool hh_show_startingScreen(){
+ static hh_e_screenStates hh_e_startingScreen = hh_e_STATE_SHOW;
+
+ switch (hh_e_startingScreen)
+ {
+ case hh_e_STATE_SHOW:
+ hh_clear_screen();
+ hh_init_title_screen();
+ hh_e_startingScreen = hh_e_STATE_Input;
+ return false;
+ break;
+ case hh_e_STATE_Input:
+ if(g_hh_controller_p1.button_primary){
+ hh_e_startingScreen = hh_e_STATE_END;
+ }
+ break;
+ case hh_e_STATE_END:
+ hh_e_startingScreen = hh_e_STATE_SHOW;
+ return true;
+ break;
+ default:
+ hh_e_startingScreen = hh_e_STATE_SHOW;
+ break;
+ }
+ return false;
+}
diff --git a/src/GameLoop/startingScreen.h b/src/GameLoop/startingScreen.h
new file mode 100644
index 0000000..f51cc66
--- /dev/null
+++ b/src/GameLoop/startingScreen.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef enum {
+ hh_e_STATE_SHOW,
+ hh_e_STATE_Input,
+ hh_e_STATE_END
+} hh_e_screenStates;
+
+
+bool hh_show_startingScreen();
+