aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine/camera.c16
-rw-r--r--src/engine/camera.h6
-rw-r--r--src/engine/draw_screen.c9
-rw-r--r--src/engine/draw_screen.h2
-rw-r--r--src/engine/maths.c15
-rw-r--r--src/engine/maths.h3
-rw-r--r--src/engine/sprite_controller.c11
-rw-r--r--src/engine/sprite_controller.h24
8 files changed, 69 insertions, 17 deletions
diff --git a/src/engine/camera.c b/src/engine/camera.c
new file mode 100644
index 0000000..46c2d93
--- /dev/null
+++ b/src/engine/camera.c
@@ -0,0 +1,16 @@
+#include "engine/camera.h"
+
+#include "ppu/consts.h"
+
+
+vec_cor hh_update_camera(vec_cen new, vec2 min, vec2 max){
+
+ new = vec_cen2cor(new,(vec2){.x=20,.y=30});
+ static vec_cor old;
+
+ old.x = CLAMP(new.x,min.x,max.x);
+ old.y = CLAMP(new.y,min.y,max.y);
+
+ return old;
+}
+
diff --git a/src/engine/camera.h b/src/engine/camera.h
new file mode 100644
index 0000000..b3ffb52
--- /dev/null
+++ b/src/engine/camera.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#include "engine/maths.h"
+
+vec_cor hh_update_camera(vec_cor new, vec2 min, vec2 max);
+
diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c
index acf5b41..0295241 100644
--- a/src/engine/draw_screen.c
+++ b/src/engine/draw_screen.c
@@ -1,4 +1,5 @@
-#include "draw_screen.h"
+#include "engine/draw_screen.h"
+#include "engine/sprite_controller.h"
uint8_t hh_world_to_tile(vec2 pos){
@@ -37,8 +38,8 @@ void hh_draw_screen(vec_cor viewport){
void hh_setup_screen(){
//(HH_map_size_X*HH_map_size_Y)
- int size = 3200; // max X = 40 en max Y = 80
- FILE* level = fopen("../test/bin/test_map.bin", "rb"); /* open binary file */
+ int size = 2400; // max X = 40 en max Y = 80
+ FILE* level = fopen("../test/bin/level1_test.bin", "rb"); /* open binary file */
if (!level) { /* check if file opened successfully */
fprintf(stderr, "Error: Failed to open file.\n");
return;
@@ -53,7 +54,7 @@ void hh_setup_screen(){
hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){
.horizontal_flip = false,
.vertical_flip = false,
- .palette_index = tile[BAM_index]+1,
+ .palette_index = hh_get_palette(tile[BAM_index]),
.tilemap_index = tile[BAM_index],
});
}
diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h
index 8d7df47..b181108 100644
--- a/src/engine/draw_screen.h
+++ b/src/engine/draw_screen.h
@@ -2,7 +2,7 @@
// every function call for drawing the screen goes here.
-#include "../engine/maths.h"
+#include "engine/maths.h"
#include "ppu/ppu.h"
#include <stdio.h>
diff --git a/src/engine/maths.c b/src/engine/maths.c
new file mode 100644
index 0000000..ebd699c
--- /dev/null
+++ b/src/engine/maths.c
@@ -0,0 +1,15 @@
+#include "engine/maths.h"
+
+vec_cor vec_cen2cor(vec_cen in, vec2 halfDistance){
+ return (vec_cor){
+ .x = in.x - halfDistance.x,
+ .y = in.y - halfDistance.y,
+ };
+}
+
+vec_cen vec_cor2cen(vec_cor in, vec2 halfDistance){
+ return (vec_cen){
+ .x = in.x + halfDistance.x,
+ .y = in.y + halfDistance.y,
+ };
+}
diff --git a/src/engine/maths.h b/src/engine/maths.h
index c7f1b44..bd20202 100644
--- a/src/engine/maths.h
+++ b/src/engine/maths.h
@@ -9,6 +9,9 @@ typedef struct {
typedef vec2 vec_cen;//centered
typedef vec2 vec_cor;//left upper corner
+vec_cor vec_cen2cor(vec_cen in, vec2 halfDistance);
+vec_cor vec_cor2cen(vec_cen in, vec2 halfDistance);
+
//fixed point at decimal 7lsb (world positions in pixels (with fixed decimal point))
#define HH_MATH_FIXED_POINT 7
diff --git a/src/engine/sprite_controller.c b/src/engine/sprite_controller.c
index c224ff7..d4c44ab 100644
--- a/src/engine/sprite_controller.c
+++ b/src/engine/sprite_controller.c
@@ -4,7 +4,16 @@
// #include "engine/maths.h"
#include "ppu/types.h"
#include "ppu/consts.h"
+#include "ppu/ppu.h"
-uint8_t hh_get_palette(uint16_t tile_idx) {
+uint8_t hh_get_palette(uint8_t tile_idx) {
return hh_g_sprite_palette[tile_idx];
}
+
+void hh_setup_palettes(){
+ for (int idx = 0; idx < HH_PPU_PALETTE_COUNT; idx++) {
+ for (int col = 0; col < HH_PPU_PALETTE_COLOR_COUNT; col++) {
+ hh_ppu_update_color(idx,col,hh_g_palette[idx][col]);
+ }
+ }
+}
diff --git a/src/engine/sprite_controller.h b/src/engine/sprite_controller.h
index 47ab0af..001a459 100644
--- a/src/engine/sprite_controller.h
+++ b/src/engine/sprite_controller.h
@@ -11,10 +11,10 @@
//TODO: pack data inside of sprite_palette LUT
//HH_PPU_PALETTE_COUNT
-#define HH_SPRITE_COUNT 32
+#define HH_SPRITE_COUNT 40
#define HH_PAL_IDX_SKY 0
#define HH_PAL_IDX_BRICK 1
-uint8_t hh_g_sprite_palette[HH_SPRITE_COUNT] = {
+const static uint8_t hh_g_sprite_palette[HH_SPRITE_COUNT] = {
0,1,1,1,1,1,1,1,1,1, //1+9
1,1,1,1,1,1,1,1,1,1, //6+4
1,1,1,1,1,1,1,1,1, //9
@@ -23,7 +23,7 @@ uint8_t hh_g_sprite_palette[HH_SPRITE_COUNT] = {
};
-hh_ppu_loc_palette_table_t hh_g_palette = {
+const static hh_ppu_loc_palette_table_t hh_g_palette = {
{//palette info here
{0x1,0x2,0x3},
{0x0,0x0,0x0},
@@ -88,17 +88,19 @@ hh_ppu_loc_palette_table_t hh_g_palette = {
{0x0,0x0,0x0},
{0x0,0x0,0x0}},
{
+ {0x0,0xf,0xf},
{0xf,0xf,0xf},
- {0xf,0xf,0xf},
- {0x0,0x0,0x0},
- {0x0,0x0,0x0},
- {0x0,0x0,0x0},
- {0x0,0x0,0x0},
- {0x0,0x0,0x0},
+ {0xf,0x0,0xf},
+ {0xf,0xf,0x0},
+ {0xf,0x0,0x0},
+ {0x0,0xf,0x0},
+ {0x0,0x0,0xf},
{0x0,0x0,0x0}}
};
+void hh_setup_palettes();
+
/** @brief return palette index that belongs to tilemap index */
-uint8_t hh_get_palette(uint16_t tile_idx);
+uint8_t hh_get_palette(uint8_t tile_idx);
-bool hh_colidable(uint16_t tile_idx);
+bool hh_colidable(uint8_t tile_idx);