aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2023-03-10 10:32:46 +0100
committerGitHub <noreply@github.com>2023-03-10 10:32:46 +0100
commit458d620a4ae17c42e97413a49db6c1c5f53393e5 (patch)
tree2ec54be53445720aac90b10bd9c6a3d1bdbe3cfa /src
parentcf1effe02d99d74db684ff324a46fa32cf186417 (diff)
parenta7ddcb50ae67cd7178f3c3582faae68366c6e049 (diff)
Merge pull request #25 from lonkaars/game-engine
Game engine
Diffstat (limited to 'src')
-rw-r--r--src/stm32/TODO/hh_combat.h9
-rw-r--r--src/stm32/TODO/hh_draw_screen.h1
-rw-r--r--src/stm32/TODO/hh_entity.c41
-rw-r--r--src/stm32/TODO/hh_entity.h24
-rw-r--r--src/stm32/TODO/hh_level.h1
-rw-r--r--src/stm32/TODO/hh_rand.h1
-rw-r--r--src/stm32/TODO/maths.c10
-rw-r--r--src/stm32/TODO/maths.h16
-rw-r--r--src/stm32/TODO/player_controller.h4
-rw-r--r--src/stm32/TODO/sprite_controller.h6
10 files changed, 113 insertions, 0 deletions
diff --git a/src/stm32/TODO/hh_combat.h b/src/stm32/TODO/hh_combat.h
new file mode 100644
index 0000000..16c41f5
--- /dev/null
+++ b/src/stm32/TODO/hh_combat.h
@@ -0,0 +1,9 @@
+#include "hh_entity.h"
+
+
+// attacktypes:
+
+/// @brief basic attack
+/// @param dmg damage number
+/// @param target entity under attack (damage changes this hp value)
+void hh_attack_basic( int8_t dmg, hh_entity* target );
diff --git a/src/stm32/TODO/hh_draw_screen.h b/src/stm32/TODO/hh_draw_screen.h
new file mode 100644
index 0000000..f5d7507
--- /dev/null
+++ b/src/stm32/TODO/hh_draw_screen.h
@@ -0,0 +1 @@
+// every function call for drawing the screen goes here.
diff --git a/src/stm32/TODO/hh_entity.c b/src/stm32/TODO/hh_entity.c
new file mode 100644
index 0000000..fa550d5
--- /dev/null
+++ b/src/stm32/TODO/hh_entity.c
@@ -0,0 +1,41 @@
+#include <stdbool.h>
+
+#include "hh_entity.h"
+#include "maths.h"
+
+/*
+ PLAYER: (pos on X)
+ ,___,
+ | |
+ | X |
+ |___|
+
+*/
+
+bool hh_collision(vec2* pos1, vec2* pos2){
+ if (pos2->x == CLAMP(pos2->x,pos1->x,pos1->x+1.0f)){// hit x
+ return true;
+ }
+
+ if (pos2->y == CLAMP(pos2->y,pos1->y,pos1->y+0.99f)){// hit y
+ return true;
+ }
+ return false;
+}
+
+void hh_solve_collision(vec2* pos_environment, hh_entity* entity){
+ if (entity->vec.x > 0.0f){
+ entity->pos.x = MIN(entity->pos.x,pos_environment->x-1.0f);
+ entity->vec.x = 0.0f;
+ } else if (entity->vec.x < 0.0f){
+ entity->pos.x = MAX(entity->pos.x,pos_environment->x+1.0f);
+ entity->vec.x = 0.0f;
+ } else if (entity->vec.y > 0.0f){
+ entity->pos.x = MIN(entity->pos.x,pos_environment->x-1.0f);
+ entity->vec.x = 0.0f;
+ } else if (entity->vec.y < 0.0f){
+ entity->pos.x = MAX(entity->pos.x,pos_environment->x+1.0f);
+ entity->vec.x = 0.0f;
+ }
+}
+
diff --git a/src/stm32/TODO/hh_entity.h b/src/stm32/TODO/hh_entity.h
new file mode 100644
index 0000000..fdbeb8a
--- /dev/null
+++ b/src/stm32/TODO/hh_entity.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <stdint.h>
+
+#include "maths.h"
+
+typedef struct {
+ vec2 pos, vec;
+ bool is_grounded;
+ int8_t hp;
+ //armor/block?
+}hh_entity;
+
+/// @brief detect for collision enity and eviroment
+/// @param pos1 position of environment tile to be checked
+/// @param pos2 position entity
+/// @return true if collision between enity and environment
+bool hh_collision(vec2* pos1, vec2* pos2);
+
+/// @brief solve collisions
+/// @param environment position
+/// @param entity position
+/// @return solved new entity position
+void hh_solve_collision(vec2* pos_environment, hh_entity* entity);
diff --git a/src/stm32/TODO/hh_level.h b/src/stm32/TODO/hh_level.h
new file mode 100644
index 0000000..43b19a3
--- /dev/null
+++ b/src/stm32/TODO/hh_level.h
@@ -0,0 +1 @@
+//deal with loading/saving the correct level
diff --git a/src/stm32/TODO/hh_rand.h b/src/stm32/TODO/hh_rand.h
new file mode 100644
index 0000000..ea7c1d4
--- /dev/null
+++ b/src/stm32/TODO/hh_rand.h
@@ -0,0 +1 @@
+// deal with Pseudo random number generation here.
diff --git a/src/stm32/TODO/maths.c b/src/stm32/TODO/maths.c
new file mode 100644
index 0000000..2f4444a
--- /dev/null
+++ b/src/stm32/TODO/maths.c
@@ -0,0 +1,10 @@
+#include "maths.h"
+
+float clamp( float* x, float *min, float *max ){
+ if (*x < *min)
+ return *min;
+ else if (*x > *max)
+ return *max;
+ else
+ return *x;
+}
diff --git a/src/stm32/TODO/maths.h b/src/stm32/TODO/maths.h
new file mode 100644
index 0000000..0889c47
--- /dev/null
+++ b/src/stm32/TODO/maths.h
@@ -0,0 +1,16 @@
+#pragma once
+
+// #include <math.h>
+
+typedef struct {
+ u_int32_t x,y;
+} vec2;
+
+typedef vec2 vec_cen;//centered
+typedef vec2 vec_cor;//left upper corner
+
+#define HH_MATH_FIXED_POINT 7 //fixed point at decimal 7lsb (world positions in pixels (with fixed decimal point))
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+#define CLAMP(N,LOWER,UPPER) (MIN(MAX(LOWER, N), UPPER))
diff --git a/src/stm32/TODO/player_controller.h b/src/stm32/TODO/player_controller.h
new file mode 100644
index 0000000..1e9b86c
--- /dev/null
+++ b/src/stm32/TODO/player_controller.h
@@ -0,0 +1,4 @@
+#include "maths.h"
+#include "hh_entity.h"
+
+// inputs
diff --git a/src/stm32/TODO/sprite_controller.h b/src/stm32/TODO/sprite_controller.h
new file mode 100644
index 0000000..c1fadff
--- /dev/null
+++ b/src/stm32/TODO/sprite_controller.h
@@ -0,0 +1,6 @@
+// handles sprites
+
+// Bg sprites
+
+
+// Fg or entity sprites