aboutsummaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
authorUnavailableDev <ggwildplay@gmail.com>2023-03-15 20:44:06 +0100
committerUnavailableDev <ggwildplay@gmail.com>2023-03-15 20:44:06 +0100
commit623bcb03aead264b412bcba9fed75df22e115fab (patch)
treef71e0eaa78d17f997c275f7ca5b457f11752dc01 /src/engine
parent0c3292879774e33dfb3e8c7d787b236876508467 (diff)
added title screen
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/draw_screen.c33
-rw-r--r--src/engine/draw_screen.h5
-rw-r--r--src/engine/sprite_controller.c4
-rw-r--r--src/engine/sprite_controller.h31
-rw-r--r--src/engine/title_screen.c93
-rw-r--r--src/engine/title_screen.h3
6 files changed, 154 insertions, 15 deletions
diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c
index c4f3389..58553bd 100644
--- a/src/engine/draw_screen.c
+++ b/src/engine/draw_screen.c
@@ -2,8 +2,8 @@
#include "engine/sprite_controller.h"
uint8_t hh_world_to_tile(vec2 pos){
-
- FILE* level = fopen("../test/bin/level1_test.bin", "rb"); /* open binary file */
+ //TODO: remove magic file name here
+ FILE* level = fopen("static/tiles.bin", "rb"); /* open binary file */
if (!level) { /* check if file opened successfully */
fprintf(stderr, "Error: Failed to open file.\n");
return 0;
@@ -39,9 +39,10 @@ void hh_draw_screen(vec_cor viewport){
void hh_setup_screen(){
//(HH_map_size_X*HH_map_size_Y)
int size = 2400; // max X = 40 en max Y = 80
- FILE* level = fopen("../test/bin/level1_test.bin", "rb"); /* open binary file */
+ //TODO: remove magic file name here
+ FILE* level = fopen("static/level1_test.bin", "rb"); /* open binary file */
if (!level) { /* check if file opened successfully */
- fprintf(stderr, "Error: Failed to open file.\n");
+ fprintf(stderr, "Error: Failed to open level file.\n");
return;
}
fseek(level, (0* sizeof(int)) + sizeof(int), SEEK_SET);
@@ -60,3 +61,27 @@ void hh_setup_screen(){
}
free(tile);
}
+
+void hh_clear_screen(){
+ // (HH_PPU_SCREEN_HEIGHT*HH_PPU_SCREEN_WIDTH)/(HH_PPU_SPRITE_HEIGHT*HH_PPU_SPRITE_WIDTH)
+ for (int i = 0; i < HH_PPU_BG_CANVAS_TILES_H*HH_PPU_BG_CANVAS_TILES_V; i++) {
+ hh_s_ppu_loc_bam_entry temp = {
+ .vertical_flip=false,.horizontal_flip = false,
+ .palette_index = 3,.tilemap_index = 0
+ };
+ hh_ppu_update_background(i,temp);
+ hh_ppu_update_color(3,0,(hh_ppu_rgb_color_t){0x0,0x0,0x0});
+ }
+ hh_ppu_update_aux((hh_s_ppu_loc_aux){
+ .bg_shift_x = 0,
+ .bg_shift_y = 0,
+ .fg_fetch = 0,
+ .sysreset = 0,
+ });
+}
+
+void hh_clear_sprite(){
+ for (int i = 0; i < HH_PPU_FG_SPRITE_COUNT; i++) {
+ hh_ppu_update_sprite(i,(hh_s_ppu_loc_sprite){0});
+ }
+}
diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h
index b181108..95765e5 100644
--- a/src/engine/draw_screen.h
+++ b/src/engine/draw_screen.h
@@ -3,6 +3,7 @@
// every function call for drawing the screen goes here.
#include "engine/maths.h"
+#include "ppu/consts.h"
#include "ppu/ppu.h"
#include <stdio.h>
@@ -19,3 +20,7 @@ uint8_t hh_world_to_tile(vec2 pos);
void hh_draw_screen(vec2 viewport);
/** @brief send data to BAM memory from binary level */
void hh_setup_screen();
+/** @brief send black screen to background memory */
+void hh_clear_screen();
+/** @brief clears all sprite data */
+void hh_clear_sprite();
diff --git a/src/engine/sprite_controller.c b/src/engine/sprite_controller.c
index 5d93cf8..b38b647 100644
--- a/src/engine/sprite_controller.c
+++ b/src/engine/sprite_controller.c
@@ -10,11 +10,13 @@ uint8_t hh_get_palette(uint8_t tile_idx) {
}
void hh_setup_palettes(){
+ //TODO: use simpler function
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]);
}
- }
+ }
+ // hh_ppu_update_palette_table(hh_g_palette);
}
bool hh_colidable(uint8_t tile_idx){
diff --git a/src/engine/sprite_controller.h b/src/engine/sprite_controller.h
index fbb230c..c6ebc93 100644
--- a/src/engine/sprite_controller.h
+++ b/src/engine/sprite_controller.h
@@ -11,14 +11,25 @@
//TODO: pack data inside of sprite_palette LUT
//HH_PPU_PALETTE_COUNT
-#define HH_SPRITE_COUNT 40
+#define HH_SPRITE_COUNT 80
#define HH_PAL_IDX_SKY 0
#define HH_PAL_IDX_BRICK 1
const static uint8_t hh_g_sprite_palette[HH_SPRITE_COUNT] = {
+ //TODO: make a buffer of 16 no-collider sprites (instead of the current 1)
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
- 7,7,7,2,7,7,1,2,7
+ 7,7,7,2,7,7,1,2,7,
+ 7,7,7,7, //??
+
+ 7,6,6,6,6,6,6,6, //baskets
+ 7,7,7,7,7,7,7,7,7,7, //shop
+ 7,7,7,7,7, //shop
+ 6,6,6,6,6, //(hi-)score
+
+ 3,3,3,3,3,3, //title_screen icon
+ 6,6,6,6,/*6,6,6,6,6,6, //title_screen large letters
+ 6,6,6,6,*/
//other palettes here:
};
@@ -51,14 +62,14 @@ const static hh_ppu_loc_palette_table_t hh_g_palette = {
{0x0,0x0,0x0},
{0x0,0x0,0x0},
{0x0,0x0,0x0}},
- {//player
+ {//player //TODO: use one less color && update player indexed sprites
{0x0,0x0,0x0},
{0x1,0x1,0x1},
{0x4,0x2,0x5},
- {0x7,0x3,0x6},
- {0x1,0x1,0x3},
- {0xe,0xe,0xe},
- {0x0,0x0,0x0},
+ {0x7,0x3,0x7},
+ {0x1,0x1,0x3},
+ {0xe,0xe,0xe},
+ {0x0,0x0,0x0},
{0x0,0x0,0x0}},
{
{0x0,0x0,0x0},
@@ -69,7 +80,7 @@ const static hh_ppu_loc_palette_table_t hh_g_palette = {
{0x0,0x0,0x0},
{0x0,0x0,0x0},
{0x0,0x0,0x0}},
- {
+ {//elemental
{0x0,0x0,0x0},
{0x0,0x0,0x0},
{0x0,0x0,0x0},
@@ -79,7 +90,7 @@ const static hh_ppu_loc_palette_table_t hh_g_palette = {
{0x0,0x0,0x0},
{0x0,0x0,0x0}},
{//white
- {0xf,0xf,0xf},
+ {0x1,0x2,0x3},
{0xf,0xf,0xf},
{0xf,0xf,0xf},
{0xf,0xf,0xf},
@@ -87,7 +98,7 @@ const static hh_ppu_loc_palette_table_t hh_g_palette = {
{0xf,0xf,0xf},
{0xf,0xf,0xf},
{0xf,0xf,0xf}},
- {
+ {//Dev palette (7)
{0x0,0xf,0xf},
{0xf,0xf,0xf},
{0xf,0x0,0xf},
diff --git a/src/engine/title_screen.c b/src/engine/title_screen.c
new file mode 100644
index 0000000..9c7ed48
--- /dev/null
+++ b/src/engine/title_screen.c
@@ -0,0 +1,93 @@
+#include "ppu/ppu.h"
+#include "ppu/types.h"
+#include "ppu/consts.h"
+
+
+#include "engine/draw_screen.h"
+#include "engine/entity.h"
+
+void hh_init_title_screen(){
+
+ // hh_clear_screen();
+
+ //send data
+ uint8_t idx = 0;
+ const uint8_t tilemap_offset = 59;
+ int tiles_h = HH_PPU_BG_CANVAS_TILES_H;
+ int vp_h = HH_PPU_SCREEN_WIDTH/HH_PPU_SPRITE_WIDTH; //screen_h in tiles
+ int vert_offset = tiles_h*3;
+
+ const uint8_t arr[4][4] = {
+ {0,1,1,0},
+ {2,3,3,2},
+ {4,0,0,4},
+ {5,6,6,5},
+ };
+ int val, counter =0;
+ hh_ppu_update_color(5, 0, (hh_ppu_rgb_color_t) {0x1, 0x1, 0x1});
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ val = arr[i][j];
+
+ hh_s_ppu_loc_bam_entry temp = {
+ .vertical_flip=false, .horizontal_flip = ((j % 4 < 2) ? false : true),
+ .palette_index = (counter == 9 || counter == 10? 5:3), .tilemap_index = (val > 0 ? (tilemap_offset + val) : 0)
+ };
+
+ int vert_pos = tiles_h*i;
+ int x_pos = j;
+ idx = vert_offset + vert_pos + x_pos + vp_h/2-2;
+
+ hh_ppu_update_background(idx,temp);
+ counter++;
+ }
+
+ }
+
+
+ const uint8_t letters_offset = 66;
+ const int _size_hooded = 7, _size_v = 2;
+
+ // char* hh = "hooded";
+ int hooded_lookup[7][2]={
+ {0,1},{0,2},//H
+ {3,4},{3,4},//oo
+ {5,6},{13,9},//de
+ {5,6}//d
+ };
+
+ counter = 8;
+ for (int i = 0; i < _size_hooded; i++) {
+ for (int vert = 1; vert <= _size_v; vert++) {
+ //TODO: move 'H' a few pixels to the right for a more cohesive font spacing
+ hh_ppu_update_foreground(counter++, (hh_s_ppu_loc_fam_entry) {
+ .vertical_flip = false, .horizontal_flip = false,
+ .palette_index = 6, .tilemap_index = letters_offset + hooded_lookup[i][vert-1],
+ .position_x = (16*i + 64+48), .position_y = (16*(vert > 1 ? 0:1)*-1 + 64+8+16 +(i==2 || i==3 ? 6:0))
+ });
+ }
+ }
+
+
+ hh_ppu_update_color(5, 1, (hh_ppu_rgb_color_t) {0xa, 0x3, 0x3});
+ hh_ppu_update_color(5, 2, (hh_ppu_rgb_color_t) {0xc, 0x5, 0x3});
+
+ const int _size_havoc = 6;
+ int lookup_havoc[6][2]={
+ {0,1},{0,2},//H
+ {13,10},{7,8},//av
+ {13,11},{13,12}//oc
+ };
+
+ counter = 8 + (_size_hooded * _size_v);
+ for (int i = 0; i < _size_havoc; i++) {
+ for (int vert = 1; vert <= _size_v; vert++) {
+ //TODO: move 'H' a few pixels to the right for a more cohesive font spacing
+ hh_ppu_update_foreground(counter++, (hh_s_ppu_loc_fam_entry) {
+ .vertical_flip = false, .horizontal_flip = (i > 4 && vert==0 ? 1:0),
+ .palette_index = 5, .tilemap_index = letters_offset + lookup_havoc[i][vert-1],
+ .position_x = (16*i +64+32+8), .position_y = (16*(vert > 1 ? 0:1)*-1 + 64+8+48)
+ });
+ }
+ }
+}
diff --git a/src/engine/title_screen.h b/src/engine/title_screen.h
new file mode 100644
index 0000000..b5eda63
--- /dev/null
+++ b/src/engine/title_screen.h
@@ -0,0 +1,3 @@
+#pragma once
+
+void hh_init_title_screen();