From f4e4b53fe3ef96a7bd2d4052c5a181f05945a0aa Mon Sep 17 00:00:00 2001 From: NielsCoding <101340368+NielsCoding@users.noreply.github.com> Date: Sat, 11 Mar 2023 11:16:50 +0100 Subject: makefile engine --- src/makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index c69bfb5..96751fb 100644 --- a/src/makefile +++ b/src/makefile @@ -30,7 +30,8 @@ CFLAGS += $(if $(DESKTOP), -DHH_TARGET_DESKTOP, ) LOCAL_SRCS += main.c \ ppu/internals.c \ ppu/ppu.c \ - demo.c + demo.c \ + engine/engine.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) -- cgit v1.2.3 From 557cbed3ab2dea1dafd61ccdc3521aeed9b63a43 Mon Sep 17 00:00:00 2001 From: NielsCoding <101340368+NielsCoding@users.noreply.github.com> Date: Sat, 11 Mar 2023 19:46:57 +0100 Subject: drawing map en read from binary complete. shift to background. --- src/engine/draw_screen.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ src/engine/draw_screen.h | 18 +++++++++++--- src/makefile | 3 ++- 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/engine/draw_screen.c (limited to 'src/makefile') diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c new file mode 100644 index 0000000..3e4d8c4 --- /dev/null +++ b/src/engine/draw_screen.c @@ -0,0 +1,61 @@ +#include "draw_screen.h" + +uint8_t hh_world_to_tile(vec2 pos){ + + FILE* level = fopen("../test/bin/test_map.bin", "rb"); /* open binary file */ + if (!level) { /* check if file opened successfully */ + fprintf(stderr, "Error: Failed to open file.\n"); + return 0; + } + int index = (pos.y + pos.x); + fseek(level, (index * sizeof(int)) + sizeof(int), SEEK_SET); + int* tile = (int*)malloc(sizeof(int)); + fread(tile, sizeof(int), 1, level); // read 1 tile from binary + + fclose(level); + int val = *tile; + free(tile); + return val; +} + + +// remeber old value to know which part to update. +vec2 previousViewport = { .x = 0, .y = 0 }; +void hh_draw_screen(vec2 viewport){ + if (viewport.x == previousViewport.x && viewport.y == previousViewport.y) return; + + hh_ppu_update_aux((hh_s_ppu_loc_aux){ + .bg_shift_x = viewport.x*HH_PPU_SPRITE_WIDTH, + .bg_shift_y = viewport.y*HH_PPU_SPRITE_HEIGHT, + .fg_fetch = 0, + .sysreset = 0, + }); + + // update previous viewport values + previousViewport = 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 */ + if (!level) { /* check if file opened successfully */ + fprintf(stderr, "Error: Failed to open file.\n"); + return; + } + fseek(level, (0* sizeof(int)) + sizeof(int), SEEK_SET); + int* tile = (int*)malloc(size*sizeof(int)); + fread(tile, sizeof(int), size, level); // read 1 tile from binary + + fclose(level); + + for(int BAM_index = 0; BAM_index < size; BAM_index++){ + hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = tile[BAM_index]+1, + .tilemap_index = tile[BAM_index], + }); + } + free(tile); +} diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h index 4af5865..8d7df47 100644 --- a/src/engine/draw_screen.h +++ b/src/engine/draw_screen.h @@ -2,8 +2,20 @@ // every function call for drawing the screen goes here. -#include "engine/maths.h" +#include "../engine/maths.h" +#include "ppu/ppu.h" +#include #include -uint16_t hh_world_to_tile(vec2 pos); -void hh_draw_screen(vec2 viewport); \ No newline at end of file +#include + + +#define HH_map_size_X 80 +#define HH_map_size_Y 60 + +/** @brief return a single tile from world binary */ +uint8_t hh_world_to_tile(vec2 pos); +/** @brief shift to level if viewport changed position */ +void hh_draw_screen(vec2 viewport); +/** @brief send data to BAM memory from binary level */ +void hh_setup_screen(); diff --git a/src/makefile b/src/makefile index 96751fb..96f3108 100644 --- a/src/makefile +++ b/src/makefile @@ -31,7 +31,8 @@ LOCAL_SRCS += main.c \ ppu/internals.c \ ppu/ppu.c \ demo.c \ - engine/engine.c + engine/engine.c \ + engine/draw_screen.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) -- cgit v1.2.3 From a386709d12167ab8f85336a1764040c3f573e9eb Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Sun, 12 Mar 2023 11:37:58 +0100 Subject: integrated palettes and fixed reading tiles --- src/engine/engine.c | 1 + src/engine/sprite_controller.c | 10 + src/engine/sprite_controller.h | 96 ++++++++ src/makefile | 3 +- src/ppusim/sim.c | 12 +- test/bin/exportingPalettes.md | 4 + test/bin/test_file_read.c | 11 +- test/bin/tilemap.pip | 512 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 637 insertions(+), 12 deletions(-) create mode 100644 test/bin/exportingPalettes.md create mode 100644 test/bin/tilemap.pip (limited to 'src/makefile') diff --git a/src/engine/engine.c b/src/engine/engine.c index f3410a4..799ee7c 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -1,3 +1,4 @@ #include "engine/draw_screen.h" #include "engine/level.h" #include "engine/maths.h" +#include "engine/sprite_controller.h" diff --git a/src/engine/sprite_controller.c b/src/engine/sprite_controller.c index e69de29..c224ff7 100644 --- a/src/engine/sprite_controller.c +++ b/src/engine/sprite_controller.c @@ -0,0 +1,10 @@ +#include + +#include "engine/sprite_controller.h" +// #include "engine/maths.h" +#include "ppu/types.h" +#include "ppu/consts.h" + +uint8_t hh_get_palette(uint16_t tile_idx) { + return hh_g_sprite_palette[tile_idx]; +} diff --git a/src/engine/sprite_controller.h b/src/engine/sprite_controller.h index a433bd6..47ab0af 100644 --- a/src/engine/sprite_controller.h +++ b/src/engine/sprite_controller.h @@ -1,8 +1,104 @@ #pragma once +#include + +#include "ppu/types.h" + // handles sprites // Bg sprites // Fg or entity sprites +//TODO: pack data inside of sprite_palette LUT +//HH_PPU_PALETTE_COUNT +#define HH_SPRITE_COUNT 32 +#define HH_PAL_IDX_SKY 0 +#define HH_PAL_IDX_BRICK 1 +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 + 7,7,7,2,7,7,1,2,7 + //other palettes here: +}; + + +hh_ppu_loc_palette_table_t hh_g_palette = { + {//palette info here + {0x1,0x2,0x3}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + {//Bricks + {0x1,0x2,0x3},//01 + {0xd,0x8,0xa},//24 + {0x0,0x0,0x1},//25 + {0x1,0x1,0x1},//26 + {0x1,0x1,0x2},//27 + {0x2,0x2,0x3},//28 + {0x3,0x4,0x5},//29 + {0x5,0x1,0x7}}, + {//slime + {0x1,0x2,0x3}, + {0x1,0x3,0x2}, + {0x4,0x8,0x3}, + {0x7,0xa,0x4}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0xf,0xf,0xf}, + {0xf,0xf,0xf}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}} +}; + +/** @brief return palette index that belongs to tilemap index */ +uint8_t hh_get_palette(uint16_t tile_idx); +bool hh_colidable(uint16_t tile_idx); diff --git a/src/makefile b/src/makefile index 96751fb..02fcb12 100644 --- a/src/makefile +++ b/src/makefile @@ -31,7 +31,8 @@ LOCAL_SRCS += main.c \ ppu/internals.c \ ppu/ppu.c \ demo.c \ - engine/engine.c + engine/engine.c \ + engine/sprite_controller.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index a759039..1e7e609 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -29,21 +29,21 @@ void hh_ppu_init() { } void hh_ppu_load_tilemap() { - char* filename = "tiles.bin"; + char* filename = "../test/bin/tiles.bin"; FILE* fp = fopen(filename,"rb"); if (!fp){ - printf("File error!"); + fprintf(stderr,"File error!"); return;//error } - + int sprite_size = (HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT); fseek(fp, 0, SEEK_END);//goto EOF - int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE; + int _size = ftell(fp)/sprite_size; fseek(fp, 0, 0);//goto start of file for (int i = 0; i < _size; i++) { - uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE]; + uint8_t data[sprite_size]; - fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); + fread(data,sizeof(uint8_t),sprite_size,fp); hh_s_ppu_vram_data sprite = hh_ppu_2nat_sprite(data); sprite.offset = i*HH_PPU_VRAM_TMM_SPRITE_SIZE; diff --git a/test/bin/exportingPalettes.md b/test/bin/exportingPalettes.md new file mode 100644 index 0000000..be4a354 --- /dev/null +++ b/test/bin/exportingPalettes.md @@ -0,0 +1,4 @@ +```sh +cat test.src|head -n 46 | awk '{printf "%02x: {0x%x,0x%x,0x%x}\n",NR,$1/2,$2/2,$3/2 }' > hex_palettes +``` + diff --git a/test/bin/test_file_read.c b/test/bin/test_file_read.c index 391e2c6..df93395 100644 --- a/test/bin/test_file_read.c +++ b/test/bin/test_file_read.c @@ -18,19 +18,20 @@ void printData(uint8_t* in) { void hh_ppu_load_tilemap() { - char* filename = "tiles.bin"; + char* filename = "slime.bin"; FILE* fp = fopen(filename,"rb"); if (!fp){ return;//error } + int sprite_size = (16 * 16); fseek(fp, 0, SEEK_END); - int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE; - fseek(fp, 0, 0); + int _size = ftell(fp)/sprite_size; + rewind(fp); // printf("%i",_size); for (int i = 0; i < _size; i++) { - uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE]; - fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); + uint8_t data[sprite_size]; + fread(data,1,sprite_size,fp); printData(data); } diff --git a/test/bin/tilemap.pip b/test/bin/tilemap.pip new file mode 100644 index 0000000..c0c646e --- /dev/null +++ b/test/bin/tilemap.pip @@ -0,0 +1,512 @@ +0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0100: 06 06 06 06 06 05 06 06 06 06 06 05 06 06 06 06 +0110: 06 05 05 05 05 03 05 05 05 05 05 03 05 05 05 05 +0120: 06 05 04 04 04 03 05 05 05 05 05 03 05 05 05 05 +0130: 06 04 04 04 04 02 02 02 02 02 02 02 02 02 02 02 +0140: 06 04 04 04 04 02 02 03 03 03 03 03 03 02 03 03 +0150: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0160: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0170: 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 02 +0180: 06 06 04 04 04 04 04 02 02 02 03 03 03 03 02 02 +0190: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +01a0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 +01b0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +01c0: 00 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 +01d0: 00 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 +01e0: 00 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 +01f0: 06 06 06 05 05 05 02 02 02 02 02 02 02 02 02 02 +0200: 06 06 06 05 06 06 06 06 06 06 06 05 06 06 06 06 +0210: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 +0220: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 +0230: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0240: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0250: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0260: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +0270: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0280: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +0290: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +02a0: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +02b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +02c0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +02d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +02e0: 02 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +02f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0300: 06 06 06 05 06 06 06 06 06 06 05 06 06 06 06 06 +0310: 05 05 05 03 05 05 05 05 05 05 03 05 05 05 05 06 +0320: 05 05 05 03 05 05 05 05 05 05 03 04 04 05 05 06 +0330: 02 02 02 02 02 02 02 02 02 02 02 04 04 04 04 06 +0340: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 06 +0350: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 +0360: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 +0370: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 +0380: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 +0390: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +03a0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +03b0: 02 02 02 02 02 02 02 02 02 02 02 05 05 06 06 06 +03c0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 06 +03d0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 06 +03e0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 05 +03f0: 02 02 02 02 02 02 02 02 02 02 02 02 03 03 03 05 +0400: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0410: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0420: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 02 02 +0430: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +0440: 00 05 04 04 04 03 02 03 03 03 03 03 03 02 03 03 +0450: 00 05 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0460: 00 04 04 04 04 02 03 03 03 03 03 02 02 02 02 03 +0470: 06 06 05 05 02 02 02 02 02 02 02 02 02 02 02 02 +0480: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0490: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +04a0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 +04b0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +04c0: 00 05 05 04 04 04 04 03 02 03 03 03 03 03 03 03 +04d0: 00 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 +04e0: 00 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 +04f0: 00 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 +0500: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +0510: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +0520: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +0530: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0540: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +0550: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0560: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +0570: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0580: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +0590: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +05a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +05b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +05c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +05d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +05e0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +05f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0600: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 +0610: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 +0620: 03 03 02 02 03 03 03 03 03 03 03 02 04 04 04 00 +0630: 02 02 02 02 02 02 02 02 02 02 02 02 02 06 06 06 +0640: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 06 +0650: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 +0660: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 +0670: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 +0680: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 +0690: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +06a0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +06b0: 02 02 02 02 02 02 02 02 02 02 02 03 03 06 06 06 +06c0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 06 +06d0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 05 +06e0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 05 +06f0: 02 02 02 02 02 02 02 02 02 02 02 02 03 03 03 05 +0700: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0710: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0720: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 02 02 +0730: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +0740: 00 05 04 04 04 03 02 03 03 03 03 03 03 02 03 03 +0750: 00 05 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0760: 00 04 04 04 04 02 03 03 03 03 03 02 02 02 02 03 +0770: 06 06 05 05 02 02 02 02 02 02 02 02 02 02 02 02 +0780: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0790: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +07a0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 +07b0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +07c0: 00 05 05 04 04 04 04 04 04 04 04 02 02 02 02 04 +07d0: 00 05 05 04 04 04 04 04 04 04 04 04 02 04 04 04 +07e0: 00 06 05 05 05 04 04 04 04 04 04 04 03 04 04 04 +07f0: 00 06 06 06 05 05 05 05 05 05 05 05 03 05 05 05 +0800: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +0810: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +0820: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +0830: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0840: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +0850: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0860: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +0870: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0880: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +0890: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +08a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +08b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +08c0: 04 04 04 04 04 04 04 04 03 03 03 04 04 04 04 04 +08d0: 04 04 04 04 04 04 04 04 04 03 03 04 04 04 04 04 +08e0: 04 04 04 04 04 04 04 04 04 03 04 04 04 04 04 04 +08f0: 05 05 05 05 05 05 05 05 05 03 05 05 05 05 05 05 +0900: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 +0910: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 +0920: 03 03 02 02 03 03 03 03 03 03 03 02 04 04 04 00 +0930: 02 02 02 02 02 02 02 02 02 02 02 02 02 06 06 06 +0940: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 06 +0950: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 +0960: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 +0970: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 +0980: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 +0990: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +09a0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +09b0: 02 02 02 02 02 02 03 03 03 03 03 03 03 06 06 06 +09c0: 04 04 03 03 03 04 04 04 04 04 04 04 04 04 05 06 +09d0: 04 04 04 03 03 04 04 04 04 04 04 04 04 05 05 05 +09e0: 04 04 04 03 04 04 04 04 04 04 04 05 05 05 05 06 +09f0: 05 05 05 03 05 05 05 05 05 05 05 05 05 06 06 06 +0a00: 06 06 06 06 06 05 06 06 06 06 06 05 06 06 06 06 +0a10: 06 05 05 05 05 03 05 05 05 05 05 03 05 05 05 05 +0a20: 06 05 04 04 04 03 05 05 05 05 05 03 05 05 05 05 +0a30: 06 04 04 04 04 02 02 02 02 02 02 02 02 02 02 02 +0a40: 06 04 04 04 04 02 02 03 03 03 03 03 03 02 03 03 +0a50: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0a60: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0a70: 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 02 +0a80: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0a90: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0aa0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 +0ab0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +0ac0: 00 05 05 04 04 04 04 04 04 04 04 02 02 02 02 04 +0ad0: 00 05 05 04 04 04 04 04 04 04 04 04 02 04 04 04 +0ae0: 00 06 05 05 05 04 04 04 04 04 04 04 03 04 04 04 +0af0: 00 06 06 06 05 05 05 05 05 05 05 05 03 05 05 05 +0b00: 06 06 06 05 06 06 06 06 06 06 06 05 06 06 06 06 +0b10: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 +0b20: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 +0b30: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0b40: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0b50: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0b60: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +0b70: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0b80: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +0b90: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +0ba0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +0bb0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0bc0: 04 04 04 04 04 04 04 04 03 03 03 04 04 04 04 04 +0bd0: 04 04 04 04 04 04 04 04 04 03 03 04 04 04 04 04 +0be0: 04 04 04 04 04 04 04 04 04 03 04 04 04 04 04 04 +0bf0: 05 05 05 05 05 05 05 05 05 03 05 05 05 05 05 05 +0c00: 06 06 06 05 06 06 06 06 06 06 05 06 06 06 06 06 +0c10: 05 05 05 03 05 05 05 05 05 05 03 05 05 05 05 06 +0c20: 05 05 05 03 05 05 05 05 05 05 03 04 04 05 05 06 +0c30: 02 02 02 02 02 02 02 02 02 02 02 04 04 04 04 06 +0c40: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 06 +0c50: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 +0c60: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 +0c70: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 +0c80: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 +0c90: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +0ca0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +0cb0: 02 02 02 02 02 02 03 03 03 03 03 03 03 06 06 06 +0cc0: 04 04 03 03 03 04 04 04 04 04 04 04 04 04 05 06 +0cd0: 04 04 04 03 03 04 04 04 04 04 04 04 04 05 05 05 +0ce0: 04 04 04 03 04 04 04 04 04 04 04 05 05 05 05 06 +0cf0: 05 05 05 03 05 05 05 05 05 05 05 05 05 06 06 06 +0d00: 06 06 06 06 06 05 06 06 06 06 05 06 06 06 06 06 +0d10: 06 05 05 05 05 03 05 05 05 05 03 05 05 05 05 06 +0d20: 06 05 04 04 04 03 05 05 05 05 03 04 04 05 05 06 +0d30: 06 04 04 04 04 02 02 02 02 02 02 04 04 04 04 06 +0d40: 06 04 04 04 04 02 02 03 03 03 02 04 04 04 04 06 +0d50: 05 04 04 04 04 02 03 03 03 03 02 04 04 04 04 05 +0d60: 05 04 04 04 04 02 03 03 03 03 02 04 04 04 04 05 +0d70: 03 03 03 03 03 02 02 02 02 02 02 03 03 03 03 05 +0d80: 06 06 04 04 04 04 04 02 04 04 04 04 04 05 05 00 +0d90: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0da0: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0db0: 05 03 03 03 03 03 02 02 02 02 02 05 05 06 06 06 +0dc0: 00 05 04 04 04 04 04 04 03 02 04 04 04 04 04 06 +0dd0: 00 05 04 04 04 04 04 04 03 02 04 04 04 04 04 06 +0de0: 00 05 04 04 04 04 04 04 03 02 04 04 04 04 04 05 +0df0: 06 06 06 05 05 05 02 02 02 02 02 02 03 03 03 05 +0e00: 06 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 +0e10: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 +0e20: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 04 00 +0e30: 05 03 03 03 03 03 02 02 02 02 02 02 02 06 06 06 +0e40: 00 05 04 04 04 03 02 03 03 02 04 04 04 04 04 06 +0e50: 00 05 04 04 04 02 03 03 03 02 04 04 04 04 04 05 +0e60: 00 04 04 04 04 02 03 03 03 02 03 04 04 04 04 05 +0e70: 06 06 05 05 02 02 02 02 02 02 02 03 03 03 03 05 +0e80: 06 04 04 04 04 04 04 02 04 04 04 04 04 05 05 00 +0e90: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0ea0: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0eb0: 05 03 03 03 03 03 02 02 02 02 02 03 03 06 06 06 +0ec0: 00 05 05 04 04 04 03 03 03 03 03 04 04 04 04 06 +0ed0: 00 05 04 04 04 04 03 03 03 03 04 04 04 04 04 05 +0ee0: 00 05 04 04 04 03 03 03 03 03 04 04 04 04 04 05 +0ef0: 00 05 03 03 03 03 03 02 02 02 02 02 03 03 03 05 +0f00: 06 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 +0f10: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 +0f20: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 04 00 +0f30: 05 03 03 03 03 03 02 02 02 02 02 02 02 06 06 06 +0f40: 00 05 04 04 04 03 02 03 03 02 04 04 04 04 04 06 +0f50: 00 05 04 04 04 02 03 03 03 02 04 04 04 04 04 05 +0f60: 00 04 04 04 04 02 03 03 03 02 04 04 04 04 04 05 +0f70: 06 06 05 05 02 02 02 02 02 02 02 03 03 03 03 05 +0f80: 06 04 04 04 04 04 04 02 04 04 04 04 04 05 05 00 +0f90: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0fa0: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0fb0: 05 03 03 03 03 03 02 02 03 03 03 03 03 06 06 06 +0fc0: 00 05 05 04 04 04 04 04 04 04 04 04 04 04 05 06 +0fd0: 00 05 05 04 04 04 04 04 04 04 04 04 04 05 05 05 +0fe0: 00 06 05 05 05 04 04 04 04 04 04 05 05 05 05 06 +0ff0: 00 06 06 06 05 05 05 05 05 05 05 05 05 06 06 06 +1000: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1010: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1020: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1030: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1040: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +1050: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +1060: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +1070: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1080: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +1090: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +10a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +10b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +10c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 04 04 04 +10d0: 03 02 03 03 03 03 03 03 03 02 03 03 04 04 04 04 +10e0: 03 02 03 03 03 03 03 03 02 02 02 03 04 04 04 04 +10f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1100: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1110: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1120: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1130: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1140: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +1150: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +1160: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +1170: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1180: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +1190: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +11a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +11b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +11c0: 02 02 02 04 04 03 03 03 03 02 03 03 03 03 03 03 +11d0: 04 02 04 04 04 04 03 03 03 02 03 03 03 03 03 03 +11e0: 04 02 04 04 04 04 03 03 02 02 02 03 03 03 03 03 +11f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1200: 03 03 02 02 02 03 03 03 03 03 03 02 02 05 05 05 +1210: 03 03 03 02 03 03 03 03 03 03 03 02 03 05 05 05 +1220: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 05 05 +1230: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1240: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +1250: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +1260: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +1270: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1280: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +1290: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +12a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +12b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +12c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +12d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +12e0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +12f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1300: 06 05 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1310: 05 05 05 02 03 03 03 03 03 03 03 02 03 03 03 03 +1320: 05 05 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1330: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1340: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +1350: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +1360: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +1370: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1380: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +1390: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +13a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +13b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +13c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +13d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +13e0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +13f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1400: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1410: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1420: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1430: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1440: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1450: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1460: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1470: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1480: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1490: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14a0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14b0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14c0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14d0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14e0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14f0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1500: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1510: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1520: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1530: 02 02 02 02 02 02 02 02 02 02 02 02 02 01 01 01 +1540: 03 03 03 03 02 02 03 03 02 02 02 02 02 01 02 02 +1550: 03 03 03 03 03 02 02 02 02 02 02 02 02 01 02 02 +1560: 03 03 03 03 03 01 02 02 02 02 02 02 01 01 01 02 +1570: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 +1580: 02 03 03 03 02 02 02 01 02 02 02 02 02 02 01 01 +1590: 03 03 03 03 02 02 02 01 02 02 02 02 02 02 02 01 +15a0: 03 03 03 03 02 02 01 01 01 01 02 02 02 02 01 01 +15b0: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +15c0: 02 02 02 03 03 02 02 02 02 01 02 02 02 01 01 01 +15d0: 03 02 03 03 03 02 02 02 02 01 02 02 01 01 01 01 +15e0: 03 02 03 03 03 03 02 02 01 01 01 02 01 01 01 01 +15f0: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 +1600: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1610: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1620: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1630: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1640: 02 02 02 02 01 01 02 02 02 02 02 02 02 01 02 02 +1650: 02 02 02 02 02 01 02 02 02 02 02 02 02 01 02 02 +1660: 02 02 02 02 02 01 02 02 02 02 02 02 01 01 01 02 +1670: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1680: 01 02 02 02 02 02 02 01 02 02 02 02 02 02 01 01 +1690: 01 02 02 02 02 02 02 01 02 02 02 02 02 02 02 01 +16a0: 01 02 02 02 01 01 01 01 01 01 02 02 02 02 02 01 +16b0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +16c0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +16d0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +16e0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +16f0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1700: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1710: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1720: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1730: 01 01 01 01 02 02 02 02 02 02 02 02 02 02 02 02 +1740: 02 02 02 02 01 01 03 03 03 03 03 03 03 02 03 03 +1750: 02 02 02 02 02 01 02 02 03 03 03 03 03 02 03 03 +1760: 02 02 02 02 02 01 02 02 02 03 03 03 02 02 02 03 +1770: 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 +1780: 01 02 02 02 02 02 02 01 02 02 03 03 03 03 02 02 +1790: 02 02 02 02 02 02 02 01 02 02 02 03 03 03 03 02 +17a0: 02 02 02 02 02 02 01 01 01 01 02 03 03 03 03 02 +17b0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +17c0: 01 01 01 02 02 02 02 02 02 01 02 03 03 03 03 03 +17d0: 01 01 02 02 02 02 02 02 02 01 02 03 03 03 03 03 +17e0: 01 01 02 02 02 02 02 02 01 01 01 03 03 03 03 03 +17f0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +1800: 03 03 02 02 02 02 02 02 02 02 02 01 01 01 01 01 +1810: 03 03 03 02 03 02 02 02 02 02 02 01 01 01 01 01 +1820: 03 03 03 02 03 02 02 02 02 02 01 01 01 01 01 01 +1830: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 +1840: 03 03 03 03 02 01 02 02 02 02 02 02 01 01 01 01 +1850: 03 03 03 03 02 01 02 02 02 02 02 02 01 01 01 01 +1860: 03 03 03 03 02 01 02 02 02 02 02 01 01 01 01 01 +1870: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +1880: 02 03 03 03 02 02 02 01 02 02 02 01 01 01 01 01 +1890: 03 03 03 03 02 02 02 01 02 02 02 01 01 01 01 01 +18a0: 03 03 03 03 02 02 01 01 01 01 02 01 01 01 01 01 +18b0: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +18c0: 02 02 02 03 02 02 02 02 02 01 02 02 01 01 01 01 +18d0: 03 02 03 03 03 02 02 02 02 01 02 02 02 01 01 01 +18e0: 03 02 03 03 02 02 02 02 01 01 01 02 02 01 01 01 +18f0: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +1900: 01 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 +1910: 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 03 +1920: 01 01 01 01 02 02 02 02 02 02 02 02 02 03 03 03 +1930: 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 +1940: 01 01 01 01 01 02 02 02 02 02 03 03 03 02 03 03 +1950: 01 01 01 01 01 02 02 02 02 02 03 03 03 02 03 03 +1960: 01 01 01 01 01 01 02 02 02 02 03 03 02 02 02 03 +1970: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +1980: 01 01 01 01 02 02 02 01 02 02 02 03 03 03 02 02 +1990: 01 01 01 01 02 02 02 01 02 02 02 03 03 03 03 02 +19a0: 01 01 01 01 01 02 01 01 01 01 02 03 03 03 03 02 +19b0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +19c0: 01 01 01 01 01 02 02 02 02 01 02 03 03 03 03 03 +19d0: 01 01 01 01 02 02 02 02 02 01 02 03 03 03 03 03 +19e0: 01 01 01 01 02 02 02 02 01 01 02 03 03 03 03 03 +19f0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +1a00: 03 03 02 02 01 02 02 02 02 02 02 01 01 02 01 01 +1a10: 03 03 03 02 02 02 02 02 02 02 02 01 02 02 02 01 +1a20: 03 03 03 02 02 02 02 02 02 02 01 01 01 02 02 02 +1a30: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +1a40: 03 03 03 03 01 01 02 02 02 02 02 02 02 01 02 02 +1a50: 03 03 03 03 02 01 02 02 02 02 02 02 02 01 02 02 +1a60: 03 03 03 03 03 01 02 02 02 02 02 02 01 01 01 02 +1a70: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 +1a80: 02 03 03 03 03 03 02 01 02 02 02 02 02 02 01 01 +1a90: 03 03 03 03 03 03 03 02 02 02 02 02 02 02 02 01 +1aa0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +1ab0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1ac0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +1ad0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +1ae0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +1af0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1b00: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1b10: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1b20: 02 01 01 01 01 01 01 01 01 01 01 01 01 01 02 02 +1b30: 01 01 01 01 01 01 01 01 02 02 02 02 01 01 01 01 +1b40: 02 02 02 02 01 01 02 02 02 02 02 02 02 01 02 02 +1b50: 02 02 02 02 02 01 02 02 02 02 02 02 02 01 02 02 +1b60: 02 02 02 02 02 01 02 02 02 02 02 02 01 01 01 02 +1b70: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1b80: 01 02 02 02 02 02 02 01 02 02 02 02 02 02 01 01 +1b90: 02 02 02 02 02 02 02 01 02 02 02 02 02 02 02 01 +1ba0: 03 03 02 02 02 02 01 01 01 01 02 02 02 02 02 01 +1bb0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1bc0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +1bd0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +1be0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +1bf0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1c00: 01 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 +1c10: 02 02 02 01 02 02 02 02 02 02 02 02 03 03 03 03 +1c20: 02 02 02 01 02 02 02 02 02 02 01 02 02 03 03 03 +1c30: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +1c40: 02 02 02 02 01 01 02 02 02 02 02 03 03 02 03 03 +1c50: 02 02 02 02 02 01 02 02 02 02 02 03 03 02 03 03 +1c60: 02 02 02 02 02 01 02 02 02 02 02 03 02 02 02 03 +1c70: 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 +1c80: 01 02 02 02 02 02 02 01 02 02 03 03 03 03 02 02 +1c90: 02 02 02 02 02 02 02 01 02 03 03 03 03 03 03 02 +1ca0: 02 02 02 02 02 02 01 02 02 02 03 03 03 03 03 02 +1cb0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1cc0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +1cd0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +1ce0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +1cf0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1d10: 00 00 01 01 01 01 01 00 00 00 01 01 01 00 00 00 +1d20: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 +1d30: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 +1d40: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 +1d50: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 +1d60: 00 00 00 00 01 00 00 00 00 00 01 01 01 00 00 00 +1d70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1d80: 00 00 01 01 01 01 00 00 00 00 01 01 01 00 00 00 +1d90: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 +1da0: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 +1db0: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 +1dc0: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 +1dd0: 00 00 01 01 01 01 00 00 00 00 01 01 01 00 00 00 +1de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1df0: 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 00 +1e00: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 +1e10: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1e20: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e30: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e40: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e50: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e60: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e70: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1e80: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1e90: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 +1ea0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1eb0: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 +1ec0: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1ed0: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1ee0: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1ef0: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 +1f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1f10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1f20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1f30: 00 00 00 00 00 01 01 01 01 01 01 00 00 00 00 00 +1f40: 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 +1f50: 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 +1f60: 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 +1f70: 00 00 00 00 00 00 00 00 00 01 01 00 00 00 00 00 +1f80: 00 00 00 00 00 00 00 00 01 01 00 00 00 00 00 00 +1f90: 00 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 +1fa0: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 +1fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1fe0: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 +1ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -- cgit v1.2.3 From bb2839a81d64e8644c57d83806ae41cc4cfad9dd Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Sun, 12 Mar 2023 13:00:45 +0100 Subject: makefile update --- src/engine/TODO/entity.c | 41 ----------------------------------------- src/engine/TODO/entity.h | 24 ------------------------ src/engine/entity.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/engine/entity.h | 24 ++++++++++++++++++++++++ src/makefile | 7 +++++-- 5 files changed, 70 insertions(+), 67 deletions(-) delete mode 100644 src/engine/TODO/entity.c delete mode 100644 src/engine/TODO/entity.h create mode 100644 src/engine/entity.c create mode 100644 src/engine/entity.h (limited to 'src/makefile') diff --git a/src/engine/TODO/entity.c b/src/engine/TODO/entity.c deleted file mode 100644 index fa550d5..0000000 --- a/src/engine/TODO/entity.c +++ /dev/null @@ -1,41 +0,0 @@ -#include - -#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/engine/TODO/entity.h b/src/engine/TODO/entity.h deleted file mode 100644 index fdbeb8a..0000000 --- a/src/engine/TODO/entity.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -#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/engine/entity.c b/src/engine/entity.c new file mode 100644 index 0000000..1dc1df8 --- /dev/null +++ b/src/engine/entity.c @@ -0,0 +1,41 @@ +#include + +#include "engine/hh_entity.h" +#include "engine/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/engine/entity.h b/src/engine/entity.h new file mode 100644 index 0000000..b2a0c49 --- /dev/null +++ b/src/engine/entity.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "engine/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/makefile b/src/makefile index 10baa14..142d918 100644 --- a/src/makefile +++ b/src/makefile @@ -32,8 +32,11 @@ LOCAL_SRCS += main.c \ ppu/ppu.c \ demo.c \ engine/engine.c \ - engine/sprite_controller.c \ - engine/draw_screen.c + engine/sprite_controller.c \ + engine/draw_screen.c \ + engine/camera.c \ + engine/maths.c \ + engine/entity.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) -- cgit v1.2.3 From 5c4bf7d451135cd3af3e51976251f01cbb6e6573 Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Mon, 13 Mar 2023 09:57:34 +0100 Subject: camera, movement, collisions --- src/engine/TODO/player_controller.h | 4 ---- src/engine/camera.c | 20 +++++++++++++++++- src/engine/draw_screen.c | 18 ++++++++-------- src/engine/entity.c | 41 +++++++++++++++++++++---------------- src/engine/entity.h | 6 ++++-- src/engine/maths.c | 4 ++++ src/engine/maths.h | 4 +++- src/engine/player_controller.c | 1 + src/engine/player_controller.h | 7 +++++++ src/engine/sprite_controller.c | 5 ++++- src/makefile | 1 + src/ppusim/input.c | 1 + src/ppusim/sim.c | 2 +- 13 files changed, 77 insertions(+), 37 deletions(-) delete mode 100644 src/engine/TODO/player_controller.h create mode 100644 src/engine/player_controller.c create mode 100644 src/engine/player_controller.h (limited to 'src/makefile') diff --git a/src/engine/TODO/player_controller.h b/src/engine/TODO/player_controller.h deleted file mode 100644 index 1e9b86c..0000000 --- a/src/engine/TODO/player_controller.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "maths.h" -#include "hh_entity.h" - -// inputs diff --git a/src/engine/camera.c b/src/engine/camera.c index 46c2d93..e756bd4 100644 --- a/src/engine/camera.c +++ b/src/engine/camera.c @@ -5,8 +5,26 @@ vec_cor hh_update_camera(vec_cen new, vec2 min, vec2 max){ - new = vec_cen2cor(new,(vec2){.x=20,.y=30}); + //TODO: change floating point math to fix point math + //TODO: fix buggy y-axis ?? + + // new = vec_cen2cor(new,(vec2){.x=max.x/2,.y=max.y/2}); + new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH/2),.y=(new.y+(HH_PPU_SPRITE_HEIGHT/2))*2},(vec2){.x=max.x/2,.y=max.y/2}); + // new.x = new.x << HH_MATH_FIXED_POINT; + // new.y = new.y << HH_MATH_FIXED_POINT; static vec_cor old; + // old.x = old.x << HH_MATH_FIXED_POINT; + // old.y = old.y << HH_MATH_FIXED_POINT; + + // int16_t some = 0; + // some = some <<= HH_MATH_FIXED_POINT-1; + + new.x = (int)((float)new.x*0.1f + (float)old.x*0.9f); + new.y = (int)((float)new.y*0.1f + (float)old.y*0.9f); + + // old.x = old.x >> HH_MATH_FIXED_POINT; + // old.y = old.y >> HH_MATH_FIXED_POINT; + old.x = CLAMP(new.x,min.x,max.x); old.y = CLAMP(new.y,min.y,max.y); diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c index 0295241..c4f3389 100644 --- a/src/engine/draw_screen.c +++ b/src/engine/draw_screen.c @@ -3,20 +3,20 @@ uint8_t hh_world_to_tile(vec2 pos){ - FILE* level = fopen("../test/bin/test_map.bin", "rb"); /* open binary file */ + 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 0; } - int index = (pos.y + pos.x); + int index = ((pos.y/16)*40 + pos.x/16);//TODO: remove magic number(s) fseek(level, (index * sizeof(int)) + sizeof(int), SEEK_SET); - int* tile = (int*)malloc(sizeof(int)); - fread(tile, sizeof(int), 1, level); // read 1 tile from binary + int tile;// = (int*)malloc(sizeof(int)); + fread(&tile, sizeof(int), 1, level); // read 1 tile from binary fclose(level); - int val = *tile; - free(tile); - return val; + // int val = tile; + // free(tile); + return tile; } @@ -26,8 +26,8 @@ void hh_draw_screen(vec_cor viewport){ if (viewport.x == previousViewport.x && viewport.y == previousViewport.y) return; hh_ppu_update_aux((hh_s_ppu_loc_aux){ - .bg_shift_x = viewport.x*HH_PPU_SPRITE_WIDTH, - .bg_shift_y = viewport.y*HH_PPU_SPRITE_HEIGHT, + .bg_shift_x = viewport.x, + .bg_shift_y = viewport.y, .fg_fetch = 0, .sysreset = 0, }); diff --git a/src/engine/entity.c b/src/engine/entity.c index 1dc1df8..152cf1d 100644 --- a/src/engine/entity.c +++ b/src/engine/entity.c @@ -1,6 +1,6 @@ #include -#include "engine/hh_entity.h" +#include "engine/entity.h" #include "engine/maths.h" /* @@ -12,30 +12,35 @@ */ -bool hh_collision(vec2* pos1, vec2* pos2){ - if (pos2->x == CLAMP(pos2->x,pos1->x,pos1->x+1.0f)){// hit x +bool hh_collision(vec_cor pos1, vec2 pos2){ + if (pos2.x == CLAMP(pos2.x, pos1.x, pos1.x+16)){// hit x return true; } - if (pos2->y == CLAMP(pos2->y,pos1->y,pos1->y+0.99f)){// hit y + if (pos2.y == CLAMP(pos2.y, pos1.y, pos1.y+16)){// 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; - } +void hh_solve_collision(vec2 pos_environment, hh_entity* entity){ + if (!hh_collision(pos_environment,entity->pos)) + return; + + printf("BONK!/n"); + // if (entity->vec.y > 0){ + // entity->pos.y = MAX(entity->pos.y,pos_environment.y); + // entity->vec.y = 0; + // } else { + // entity->pos.y = MIN(entity->pos.y,pos_environment.y); + // entity->vec.y = 0; + // } + // if (entity->vec.x <= 0){ + // entity->pos.x = MIN(entity->pos.x,pos_environment.x-16); + // entity->vec.x = 0; + // } else { + // entity->pos.x = MAX(entity->pos.x,pos_environment.x+16); + // entity->vec.x = 0; + // } } diff --git a/src/engine/entity.h b/src/engine/entity.h index b2a0c49..dee4aed 100644 --- a/src/engine/entity.h +++ b/src/engine/entity.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "engine/maths.h" @@ -8,6 +9,7 @@ typedef struct { vec2 pos, vec; bool is_grounded; int8_t hp; + int8_t speed; //armor/block? }hh_entity; @@ -15,10 +17,10 @@ typedef struct { /// @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); +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); +void hh_solve_collision(vec2 pos_environment, hh_entity* entity); diff --git a/src/engine/maths.c b/src/engine/maths.c index ebd699c..475bba2 100644 --- a/src/engine/maths.c +++ b/src/engine/maths.c @@ -1,5 +1,9 @@ #include "engine/maths.h" +vec2 vec_add(vec2 a, vec2 b){ + return (vec2){a.x + b.x, a.y + b.y}; +} + vec_cor vec_cen2cor(vec_cen in, vec2 halfDistance){ return (vec_cor){ .x = in.x - halfDistance.x, diff --git a/src/engine/maths.h b/src/engine/maths.h index bd20202..bef287e 100644 --- a/src/engine/maths.h +++ b/src/engine/maths.h @@ -3,12 +3,14 @@ // #include typedef struct { - uint32_t x,y; + int32_t x,y; } vec2; typedef vec2 vec_cen;//centered typedef vec2 vec_cor;//left upper corner +vec2 vec_add(vec2 a, vec2 b); + vec_cor vec_cen2cor(vec_cen in, vec2 halfDistance); vec_cor vec_cor2cen(vec_cen in, vec2 halfDistance); diff --git a/src/engine/player_controller.c b/src/engine/player_controller.c new file mode 100644 index 0000000..27e522e --- /dev/null +++ b/src/engine/player_controller.c @@ -0,0 +1 @@ +#include "engine/player_controller.h" diff --git a/src/engine/player_controller.h b/src/engine/player_controller.h new file mode 100644 index 0000000..400c18e --- /dev/null +++ b/src/engine/player_controller.h @@ -0,0 +1,7 @@ +#pragma once + +#include "engine/maths.h" +#include "engine/entity.h" +// inputs + +void hh_player_actions(); diff --git a/src/engine/sprite_controller.c b/src/engine/sprite_controller.c index d4c44ab..5d93cf8 100644 --- a/src/engine/sprite_controller.c +++ b/src/engine/sprite_controller.c @@ -1,7 +1,6 @@ #include #include "engine/sprite_controller.h" -// #include "engine/maths.h" #include "ppu/types.h" #include "ppu/consts.h" #include "ppu/ppu.h" @@ -17,3 +16,7 @@ void hh_setup_palettes(){ } } } + +bool hh_colidable(uint8_t tile_idx){ + return (hh_get_palette(tile_idx) != 0); +} diff --git a/src/makefile b/src/makefile index 142d918..d7d9087 100644 --- a/src/makefile +++ b/src/makefile @@ -33,6 +33,7 @@ LOCAL_SRCS += main.c \ demo.c \ engine/engine.c \ engine/sprite_controller.c \ + engine/player_controller.c \ engine/draw_screen.c \ engine/camera.c \ engine/maths.c \ diff --git a/src/ppusim/input.c b/src/ppusim/input.c index 08bc382..5323fb1 100644 --- a/src/ppusim/input.c +++ b/src/ppusim/input.c @@ -12,4 +12,5 @@ void hh_input_read() { g_hh_controller_p1.dpad_down = kb[SDL_SCANCODE_S]; g_hh_controller_p1.dpad_left = kb[SDL_SCANCODE_A]; g_hh_controller_p1.dpad_right = kb[SDL_SCANCODE_D]; + g_hh_controller_p1.button_primary = kb[SDL_SCANCODE_SPACE]; } diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index 1e7e609..a5fec45 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -32,7 +32,7 @@ void hh_ppu_load_tilemap() { char* filename = "../test/bin/tiles.bin"; FILE* fp = fopen(filename,"rb"); if (!fp){ - fprintf(stderr,"File error!"); + fprintf(stderr,"Error: Failed to load tiles."); return;//error } int sprite_size = (HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT); -- cgit v1.2.3 From a9ad8e0a8ac5346108f1e2c1a0bf9360fadc20da Mon Sep 17 00:00:00 2001 From: Flenk008 Date: Mon, 13 Mar 2023 18:02:59 +0100 Subject: Revert "Merge branch 'dev' of https://github.com/Flenk008/avans-arcade into dev" This reverts commit 4f489426e05fb3b296998b17859d8702cc4f37e1, reversing changes made to e47f7fa198229b8598b8ab03ef8b2483f7c685bc. --- features.md | 72 ----- src/.gitignore | 1 - src/engine/TODO/entity.c | 41 +++ src/engine/TODO/entity.h | 24 ++ src/engine/TODO/player_controller.h | 4 + src/engine/TODO/sprite_controller.h | 6 + src/engine/camera.c | 34 --- src/engine/camera.h | 6 - src/engine/draw_screen.c | 62 ----- src/engine/draw_screen.h | 16 +- src/engine/engine.c | 1 - src/engine/entity.c | 46 ---- src/engine/entity.h | 57 ---- src/engine/maths.c | 19 -- src/engine/maths.h | 7 +- src/engine/player_controller.c | 167 ------------ src/engine/player_controller.h | 7 - src/engine/sprite_controller.c | 22 -- src/engine/sprite_controller.h | 106 -------- src/makefile | 8 +- src/ppusim/sim.c | 11 +- test/bin/exportingPalettes.md | 4 - test/bin/test_file_read.c | 13 +- test/bin/tilemap.pip | 512 ------------------------------------ 24 files changed, 89 insertions(+), 1157 deletions(-) delete mode 100644 features.md create mode 100644 src/engine/TODO/entity.c create mode 100644 src/engine/TODO/entity.h create mode 100644 src/engine/TODO/player_controller.h create mode 100644 src/engine/TODO/sprite_controller.h delete mode 100644 src/engine/camera.c delete mode 100644 src/engine/camera.h delete mode 100644 src/engine/draw_screen.c delete mode 100644 src/engine/entity.c delete mode 100644 src/engine/entity.h delete mode 100644 src/engine/maths.c delete mode 100644 src/engine/player_controller.c delete mode 100644 src/engine/player_controller.h delete mode 100644 src/engine/sprite_controller.c delete mode 100644 src/engine/sprite_controller.h delete mode 100644 test/bin/exportingPalettes.md delete mode 100644 test/bin/tilemap.pip (limited to 'src/makefile') diff --git a/features.md b/features.md deleted file mode 100644 index d044232..0000000 --- a/features.md +++ /dev/null @@ -1,72 +0,0 @@ -Af/Cancelled/Implement in sprint 3 -Done -## Checkpoint room (shop) -| feature | status | -|-|-| -|Upgrade abilities|Implement in sprint 3| -|Interaction with shopkeeper|Implement in sprint 3| - -## Upgrades abilities -| feature | status | -|-|-| -|HP boost|Implement in sprint 3| -|Jump boost|Implement in sprint 3| -|Speed boost|Implement in sprint 3| -|Regular dash|Implement in sprint 3| -|Super punch|Implement in sprint 3| -|Smoke bomb|Implement in sprint 3| - -## Levels -| feature | status | -|-|-| -|Breakable blocks|Implement in sprint 3| -|Hidden secrets|Implement in sprint 3| -|Boss fights|Implement in sprint 3| -|Enemies|Implement in sprint 3| -|audio|Implement in sprint 3| - -## player (Gozer) -| feature | status | -|-|-| -|Move X-as|Done| -|Jump|Done| -|Special ability|Implement in sprint 3| -|Health|Implement in sprint 3| -|Currency/Scoreboard|Implement in sprint 3| - -## Enemy (Menneke) -| feature | status | -|-|-| -|Move X-as|Implement in sprint 3| -|Jump|Implement in sprint 3| -|Hunt player|Implement in sprint 3| -|Health (1 HP)|Implement in sprint 3| -|Currency/Scoreboard|Implement in sprint 3| - -## Enemy (Ventje) -| feature | status | -|-|-| -|Move X-as|Implement in sprint 3| -|Jump|Implement in sprint 3| -|Hunt player|Implement in sprint 3| -|Health (2 HP) |Implement in sprint 3| -|Splitting upon defeat|Implement in sprint 3| -|Currency/Scoreboard|Implement in sprint 3| - -## Enemy (Terror uil) -| feature | status | -|-|-| -|Movement|Implement in sprint 3| -|Hunt player|Implement in sprint 3| -|Health (1 HP) |Implement in sprint 3| -|Splitting upon defeat|Implement in sprint 3| -|Currency/Scoreboard|Implement in sprint 3| - -## Could have additions if time is enough -| feature | status | -|-|-| -|Multiplayer|Implement in sprint 3| -|Shared HP|Implement in sprint 3| -|Special ability|Implement in sprint 3| -|Health|Implement in sprint 3| -|Currency/Scoreboard|Implement in sprint 3| diff --git a/src/.gitignore b/src/.gitignore index 504b995..d8325cf 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -4,4 +4,3 @@ main.bin main main.exe static/ -*.bin diff --git a/src/engine/TODO/entity.c b/src/engine/TODO/entity.c new file mode 100644 index 0000000..fa550d5 --- /dev/null +++ b/src/engine/TODO/entity.c @@ -0,0 +1,41 @@ +#include + +#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/engine/TODO/entity.h b/src/engine/TODO/entity.h new file mode 100644 index 0000000..fdbeb8a --- /dev/null +++ b/src/engine/TODO/entity.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#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/engine/TODO/player_controller.h b/src/engine/TODO/player_controller.h new file mode 100644 index 0000000..1e9b86c --- /dev/null +++ b/src/engine/TODO/player_controller.h @@ -0,0 +1,4 @@ +#include "maths.h" +#include "hh_entity.h" + +// inputs diff --git a/src/engine/TODO/sprite_controller.h b/src/engine/TODO/sprite_controller.h new file mode 100644 index 0000000..c1fadff --- /dev/null +++ b/src/engine/TODO/sprite_controller.h @@ -0,0 +1,6 @@ +// handles sprites + +// Bg sprites + + +// Fg or entity sprites diff --git a/src/engine/camera.c b/src/engine/camera.c deleted file mode 100644 index e756bd4..0000000 --- a/src/engine/camera.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "engine/camera.h" - -#include "ppu/consts.h" - - -vec_cor hh_update_camera(vec_cen new, vec2 min, vec2 max){ - - //TODO: change floating point math to fix point math - //TODO: fix buggy y-axis ?? - - // new = vec_cen2cor(new,(vec2){.x=max.x/2,.y=max.y/2}); - new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH/2),.y=(new.y+(HH_PPU_SPRITE_HEIGHT/2))*2},(vec2){.x=max.x/2,.y=max.y/2}); - // new.x = new.x << HH_MATH_FIXED_POINT; - // new.y = new.y << HH_MATH_FIXED_POINT; - static vec_cor old; - // old.x = old.x << HH_MATH_FIXED_POINT; - // old.y = old.y << HH_MATH_FIXED_POINT; - - // int16_t some = 0; - // some = some <<= HH_MATH_FIXED_POINT-1; - - new.x = (int)((float)new.x*0.1f + (float)old.x*0.9f); - new.y = (int)((float)new.y*0.1f + (float)old.y*0.9f); - - // old.x = old.x >> HH_MATH_FIXED_POINT; - // old.y = old.y >> HH_MATH_FIXED_POINT; - - - 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 deleted file mode 100644 index b3ffb52..0000000 --- a/src/engine/camera.h +++ /dev/null @@ -1,6 +0,0 @@ -#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 deleted file mode 100644 index c4f3389..0000000 --- a/src/engine/draw_screen.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "engine/draw_screen.h" -#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 */ - if (!level) { /* check if file opened successfully */ - fprintf(stderr, "Error: Failed to open file.\n"); - return 0; - } - int index = ((pos.y/16)*40 + pos.x/16);//TODO: remove magic number(s) - fseek(level, (index * sizeof(int)) + sizeof(int), SEEK_SET); - int tile;// = (int*)malloc(sizeof(int)); - fread(&tile, sizeof(int), 1, level); // read 1 tile from binary - - fclose(level); - // int val = tile; - // free(tile); - return tile; -} - - -// remeber old value to know which part to update. -vec2 previousViewport = { .x = 0, .y = 0 }; -void hh_draw_screen(vec_cor viewport){ - if (viewport.x == previousViewport.x && viewport.y == previousViewport.y) return; - - hh_ppu_update_aux((hh_s_ppu_loc_aux){ - .bg_shift_x = viewport.x, - .bg_shift_y = viewport.y, - .fg_fetch = 0, - .sysreset = 0, - }); - - // update previous viewport values - previousViewport = 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 */ - if (!level) { /* check if file opened successfully */ - fprintf(stderr, "Error: Failed to open file.\n"); - return; - } - fseek(level, (0* sizeof(int)) + sizeof(int), SEEK_SET); - int* tile = (int*)malloc(size*sizeof(int)); - fread(tile, sizeof(int), size, level); // read 1 tile from binary - - fclose(level); - - for(int BAM_index = 0; BAM_index < size; BAM_index++){ - hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = hh_get_palette(tile[BAM_index]), - .tilemap_index = tile[BAM_index], - }); - } - free(tile); -} diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h index b181108..4af5865 100644 --- a/src/engine/draw_screen.h +++ b/src/engine/draw_screen.h @@ -3,19 +3,7 @@ // every function call for drawing the screen goes here. #include "engine/maths.h" -#include "ppu/ppu.h" -#include #include -#include - - -#define HH_map_size_X 80 -#define HH_map_size_Y 60 - -/** @brief return a single tile from world binary */ -uint8_t hh_world_to_tile(vec2 pos); -/** @brief shift to level if viewport changed position */ -void hh_draw_screen(vec2 viewport); -/** @brief send data to BAM memory from binary level */ -void hh_setup_screen(); +uint16_t hh_world_to_tile(vec2 pos); +void hh_draw_screen(vec2 viewport); \ No newline at end of file diff --git a/src/engine/engine.c b/src/engine/engine.c index 799ee7c..f3410a4 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -1,4 +1,3 @@ #include "engine/draw_screen.h" #include "engine/level.h" #include "engine/maths.h" -#include "engine/sprite_controller.h" diff --git a/src/engine/entity.c b/src/engine/entity.c deleted file mode 100644 index 153e7e1..0000000 --- a/src/engine/entity.c +++ /dev/null @@ -1,46 +0,0 @@ -#include - -#include "engine/entity.h" -#include "engine/maths.h" - -/* - PLAYER: (pos on X) - ,___, - | | - | X | - |___| - -*/ - -bool hh_collision(vec_cor pos1, vec2 pos2){ - if (pos2.x == CLAMP(pos2.x, pos1.x, pos1.x+16)){// hit x - return true; - } - - if (pos2.y == CLAMP(pos2.y, pos1.y, pos1.y+16)){// hit y - return true; - } - return false; -} - -void hh_solve_collision(vec2 pos_environment, hh_entity* entity){ - if (!hh_collision(pos_environment,entity->pos)) - return; - - printf("BONK!/n"); - // if (entity->vel.y > 0){ - // entity->pos.y = MAX(entity->pos.y,pos_environment.y); - // entity->vel.y = 0; - // } else { - // entity->pos.y = MIN(entity->pos.y,pos_environment.y); - // entity->vel.y = 0; - // } - // if (entity->vel.x <= 0){ - // entity->pos.x = MIN(entity->pos.x,pos_environment.x-16); - // entity->vel.x = 0; - // } else { - // entity->pos.x = MAX(entity->pos.x,pos_environment.x+16); - // entity->vel.x = 0; - // } -} - diff --git a/src/engine/entity.h b/src/engine/entity.h deleted file mode 100644 index f45dae2..0000000 --- a/src/engine/entity.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include -#include - -#include "ppu/types.h" - -#include "engine/maths.h" - -typedef uint8_t hh_idx_t; - -typedef enum { - fire, ice, poison -}hh_e_damage_t; - -typedef struct { - hh_s_ppu_loc_fam_entry fam; //screen - hh_idx_t frame0; - hh_idx_t palette; - -}hh_s_rendering; - -typedef struct { - int8_t hp; - int8_t dmg; - hh_e_damage_t dmg_type; - int8_t speed_x, speed_y; - -} hh_s_atributes; - - -typedef struct { - vec2 pos, vel, vec; - bool is_grounded; - int8_t hp; - int8_t speed; - hh_s_rendering render; - //armor/block? -}hh_entity; - -typedef struct { - hh_entity p; - hh_s_atributes atr; -}hh_s_player; - - -/// @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/engine/maths.c b/src/engine/maths.c deleted file mode 100644 index 475bba2..0000000 --- a/src/engine/maths.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "engine/maths.h" - -vec2 vec_add(vec2 a, vec2 b){ - return (vec2){a.x + b.x, a.y + b.y}; -} - -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 bef287e..c7f1b44 100644 --- a/src/engine/maths.h +++ b/src/engine/maths.h @@ -3,17 +3,12 @@ // #include typedef struct { - int32_t x,y; + uint32_t x,y; } vec2; typedef vec2 vec_cen;//centered typedef vec2 vec_cor;//left upper corner -vec2 vec_add(vec2 a, vec2 b); - -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/player_controller.c b/src/engine/player_controller.c deleted file mode 100644 index 6735620..0000000 --- a/src/engine/player_controller.c +++ /dev/null @@ -1,167 +0,0 @@ -#include "ppu/types.h" -#include "engine/camera.h" -#include "engine/draw_screen.h" -#include "engine/sprite_controller.h" -#include "engine/player_controller.h" - -#include "demo.h" -#include - -#include "input.h" - -void hh_player_actions() { - static hh_entity player={ - .hp = 4, - .speed = 6, - .is_grounded = false, - .pos = (vec2){32,32}, - .vel = (vec2){0,0}, - .vec = (vec2){0,0}, - .render = { - .frame0 = 20, - .palette = 7, - .fam = (hh_s_ppu_loc_fam_entry){ - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = 7, - .tilemap_index = 2, - } - } - }, player_new = {0}; - - // hh_input_read(); - player.vel = (vec2){.x = (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right), - .y = (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down) }; - // const int8_t maa = 3; - // const int8_t mbb = -3; - // if (g_hh_controller_p1.dpad_up) - // - // if (g_hh_controller_p1.dpad_down) - // - // if (g_hh_controller_p1.dpad_left) { - // player.vel.x += mbb; - // // g_hh_demo_balls[0].horizontal_flip = true; - // } - // if (g_hh_controller_p1.dpad_right) { - // player.vel.x += maa; - // // g_hh_demo_balls[0].horizontal_flip = true; - // } - // if (g_hh_controller_p1.button_primary /*&& player.is_grounded*/) //JUMP - // player.vel.y += -6; - // // // if (g_hh_controller_p1.button_secondary) - - // player.render.fam.palette_index = 7; - // player.render.fam.tilemap_index = 7; - - // printf("%x ",player.render.fam.palette_index); - - // player.vel.y += 1; //gravity - - - //END OF VECTOR CHANGES - // player.vel.y = CLAMP(player.vel.y,-32,32); - // player.vel.x = CLAMP(player.vel.x,-32,32); - - player_new.pos = (vec2){ - .x = player.pos.x + player.vel.x, - .y = player.pos.y + player.vel.y, - }; - - - - // const uint8_t empty = 0; - // hh_s_tiles tiles[9]; - // const vec2 tile_offset[9] = { - // (vec2){-16,-16},(vec2){0,-16},(vec2){+16,-16}, - // (vec2){-16,0}, (vec2){0,0}, (vec2){+16,0}, - // (vec2){-16,+16},(vec2){0,+16},(vec2){+16,+16}, - // }; - // for (int i = 0; i < 9; i++) { - // vec2 temp_pos = vec_add(player.pos, tile_offset[i]); - // temp_pos =(vec2){ - // .x = temp_pos.x, - // .y = temp_pos.y, - // }; - // hh_s_tiles tile = { - // .pos = temp_pos, - // .idx = hh_world_to_tile(temp_pos) - // }; - // if(hh_colidable(tile.idx)) { - // tiles[i]=tile; - // // printf(" collidable near!"); - // } else { - // tiles[i].idx = 0; - // } - // } - /* - 012 - 345 - 678 - */ - // for (int i = 0; i < 9; i++) - // { - // if (tiles[i].idx != 0){ - // hh_solve_collision(tiles[i].pos, &player); - // } - // } - - player_new.is_grounded = false; - - // solves x collision - if (player.vel.x <= 0) { - if (hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player.pos.y + 0})) || - hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player.pos.y + 15}))) { - player_new.pos.x = (player_new.pos.x & ~15) + 16, - player_new.vel.x = 0; - } - } else { - if (hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 16, .y=player.pos.y + 0})) || - hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 16, .y=player.pos.y + 15}))) { - player_new.pos.x = player_new.pos.x & ~15, // <-- magic comma, NOT TOUCHY - player_new.vel.x = 0; - } - } - - //solves y collision - if (player.vel.y <= 0) { - if (hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player_new.pos.y + 0})) || - hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player_new.pos.y + 15}))) { - player_new.pos.y = (player_new.pos.y & ~15) + 16, - player_new.vel.y = 0; - } - } else { - if (hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player_new.pos.y + 16})) || - hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 16, .y=player_new.pos.y + 15}))) { - player_new.pos.y = player_new.pos.y & ~15, - player_new.vel.y = 0; - player_new.is_grounded = true; - } - } - - player = player_new; - - vec_cor cam_pos;//value in tiles - // cam_pos = (vec2){0,0}; - cam_pos = hh_update_camera(player.pos,(vec2){0,0},(vec2){.x=20*16,.y=30*16});//TODO: remove magic number(s) - // printf("%i, %i:%i, %i\n",player.pos.x,player.pos.y,cam_pos.x,cam_pos.y); - hh_draw_screen(cam_pos); - // update player sprite on ppu - player.render.fam.position_x = (player.pos.x-cam_pos.x); - player.render.fam.position_y = (player.pos.y-cam_pos.y); - - - player.render.fam.tilemap_index = 2;//TODO: these two lines should be redundant - player.render.fam.palette_index = 7; - hh_ppu_update_foreground(0, player.render.fam); - - - hh_s_ppu_loc_fam_entry sprite = { - .position_x = 16, - .position_y = 16, - .palette_index = 7, - .tilemap_index = 2, - }; - hh_ppu_update_foreground(1, sprite); - -} - diff --git a/src/engine/player_controller.h b/src/engine/player_controller.h deleted file mode 100644 index 400c18e..0000000 --- a/src/engine/player_controller.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "engine/maths.h" -#include "engine/entity.h" -// inputs - -void hh_player_actions(); diff --git a/src/engine/sprite_controller.c b/src/engine/sprite_controller.c deleted file mode 100644 index 5d93cf8..0000000 --- a/src/engine/sprite_controller.c +++ /dev/null @@ -1,22 +0,0 @@ -#include - -#include "engine/sprite_controller.h" -#include "ppu/types.h" -#include "ppu/consts.h" -#include "ppu/ppu.h" - -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]); - } - } -} - -bool hh_colidable(uint8_t tile_idx){ - return (hh_get_palette(tile_idx) != 0); -} diff --git a/src/engine/sprite_controller.h b/src/engine/sprite_controller.h deleted file mode 100644 index 001a459..0000000 --- a/src/engine/sprite_controller.h +++ /dev/null @@ -1,106 +0,0 @@ -#pragma once -#include - -#include "ppu/types.h" - -// handles sprites - -// Bg sprites - -// Fg or entity sprites - -//TODO: pack data inside of sprite_palette LUT -//HH_PPU_PALETTE_COUNT -#define HH_SPRITE_COUNT 40 -#define HH_PAL_IDX_SKY 0 -#define HH_PAL_IDX_BRICK 1 -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 - 7,7,7,2,7,7,1,2,7 - //other palettes here: -}; - - -const static hh_ppu_loc_palette_table_t hh_g_palette = { - {//palette info here - {0x1,0x2,0x3}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}}, - {//Bricks - {0x1,0x2,0x3},//01 - {0xd,0x8,0xa},//24 - {0x0,0x0,0x1},//25 - {0x1,0x1,0x1},//26 - {0x1,0x1,0x2},//27 - {0x2,0x2,0x3},//28 - {0x3,0x4,0x5},//29 - {0x5,0x1,0x7}}, - {//slime - {0x1,0x2,0x3}, - {0x1,0x3,0x2}, - {0x4,0x8,0x3}, - {0x7,0xa,0x4}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}}, - { - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}}, - { - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}}, - { - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}}, - { - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}, - {0x0,0x0,0x0}}, - { - {0x0,0xf,0xf}, - {0xf,0xf,0xf}, - {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(uint8_t tile_idx); - -bool hh_colidable(uint8_t tile_idx); diff --git a/src/makefile b/src/makefile index d7d9087..96751fb 100644 --- a/src/makefile +++ b/src/makefile @@ -31,13 +31,7 @@ LOCAL_SRCS += main.c \ ppu/internals.c \ ppu/ppu.c \ demo.c \ - engine/engine.c \ - engine/sprite_controller.c \ - engine/player_controller.c \ - engine/draw_screen.c \ - engine/camera.c \ - engine/maths.c \ - engine/entity.c + engine/engine.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index a5fec45..1fceb82 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -29,21 +29,20 @@ void hh_ppu_init() { } void hh_ppu_load_tilemap() { - char* filename = "../test/bin/tiles.bin"; + char* filename = "tiles.bin"; FILE* fp = fopen(filename,"rb"); if (!fp){ - fprintf(stderr,"Error: Failed to load tiles."); return;//error } - int sprite_size = (HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT); + fseek(fp, 0, SEEK_END);//goto EOF - int _size = ftell(fp)/sprite_size; + int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE; fseek(fp, 0, 0);//goto start of file for (int i = 0; i < _size; i++) { - uint8_t data[sprite_size]; + uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE]; - fread(data,sizeof(uint8_t),sprite_size,fp); + fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); hh_s_ppu_vram_data sprite = hh_ppu_2nat_sprite(data); sprite.offset = i*HH_PPU_VRAM_TMM_SPRITE_SIZE; diff --git a/test/bin/exportingPalettes.md b/test/bin/exportingPalettes.md deleted file mode 100644 index be4a354..0000000 --- a/test/bin/exportingPalettes.md +++ /dev/null @@ -1,4 +0,0 @@ -```sh -cat test.src|head -n 46 | awk '{printf "%02x: {0x%x,0x%x,0x%x}\n",NR,$1/2,$2/2,$3/2 }' > hex_palettes -``` - diff --git a/test/bin/test_file_read.c b/test/bin/test_file_read.c index df93395..b3357ce 100644 --- a/test/bin/test_file_read.c +++ b/test/bin/test_file_read.c @@ -16,22 +16,19 @@ void printData(uint8_t* in) { } void hh_ppu_load_tilemap() { - - - char* filename = "slime.bin"; + char* filename = "tiles.bin"; FILE* fp = fopen(filename,"rb"); if (!fp){ return;//error } - int sprite_size = (16 * 16); fseek(fp, 0, SEEK_END); - int _size = ftell(fp)/sprite_size; - rewind(fp); + int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE; + fseek(fp, 0, 0); // printf("%i",_size); for (int i = 0; i < _size; i++) { - uint8_t data[sprite_size]; - fread(data,1,sprite_size,fp); + uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE]; + fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); printData(data); } diff --git a/test/bin/tilemap.pip b/test/bin/tilemap.pip deleted file mode 100644 index c0c646e..0000000 --- a/test/bin/tilemap.pip +++ /dev/null @@ -1,512 +0,0 @@ -0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -0100: 06 06 06 06 06 05 06 06 06 06 06 05 06 06 06 06 -0110: 06 05 05 05 05 03 05 05 05 05 05 03 05 05 05 05 -0120: 06 05 04 04 04 03 05 05 05 05 05 03 05 05 05 05 -0130: 06 04 04 04 04 02 02 02 02 02 02 02 02 02 02 02 -0140: 06 04 04 04 04 02 02 03 03 03 03 03 03 02 03 03 -0150: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 -0160: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 -0170: 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 02 -0180: 06 06 04 04 04 04 04 02 02 02 03 03 03 03 02 02 -0190: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -01a0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 -01b0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 -01c0: 00 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 -01d0: 00 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 -01e0: 00 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 -01f0: 06 06 06 05 05 05 02 02 02 02 02 02 02 02 02 02 -0200: 06 06 06 05 06 06 06 06 06 06 06 05 06 06 06 06 -0210: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 -0220: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 -0230: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0240: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -0250: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -0260: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 -0270: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0280: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -0290: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -02a0: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -02b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -02c0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 -02d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 -02e0: 02 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 -02f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0300: 06 06 06 05 06 06 06 06 06 06 05 06 06 06 06 06 -0310: 05 05 05 03 05 05 05 05 05 05 03 05 05 05 05 06 -0320: 05 05 05 03 05 05 05 05 05 05 03 04 04 05 05 06 -0330: 02 02 02 02 02 02 02 02 02 02 02 04 04 04 04 06 -0340: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 06 -0350: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 -0360: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 -0370: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 -0380: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 -0390: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 -03a0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 -03b0: 02 02 02 02 02 02 02 02 02 02 02 05 05 06 06 06 -03c0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 06 -03d0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 06 -03e0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 05 -03f0: 02 02 02 02 02 02 02 02 02 02 02 02 03 03 03 05 -0400: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -0410: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -0420: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 02 02 -0430: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 -0440: 00 05 04 04 04 03 02 03 03 03 03 03 03 02 03 03 -0450: 00 05 04 04 04 02 03 03 03 03 03 03 03 02 03 03 -0460: 00 04 04 04 04 02 03 03 03 03 03 02 02 02 02 03 -0470: 06 06 05 05 02 02 02 02 02 02 02 02 02 02 02 02 -0480: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -0490: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -04a0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 -04b0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 -04c0: 00 05 05 04 04 04 04 03 02 03 03 03 03 03 03 03 -04d0: 00 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 -04e0: 00 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 -04f0: 00 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 -0500: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 -0510: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 -0520: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 -0530: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0540: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 -0550: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -0560: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 -0570: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0580: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 -0590: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -05a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 -05b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -05c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 -05d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 -05e0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 -05f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0600: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 -0610: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 -0620: 03 03 02 02 03 03 03 03 03 03 03 02 04 04 04 00 -0630: 02 02 02 02 02 02 02 02 02 02 02 02 02 06 06 06 -0640: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 06 -0650: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 -0660: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 -0670: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 -0680: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 -0690: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 -06a0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 -06b0: 02 02 02 02 02 02 02 02 02 02 02 03 03 06 06 06 -06c0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 06 -06d0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 05 -06e0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 05 -06f0: 02 02 02 02 02 02 02 02 02 02 02 02 03 03 03 05 -0700: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -0710: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -0720: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 02 02 -0730: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 -0740: 00 05 04 04 04 03 02 03 03 03 03 03 03 02 03 03 -0750: 00 05 04 04 04 02 03 03 03 03 03 03 03 02 03 03 -0760: 00 04 04 04 04 02 03 03 03 03 03 02 02 02 02 03 -0770: 06 06 05 05 02 02 02 02 02 02 02 02 02 02 02 02 -0780: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -0790: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -07a0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 -07b0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 -07c0: 00 05 05 04 04 04 04 04 04 04 04 02 02 02 02 04 -07d0: 00 05 05 04 04 04 04 04 04 04 04 04 02 04 04 04 -07e0: 00 06 05 05 05 04 04 04 04 04 04 04 03 04 04 04 -07f0: 00 06 06 06 05 05 05 05 05 05 05 05 03 05 05 05 -0800: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 -0810: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 -0820: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 -0830: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0840: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 -0850: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -0860: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 -0870: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0880: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 -0890: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -08a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 -08b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -08c0: 04 04 04 04 04 04 04 04 03 03 03 04 04 04 04 04 -08d0: 04 04 04 04 04 04 04 04 04 03 03 04 04 04 04 04 -08e0: 04 04 04 04 04 04 04 04 04 03 04 04 04 04 04 04 -08f0: 05 05 05 05 05 05 05 05 05 03 05 05 05 05 05 05 -0900: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 -0910: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 -0920: 03 03 02 02 03 03 03 03 03 03 03 02 04 04 04 00 -0930: 02 02 02 02 02 02 02 02 02 02 02 02 02 06 06 06 -0940: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 06 -0950: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 -0960: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 -0970: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 -0980: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 -0990: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 -09a0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 -09b0: 02 02 02 02 02 02 03 03 03 03 03 03 03 06 06 06 -09c0: 04 04 03 03 03 04 04 04 04 04 04 04 04 04 05 06 -09d0: 04 04 04 03 03 04 04 04 04 04 04 04 04 05 05 05 -09e0: 04 04 04 03 04 04 04 04 04 04 04 05 05 05 05 06 -09f0: 05 05 05 03 05 05 05 05 05 05 05 05 05 06 06 06 -0a00: 06 06 06 06 06 05 06 06 06 06 06 05 06 06 06 06 -0a10: 06 05 05 05 05 03 05 05 05 05 05 03 05 05 05 05 -0a20: 06 05 04 04 04 03 05 05 05 05 05 03 05 05 05 05 -0a30: 06 04 04 04 04 02 02 02 02 02 02 02 02 02 02 02 -0a40: 06 04 04 04 04 02 02 03 03 03 03 03 03 02 03 03 -0a50: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 -0a60: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 -0a70: 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 02 -0a80: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -0a90: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 -0aa0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 -0ab0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 -0ac0: 00 05 05 04 04 04 04 04 04 04 04 02 02 02 02 04 -0ad0: 00 05 05 04 04 04 04 04 04 04 04 04 02 04 04 04 -0ae0: 00 06 05 05 05 04 04 04 04 04 04 04 03 04 04 04 -0af0: 00 06 06 06 05 05 05 05 05 05 05 05 03 05 05 05 -0b00: 06 06 06 05 06 06 06 06 06 06 06 05 06 06 06 06 -0b10: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 -0b20: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 -0b30: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0b40: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -0b50: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -0b60: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 -0b70: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0b80: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 -0b90: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -0ba0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 -0bb0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -0bc0: 04 04 04 04 04 04 04 04 03 03 03 04 04 04 04 04 -0bd0: 04 04 04 04 04 04 04 04 04 03 03 04 04 04 04 04 -0be0: 04 04 04 04 04 04 04 04 04 03 04 04 04 04 04 04 -0bf0: 05 05 05 05 05 05 05 05 05 03 05 05 05 05 05 05 -0c00: 06 06 06 05 06 06 06 06 06 06 05 06 06 06 06 06 -0c10: 05 05 05 03 05 05 05 05 05 05 03 05 05 05 05 06 -0c20: 05 05 05 03 05 05 05 05 05 05 03 04 04 05 05 06 -0c30: 02 02 02 02 02 02 02 02 02 02 02 04 04 04 04 06 -0c40: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 06 -0c50: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 -0c60: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 -0c70: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 -0c80: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 -0c90: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 -0ca0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 -0cb0: 02 02 02 02 02 02 03 03 03 03 03 03 03 06 06 06 -0cc0: 04 04 03 03 03 04 04 04 04 04 04 04 04 04 05 06 -0cd0: 04 04 04 03 03 04 04 04 04 04 04 04 04 05 05 05 -0ce0: 04 04 04 03 04 04 04 04 04 04 04 05 05 05 05 06 -0cf0: 05 05 05 03 05 05 05 05 05 05 05 05 05 06 06 06 -0d00: 06 06 06 06 06 05 06 06 06 06 05 06 06 06 06 06 -0d10: 06 05 05 05 05 03 05 05 05 05 03 05 05 05 05 06 -0d20: 06 05 04 04 04 03 05 05 05 05 03 04 04 05 05 06 -0d30: 06 04 04 04 04 02 02 02 02 02 02 04 04 04 04 06 -0d40: 06 04 04 04 04 02 02 03 03 03 02 04 04 04 04 06 -0d50: 05 04 04 04 04 02 03 03 03 03 02 04 04 04 04 05 -0d60: 05 04 04 04 04 02 03 03 03 03 02 04 04 04 04 05 -0d70: 03 03 03 03 03 02 02 02 02 02 02 03 03 03 03 05 -0d80: 06 06 04 04 04 04 04 02 04 04 04 04 04 05 05 00 -0d90: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 -0da0: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 -0db0: 05 03 03 03 03 03 02 02 02 02 02 05 05 06 06 06 -0dc0: 00 05 04 04 04 04 04 04 03 02 04 04 04 04 04 06 -0dd0: 00 05 04 04 04 04 04 04 03 02 04 04 04 04 04 06 -0de0: 00 05 04 04 04 04 04 04 03 02 04 04 04 04 04 05 -0df0: 06 06 06 05 05 05 02 02 02 02 02 02 03 03 03 05 -0e00: 06 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 -0e10: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 -0e20: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 04 00 -0e30: 05 03 03 03 03 03 02 02 02 02 02 02 02 06 06 06 -0e40: 00 05 04 04 04 03 02 03 03 02 04 04 04 04 04 06 -0e50: 00 05 04 04 04 02 03 03 03 02 04 04 04 04 04 05 -0e60: 00 04 04 04 04 02 03 03 03 02 03 04 04 04 04 05 -0e70: 06 06 05 05 02 02 02 02 02 02 02 03 03 03 03 05 -0e80: 06 04 04 04 04 04 04 02 04 04 04 04 04 05 05 00 -0e90: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 -0ea0: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 -0eb0: 05 03 03 03 03 03 02 02 02 02 02 03 03 06 06 06 -0ec0: 00 05 05 04 04 04 03 03 03 03 03 04 04 04 04 06 -0ed0: 00 05 04 04 04 04 03 03 03 03 04 04 04 04 04 05 -0ee0: 00 05 04 04 04 03 03 03 03 03 04 04 04 04 04 05 -0ef0: 00 05 03 03 03 03 03 02 02 02 02 02 03 03 03 05 -0f00: 06 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 -0f10: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 -0f20: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 04 00 -0f30: 05 03 03 03 03 03 02 02 02 02 02 02 02 06 06 06 -0f40: 00 05 04 04 04 03 02 03 03 02 04 04 04 04 04 06 -0f50: 00 05 04 04 04 02 03 03 03 02 04 04 04 04 04 05 -0f60: 00 04 04 04 04 02 03 03 03 02 04 04 04 04 04 05 -0f70: 06 06 05 05 02 02 02 02 02 02 02 03 03 03 03 05 -0f80: 06 04 04 04 04 04 04 02 04 04 04 04 04 05 05 00 -0f90: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 -0fa0: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 -0fb0: 05 03 03 03 03 03 02 02 03 03 03 03 03 06 06 06 -0fc0: 00 05 05 04 04 04 04 04 04 04 04 04 04 04 05 06 -0fd0: 00 05 05 04 04 04 04 04 04 04 04 04 04 05 05 05 -0fe0: 00 06 05 05 05 04 04 04 04 04 04 05 05 05 05 06 -0ff0: 00 06 06 06 05 05 05 05 05 05 05 05 05 06 06 06 -1000: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 -1010: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 -1020: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 -1030: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1040: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 -1050: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -1060: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 -1070: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1080: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 -1090: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -10a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 -10b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -10c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 04 04 04 -10d0: 03 02 03 03 03 03 03 03 03 02 03 03 04 04 04 04 -10e0: 03 02 03 03 03 03 03 03 02 02 02 03 04 04 04 04 -10f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1100: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 -1110: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 -1120: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 -1130: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1140: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 -1150: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -1160: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 -1170: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1180: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 -1190: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -11a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 -11b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -11c0: 02 02 02 04 04 03 03 03 03 02 03 03 03 03 03 03 -11d0: 04 02 04 04 04 04 03 03 03 02 03 03 03 03 03 03 -11e0: 04 02 04 04 04 04 03 03 02 02 02 03 03 03 03 03 -11f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1200: 03 03 02 02 02 03 03 03 03 03 03 02 02 05 05 05 -1210: 03 03 03 02 03 03 03 03 03 03 03 02 03 05 05 05 -1220: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 05 05 -1230: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1240: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 -1250: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -1260: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 -1270: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1280: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 -1290: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -12a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 -12b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -12c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 -12d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 -12e0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 -12f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1300: 06 05 02 02 02 03 03 03 03 03 03 02 02 03 03 03 -1310: 05 05 05 02 03 03 03 03 03 03 03 02 03 03 03 03 -1320: 05 05 03 02 03 03 03 03 03 03 02 02 02 03 03 03 -1330: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1340: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 -1350: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 -1360: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 -1370: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1380: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 -1390: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 -13a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 -13b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -13c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 -13d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 -13e0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 -13f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1400: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1410: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1420: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1430: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1440: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1450: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1460: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1470: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1480: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1490: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -14a0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -14b0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -14c0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -14d0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -14e0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -14f0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1500: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 -1510: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 -1520: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 -1530: 02 02 02 02 02 02 02 02 02 02 02 02 02 01 01 01 -1540: 03 03 03 03 02 02 03 03 02 02 02 02 02 01 02 02 -1550: 03 03 03 03 03 02 02 02 02 02 02 02 02 01 02 02 -1560: 03 03 03 03 03 01 02 02 02 02 02 02 01 01 01 02 -1570: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 -1580: 02 03 03 03 02 02 02 01 02 02 02 02 02 02 01 01 -1590: 03 03 03 03 02 02 02 01 02 02 02 02 02 02 02 01 -15a0: 03 03 03 03 02 02 01 01 01 01 02 02 02 02 01 01 -15b0: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 -15c0: 02 02 02 03 03 02 02 02 02 01 02 02 02 01 01 01 -15d0: 03 02 03 03 03 02 02 02 02 01 02 02 01 01 01 01 -15e0: 03 02 03 03 03 03 02 02 01 01 01 02 01 01 01 01 -15f0: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 -1600: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 -1610: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 -1620: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 -1630: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1640: 02 02 02 02 01 01 02 02 02 02 02 02 02 01 02 02 -1650: 02 02 02 02 02 01 02 02 02 02 02 02 02 01 02 02 -1660: 02 02 02 02 02 01 02 02 02 02 02 02 01 01 01 02 -1670: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1680: 01 02 02 02 02 02 02 01 02 02 02 02 02 02 01 01 -1690: 01 02 02 02 02 02 02 01 02 02 02 02 02 02 02 01 -16a0: 01 02 02 02 01 01 01 01 01 01 02 02 02 02 02 01 -16b0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -16c0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -16d0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -16e0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -16f0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1700: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 -1710: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 -1720: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 -1730: 01 01 01 01 02 02 02 02 02 02 02 02 02 02 02 02 -1740: 02 02 02 02 01 01 03 03 03 03 03 03 03 02 03 03 -1750: 02 02 02 02 02 01 02 02 03 03 03 03 03 02 03 03 -1760: 02 02 02 02 02 01 02 02 02 03 03 03 02 02 02 03 -1770: 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 -1780: 01 02 02 02 02 02 02 01 02 02 03 03 03 03 02 02 -1790: 02 02 02 02 02 02 02 01 02 02 02 03 03 03 03 02 -17a0: 02 02 02 02 02 02 01 01 01 01 02 03 03 03 03 02 -17b0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 -17c0: 01 01 01 02 02 02 02 02 02 01 02 03 03 03 03 03 -17d0: 01 01 02 02 02 02 02 02 02 01 02 03 03 03 03 03 -17e0: 01 01 02 02 02 02 02 02 01 01 01 03 03 03 03 03 -17f0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 -1800: 03 03 02 02 02 02 02 02 02 02 02 01 01 01 01 01 -1810: 03 03 03 02 03 02 02 02 02 02 02 01 01 01 01 01 -1820: 03 03 03 02 03 02 02 02 02 02 01 01 01 01 01 01 -1830: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 -1840: 03 03 03 03 02 01 02 02 02 02 02 02 01 01 01 01 -1850: 03 03 03 03 02 01 02 02 02 02 02 02 01 01 01 01 -1860: 03 03 03 03 02 01 02 02 02 02 02 01 01 01 01 01 -1870: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 -1880: 02 03 03 03 02 02 02 01 02 02 02 01 01 01 01 01 -1890: 03 03 03 03 02 02 02 01 02 02 02 01 01 01 01 01 -18a0: 03 03 03 03 02 02 01 01 01 01 02 01 01 01 01 01 -18b0: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 -18c0: 02 02 02 03 02 02 02 02 02 01 02 02 01 01 01 01 -18d0: 03 02 03 03 03 02 02 02 02 01 02 02 02 01 01 01 -18e0: 03 02 03 03 02 02 02 02 01 01 01 02 02 01 01 01 -18f0: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 -1900: 01 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 -1910: 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 03 -1920: 01 01 01 01 02 02 02 02 02 02 02 02 02 03 03 03 -1930: 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 -1940: 01 01 01 01 01 02 02 02 02 02 03 03 03 02 03 03 -1950: 01 01 01 01 01 02 02 02 02 02 03 03 03 02 03 03 -1960: 01 01 01 01 01 01 02 02 02 02 03 03 02 02 02 03 -1970: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 -1980: 01 01 01 01 02 02 02 01 02 02 02 03 03 03 02 02 -1990: 01 01 01 01 02 02 02 01 02 02 02 03 03 03 03 02 -19a0: 01 01 01 01 01 02 01 01 01 01 02 03 03 03 03 02 -19b0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 -19c0: 01 01 01 01 01 02 02 02 02 01 02 03 03 03 03 03 -19d0: 01 01 01 01 02 02 02 02 02 01 02 03 03 03 03 03 -19e0: 01 01 01 01 02 02 02 02 01 01 02 03 03 03 03 03 -19f0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 -1a00: 03 03 02 02 01 02 02 02 02 02 02 01 01 02 01 01 -1a10: 03 03 03 02 02 02 02 02 02 02 02 01 02 02 02 01 -1a20: 03 03 03 02 02 02 02 02 02 02 01 01 01 02 02 02 -1a30: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 -1a40: 03 03 03 03 01 01 02 02 02 02 02 02 02 01 02 02 -1a50: 03 03 03 03 02 01 02 02 02 02 02 02 02 01 02 02 -1a60: 03 03 03 03 03 01 02 02 02 02 02 02 01 01 01 02 -1a70: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 -1a80: 02 03 03 03 03 03 02 01 02 02 02 02 02 02 01 01 -1a90: 03 03 03 03 03 03 03 02 02 02 02 02 02 02 02 01 -1aa0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 -1ab0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1ac0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 -1ad0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 -1ae0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 -1af0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1b00: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1b10: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1b20: 02 01 01 01 01 01 01 01 01 01 01 01 01 01 02 02 -1b30: 01 01 01 01 01 01 01 01 02 02 02 02 01 01 01 01 -1b40: 02 02 02 02 01 01 02 02 02 02 02 02 02 01 02 02 -1b50: 02 02 02 02 02 01 02 02 02 02 02 02 02 01 02 02 -1b60: 02 02 02 02 02 01 02 02 02 02 02 02 01 01 01 02 -1b70: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 -1b80: 01 02 02 02 02 02 02 01 02 02 02 02 02 02 01 01 -1b90: 02 02 02 02 02 02 02 01 02 02 02 02 02 02 02 01 -1ba0: 03 03 02 02 02 02 01 01 01 01 02 02 02 02 02 01 -1bb0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1bc0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 -1bd0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 -1be0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 -1bf0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1c00: 01 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 -1c10: 02 02 02 01 02 02 02 02 02 02 02 02 03 03 03 03 -1c20: 02 02 02 01 02 02 02 02 02 02 01 02 02 03 03 03 -1c30: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 -1c40: 02 02 02 02 01 01 02 02 02 02 02 03 03 02 03 03 -1c50: 02 02 02 02 02 01 02 02 02 02 02 03 03 02 03 03 -1c60: 02 02 02 02 02 01 02 02 02 02 02 03 02 02 02 03 -1c70: 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 -1c80: 01 02 02 02 02 02 02 01 02 02 03 03 03 03 02 02 -1c90: 02 02 02 02 02 02 02 01 02 03 03 03 03 03 03 02 -1ca0: 02 02 02 02 02 02 01 02 02 02 03 03 03 03 03 02 -1cb0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1cc0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 -1cd0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 -1ce0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 -1cf0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 -1d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1d10: 00 00 01 01 01 01 01 00 00 00 01 01 01 00 00 00 -1d20: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 -1d30: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 -1d40: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 -1d50: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 -1d60: 00 00 00 00 01 00 00 00 00 00 01 01 01 00 00 00 -1d70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1d80: 00 00 01 01 01 01 00 00 00 00 01 01 01 00 00 00 -1d90: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 -1da0: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 -1db0: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 -1dc0: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 -1dd0: 00 00 01 01 01 01 00 00 00 00 01 01 01 00 00 00 -1de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1df0: 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 00 -1e00: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 -1e10: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 -1e20: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 -1e30: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 -1e40: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 -1e50: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 -1e60: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 -1e70: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 -1e80: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 -1e90: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 -1ea0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1eb0: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 -1ec0: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 -1ed0: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 -1ee0: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 -1ef0: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 -1f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1f10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1f20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1f30: 00 00 00 00 00 01 01 01 01 01 01 00 00 00 00 00 -1f40: 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 -1f50: 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 -1f60: 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 -1f70: 00 00 00 00 00 00 00 00 00 01 01 00 00 00 00 00 -1f80: 00 00 00 00 00 00 00 00 01 01 00 00 00 00 00 00 -1f90: 00 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 -1fa0: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 -1fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -1fe0: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 -1ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -- cgit v1.2.3 From 47c76e5eabd2b7aa4eb0de7ca34b4ef9ac78f395 Mon Sep 17 00:00:00 2001 From: Flenk008 Date: Mon, 13 Mar 2023 18:04:59 +0100 Subject: Revert "Revert "Merge branch 'dev' of https://github.com/Flenk008/avans-arcade into dev"" This reverts commit a9ad8e0a8ac5346108f1e2c1a0bf9360fadc20da. --- features.md | 72 +++++ src/.gitignore | 1 + src/engine/TODO/entity.c | 41 --- src/engine/TODO/entity.h | 24 -- src/engine/TODO/player_controller.h | 4 - src/engine/TODO/sprite_controller.h | 6 - src/engine/camera.c | 34 +++ src/engine/camera.h | 6 + src/engine/draw_screen.c | 62 +++++ src/engine/draw_screen.h | 16 +- src/engine/engine.c | 1 + src/engine/entity.c | 46 ++++ src/engine/entity.h | 57 ++++ src/engine/maths.c | 19 ++ src/engine/maths.h | 7 +- src/engine/player_controller.c | 167 ++++++++++++ src/engine/player_controller.h | 7 + src/engine/sprite_controller.c | 22 ++ src/engine/sprite_controller.h | 106 ++++++++ src/makefile | 8 +- src/ppusim/sim.c | 11 +- test/bin/exportingPalettes.md | 4 + test/bin/test_file_read.c | 13 +- test/bin/tilemap.pip | 512 ++++++++++++++++++++++++++++++++++++ 24 files changed, 1157 insertions(+), 89 deletions(-) create mode 100644 features.md delete mode 100644 src/engine/TODO/entity.c delete mode 100644 src/engine/TODO/entity.h delete mode 100644 src/engine/TODO/player_controller.h delete mode 100644 src/engine/TODO/sprite_controller.h create mode 100644 src/engine/camera.c create mode 100644 src/engine/camera.h create mode 100644 src/engine/draw_screen.c create mode 100644 src/engine/entity.c create mode 100644 src/engine/entity.h create mode 100644 src/engine/maths.c create mode 100644 src/engine/player_controller.c create mode 100644 src/engine/player_controller.h create mode 100644 src/engine/sprite_controller.c create mode 100644 src/engine/sprite_controller.h create mode 100644 test/bin/exportingPalettes.md create mode 100644 test/bin/tilemap.pip (limited to 'src/makefile') diff --git a/features.md b/features.md new file mode 100644 index 0000000..d044232 --- /dev/null +++ b/features.md @@ -0,0 +1,72 @@ +Af/Cancelled/Implement in sprint 3 +Done +## Checkpoint room (shop) +| feature | status | +|-|-| +|Upgrade abilities|Implement in sprint 3| +|Interaction with shopkeeper|Implement in sprint 3| + +## Upgrades abilities +| feature | status | +|-|-| +|HP boost|Implement in sprint 3| +|Jump boost|Implement in sprint 3| +|Speed boost|Implement in sprint 3| +|Regular dash|Implement in sprint 3| +|Super punch|Implement in sprint 3| +|Smoke bomb|Implement in sprint 3| + +## Levels +| feature | status | +|-|-| +|Breakable blocks|Implement in sprint 3| +|Hidden secrets|Implement in sprint 3| +|Boss fights|Implement in sprint 3| +|Enemies|Implement in sprint 3| +|audio|Implement in sprint 3| + +## player (Gozer) +| feature | status | +|-|-| +|Move X-as|Done| +|Jump|Done| +|Special ability|Implement in sprint 3| +|Health|Implement in sprint 3| +|Currency/Scoreboard|Implement in sprint 3| + +## Enemy (Menneke) +| feature | status | +|-|-| +|Move X-as|Implement in sprint 3| +|Jump|Implement in sprint 3| +|Hunt player|Implement in sprint 3| +|Health (1 HP)|Implement in sprint 3| +|Currency/Scoreboard|Implement in sprint 3| + +## Enemy (Ventje) +| feature | status | +|-|-| +|Move X-as|Implement in sprint 3| +|Jump|Implement in sprint 3| +|Hunt player|Implement in sprint 3| +|Health (2 HP) |Implement in sprint 3| +|Splitting upon defeat|Implement in sprint 3| +|Currency/Scoreboard|Implement in sprint 3| + +## Enemy (Terror uil) +| feature | status | +|-|-| +|Movement|Implement in sprint 3| +|Hunt player|Implement in sprint 3| +|Health (1 HP) |Implement in sprint 3| +|Splitting upon defeat|Implement in sprint 3| +|Currency/Scoreboard|Implement in sprint 3| + +## Could have additions if time is enough +| feature | status | +|-|-| +|Multiplayer|Implement in sprint 3| +|Shared HP|Implement in sprint 3| +|Special ability|Implement in sprint 3| +|Health|Implement in sprint 3| +|Currency/Scoreboard|Implement in sprint 3| diff --git a/src/.gitignore b/src/.gitignore index d8325cf..504b995 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -4,3 +4,4 @@ main.bin main main.exe static/ +*.bin diff --git a/src/engine/TODO/entity.c b/src/engine/TODO/entity.c deleted file mode 100644 index fa550d5..0000000 --- a/src/engine/TODO/entity.c +++ /dev/null @@ -1,41 +0,0 @@ -#include - -#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/engine/TODO/entity.h b/src/engine/TODO/entity.h deleted file mode 100644 index fdbeb8a..0000000 --- a/src/engine/TODO/entity.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -#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/engine/TODO/player_controller.h b/src/engine/TODO/player_controller.h deleted file mode 100644 index 1e9b86c..0000000 --- a/src/engine/TODO/player_controller.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "maths.h" -#include "hh_entity.h" - -// inputs diff --git a/src/engine/TODO/sprite_controller.h b/src/engine/TODO/sprite_controller.h deleted file mode 100644 index c1fadff..0000000 --- a/src/engine/TODO/sprite_controller.h +++ /dev/null @@ -1,6 +0,0 @@ -// handles sprites - -// Bg sprites - - -// Fg or entity sprites diff --git a/src/engine/camera.c b/src/engine/camera.c new file mode 100644 index 0000000..e756bd4 --- /dev/null +++ b/src/engine/camera.c @@ -0,0 +1,34 @@ +#include "engine/camera.h" + +#include "ppu/consts.h" + + +vec_cor hh_update_camera(vec_cen new, vec2 min, vec2 max){ + + //TODO: change floating point math to fix point math + //TODO: fix buggy y-axis ?? + + // new = vec_cen2cor(new,(vec2){.x=max.x/2,.y=max.y/2}); + new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH/2),.y=(new.y+(HH_PPU_SPRITE_HEIGHT/2))*2},(vec2){.x=max.x/2,.y=max.y/2}); + // new.x = new.x << HH_MATH_FIXED_POINT; + // new.y = new.y << HH_MATH_FIXED_POINT; + static vec_cor old; + // old.x = old.x << HH_MATH_FIXED_POINT; + // old.y = old.y << HH_MATH_FIXED_POINT; + + // int16_t some = 0; + // some = some <<= HH_MATH_FIXED_POINT-1; + + new.x = (int)((float)new.x*0.1f + (float)old.x*0.9f); + new.y = (int)((float)new.y*0.1f + (float)old.y*0.9f); + + // old.x = old.x >> HH_MATH_FIXED_POINT; + // old.y = old.y >> HH_MATH_FIXED_POINT; + + + 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 new file mode 100644 index 0000000..c4f3389 --- /dev/null +++ b/src/engine/draw_screen.c @@ -0,0 +1,62 @@ +#include "engine/draw_screen.h" +#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 */ + if (!level) { /* check if file opened successfully */ + fprintf(stderr, "Error: Failed to open file.\n"); + return 0; + } + int index = ((pos.y/16)*40 + pos.x/16);//TODO: remove magic number(s) + fseek(level, (index * sizeof(int)) + sizeof(int), SEEK_SET); + int tile;// = (int*)malloc(sizeof(int)); + fread(&tile, sizeof(int), 1, level); // read 1 tile from binary + + fclose(level); + // int val = tile; + // free(tile); + return tile; +} + + +// remeber old value to know which part to update. +vec2 previousViewport = { .x = 0, .y = 0 }; +void hh_draw_screen(vec_cor viewport){ + if (viewport.x == previousViewport.x && viewport.y == previousViewport.y) return; + + hh_ppu_update_aux((hh_s_ppu_loc_aux){ + .bg_shift_x = viewport.x, + .bg_shift_y = viewport.y, + .fg_fetch = 0, + .sysreset = 0, + }); + + // update previous viewport values + previousViewport = 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 */ + if (!level) { /* check if file opened successfully */ + fprintf(stderr, "Error: Failed to open file.\n"); + return; + } + fseek(level, (0* sizeof(int)) + sizeof(int), SEEK_SET); + int* tile = (int*)malloc(size*sizeof(int)); + fread(tile, sizeof(int), size, level); // read 1 tile from binary + + fclose(level); + + for(int BAM_index = 0; BAM_index < size; BAM_index++){ + hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = hh_get_palette(tile[BAM_index]), + .tilemap_index = tile[BAM_index], + }); + } + free(tile); +} diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h index 4af5865..b181108 100644 --- a/src/engine/draw_screen.h +++ b/src/engine/draw_screen.h @@ -3,7 +3,19 @@ // every function call for drawing the screen goes here. #include "engine/maths.h" +#include "ppu/ppu.h" +#include #include -uint16_t hh_world_to_tile(vec2 pos); -void hh_draw_screen(vec2 viewport); \ No newline at end of file +#include + + +#define HH_map_size_X 80 +#define HH_map_size_Y 60 + +/** @brief return a single tile from world binary */ +uint8_t hh_world_to_tile(vec2 pos); +/** @brief shift to level if viewport changed position */ +void hh_draw_screen(vec2 viewport); +/** @brief send data to BAM memory from binary level */ +void hh_setup_screen(); diff --git a/src/engine/engine.c b/src/engine/engine.c index f3410a4..799ee7c 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -1,3 +1,4 @@ #include "engine/draw_screen.h" #include "engine/level.h" #include "engine/maths.h" +#include "engine/sprite_controller.h" diff --git a/src/engine/entity.c b/src/engine/entity.c new file mode 100644 index 0000000..153e7e1 --- /dev/null +++ b/src/engine/entity.c @@ -0,0 +1,46 @@ +#include + +#include "engine/entity.h" +#include "engine/maths.h" + +/* + PLAYER: (pos on X) + ,___, + | | + | X | + |___| + +*/ + +bool hh_collision(vec_cor pos1, vec2 pos2){ + if (pos2.x == CLAMP(pos2.x, pos1.x, pos1.x+16)){// hit x + return true; + } + + if (pos2.y == CLAMP(pos2.y, pos1.y, pos1.y+16)){// hit y + return true; + } + return false; +} + +void hh_solve_collision(vec2 pos_environment, hh_entity* entity){ + if (!hh_collision(pos_environment,entity->pos)) + return; + + printf("BONK!/n"); + // if (entity->vel.y > 0){ + // entity->pos.y = MAX(entity->pos.y,pos_environment.y); + // entity->vel.y = 0; + // } else { + // entity->pos.y = MIN(entity->pos.y,pos_environment.y); + // entity->vel.y = 0; + // } + // if (entity->vel.x <= 0){ + // entity->pos.x = MIN(entity->pos.x,pos_environment.x-16); + // entity->vel.x = 0; + // } else { + // entity->pos.x = MAX(entity->pos.x,pos_environment.x+16); + // entity->vel.x = 0; + // } +} + diff --git a/src/engine/entity.h b/src/engine/entity.h new file mode 100644 index 0000000..f45dae2 --- /dev/null +++ b/src/engine/entity.h @@ -0,0 +1,57 @@ +#pragma once + +#include +#include + +#include "ppu/types.h" + +#include "engine/maths.h" + +typedef uint8_t hh_idx_t; + +typedef enum { + fire, ice, poison +}hh_e_damage_t; + +typedef struct { + hh_s_ppu_loc_fam_entry fam; //screen + hh_idx_t frame0; + hh_idx_t palette; + +}hh_s_rendering; + +typedef struct { + int8_t hp; + int8_t dmg; + hh_e_damage_t dmg_type; + int8_t speed_x, speed_y; + +} hh_s_atributes; + + +typedef struct { + vec2 pos, vel, vec; + bool is_grounded; + int8_t hp; + int8_t speed; + hh_s_rendering render; + //armor/block? +}hh_entity; + +typedef struct { + hh_entity p; + hh_s_atributes atr; +}hh_s_player; + + +/// @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/engine/maths.c b/src/engine/maths.c new file mode 100644 index 0000000..475bba2 --- /dev/null +++ b/src/engine/maths.c @@ -0,0 +1,19 @@ +#include "engine/maths.h" + +vec2 vec_add(vec2 a, vec2 b){ + return (vec2){a.x + b.x, a.y + b.y}; +} + +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..bef287e 100644 --- a/src/engine/maths.h +++ b/src/engine/maths.h @@ -3,12 +3,17 @@ // #include typedef struct { - uint32_t x,y; + int32_t x,y; } vec2; typedef vec2 vec_cen;//centered typedef vec2 vec_cor;//left upper corner +vec2 vec_add(vec2 a, vec2 b); + +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/player_controller.c b/src/engine/player_controller.c new file mode 100644 index 0000000..6735620 --- /dev/null +++ b/src/engine/player_controller.c @@ -0,0 +1,167 @@ +#include "ppu/types.h" +#include "engine/camera.h" +#include "engine/draw_screen.h" +#include "engine/sprite_controller.h" +#include "engine/player_controller.h" + +#include "demo.h" +#include + +#include "input.h" + +void hh_player_actions() { + static hh_entity player={ + .hp = 4, + .speed = 6, + .is_grounded = false, + .pos = (vec2){32,32}, + .vel = (vec2){0,0}, + .vec = (vec2){0,0}, + .render = { + .frame0 = 20, + .palette = 7, + .fam = (hh_s_ppu_loc_fam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = 7, + .tilemap_index = 2, + } + } + }, player_new = {0}; + + // hh_input_read(); + player.vel = (vec2){.x = (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right), + .y = (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down) }; + // const int8_t maa = 3; + // const int8_t mbb = -3; + // if (g_hh_controller_p1.dpad_up) + // + // if (g_hh_controller_p1.dpad_down) + // + // if (g_hh_controller_p1.dpad_left) { + // player.vel.x += mbb; + // // g_hh_demo_balls[0].horizontal_flip = true; + // } + // if (g_hh_controller_p1.dpad_right) { + // player.vel.x += maa; + // // g_hh_demo_balls[0].horizontal_flip = true; + // } + // if (g_hh_controller_p1.button_primary /*&& player.is_grounded*/) //JUMP + // player.vel.y += -6; + // // // if (g_hh_controller_p1.button_secondary) + + // player.render.fam.palette_index = 7; + // player.render.fam.tilemap_index = 7; + + // printf("%x ",player.render.fam.palette_index); + + // player.vel.y += 1; //gravity + + + //END OF VECTOR CHANGES + // player.vel.y = CLAMP(player.vel.y,-32,32); + // player.vel.x = CLAMP(player.vel.x,-32,32); + + player_new.pos = (vec2){ + .x = player.pos.x + player.vel.x, + .y = player.pos.y + player.vel.y, + }; + + + + // const uint8_t empty = 0; + // hh_s_tiles tiles[9]; + // const vec2 tile_offset[9] = { + // (vec2){-16,-16},(vec2){0,-16},(vec2){+16,-16}, + // (vec2){-16,0}, (vec2){0,0}, (vec2){+16,0}, + // (vec2){-16,+16},(vec2){0,+16},(vec2){+16,+16}, + // }; + // for (int i = 0; i < 9; i++) { + // vec2 temp_pos = vec_add(player.pos, tile_offset[i]); + // temp_pos =(vec2){ + // .x = temp_pos.x, + // .y = temp_pos.y, + // }; + // hh_s_tiles tile = { + // .pos = temp_pos, + // .idx = hh_world_to_tile(temp_pos) + // }; + // if(hh_colidable(tile.idx)) { + // tiles[i]=tile; + // // printf(" collidable near!"); + // } else { + // tiles[i].idx = 0; + // } + // } + /* + 012 + 345 + 678 + */ + // for (int i = 0; i < 9; i++) + // { + // if (tiles[i].idx != 0){ + // hh_solve_collision(tiles[i].pos, &player); + // } + // } + + player_new.is_grounded = false; + + // solves x collision + if (player.vel.x <= 0) { + if (hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player.pos.y + 0})) || + hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player.pos.y + 15}))) { + player_new.pos.x = (player_new.pos.x & ~15) + 16, + player_new.vel.x = 0; + } + } else { + if (hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 16, .y=player.pos.y + 0})) || + hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 16, .y=player.pos.y + 15}))) { + player_new.pos.x = player_new.pos.x & ~15, // <-- magic comma, NOT TOUCHY + player_new.vel.x = 0; + } + } + + //solves y collision + if (player.vel.y <= 0) { + if (hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player_new.pos.y + 0})) || + hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player_new.pos.y + 15}))) { + player_new.pos.y = (player_new.pos.y & ~15) + 16, + player_new.vel.y = 0; + } + } else { + if (hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 0, .y=player_new.pos.y + 16})) || + hh_colidable(hh_world_to_tile((vec2){.x=player_new.pos.x + 16, .y=player_new.pos.y + 15}))) { + player_new.pos.y = player_new.pos.y & ~15, + player_new.vel.y = 0; + player_new.is_grounded = true; + } + } + + player = player_new; + + vec_cor cam_pos;//value in tiles + // cam_pos = (vec2){0,0}; + cam_pos = hh_update_camera(player.pos,(vec2){0,0},(vec2){.x=20*16,.y=30*16});//TODO: remove magic number(s) + // printf("%i, %i:%i, %i\n",player.pos.x,player.pos.y,cam_pos.x,cam_pos.y); + hh_draw_screen(cam_pos); + // update player sprite on ppu + player.render.fam.position_x = (player.pos.x-cam_pos.x); + player.render.fam.position_y = (player.pos.y-cam_pos.y); + + + player.render.fam.tilemap_index = 2;//TODO: these two lines should be redundant + player.render.fam.palette_index = 7; + hh_ppu_update_foreground(0, player.render.fam); + + + hh_s_ppu_loc_fam_entry sprite = { + .position_x = 16, + .position_y = 16, + .palette_index = 7, + .tilemap_index = 2, + }; + hh_ppu_update_foreground(1, sprite); + +} + diff --git a/src/engine/player_controller.h b/src/engine/player_controller.h new file mode 100644 index 0000000..400c18e --- /dev/null +++ b/src/engine/player_controller.h @@ -0,0 +1,7 @@ +#pragma once + +#include "engine/maths.h" +#include "engine/entity.h" +// inputs + +void hh_player_actions(); diff --git a/src/engine/sprite_controller.c b/src/engine/sprite_controller.c new file mode 100644 index 0000000..5d93cf8 --- /dev/null +++ b/src/engine/sprite_controller.c @@ -0,0 +1,22 @@ +#include + +#include "engine/sprite_controller.h" +#include "ppu/types.h" +#include "ppu/consts.h" +#include "ppu/ppu.h" + +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]); + } + } +} + +bool hh_colidable(uint8_t tile_idx){ + return (hh_get_palette(tile_idx) != 0); +} diff --git a/src/engine/sprite_controller.h b/src/engine/sprite_controller.h new file mode 100644 index 0000000..001a459 --- /dev/null +++ b/src/engine/sprite_controller.h @@ -0,0 +1,106 @@ +#pragma once +#include + +#include "ppu/types.h" + +// handles sprites + +// Bg sprites + +// Fg or entity sprites + +//TODO: pack data inside of sprite_palette LUT +//HH_PPU_PALETTE_COUNT +#define HH_SPRITE_COUNT 40 +#define HH_PAL_IDX_SKY 0 +#define HH_PAL_IDX_BRICK 1 +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 + 7,7,7,2,7,7,1,2,7 + //other palettes here: +}; + + +const static hh_ppu_loc_palette_table_t hh_g_palette = { + {//palette info here + {0x1,0x2,0x3}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + {//Bricks + {0x1,0x2,0x3},//01 + {0xd,0x8,0xa},//24 + {0x0,0x0,0x1},//25 + {0x1,0x1,0x1},//26 + {0x1,0x1,0x2},//27 + {0x2,0x2,0x3},//28 + {0x3,0x4,0x5},//29 + {0x5,0x1,0x7}}, + {//slime + {0x1,0x2,0x3}, + {0x1,0x3,0x2}, + {0x4,0x8,0x3}, + {0x7,0xa,0x4}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}, + {0x0,0x0,0x0}}, + { + {0x0,0xf,0xf}, + {0xf,0xf,0xf}, + {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(uint8_t tile_idx); + +bool hh_colidable(uint8_t tile_idx); diff --git a/src/makefile b/src/makefile index 96751fb..d7d9087 100644 --- a/src/makefile +++ b/src/makefile @@ -31,7 +31,13 @@ LOCAL_SRCS += main.c \ ppu/internals.c \ ppu/ppu.c \ demo.c \ - engine/engine.c + engine/engine.c \ + engine/sprite_controller.c \ + engine/player_controller.c \ + engine/draw_screen.c \ + engine/camera.c \ + engine/maths.c \ + engine/entity.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index 1fceb82..a5fec45 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -29,20 +29,21 @@ void hh_ppu_init() { } void hh_ppu_load_tilemap() { - char* filename = "tiles.bin"; + char* filename = "../test/bin/tiles.bin"; FILE* fp = fopen(filename,"rb"); if (!fp){ + fprintf(stderr,"Error: Failed to load tiles."); return;//error } - + int sprite_size = (HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT); fseek(fp, 0, SEEK_END);//goto EOF - int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE; + int _size = ftell(fp)/sprite_size; fseek(fp, 0, 0);//goto start of file for (int i = 0; i < _size; i++) { - uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE]; + uint8_t data[sprite_size]; - fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); + fread(data,sizeof(uint8_t),sprite_size,fp); hh_s_ppu_vram_data sprite = hh_ppu_2nat_sprite(data); sprite.offset = i*HH_PPU_VRAM_TMM_SPRITE_SIZE; diff --git a/test/bin/exportingPalettes.md b/test/bin/exportingPalettes.md new file mode 100644 index 0000000..be4a354 --- /dev/null +++ b/test/bin/exportingPalettes.md @@ -0,0 +1,4 @@ +```sh +cat test.src|head -n 46 | awk '{printf "%02x: {0x%x,0x%x,0x%x}\n",NR,$1/2,$2/2,$3/2 }' > hex_palettes +``` + diff --git a/test/bin/test_file_read.c b/test/bin/test_file_read.c index b3357ce..df93395 100644 --- a/test/bin/test_file_read.c +++ b/test/bin/test_file_read.c @@ -16,19 +16,22 @@ void printData(uint8_t* in) { } void hh_ppu_load_tilemap() { - char* filename = "tiles.bin"; + + + char* filename = "slime.bin"; FILE* fp = fopen(filename,"rb"); if (!fp){ return;//error } + int sprite_size = (16 * 16); fseek(fp, 0, SEEK_END); - int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE; - fseek(fp, 0, 0); + int _size = ftell(fp)/sprite_size; + rewind(fp); // printf("%i",_size); for (int i = 0; i < _size; i++) { - uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE]; - fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); + uint8_t data[sprite_size]; + fread(data,1,sprite_size,fp); printData(data); } diff --git a/test/bin/tilemap.pip b/test/bin/tilemap.pip new file mode 100644 index 0000000..c0c646e --- /dev/null +++ b/test/bin/tilemap.pip @@ -0,0 +1,512 @@ +0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +0100: 06 06 06 06 06 05 06 06 06 06 06 05 06 06 06 06 +0110: 06 05 05 05 05 03 05 05 05 05 05 03 05 05 05 05 +0120: 06 05 04 04 04 03 05 05 05 05 05 03 05 05 05 05 +0130: 06 04 04 04 04 02 02 02 02 02 02 02 02 02 02 02 +0140: 06 04 04 04 04 02 02 03 03 03 03 03 03 02 03 03 +0150: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0160: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0170: 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 02 +0180: 06 06 04 04 04 04 04 02 02 02 03 03 03 03 02 02 +0190: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +01a0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 +01b0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +01c0: 00 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 +01d0: 00 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 +01e0: 00 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 +01f0: 06 06 06 05 05 05 02 02 02 02 02 02 02 02 02 02 +0200: 06 06 06 05 06 06 06 06 06 06 06 05 06 06 06 06 +0210: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 +0220: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 +0230: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0240: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0250: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0260: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +0270: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0280: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +0290: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +02a0: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +02b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +02c0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +02d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +02e0: 02 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +02f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0300: 06 06 06 05 06 06 06 06 06 06 05 06 06 06 06 06 +0310: 05 05 05 03 05 05 05 05 05 05 03 05 05 05 05 06 +0320: 05 05 05 03 05 05 05 05 05 05 03 04 04 05 05 06 +0330: 02 02 02 02 02 02 02 02 02 02 02 04 04 04 04 06 +0340: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 06 +0350: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 +0360: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 +0370: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 +0380: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 +0390: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +03a0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +03b0: 02 02 02 02 02 02 02 02 02 02 02 05 05 06 06 06 +03c0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 06 +03d0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 06 +03e0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 05 +03f0: 02 02 02 02 02 02 02 02 02 02 02 02 03 03 03 05 +0400: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0410: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0420: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 02 02 +0430: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +0440: 00 05 04 04 04 03 02 03 03 03 03 03 03 02 03 03 +0450: 00 05 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0460: 00 04 04 04 04 02 03 03 03 03 03 02 02 02 02 03 +0470: 06 06 05 05 02 02 02 02 02 02 02 02 02 02 02 02 +0480: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0490: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +04a0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 +04b0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +04c0: 00 05 05 04 04 04 04 03 02 03 03 03 03 03 03 03 +04d0: 00 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 +04e0: 00 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 +04f0: 00 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 +0500: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +0510: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +0520: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +0530: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0540: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +0550: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0560: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +0570: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0580: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +0590: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +05a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +05b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +05c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +05d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +05e0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +05f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0600: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 +0610: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 +0620: 03 03 02 02 03 03 03 03 03 03 03 02 04 04 04 00 +0630: 02 02 02 02 02 02 02 02 02 02 02 02 02 06 06 06 +0640: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 06 +0650: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 +0660: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 +0670: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 +0680: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 +0690: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +06a0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +06b0: 02 02 02 02 02 02 02 02 02 02 02 03 03 06 06 06 +06c0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 06 +06d0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 05 +06e0: 03 02 03 03 03 03 03 03 03 02 04 04 04 04 04 05 +06f0: 02 02 02 02 02 02 02 02 02 02 02 02 03 03 03 05 +0700: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0710: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0720: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 02 02 +0730: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +0740: 00 05 04 04 04 03 02 03 03 03 03 03 03 02 03 03 +0750: 00 05 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0760: 00 04 04 04 04 02 03 03 03 03 03 02 02 02 02 03 +0770: 06 06 05 05 02 02 02 02 02 02 02 02 02 02 02 02 +0780: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0790: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +07a0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 +07b0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +07c0: 00 05 05 04 04 04 04 04 04 04 04 02 02 02 02 04 +07d0: 00 05 05 04 04 04 04 04 04 04 04 04 02 04 04 04 +07e0: 00 06 05 05 05 04 04 04 04 04 04 04 03 04 04 04 +07f0: 00 06 06 06 05 05 05 05 05 05 05 05 03 05 05 05 +0800: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +0810: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +0820: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +0830: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0840: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +0850: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0860: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +0870: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0880: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +0890: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +08a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +08b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +08c0: 04 04 04 04 04 04 04 04 03 03 03 04 04 04 04 04 +08d0: 04 04 04 04 04 04 04 04 04 03 03 04 04 04 04 04 +08e0: 04 04 04 04 04 04 04 04 04 03 04 04 04 04 04 04 +08f0: 05 05 05 05 05 05 05 05 05 03 05 05 05 05 05 05 +0900: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 +0910: 03 03 03 02 03 03 03 03 03 03 03 02 04 04 05 00 +0920: 03 03 02 02 03 03 03 03 03 03 03 02 04 04 04 00 +0930: 02 02 02 02 02 02 02 02 02 02 02 02 02 06 06 06 +0940: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 06 +0950: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 +0960: 03 03 03 03 03 02 03 03 03 02 04 04 04 04 04 05 +0970: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 +0980: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 +0990: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +09a0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +09b0: 02 02 02 02 02 02 03 03 03 03 03 03 03 06 06 06 +09c0: 04 04 03 03 03 04 04 04 04 04 04 04 04 04 05 06 +09d0: 04 04 04 03 03 04 04 04 04 04 04 04 04 05 05 05 +09e0: 04 04 04 03 04 04 04 04 04 04 04 05 05 05 05 06 +09f0: 05 05 05 03 05 05 05 05 05 05 05 05 05 06 06 06 +0a00: 06 06 06 06 06 05 06 06 06 06 06 05 06 06 06 06 +0a10: 06 05 05 05 05 03 05 05 05 05 05 03 05 05 05 05 +0a20: 06 05 04 04 04 03 05 05 05 05 05 03 05 05 05 05 +0a30: 06 04 04 04 04 02 02 02 02 02 02 02 02 02 02 02 +0a40: 06 04 04 04 04 02 02 03 03 03 03 03 03 02 03 03 +0a50: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0a60: 05 04 04 04 04 02 03 03 03 03 03 03 03 02 03 03 +0a70: 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 02 +0a80: 06 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0a90: 05 04 04 04 04 04 04 02 03 03 03 03 03 03 03 02 +0aa0: 05 04 04 04 04 04 04 02 02 03 03 03 03 03 03 02 +0ab0: 05 03 03 03 03 03 02 02 02 02 02 02 02 02 02 02 +0ac0: 00 05 05 04 04 04 04 04 04 04 04 02 02 02 02 04 +0ad0: 00 05 05 04 04 04 04 04 04 04 04 04 02 04 04 04 +0ae0: 00 06 05 05 05 04 04 04 04 04 04 04 03 04 04 04 +0af0: 00 06 06 06 05 05 05 05 05 05 05 05 03 05 05 05 +0b00: 06 06 06 05 06 06 06 06 06 06 06 05 06 06 06 06 +0b10: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 +0b20: 05 05 05 03 05 05 05 05 05 05 05 03 05 05 05 05 +0b30: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0b40: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0b50: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +0b60: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +0b70: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0b80: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +0b90: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +0ba0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +0bb0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +0bc0: 04 04 04 04 04 04 04 04 03 03 03 04 04 04 04 04 +0bd0: 04 04 04 04 04 04 04 04 04 03 03 04 04 04 04 04 +0be0: 04 04 04 04 04 04 04 04 04 03 04 04 04 04 04 04 +0bf0: 05 05 05 05 05 05 05 05 05 03 05 05 05 05 05 05 +0c00: 06 06 06 05 06 06 06 06 06 06 05 06 06 06 06 06 +0c10: 05 05 05 03 05 05 05 05 05 05 03 05 05 05 05 06 +0c20: 05 05 05 03 05 05 05 05 05 05 03 04 04 05 05 06 +0c30: 02 02 02 02 02 02 02 02 02 02 02 04 04 04 04 06 +0c40: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 06 +0c50: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 +0c60: 03 03 03 03 03 02 03 03 03 03 02 04 04 04 04 05 +0c70: 02 02 02 02 02 02 02 02 02 02 02 03 03 03 03 05 +0c80: 03 03 03 03 03 03 03 02 04 04 04 04 04 05 05 00 +0c90: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +0ca0: 03 03 03 03 03 03 03 02 04 04 04 04 04 04 05 00 +0cb0: 02 02 02 02 02 02 03 03 03 03 03 03 03 06 06 06 +0cc0: 04 04 03 03 03 04 04 04 04 04 04 04 04 04 05 06 +0cd0: 04 04 04 03 03 04 04 04 04 04 04 04 04 05 05 05 +0ce0: 04 04 04 03 04 04 04 04 04 04 04 05 05 05 05 06 +0cf0: 05 05 05 03 05 05 05 05 05 05 05 05 05 06 06 06 +0d00: 06 06 06 06 06 05 06 06 06 06 05 06 06 06 06 06 +0d10: 06 05 05 05 05 03 05 05 05 05 03 05 05 05 05 06 +0d20: 06 05 04 04 04 03 05 05 05 05 03 04 04 05 05 06 +0d30: 06 04 04 04 04 02 02 02 02 02 02 04 04 04 04 06 +0d40: 06 04 04 04 04 02 02 03 03 03 02 04 04 04 04 06 +0d50: 05 04 04 04 04 02 03 03 03 03 02 04 04 04 04 05 +0d60: 05 04 04 04 04 02 03 03 03 03 02 04 04 04 04 05 +0d70: 03 03 03 03 03 02 02 02 02 02 02 03 03 03 03 05 +0d80: 06 06 04 04 04 04 04 02 04 04 04 04 04 05 05 00 +0d90: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0da0: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0db0: 05 03 03 03 03 03 02 02 02 02 02 05 05 06 06 06 +0dc0: 00 05 04 04 04 04 04 04 03 02 04 04 04 04 04 06 +0dd0: 00 05 04 04 04 04 04 04 03 02 04 04 04 04 04 06 +0de0: 00 05 04 04 04 04 04 04 03 02 04 04 04 04 04 05 +0df0: 06 06 06 05 05 05 02 02 02 02 02 02 03 03 03 05 +0e00: 06 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 +0e10: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 +0e20: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 04 00 +0e30: 05 03 03 03 03 03 02 02 02 02 02 02 02 06 06 06 +0e40: 00 05 04 04 04 03 02 03 03 02 04 04 04 04 04 06 +0e50: 00 05 04 04 04 02 03 03 03 02 04 04 04 04 04 05 +0e60: 00 04 04 04 04 02 03 03 03 02 03 04 04 04 04 05 +0e70: 06 06 05 05 02 02 02 02 02 02 02 03 03 03 03 05 +0e80: 06 04 04 04 04 04 04 02 04 04 04 04 04 05 05 00 +0e90: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0ea0: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0eb0: 05 03 03 03 03 03 02 02 02 02 02 03 03 06 06 06 +0ec0: 00 05 05 04 04 04 03 03 03 03 03 04 04 04 04 06 +0ed0: 00 05 04 04 04 04 03 03 03 03 04 04 04 04 04 05 +0ee0: 00 05 04 04 04 03 03 03 03 03 04 04 04 04 04 05 +0ef0: 00 05 03 03 03 03 03 02 02 02 02 02 03 03 03 05 +0f00: 06 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 +0f10: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 05 00 +0f20: 05 04 04 04 04 04 04 02 03 03 03 02 04 04 04 00 +0f30: 05 03 03 03 03 03 02 02 02 02 02 02 02 06 06 06 +0f40: 00 05 04 04 04 03 02 03 03 02 04 04 04 04 04 06 +0f50: 00 05 04 04 04 02 03 03 03 02 04 04 04 04 04 05 +0f60: 00 04 04 04 04 02 03 03 03 02 04 04 04 04 04 05 +0f70: 06 06 05 05 02 02 02 02 02 02 02 03 03 03 03 05 +0f80: 06 04 04 04 04 04 04 02 04 04 04 04 04 05 05 00 +0f90: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0fa0: 05 04 04 04 04 04 04 02 04 04 04 04 04 04 05 00 +0fb0: 05 03 03 03 03 03 02 02 03 03 03 03 03 06 06 06 +0fc0: 00 05 05 04 04 04 04 04 04 04 04 04 04 04 05 06 +0fd0: 00 05 05 04 04 04 04 04 04 04 04 04 04 05 05 05 +0fe0: 00 06 05 05 05 04 04 04 04 04 04 05 05 05 05 06 +0ff0: 00 06 06 06 05 05 05 05 05 05 05 05 05 06 06 06 +1000: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1010: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1020: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1030: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1040: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +1050: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +1060: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +1070: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1080: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +1090: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +10a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +10b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +10c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 04 04 04 +10d0: 03 02 03 03 03 03 03 03 03 02 03 03 04 04 04 04 +10e0: 03 02 03 03 03 03 03 03 02 02 02 03 04 04 04 04 +10f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1100: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1110: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1120: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1130: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1140: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +1150: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +1160: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +1170: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1180: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +1190: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +11a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +11b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +11c0: 02 02 02 04 04 03 03 03 03 02 03 03 03 03 03 03 +11d0: 04 02 04 04 04 04 03 03 03 02 03 03 03 03 03 03 +11e0: 04 02 04 04 04 04 03 03 02 02 02 03 03 03 03 03 +11f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1200: 03 03 02 02 02 03 03 03 03 03 03 02 02 05 05 05 +1210: 03 03 03 02 03 03 03 03 03 03 03 02 03 05 05 05 +1220: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 05 05 +1230: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1240: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +1250: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +1260: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +1270: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1280: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +1290: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +12a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +12b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +12c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +12d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +12e0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +12f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1300: 06 05 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1310: 05 05 05 02 03 03 03 03 03 03 03 02 03 03 03 03 +1320: 05 05 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1330: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1340: 03 03 03 03 02 02 03 03 03 03 03 03 03 02 03 03 +1350: 03 03 03 03 03 02 03 03 03 03 03 03 03 02 03 03 +1360: 03 03 03 03 03 02 03 03 03 03 03 03 02 02 02 03 +1370: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1380: 02 03 03 03 03 03 03 02 03 03 03 03 03 03 02 02 +1390: 03 03 03 03 03 03 03 02 03 03 03 03 03 03 03 02 +13a0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +13b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +13c0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +13d0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +13e0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +13f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1400: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1410: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1420: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1430: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1440: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1450: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1460: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1470: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1480: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1490: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14a0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14b0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14c0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14d0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14e0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +14f0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1500: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1510: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1520: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1530: 02 02 02 02 02 02 02 02 02 02 02 02 02 01 01 01 +1540: 03 03 03 03 02 02 03 03 02 02 02 02 02 01 02 02 +1550: 03 03 03 03 03 02 02 02 02 02 02 02 02 01 02 02 +1560: 03 03 03 03 03 01 02 02 02 02 02 02 01 01 01 02 +1570: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 +1580: 02 03 03 03 02 02 02 01 02 02 02 02 02 02 01 01 +1590: 03 03 03 03 02 02 02 01 02 02 02 02 02 02 02 01 +15a0: 03 03 03 03 02 02 01 01 01 01 02 02 02 02 01 01 +15b0: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +15c0: 02 02 02 03 03 02 02 02 02 01 02 02 02 01 01 01 +15d0: 03 02 03 03 03 02 02 02 02 01 02 02 01 01 01 01 +15e0: 03 02 03 03 03 03 02 02 01 01 01 02 01 01 01 01 +15f0: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 +1600: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1610: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1620: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1630: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1640: 02 02 02 02 01 01 02 02 02 02 02 02 02 01 02 02 +1650: 02 02 02 02 02 01 02 02 02 02 02 02 02 01 02 02 +1660: 02 02 02 02 02 01 02 02 02 02 02 02 01 01 01 02 +1670: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1680: 01 02 02 02 02 02 02 01 02 02 02 02 02 02 01 01 +1690: 01 02 02 02 02 02 02 01 02 02 02 02 02 02 02 01 +16a0: 01 02 02 02 01 01 01 01 01 01 02 02 02 02 02 01 +16b0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +16c0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +16d0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +16e0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +16f0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1700: 03 03 02 02 02 03 03 03 03 03 03 02 02 03 03 03 +1710: 03 03 03 02 03 03 03 03 03 03 03 02 03 03 03 03 +1720: 03 03 03 02 03 03 03 03 03 03 02 02 02 03 03 03 +1730: 01 01 01 01 02 02 02 02 02 02 02 02 02 02 02 02 +1740: 02 02 02 02 01 01 03 03 03 03 03 03 03 02 03 03 +1750: 02 02 02 02 02 01 02 02 03 03 03 03 03 02 03 03 +1760: 02 02 02 02 02 01 02 02 02 03 03 03 02 02 02 03 +1770: 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 +1780: 01 02 02 02 02 02 02 01 02 02 03 03 03 03 02 02 +1790: 02 02 02 02 02 02 02 01 02 02 02 03 03 03 03 02 +17a0: 02 02 02 02 02 02 01 01 01 01 02 03 03 03 03 02 +17b0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +17c0: 01 01 01 02 02 02 02 02 02 01 02 03 03 03 03 03 +17d0: 01 01 02 02 02 02 02 02 02 01 02 03 03 03 03 03 +17e0: 01 01 02 02 02 02 02 02 01 01 01 03 03 03 03 03 +17f0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +1800: 03 03 02 02 02 02 02 02 02 02 02 01 01 01 01 01 +1810: 03 03 03 02 03 02 02 02 02 02 02 01 01 01 01 01 +1820: 03 03 03 02 03 02 02 02 02 02 01 01 01 01 01 01 +1830: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 +1840: 03 03 03 03 02 01 02 02 02 02 02 02 01 01 01 01 +1850: 03 03 03 03 02 01 02 02 02 02 02 02 01 01 01 01 +1860: 03 03 03 03 02 01 02 02 02 02 02 01 01 01 01 01 +1870: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +1880: 02 03 03 03 02 02 02 01 02 02 02 01 01 01 01 01 +1890: 03 03 03 03 02 02 02 01 02 02 02 01 01 01 01 01 +18a0: 03 03 03 03 02 02 01 01 01 01 02 01 01 01 01 01 +18b0: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +18c0: 02 02 02 03 02 02 02 02 02 01 02 02 01 01 01 01 +18d0: 03 02 03 03 03 02 02 02 02 01 02 02 02 01 01 01 +18e0: 03 02 03 03 02 02 02 02 01 01 01 02 02 01 01 01 +18f0: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +1900: 01 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 +1910: 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 03 +1920: 01 01 01 01 02 02 02 02 02 02 02 02 02 03 03 03 +1930: 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 +1940: 01 01 01 01 01 02 02 02 02 02 03 03 03 02 03 03 +1950: 01 01 01 01 01 02 02 02 02 02 03 03 03 02 03 03 +1960: 01 01 01 01 01 01 02 02 02 02 03 03 02 02 02 03 +1970: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +1980: 01 01 01 01 02 02 02 01 02 02 02 03 03 03 02 02 +1990: 01 01 01 01 02 02 02 01 02 02 02 03 03 03 03 02 +19a0: 01 01 01 01 01 02 01 01 01 01 02 03 03 03 03 02 +19b0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +19c0: 01 01 01 01 01 02 02 02 02 01 02 03 03 03 03 03 +19d0: 01 01 01 01 02 02 02 02 02 01 02 03 03 03 03 03 +19e0: 01 01 01 01 02 02 02 02 01 01 02 03 03 03 03 03 +19f0: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +1a00: 03 03 02 02 01 02 02 02 02 02 02 01 01 02 01 01 +1a10: 03 03 03 02 02 02 02 02 02 02 02 01 02 02 02 01 +1a20: 03 03 03 02 02 02 02 02 02 02 01 01 01 02 02 02 +1a30: 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 01 +1a40: 03 03 03 03 01 01 02 02 02 02 02 02 02 01 02 02 +1a50: 03 03 03 03 02 01 02 02 02 02 02 02 02 01 02 02 +1a60: 03 03 03 03 03 01 02 02 02 02 02 02 01 01 01 02 +1a70: 02 02 02 02 02 01 01 01 01 01 01 01 01 01 01 01 +1a80: 02 03 03 03 03 03 02 01 02 02 02 02 02 02 01 01 +1a90: 03 03 03 03 03 03 03 02 02 02 02 02 02 02 02 01 +1aa0: 03 03 03 03 03 03 02 02 02 02 03 03 03 03 03 02 +1ab0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1ac0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +1ad0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +1ae0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +1af0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1b00: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1b10: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1b20: 02 01 01 01 01 01 01 01 01 01 01 01 01 01 02 02 +1b30: 01 01 01 01 01 01 01 01 02 02 02 02 01 01 01 01 +1b40: 02 02 02 02 01 01 02 02 02 02 02 02 02 01 02 02 +1b50: 02 02 02 02 02 01 02 02 02 02 02 02 02 01 02 02 +1b60: 02 02 02 02 02 01 02 02 02 02 02 02 01 01 01 02 +1b70: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 +1b80: 01 02 02 02 02 02 02 01 02 02 02 02 02 02 01 01 +1b90: 02 02 02 02 02 02 02 01 02 02 02 02 02 02 02 01 +1ba0: 03 03 02 02 02 02 01 01 01 01 02 02 02 02 02 01 +1bb0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1bc0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +1bd0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +1be0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +1bf0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1c00: 01 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 +1c10: 02 02 02 01 02 02 02 02 02 02 02 02 03 03 03 03 +1c20: 02 02 02 01 02 02 02 02 02 02 01 02 02 03 03 03 +1c30: 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 +1c40: 02 02 02 02 01 01 02 02 02 02 02 03 03 02 03 03 +1c50: 02 02 02 02 02 01 02 02 02 02 02 03 03 02 03 03 +1c60: 02 02 02 02 02 01 02 02 02 02 02 03 02 02 02 03 +1c70: 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 +1c80: 01 02 02 02 02 02 02 01 02 02 03 03 03 03 02 02 +1c90: 02 02 02 02 02 02 02 01 02 03 03 03 03 03 03 02 +1ca0: 02 02 02 02 02 02 01 02 02 02 03 03 03 03 03 02 +1cb0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1cc0: 02 02 02 03 03 03 03 03 03 02 03 03 03 03 03 03 +1cd0: 03 02 03 03 03 03 03 03 03 02 03 03 03 03 03 03 +1ce0: 03 02 03 03 03 03 03 03 02 02 02 03 03 03 03 03 +1cf0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 +1d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1d10: 00 00 01 01 01 01 01 00 00 00 01 01 01 00 00 00 +1d20: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 +1d30: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 +1d40: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 +1d50: 00 00 00 00 01 00 00 00 00 01 00 00 00 01 00 00 +1d60: 00 00 00 00 01 00 00 00 00 00 01 01 01 00 00 00 +1d70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1d80: 00 00 01 01 01 01 00 00 00 00 01 01 01 00 00 00 +1d90: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 +1da0: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 +1db0: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 +1dc0: 00 00 01 00 00 00 01 00 00 01 00 00 00 01 00 00 +1dd0: 00 00 01 01 01 01 00 00 00 00 01 01 01 00 00 00 +1de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1df0: 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 00 +1e00: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 +1e10: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1e20: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e30: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e40: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e50: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e60: 00 00 00 00 00 01 01 01 01 01 01 01 00 00 00 00 +1e70: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1e80: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1e90: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 +1ea0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1eb0: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 +1ec0: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1ed0: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1ee0: 00 00 00 00 00 00 01 01 01 01 01 00 00 00 00 00 +1ef0: 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00 +1f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1f10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1f20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1f30: 00 00 00 00 00 01 01 01 01 01 01 00 00 00 00 00 +1f40: 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 +1f50: 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 +1f60: 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 +1f70: 00 00 00 00 00 00 00 00 00 01 01 00 00 00 00 00 +1f80: 00 00 00 00 00 00 00 00 01 01 00 00 00 00 00 00 +1f90: 00 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 +1fa0: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 +1fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +1fe0: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 +1ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -- cgit v1.2.3 From 72295b9df9c0de9e585cce3f41437965eb0390cb Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Mon, 20 Mar 2023 19:11:41 +0100 Subject: demo version --- .vscode/settings.json | 4 +- src/GameLoop/shop.c | 30 ++++++++++++++ src/GameLoop/shop.h | 16 ++++++++ src/GameLoop/startingScreen.c | 32 +++++++++++++++ src/GameLoop/startingScreen.h | 14 +++++++ src/demo.c | 54 ++++++++++++++++++++++-- src/engine/bullet.c | 44 ++++++++++++++++++++ src/engine/bullet.h | 16 ++++++++ src/engine/draw_screen.c | 26 ++++++++++++ src/engine/draw_screen.h | 5 +++ src/engine/player_controller.c | 35 ++++++++++++---- src/engine/title_screen.c | 93 ++++++++++++++++++++++++++++++++++++++++++ src/engine/title_screen.h | 3 ++ src/makefile | 6 ++- src/ppusim/input.c | 1 + 15 files changed, 367 insertions(+), 12 deletions(-) create mode 100644 src/GameLoop/shop.c create mode 100644 src/GameLoop/shop.h create mode 100644 src/GameLoop/startingScreen.c create mode 100644 src/GameLoop/startingScreen.h create mode 100644 src/engine/bullet.c create mode 100644 src/engine/bullet.h create mode 100644 src/engine/title_screen.c create mode 100644 src/engine/title_screen.h (limited to 'src/makefile') diff --git a/.vscode/settings.json b/.vscode/settings.json index d027762..f4d72ed 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,5 +8,7 @@ } }, "cmake.configureOnOpen": false, - "files.eol": "\n" + "files.eol": "\n", + "nrf-connect.topdir": "${nrf-connect.sdk:2.1.2}", + "nrf-connect.toolchain.path": "${nrf-connect.toolchain:2.1.2}" } diff --git a/src/GameLoop/shop.c b/src/GameLoop/shop.c new file mode 100644 index 0000000..eb6bed5 --- /dev/null +++ b/src/GameLoop/shop.c @@ -0,0 +1,30 @@ +#include "shop.h" + + +bool hh_show_Shop(){ + static hh_e_ShopStates hh_e_Shop = hh_e_STATE_SHOW; + + switch (hh_e_Shop) + { + case hh_e_STATE_SHOW: + //hh_clear_screen(); + + //hh_setup_shop(); + hh_e_Shop = hh_e_STATE_Input; + return false; + break; + case hh_e_STATE_Input: + if(g_hh_controller_p1.button_primary){ + hh_e_Shop = hh_e_STATE_END; + } + break; + case hh_e_STATE_END: + hh_e_Shop = hh_e_STATE_SHOW; + return true; + break; + default: + hh_e_Shop = hh_e_STATE_SHOW; + break; + } + return false; +} diff --git a/src/GameLoop/shop.h b/src/GameLoop/shop.h new file mode 100644 index 0000000..4014f58 --- /dev/null +++ b/src/GameLoop/shop.h @@ -0,0 +1,16 @@ +#include "input.h" +#include "engine/draw_screen.h" + + + +#include +#include + +typedef enum { + hh_e_STATE_SHOW, + hh_e_STATE_Input, + hh_e_STATE_END +} hh_e_ShopStates; + + +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 +#include + +typedef enum { + hh_e_STATE_SHOW, + hh_e_STATE_Input, + hh_e_STATE_END +} hh_e_screenStates; + + +bool hh_show_startingScreen(); + diff --git a/src/demo.c b/src/demo.c index d4d1bf7..22ee8b7 100644 --- a/src/demo.c +++ b/src/demo.c @@ -11,8 +11,18 @@ #include "engine/draw_screen.h" #include "engine/player_controller.h" #include "engine/sprite_controller.h" +#include "GameLoop/startingScreen.h" +typedef enum { + hh_e_STATE_startingScreen, + hh_e_STATE_Shop, + hh_e_STATE_Gameplay, + hh_e_STATE_GameOver, + hh_e_STATE_HighScore +} hh_e_GameState; +hh_e_GameState hh_gameStates; + uint16_t g_hh_pos_x = 1000; // 0b0000 0001 0011 0110 @@ -37,7 +47,7 @@ hh_entity hh_g_player, hh_g_player_new; void hh_demo_setup() { hh_setup_palettes(); - hh_setup_screen(); + // hh_setup_screen(); } @@ -45,8 +55,46 @@ void hh_demo_setup() { void hh_demo_loop(unsigned long frame) { - hh_player_actions(); - + switch (hh_gameStates) + { + case hh_e_STATE_startingScreen: + bool ret = hh_show_startingScreen(); + if(ret){ + hh_gameStates = hh_e_STATE_Shop; + } + break; + case hh_e_STATE_Shop: + // TODO: + // if(hh_show_Shop()){ + hh_clear_screen(); + hh_clear_sprite(); + hh_setup_screen(); + hh_clear_sprite(); + hh_gameStates = hh_e_STATE_Gameplay; + // } + // function: new level is chosen goto level + break; + case hh_e_STATE_Gameplay: + hh_player_actions(); + + // TODO: + // function: if level complete goto shop + // function: if player is dead goto game over + break; + case hh_e_STATE_GameOver: + // TODO: + // function: show game over screen + // function: after time goto high score + break; + case hh_e_STATE_HighScore: + // TODO: + // fucntion: show all previously scored points + // function: button pressed goto starting screen + break; + default: + hh_gameStates = hh_e_STATE_startingScreen; + break; + } } // void sendData(uint8_t address, uint16_t data) { diff --git a/src/engine/bullet.c b/src/engine/bullet.c new file mode 100644 index 0000000..5aa9e51 --- /dev/null +++ b/src/engine/bullet.c @@ -0,0 +1,44 @@ +#include "bullet.h" +#include "engine/sprite_controller.h" + + +void shootBullet(vec2 playerPos, Bullet* bullet){ + // Set bullet's x and y coordinates to player's coordinates + bullet->x = playerPos.x; + bullet->y = playerPos.y; + // Set bullet's velocity to a fixed value + bullet->velocity = 1; + // Set bullet's status to active + bullet->isActive = true; +} +void updateBullet(Bullet* bullet, int deltaTime){ + // Only update bullet if it is active + static int latestLocationBullet = 0; + if (bullet->isActive) { + // Move bullet based on velocity and deltaTime + bullet->x += bullet->velocity * deltaTime; + drawBullet(bullet); + // Check if bullet has moved 16 pixels + if (bullet->x - latestLocationBullet > 32) { + // Set bullet's status to inactive + bullet->isActive = false; + drawBullet(&(Bullet){.x = -16,.y = -16. }); + } + } + else{ + latestLocationBullet = bullet->x; + } +} +void drawBullet(Bullet* bullet){ + + + hh_ppu_update_foreground(10, (hh_s_ppu_loc_fam_entry) + { + .position_x = bullet->x, + .position_y = bullet->y, + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = 7, + .tilemap_index = 84, // change tilemap to the correct foreground index; + }); +} diff --git a/src/engine/bullet.h b/src/engine/bullet.h new file mode 100644 index 0000000..ad67d84 --- /dev/null +++ b/src/engine/bullet.h @@ -0,0 +1,16 @@ +#pragma once +#include "player_controller.h" + +typedef struct { + int x; + int y; + int velocity; + int isActive; + int hit; +} Bullet; + + +//Bullet* createBullet(float x, float y, float velocity, float direction); +void shootBullet(vec2 playerPos, Bullet* bullet); +void updateBullet(Bullet* bullet, int deltaTime); +void drawBullet(Bullet* bullet); diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c index c4f3389..fed2cfa 100644 --- a/src/engine/draw_screen.c +++ b/src/engine/draw_screen.c @@ -60,3 +60,29 @@ 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_foreground(i,(hh_s_ppu_loc_fam_entry){ + .position_x = -16, + .position_y = -16, + }); + } +} diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h index b181108..d3abca6 100644 --- a/src/engine/draw_screen.h +++ b/src/engine/draw_screen.h @@ -19,3 +19,8 @@ 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/player_controller.c b/src/engine/player_controller.c index d351bee..647b00c 100644 --- a/src/engine/player_controller.c +++ b/src/engine/player_controller.c @@ -6,7 +6,11 @@ #include "input.h" +#include "engine/bullet.h" void hh_player_actions() { + static Bullet bullet ={ + .isActive=false, + }; static hh_entity player={ .hp = 4, .speed = 6, @@ -17,13 +21,13 @@ void hh_player_actions() { .vel = (vec2){0,0}, .vec = (vec2){0,0}, .render = { - .frame0 = 20, - .palette = 7, + .frame0 = 80, + .palette = 3, .fam = (hh_s_ppu_loc_fam_entry){ .horizontal_flip = false, .vertical_flip = false, - .palette_index = 7, - .tilemap_index = 2, + .palette_index = 2, + .tilemap_index = 60, } } }, player_new = {0}; @@ -114,6 +118,10 @@ void hh_player_actions() { player.vel.y += 1; //gravity } + if(g_hh_controller_p1.button_secondary==true){ + shootBullet(player.pos,&bullet); + } + updateBullet(&bullet,5); @@ -202,7 +210,7 @@ void hh_player_actions() { // hh_solve_collision(tiles[i].pos, &player); // } // } - + player = hh_background_collision ( player, player_new); //player = player_new; @@ -221,9 +229,22 @@ void hh_player_actions() { player.render.fam.tilemap_index = 2;//TODO: these two lines should be redundant player.render.fam.palette_index = 7; - hh_ppu_update_foreground(0, player.render.fam); + // hh_ppu_update_foreground(0, player.render.fam); + + for (int i = 0; i < 4; i++) + { + hh_s_ppu_loc_fam_entry temp = player.render.fam; + temp.position_x = player.render.fam.position_x+(!(player.vel.x>0)?-1:1)*(i%2?8:-8); + temp.position_y = player.render.fam.position_y+(i>1?0:-16); + temp.tilemap_index = player.render.frame0 + i; + temp.palette_index = player.render.palette; + temp.horizontal_flip = !(player.vel.x>0); + hh_ppu_update_foreground(i,temp); + } + + - hh_ppu_update_foreground(1, enemy.render.fam); + hh_ppu_update_foreground(4, enemy.render.fam); } 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(); diff --git a/src/makefile b/src/makefile index d7d9087..cd248e2 100644 --- a/src/makefile +++ b/src/makefile @@ -37,7 +37,11 @@ LOCAL_SRCS += main.c \ engine/draw_screen.c \ engine/camera.c \ engine/maths.c \ - engine/entity.c + engine/entity.c \ + engine/bullet.c \ + engine/title_screen.c \ + GameLoop/shop.c \ + GameLoop/startingScreen.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) diff --git a/src/ppusim/input.c b/src/ppusim/input.c index 5323fb1..4bc7018 100644 --- a/src/ppusim/input.c +++ b/src/ppusim/input.c @@ -13,4 +13,5 @@ void hh_input_read() { g_hh_controller_p1.dpad_left = kb[SDL_SCANCODE_A]; g_hh_controller_p1.dpad_right = kb[SDL_SCANCODE_D]; g_hh_controller_p1.button_primary = kb[SDL_SCANCODE_SPACE]; + g_hh_controller_p1.button_secondary = kb[SDL_SCANCODE_R]; } -- cgit v1.2.3 From 552dcc17db2b98287ba1b480c2e70759cd94d81f Mon Sep 17 00:00:00 2001 From: NielsCoding <48092678+heavydemon21@users.noreply.github.com> Date: Thu, 30 Mar 2023 13:02:36 +0200 Subject: gameloop/bullet/levels gameloop moet nog wat gefixt worden. shop moet nog wat art en functie krijgen zefde voor gameover/highscore bullet moet meerdere entityten kunnen doen nu nog alleen gemaakt voor 1. levels moet alleen nog backwords kunnen --- src/GameLoop/game_over.c | 28 +++++++++++++ src/GameLoop/game_over.h | 18 +++++++++ src/GameLoop/gameplay.c | 44 ++++++++++++++++++++ src/GameLoop/gameplay.h | 17 ++++++++ src/GameLoop/shop.c | 28 ++++++------- src/GameLoop/shop.h | 12 +++--- src/demo.c | 35 +++++----------- src/engine/bullet.c | 65 +++++++++++++----------------- src/engine/bullet.h | 17 +++----- src/engine/draw_screen.c | 103 ++++++++++++++++++++++++++--------------------- src/engine/draw_screen.h | 22 ++++++---- src/engine/level_const.c | 22 ++++++++++ src/engine/level_const.h | 31 ++++++++++++++ src/makefile | 3 ++ 14 files changed, 299 insertions(+), 146 deletions(-) create mode 100644 src/GameLoop/game_over.c create mode 100644 src/GameLoop/game_over.h create mode 100644 src/GameLoop/gameplay.c create mode 100644 src/GameLoop/gameplay.h create mode 100644 src/engine/level_const.c create mode 100644 src/engine/level_const.h (limited to 'src/makefile') diff --git a/src/GameLoop/game_over.c b/src/GameLoop/game_over.c new file mode 100644 index 0000000..09e6858 --- /dev/null +++ b/src/GameLoop/game_over.c @@ -0,0 +1,28 @@ +#include "game_over.h" + + +void hh_game_over(hh_e_GameState* hh_game_state){ + static hh_e_game_over hh_e_states_game_over = hh_e_game_over_SHOW; + + switch (hh_e_states_game_over) + { + case hh_e_game_over_SHOW: + hh_clear_screen(); + hh_clear_sprite(); + // TODO: make function to show game over + hh_e_states_game_over = hh_e_game_over_Input; + break; + case hh_e_game_over_Input: + if(g_hh_controller_p1.button_primary){ + hh_e_states_game_over = hh_e_game_over_END; + } + break; + case hh_e_game_over_END: + hh_e_states_game_over = hh_e_game_over_SHOW; + *hh_game_state = hh_e_STATE_GameOver; + break; + default: + hh_e_states_game_over = hh_e_game_over_SHOW; + break; + } +} diff --git a/src/GameLoop/game_over.h b/src/GameLoop/game_over.h new file mode 100644 index 0000000..0d40b6c --- /dev/null +++ b/src/GameLoop/game_over.h @@ -0,0 +1,18 @@ +#pragma once + +#include "input.h" +#include "engine/draw_screen.h" +#include "engine/level_const.h" + + +#include +#include + +typedef enum { + hh_e_game_over_SHOW, + hh_e_game_over_Input, + hh_e_game_over_END, +} hh_e_game_over; + + +void hh_game_over(hh_e_GameState*); diff --git a/src/GameLoop/gameplay.c b/src/GameLoop/gameplay.c new file mode 100644 index 0000000..72297f5 --- /dev/null +++ b/src/GameLoop/gameplay.c @@ -0,0 +1,44 @@ +#include "gameplay.h" + + + +void hh_gameplay(hh_g_all_levels game, hh_e_GameState* hh_game_state){ + static hh_e_gameplay gameplay = hh_e_setup_screen; + + switch (gameplay) + { + case hh_e_setup_screen: + hh_setup_screen(game.level[game.currentLevel]); + gameplay = hh_e_play_level; + break; + case hh_e_play_level: + // TODO: here come all the different functions for the gameplay + hh_player_actions(); + + + + if(game.level[game.currentLevel].hh_level_completed){ + gameplay = hh_e_level_complete; + } + break; + case hh_e_level_complete: + if(game.currentLevel < 3){ + game.currentLevel++; + gameplay = hh_e_setup_screen; + } + else { + gameplay = hh_e_game_over; + } + break; + case hh_e_game_over: + // TODO make reset levels + hh_reset_levels(); + gameplay = hh_e_setup_screen; + *hh_game_state = hh_e_STATE_GameOver; + break; + default: + break; + } + +} +void hh_reset_levels(){} diff --git a/src/GameLoop/gameplay.h b/src/GameLoop/gameplay.h new file mode 100644 index 0000000..6e8c1ec --- /dev/null +++ b/src/GameLoop/gameplay.h @@ -0,0 +1,17 @@ +#pragma once +#include "engine/draw_screen.h" +#include "engine/player_controller.h" +#include "engine/sprite_controller.h" +#include "GameLoop/startingScreen.h" +#include "engine/level_const.h" + +typedef enum { + hh_e_setup_screen, + hh_e_play_level, + hh_e_level_complete, + hh_e_game_over, +}hh_e_gameplay; + +void hh_reset_levels(); +void hh_gameplay(hh_g_all_levels, hh_e_GameState*); + diff --git a/src/GameLoop/shop.c b/src/GameLoop/shop.c index eb6bed5..8e6dc71 100644 --- a/src/GameLoop/shop.c +++ b/src/GameLoop/shop.c @@ -1,30 +1,30 @@ #include "shop.h" -bool hh_show_Shop(){ - static hh_e_ShopStates hh_e_Shop = hh_e_STATE_SHOW; +void hh_Shop(hh_e_GameState* hh_game_state){ + static hh_e_ShopStates hh_e_Shop = hh_e_shop_SHOW; switch (hh_e_Shop) { - case hh_e_STATE_SHOW: - //hh_clear_screen(); - + case hh_e_shop_SHOW: + hh_clear_screen(); + hh_clear_sprite(); + // TODO: make function to show shop //hh_setup_shop(); - hh_e_Shop = hh_e_STATE_Input; - return false; + hh_e_Shop = hh_e_shop_Input; break; - case hh_e_STATE_Input: + case hh_e_shop_Input: + // TODO: make it so that you can choose between shop if(g_hh_controller_p1.button_primary){ - hh_e_Shop = hh_e_STATE_END; + hh_e_Shop = hh_e_shop_END; } break; - case hh_e_STATE_END: - hh_e_Shop = hh_e_STATE_SHOW; - return true; + case hh_e_shop_END: + hh_e_Shop = hh_e_shop_SHOW; + *hh_game_state = hh_e_STATE_Gameplay; break; default: - hh_e_Shop = hh_e_STATE_SHOW; + hh_e_Shop = hh_e_shop_SHOW; break; } - return false; } diff --git a/src/GameLoop/shop.h b/src/GameLoop/shop.h index 4014f58..1efc057 100644 --- a/src/GameLoop/shop.h +++ b/src/GameLoop/shop.h @@ -1,16 +1,18 @@ +#pragma once + #include "input.h" #include "engine/draw_screen.h" - +#include "engine/level_const.h" #include #include typedef enum { - hh_e_STATE_SHOW, - hh_e_STATE_Input, - hh_e_STATE_END + hh_e_shop_SHOW, + hh_e_shop_Input, + hh_e_shop_END, } hh_e_ShopStates; -bool hh_show_Shop(); +void hh_Shop(hh_e_GameState*); diff --git a/src/demo.c b/src/demo.c index 22ee8b7..886dda8 100644 --- a/src/demo.c +++ b/src/demo.c @@ -11,19 +11,14 @@ #include "engine/draw_screen.h" #include "engine/player_controller.h" #include "engine/sprite_controller.h" -#include "GameLoop/startingScreen.h" - +#include "engine/level_const.h" -typedef enum { - hh_e_STATE_startingScreen, - hh_e_STATE_Shop, - hh_e_STATE_Gameplay, - hh_e_STATE_GameOver, - hh_e_STATE_HighScore -} hh_e_GameState; -hh_e_GameState hh_gameStates; +#include "GameLoop/startingScreen.h" +#include "GameLoop/gameplay.h" +#include "GameLoop/shop.h" +hh_g_all_levels hh_game; uint16_t g_hh_pos_x = 1000; // 0b0000 0001 0011 0110 uint16_t g_hh_pos_y; @@ -43,13 +38,13 @@ typedef struct { }hh_s_tiles; +hh_e_GameState hh_gameStates; hh_entity hh_g_player, hh_g_player_new; void hh_demo_setup() { hh_setup_palettes(); // hh_setup_screen(); - - + hh_game = hh_init_game_levels(); } void hh_demo_loop(unsigned long frame) { @@ -64,22 +59,10 @@ void hh_demo_loop(unsigned long frame) { } break; case hh_e_STATE_Shop: - // TODO: - // if(hh_show_Shop()){ - hh_clear_screen(); - hh_clear_sprite(); - hh_setup_screen(); - hh_clear_sprite(); - hh_gameStates = hh_e_STATE_Gameplay; - // } - // function: new level is chosen goto level + hh_Shop(&hh_gameStates); break; case hh_e_STATE_Gameplay: - hh_player_actions(); - - // TODO: - // function: if level complete goto shop - // function: if player is dead goto game over + hh_gameplay(hh_game, &hh_gameStates); break; case hh_e_STATE_GameOver: // TODO: diff --git a/src/engine/bullet.c b/src/engine/bullet.c index 5aa9e51..2016a4d 100644 --- a/src/engine/bullet.c +++ b/src/engine/bullet.c @@ -1,44 +1,35 @@ #include "bullet.h" -#include "engine/sprite_controller.h" -void shootBullet(vec2 playerPos, Bullet* bullet){ - // Set bullet's x and y coordinates to player's coordinates - bullet->x = playerPos.x; - bullet->y = playerPos.y; - // Set bullet's velocity to a fixed value - bullet->velocity = 1; - // Set bullet's status to active - bullet->isActive = true; -} -void updateBullet(Bullet* bullet, int deltaTime){ - // Only update bullet if it is active - static int latestLocationBullet = 0; - if (bullet->isActive) { - // Move bullet based on velocity and deltaTime - bullet->x += bullet->velocity * deltaTime; - drawBullet(bullet); - // Check if bullet has moved 16 pixels - if (bullet->x - latestLocationBullet > 32) { - // Set bullet's status to inactive - bullet->isActive = false; - drawBullet(&(Bullet){.x = -16,.y = -16. }); - } - } - else{ - latestLocationBullet = bullet->x; - } + +// TODO: use hh_entity as bullet struct +void shootBullet(vec2 playerPos, vec_cor cam_pos, hh_entity* bullet){ + vec2 temp; + if(g_hh_controller_p1.button_secondary){ + if(bullet->is_grounded){ + bullet->is_grounded=false; + bullet->pos = playerPos; + } + } + else{ + if(!bullet->is_grounded){ + updateBullet(bullet , cam_pos, temp); + drawBullet(*bullet); + } + } + + } -void drawBullet(Bullet* bullet){ +void collision +void updateBullet(hh_entity* bullet, vec_cor cam_pos, vec2 start){ + bullet->pos.x += 1; + // update bullet sprite on ppu + bullet->render.fam.position_x = (bullet->pos.x-cam_pos.x); + bullet->render.fam.position_y = (bullet->pos.y-cam_pos.y); - hh_ppu_update_foreground(10, (hh_s_ppu_loc_fam_entry) - { - .position_x = bullet->x, - .position_y = bullet->y, - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = 7, - .tilemap_index = 84, // change tilemap to the correct foreground index; - }); +} +void drawBullet(hh_entity bullet){ + hh_s_ppu_loc_fam_entry temp = bullet.render.fam; + hh_ppu_update_foreground(10,temp); } diff --git a/src/engine/bullet.h b/src/engine/bullet.h index ad67d84..5bbc031 100644 --- a/src/engine/bullet.h +++ b/src/engine/bullet.h @@ -1,16 +1,11 @@ #pragma once #include "player_controller.h" +#include "engine/sprite_controller.h" +#include "input.h" -typedef struct { - int x; - int y; - int velocity; - int isActive; - int hit; -} Bullet; +void shootBullet(vec2 playerPos, vec_cor cam_pos, hh_entity*); -//Bullet* createBullet(float x, float y, float velocity, float direction); -void shootBullet(vec2 playerPos, Bullet* bullet); -void updateBullet(Bullet* bullet, int deltaTime); -void drawBullet(Bullet* bullet); +void updateBullet(hh_entity* , vec_cor, vec2 ); + +void drawBullet(hh_entity); diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c index 0c31bf6..4a5ca68 100644 --- a/src/engine/draw_screen.c +++ b/src/engine/draw_screen.c @@ -1,66 +1,77 @@ #include "engine/draw_screen.h" -#include "engine/sprite_controller.h" +//#include "engine/sprite_controller.h" +hh_level_entity level; +uint64_t offset=0; uint8_t hh_world_to_tile(vec2 pos){ - //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"); - return 0; - } - int index = ((pos.y/16)*40 + pos.x/16);//TODO: remove magic number(s) - fseek(level, (index * sizeof(int)) + sizeof(int), SEEK_SET); - int tile;// = (int*)malloc(sizeof(int)); - fread(&tile, sizeof(int), 1, level); // read 1 tile from binary - - fclose(level); - // int val = tile; - // free(tile); + + int index = (((pos.y/16)*hh_max_x_size) + (pos.x/16));//TODO: remove magic number(s) + int tile= level.place[index]; return tile; } +void hh_update_screen(vec2 view, vec2 player){ + int currentTileY = view.y / 16; + int offset_px = view.y-(offset / 40 * 16); -// remeber old value to know which part to update. -vec2 previousViewport = { .x = 0, .y = 0 }; -void hh_draw_screen(vec_cor viewport){ - if (viewport.x == previousViewport.x && viewport.y == previousViewport.y) return; - - hh_ppu_update_aux((hh_s_ppu_loc_aux){ - .bg_shift_x = viewport.x, - .bg_shift_y = viewport.y, - .fg_fetch = 0, - .sysreset = 0, - }); - // update previous viewport values - previousViewport = viewport; -} + // || (offset_px == 0 && lastUpdated != 0 && player.y/16 == currentTileY-5) + if( (offset_px > 230) ){ + int size = (hh_max_x_size) * hh_max_y_size; + offset = currentTileY * level.x; -void hh_setup_screen(){ - //(HH_map_size_X*HH_map_size_Y) - int size = 2400; // max X = 40 en max Y = 80 - //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 level file.\n"); - return; + // Update the background screen + for (int BAM_index = 0; BAM_index < size; BAM_index++) { + hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = hh_get_palette(level.place[offset+BAM_index]), + .tilemap_index = level.place[offset+BAM_index], + }); + } } - fseek(level, (0* sizeof(int)) + sizeof(int), SEEK_SET); - int* tile = (int*)malloc(size*sizeof(int)); - fread(tile, sizeof(int), size, level); // read 1 tile from binary - - fclose(level); - +} +void hh_setup_screen(hh_level_entity currentlevel){ + hh_clear_screen(); + hh_clear_sprite(); + level = currentlevel; + int size = hh_max_x_size* hh_max_y_size; + printf("hier\n"); for(int BAM_index = 0; BAM_index < size; BAM_index++){ hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ .horizontal_flip = false, .vertical_flip = false, - .palette_index = hh_get_palette(tile[BAM_index]), - .tilemap_index = tile[BAM_index], + .palette_index = hh_get_palette(currentlevel.place[BAM_index]), + .tilemap_index = currentlevel.place[BAM_index], }); } - free(tile); } +vec_cor hh_draw_screen(vec2 player) { + static vec_cor previousViewport = {0, 0}; + int offset_px = offset/40*16; + //printf("%d\n",offset_px%2); + vec_cor viewport = hh_update_camera(player,(vec2){.x=0,.y=offset_px},(vec2){.x=20*16,.y=30*16+offset_px/4});//TODO: remove magic number(s) + + hh_update_screen((vec2){.y=viewport.y,.x=0},player); + if (viewport.x == previousViewport.x && viewport.y == previousViewport.y){} + else{ + // update previous viewport values + + //printf("viewport y %d\n",viewport.y-(offset/40*16)); + //printf("offset %d\n",offset); + hh_ppu_update_aux((hh_s_ppu_loc_aux){ + .bg_shift_x = viewport.x - 0, + .bg_shift_y = viewport.y-(offset/40*16), + .fg_fetch = 0, + .sysreset = 0, + }); + previousViewport = viewport; + + } + + return viewport; +} + 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++) { diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h index 95765e5..0d1b68a 100644 --- a/src/engine/draw_screen.h +++ b/src/engine/draw_screen.h @@ -3,24 +3,32 @@ // every function call for drawing the screen goes here. #include "engine/maths.h" -#include "ppu/consts.h" #include "ppu/ppu.h" - +#include "engine/level_const.h" +#include "engine/sprite_controller.h" #include #include #include +#include "engine/camera.h" - -#define HH_map_size_X 80 -#define HH_map_size_Y 60 +#define hh_max_x_size 40 +#define hh_max_y_size 30 /** @brief return a single tile from world binary */ uint8_t hh_world_to_tile(vec2 pos); + /** @brief shift to level if viewport changed position */ -void hh_draw_screen(vec2 viewport); +vec_cor hh_draw_screen(vec2 player); + /** @brief send data to BAM memory from binary level */ -void hh_setup_screen(); +void hh_setup_screen(hh_level_entity currentlevel); +/** @brief updates screen based on view and maybe player position if it needs to turn back*/ +void hh_update_screen(vec2 view, vec2 ); + /** @brief send black screen to background memory */ void hh_clear_screen(); + /** @brief clears all sprite data */ void hh_clear_sprite(); +/** @brief send data to BAM memory from binary from shop */ +void hh_setup_Shop(); diff --git a/src/engine/level_const.c b/src/engine/level_const.c new file mode 100644 index 0000000..b568e86 --- /dev/null +++ b/src/engine/level_const.c @@ -0,0 +1,22 @@ +#include "engine/level_const.h" + + +hh_g_all_levels hh_init_game_levels(){ + hh_g_all_levels levels; + levels.currentLevel=0; + + levels.level[0].x=40; + levels.level[0].y=60; + levels.level[0].hh_level_completed=false; + FILE *fp = fopen("../test/bin/level1_test.bin", "rb"); + fseek(fp, 0, SEEK_END); + int size = ftell(fp) / sizeof(int); + fseek(fp, (0 * sizeof(int)) + sizeof(int), SEEK_SET); + int* hh_game_level1 = malloc(size * sizeof(int)); + fread(hh_game_level1, sizeof(int), size, fp); + fclose(fp); + levels.level[0].place = hh_game_level1; + + return levels; +} + diff --git a/src/engine/level_const.h b/src/engine/level_const.h new file mode 100644 index 0000000..7a4aac5 --- /dev/null +++ b/src/engine/level_const.h @@ -0,0 +1,31 @@ +#pragma once +#include +#include +#include +#include +#include ` + +typedef enum { + hh_e_STATE_startingScreen, + hh_e_STATE_Shop, + hh_e_STATE_Gameplay, + hh_e_STATE_GameOver, + hh_e_STATE_HighScore +} hh_e_GameState; + +typedef struct { + int x; + int y; + int hh_total_enemies; + int* place; + bool hh_level_completed; +}hh_level_entity; + +typedef struct { + hh_level_entity level[1]; + int currentLevel; + + +}hh_g_all_levels; + +hh_g_all_levels hh_init_game_levels(); diff --git a/src/makefile b/src/makefile index cd248e2..d00b0ee 100644 --- a/src/makefile +++ b/src/makefile @@ -40,7 +40,10 @@ LOCAL_SRCS += main.c \ engine/entity.c \ engine/bullet.c \ engine/title_screen.c \ + engine/level_const.c \ GameLoop/shop.c \ + GameLoop/gameplay.c \ + GameLoop/game_over.c \ GameLoop/startingScreen.c CFLAGS += $(SHARED_FLAGS) -- cgit v1.2.3 From e987d23d915942ec4a3910b9cc2729f1b21361a9 Mon Sep 17 00:00:00 2001 From: NielsCoding <48092678+heavydemon21@users.noreply.github.com> Date: Sun, 2 Apr 2023 20:48:06 +0200 Subject: snake case/background --- src/GameLoop/game_over.c | 28 ------------- src/GameLoop/game_over.h | 18 -------- src/GameLoop/gameplay.c | 44 -------------------- src/GameLoop/gameplay.h | 17 -------- src/GameLoop/shop.c | 30 -------------- src/GameLoop/shop.h | 18 -------- src/GameLoop/startingScreen.c | 32 --------------- src/GameLoop/startingScreen.h | 14 ------- src/demo.c | 53 ++++++++++++------------ src/engine/bullet.c | 14 +++---- src/engine/bullet.h | 6 +-- src/engine/camera.c | 7 +++- src/engine/draw_screen.c | 91 +++++++++++++++++++++++++++-------------- src/engine/draw_screen.h | 2 +- src/engine/level_const.c | 23 +++++++++-- src/engine/level_const.h | 24 +++++------ src/game_loop/game_over.c | 28 +++++++++++++ src/game_loop/game_over.h | 18 ++++++++ src/game_loop/gameplay.c | 47 +++++++++++++++++++++ src/game_loop/gameplay.h | 17 ++++++++ src/game_loop/shop.c | 30 ++++++++++++++ src/game_loop/shop.h | 18 ++++++++ src/game_loop/starting_screen.c | 32 +++++++++++++++ src/game_loop/starting_screen.h | 14 +++++++ src/makefile | 8 ++-- 25 files changed, 341 insertions(+), 292 deletions(-) delete mode 100644 src/GameLoop/game_over.c delete mode 100644 src/GameLoop/game_over.h delete mode 100644 src/GameLoop/gameplay.c delete mode 100644 src/GameLoop/gameplay.h delete mode 100644 src/GameLoop/shop.c delete mode 100644 src/GameLoop/shop.h delete mode 100644 src/GameLoop/startingScreen.c delete mode 100644 src/GameLoop/startingScreen.h create mode 100644 src/game_loop/game_over.c create mode 100644 src/game_loop/game_over.h create mode 100644 src/game_loop/gameplay.c create mode 100644 src/game_loop/gameplay.h create mode 100644 src/game_loop/shop.c create mode 100644 src/game_loop/shop.h create mode 100644 src/game_loop/starting_screen.c create mode 100644 src/game_loop/starting_screen.h (limited to 'src/makefile') diff --git a/src/GameLoop/game_over.c b/src/GameLoop/game_over.c deleted file mode 100644 index 09e6858..0000000 --- a/src/GameLoop/game_over.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "game_over.h" - - -void hh_game_over(hh_e_GameState* hh_game_state){ - static hh_e_game_over hh_e_states_game_over = hh_e_game_over_SHOW; - - switch (hh_e_states_game_over) - { - case hh_e_game_over_SHOW: - hh_clear_screen(); - hh_clear_sprite(); - // TODO: make function to show game over - hh_e_states_game_over = hh_e_game_over_Input; - break; - case hh_e_game_over_Input: - if(g_hh_controller_p1.button_primary){ - hh_e_states_game_over = hh_e_game_over_END; - } - break; - case hh_e_game_over_END: - hh_e_states_game_over = hh_e_game_over_SHOW; - *hh_game_state = hh_e_STATE_GameOver; - break; - default: - hh_e_states_game_over = hh_e_game_over_SHOW; - break; - } -} diff --git a/src/GameLoop/game_over.h b/src/GameLoop/game_over.h deleted file mode 100644 index 0d40b6c..0000000 --- a/src/GameLoop/game_over.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "input.h" -#include "engine/draw_screen.h" -#include "engine/level_const.h" - - -#include -#include - -typedef enum { - hh_e_game_over_SHOW, - hh_e_game_over_Input, - hh_e_game_over_END, -} hh_e_game_over; - - -void hh_game_over(hh_e_GameState*); diff --git a/src/GameLoop/gameplay.c b/src/GameLoop/gameplay.c deleted file mode 100644 index 72297f5..0000000 --- a/src/GameLoop/gameplay.c +++ /dev/null @@ -1,44 +0,0 @@ -#include "gameplay.h" - - - -void hh_gameplay(hh_g_all_levels game, hh_e_GameState* hh_game_state){ - static hh_e_gameplay gameplay = hh_e_setup_screen; - - switch (gameplay) - { - case hh_e_setup_screen: - hh_setup_screen(game.level[game.currentLevel]); - gameplay = hh_e_play_level; - break; - case hh_e_play_level: - // TODO: here come all the different functions for the gameplay - hh_player_actions(); - - - - if(game.level[game.currentLevel].hh_level_completed){ - gameplay = hh_e_level_complete; - } - break; - case hh_e_level_complete: - if(game.currentLevel < 3){ - game.currentLevel++; - gameplay = hh_e_setup_screen; - } - else { - gameplay = hh_e_game_over; - } - break; - case hh_e_game_over: - // TODO make reset levels - hh_reset_levels(); - gameplay = hh_e_setup_screen; - *hh_game_state = hh_e_STATE_GameOver; - break; - default: - break; - } - -} -void hh_reset_levels(){} diff --git a/src/GameLoop/gameplay.h b/src/GameLoop/gameplay.h deleted file mode 100644 index 6e8c1ec..0000000 --- a/src/GameLoop/gameplay.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "engine/draw_screen.h" -#include "engine/player_controller.h" -#include "engine/sprite_controller.h" -#include "GameLoop/startingScreen.h" -#include "engine/level_const.h" - -typedef enum { - hh_e_setup_screen, - hh_e_play_level, - hh_e_level_complete, - hh_e_game_over, -}hh_e_gameplay; - -void hh_reset_levels(); -void hh_gameplay(hh_g_all_levels, hh_e_GameState*); - diff --git a/src/GameLoop/shop.c b/src/GameLoop/shop.c deleted file mode 100644 index 8e6dc71..0000000 --- a/src/GameLoop/shop.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "shop.h" - - -void hh_Shop(hh_e_GameState* hh_game_state){ - static hh_e_ShopStates hh_e_Shop = hh_e_shop_SHOW; - - switch (hh_e_Shop) - { - case hh_e_shop_SHOW: - hh_clear_screen(); - hh_clear_sprite(); - // TODO: make function to show shop - //hh_setup_shop(); - hh_e_Shop = hh_e_shop_Input; - break; - case hh_e_shop_Input: - // TODO: make it so that you can choose between shop - if(g_hh_controller_p1.button_primary){ - hh_e_Shop = hh_e_shop_END; - } - break; - case hh_e_shop_END: - hh_e_Shop = hh_e_shop_SHOW; - *hh_game_state = hh_e_STATE_Gameplay; - break; - default: - hh_e_Shop = hh_e_shop_SHOW; - break; - } -} diff --git a/src/GameLoop/shop.h b/src/GameLoop/shop.h deleted file mode 100644 index 1efc057..0000000 --- a/src/GameLoop/shop.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "input.h" -#include "engine/draw_screen.h" -#include "engine/level_const.h" - - -#include -#include - -typedef enum { - hh_e_shop_SHOW, - hh_e_shop_Input, - hh_e_shop_END, -} hh_e_ShopStates; - - -void hh_Shop(hh_e_GameState*); diff --git a/src/GameLoop/startingScreen.c b/src/GameLoop/startingScreen.c deleted file mode 100644 index 4fc5af9..0000000 --- a/src/GameLoop/startingScreen.c +++ /dev/null @@ -1,32 +0,0 @@ -#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 deleted file mode 100644 index f51cc66..0000000 --- a/src/GameLoop/startingScreen.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include - -typedef enum { - hh_e_STATE_SHOW, - hh_e_STATE_Input, - hh_e_STATE_END -} hh_e_screenStates; - - -bool hh_show_startingScreen(); - diff --git a/src/demo.c b/src/demo.c index 886dda8..4fa1be2 100644 --- a/src/demo.c +++ b/src/demo.c @@ -13,9 +13,9 @@ #include "engine/sprite_controller.h" #include "engine/level_const.h" -#include "GameLoop/startingScreen.h" -#include "GameLoop/gameplay.h" -#include "GameLoop/shop.h" +#include "game_loop/starting_screen.h" +#include "game_loop/gameplay.h" +#include "game_loop/shop.h" hh_g_all_levels hh_game; @@ -38,57 +38,56 @@ typedef struct { }hh_s_tiles; -hh_e_GameState hh_gameStates; -hh_entity hh_g_player, hh_g_player_new; +hh_e_game_state hh_game_states; + hh_entity hh_g_player, hh_g_player_new; void hh_demo_setup() { hh_setup_palettes(); - // hh_setup_screen(); hh_game = hh_init_game_levels(); } void hh_demo_loop(unsigned long frame) { - switch (hh_gameStates) + switch (hh_game_states) { - case hh_e_STATE_startingScreen: - bool ret = hh_show_startingScreen(); + case hh_e_state_starting_screen: + bool ret = hh_show_starting_screen(); if(ret){ - hh_gameStates = hh_e_STATE_Shop; + hh_game_states = hh_e_state_shop; } break; - case hh_e_STATE_Shop: - hh_Shop(&hh_gameStates); + case hh_e_state_shop: + hh_shop(&hh_game_states); break; - case hh_e_STATE_Gameplay: - hh_gameplay(hh_game, &hh_gameStates); + case hh_e_state_gameplay: + hh_gameplay(hh_game, &hh_game_states); break; - case hh_e_STATE_GameOver: - // TODO: + case hh_e_state_game_over: + // todo: // function: show game over screen // function: after time goto high score break; - case hh_e_STATE_HighScore: - // TODO: + case hh_e_state_high_score: + // todo: // fucntion: show all previously scored points // function: button pressed goto starting screen break; default: - hh_gameStates = hh_e_STATE_startingScreen; + hh_game_states = hh_e_state_starting_screen; break; } } -// void sendData(uint8_t address, uint16_t data) { -// uint8_t bitData[3]; -// bitData[2] = data & 0xff; -// bitData[1] = (data >> 8); -// bitData[0] = address; // first byte is address +// void send_data(uint8_t address, uint16_t data) { +// uint8_t bit_data[3]; +// bit_data[2] = data & 0xff; +// bit_data[1] = (data >> 8); +// bit_data[0] = address; // first byte is address // -// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET); -// HAL_SPI_Transmit(&hspi1, bitData, 3, 100); //2*8 bit data -// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET); +// hal_gpio_write_pin(gpioa, gpio_pin_9, gpio_pin_reset); +// hal_spi_transmit(&hspi1, bit_data, 3, 100); //2*8 bit data +// hal_gpio_write_pin(gpioa, gpio_pin_9, gpio_pin_set); // } diff --git a/src/engine/bullet.c b/src/engine/bullet.c index 2016a4d..e6ca6df 100644 --- a/src/engine/bullet.c +++ b/src/engine/bullet.c @@ -3,25 +3,25 @@ // TODO: use hh_entity as bullet struct -void shootBullet(vec2 playerPos, vec_cor cam_pos, hh_entity* bullet){ +void hh_shoot_bullet(vec2 player, vec_cor cam_pos, hh_entity* bullet){ vec2 temp; if(g_hh_controller_p1.button_secondary){ if(bullet->is_grounded){ bullet->is_grounded=false; - bullet->pos = playerPos; + bullet->pos = player; } } else{ if(!bullet->is_grounded){ - updateBullet(bullet , cam_pos, temp); - drawBullet(*bullet); + hh_update_bullet(bullet , cam_pos); + hh_draw_bullet(*bullet); } } } -void collision -void updateBullet(hh_entity* bullet, vec_cor cam_pos, vec2 start){ + +void hh_update_bullet(hh_entity* bullet, vec_cor cam_pos){ bullet->pos.x += 1; // update bullet sprite on ppu @@ -29,7 +29,7 @@ void updateBullet(hh_entity* bullet, vec_cor cam_pos, vec2 start){ bullet->render.fam.position_y = (bullet->pos.y-cam_pos.y); } -void drawBullet(hh_entity bullet){ +void hh_draw_bullet(hh_entity bullet){ hh_s_ppu_loc_fam_entry temp = bullet.render.fam; hh_ppu_update_foreground(10,temp); } diff --git a/src/engine/bullet.h b/src/engine/bullet.h index 5bbc031..5f07b2e 100644 --- a/src/engine/bullet.h +++ b/src/engine/bullet.h @@ -4,8 +4,8 @@ #include "input.h" -void shootBullet(vec2 playerPos, vec_cor cam_pos, hh_entity*); +void hh_shoot_bullet(vec2 playerPos, vec_cor cam_pos, hh_entity*); -void updateBullet(hh_entity* , vec_cor, vec2 ); +void hh_update_bullet(hh_entity* , vec_cor ); -void drawBullet(hh_entity); +void hh_draw_bullet(hh_entity); diff --git a/src/engine/camera.c b/src/engine/camera.c index 2c3e517..6898430 100644 --- a/src/engine/camera.c +++ b/src/engine/camera.c @@ -4,12 +4,13 @@ vec_cor hh_update_camera(vec_cen new, vec2 min, vec2 max){ - //TODO: change floating point math to fix point math //TODO: remove magic number at y camera offset // new = vec_cen2cor(new,(vec2){.x=max.x/2,.y=max.y/2}); - new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH),.y=new.y+(HH_PPU_SPRITE_HEIGHT*8)},(vec2){.x=max.x/2,.y=max.y/2}); + new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH),.y=new.y+(HH_PPU_SPRITE_HEIGHT*8)},(vec2){.x=(max.x - min.x)/2,.y=(max.y - min.y)/2}); + // new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH),.y=new.y+(HH_PPU_SPRITE_HEIGHT*8)},(vec2){.x=max.x/2,.y=max.y/2}); + // new.x = new.x << HH_MATH_FIXED_POINT; // new.y = new.y << HH_MATH_FIXED_POINT; static vec_cor old; @@ -30,6 +31,8 @@ vec_cor hh_update_camera(vec_cen new, vec2 min, vec2 max){ old.x = CLAMP(new.x,min.x,max.x); old.y = CLAMP(new.y,min.y,max.y); + //printf("camera new %d min %d max %d\n",new.y,min.y,max.y); return old; } + diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c index 4a5ca68..d1d7a04 100644 --- a/src/engine/draw_screen.c +++ b/src/engine/draw_screen.c @@ -1,72 +1,101 @@ #include "engine/draw_screen.h" -//#include "engine/sprite_controller.h" hh_level_entity level; -uint64_t offset=0; +uint64_t offsetY=0; +uint64_t offsetX=0; uint8_t hh_world_to_tile(vec2 pos){ - int index = (((pos.y/16)*hh_max_x_size) + (pos.x/16));//TODO: remove magic number(s) + int index = (((pos.y/HH_PPU_SPRITE_HEIGHT)*level.size.x) + (pos.x/HH_PPU_SPRITE_WIDTH));//TODO: remove magic number(s) int tile= level.place[index]; return tile; } void hh_update_screen(vec2 view, vec2 player){ - int currentTileY = view.y / 16; - int offset_px = view.y-(offset / 40 * 16); + int current_tile_y = view.y / HH_PPU_SPRITE_HEIGHT; + int current_tile_x = view.x / HH_PPU_SPRITE_WIDTH; + int offset_py = view.y - (offsetY / 40 * HH_PPU_SPRITE_HEIGHT); + int offset_px = view.x - offsetX * HH_PPU_SPRITE_WIDTH; + static int prev_ofsset = 0; + int size = MIN(HH_PPU_BG_CANVAS_TILES_H,level.size.x) * MIN(HH_PPU_BG_CANVAS_TILES_V,level.size.y); + if( (offset_py == 0 || offset_py > 230) && level.size.y > level.size.x && prev_ofsset != offset_py){ + if(offset_py==0){ + offsetY = (current_tile_y-14) * level.size.x; + } + else{ + offsetY = current_tile_y * level.size.x; + } - // || (offset_px == 0 && lastUpdated != 0 && player.y/16 == currentTileY-5) - if( (offset_px > 230) ){ - int size = (hh_max_x_size) * hh_max_y_size; - offset = currentTileY * level.x; - // Update the background screen for (int BAM_index = 0; BAM_index < size; BAM_index++) { hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ .horizontal_flip = false, .vertical_flip = false, - .palette_index = hh_get_palette(level.place[offset+BAM_index]), - .tilemap_index = level.place[offset+BAM_index], + .palette_index = hh_get_palette(level.place[offsetY + BAM_index]), + .tilemap_index = level.place[offsetY + BAM_index], + }); + } + prev_ofsset = offset_py; + } + else if ((offset_px == 0 || offset_px > 310) && level.size.x > level.size.y && prev_ofsset != offset_px) + { + if(offset_px==0){ + offsetX = current_tile_x - 14; + } + else{ + offsetX = current_tile_x; + } + // Update the background screen + for (int BAM_index = 0; BAM_index < size; BAM_index++) { + int var = (BAM_index / HH_PPU_BG_CANVAS_TILES_H) * level.size.x + MIN((BAM_index % HH_PPU_BG_CANVAS_TILES_H + offsetX),level.size.x); + hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = hh_get_palette(level.place[var]), + .tilemap_index = level.place[var], }); } } + + prev_ofsset = offset_px; + } void hh_setup_screen(hh_level_entity currentlevel){ hh_clear_screen(); hh_clear_sprite(); level = currentlevel; - int size = hh_max_x_size* hh_max_y_size; - printf("hier\n"); - for(int BAM_index = 0; BAM_index < size; BAM_index++){ + offsetY=0; + offsetX=0; + int size = MIN(HH_PPU_BG_CANVAS_TILES_H, level.size.x) * MIN(HH_PPU_BG_CANVAS_TILES_V, level.size.y); + for (int BAM_index = 0; BAM_index < size; BAM_index++) { + int var = (BAM_index / HH_PPU_BG_CANVAS_TILES_H) * level.size.x + BAM_index % HH_PPU_BG_CANVAS_TILES_H; hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ .horizontal_flip = false, .vertical_flip = false, - .palette_index = hh_get_palette(currentlevel.place[BAM_index]), - .tilemap_index = currentlevel.place[BAM_index], + .palette_index = hh_get_palette(currentlevel.place[var]), + .tilemap_index = currentlevel.place[var], }); } } vec_cor hh_draw_screen(vec2 player) { static vec_cor previousViewport = {0, 0}; - int offset_px = offset/40*16; - //printf("%d\n",offset_px%2); - vec_cor viewport = hh_update_camera(player,(vec2){.x=0,.y=offset_px},(vec2){.x=20*16,.y=30*16+offset_px/4});//TODO: remove magic number(s) - - hh_update_screen((vec2){.y=viewport.y,.x=0},player); + int offset_py = offsetY / 40 * HH_PPU_SPRITE_HEIGHT; + + int offset_px = (offsetX * HH_PPU_SPRITE_WIDTH) ; + vec_cor viewport = hh_update_camera(player,(vec2){.x = offset_px, .y = offset_py},(vec2){.x = HH_PPU_SCREEN_WIDTH + offset_px, .y = 480 + offset_py});//TODO: remove magic number(s) + viewport.x = CLAMP(viewport.x, 0, level.size.x * HH_PPU_SPRITE_WIDTH - HH_PPU_SCREEN_WIDTH); + viewport.y = CLAMP(viewport.y, 0, level.size.y * HH_PPU_SPRITE_HEIGHT - HH_PPU_SCREEN_HEIGHT); + + hh_update_screen((vec2){.y=viewport.y,.x=viewport.x},player); if (viewport.x == previousViewport.x && viewport.y == previousViewport.y){} else{ - // update previous viewport values - - //printf("viewport y %d\n",viewport.y-(offset/40*16)); - //printf("offset %d\n",offset); hh_ppu_update_aux((hh_s_ppu_loc_aux){ - .bg_shift_x = viewport.x - 0, - .bg_shift_y = viewport.y-(offset/40*16), + .bg_shift_x = viewport.x - offset_px, + .bg_shift_y = viewport.y - offset_py, .fg_fetch = 0, .sysreset = 0, }); previousViewport = viewport; - } return viewport; @@ -93,8 +122,8 @@ void hh_clear_screen(){ void hh_clear_sprite(){ for (int i = 0; i < HH_PPU_FG_SPRITE_COUNT; i++) { hh_ppu_update_foreground(i,(hh_s_ppu_loc_fam_entry){ - .position_x = -16, - .position_y = -16, + .position_x = -HH_PPU_SPRITE_WIDTH, + .position_y = -HH_PPU_SPRITE_HEIGHT, }); } } diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h index 0d1b68a..9130842 100644 --- a/src/engine/draw_screen.h +++ b/src/engine/draw_screen.h @@ -11,7 +11,7 @@ #include #include "engine/camera.h" -#define hh_max_x_size 40 +#define hh_max_x_size 40 #define hh_max_y_size 30 /** @brief return a single tile from world binary */ diff --git a/src/engine/level_const.c b/src/engine/level_const.c index b568e86..5ba0187 100644 --- a/src/engine/level_const.c +++ b/src/engine/level_const.c @@ -3,11 +3,16 @@ hh_g_all_levels hh_init_game_levels(){ hh_g_all_levels levels; - levels.currentLevel=0; - - levels.level[0].x=40; - levels.level[0].y=60; + levels.current_level=0; + + levels.level[0].size.x=40; + levels.level[0].size.y=100; levels.level[0].hh_level_completed=false; + + levels.level[1].size.x=100; + levels.level[1].size.y=28; + levels.level[1].hh_level_completed=false; + FILE *fp = fopen("../test/bin/level1_test.bin", "rb"); fseek(fp, 0, SEEK_END); int size = ftell(fp) / sizeof(int); @@ -15,7 +20,17 @@ hh_g_all_levels hh_init_game_levels(){ int* hh_game_level1 = malloc(size * sizeof(int)); fread(hh_game_level1, sizeof(int), size, fp); fclose(fp); + + FILE *lvl2 = fopen("../test/bin/level2_test.bin", "rb"); + fseek(lvl2, 0, SEEK_END); + size = ftell(lvl2) / sizeof(int); + fseek(lvl2, (0 * sizeof(int)) + sizeof(int), SEEK_SET); + int* hh_game_level2 = malloc(size * sizeof(int)); + fread(hh_game_level2, sizeof(int), size, lvl2); + fclose(lvl2); + levels.level[0].place = hh_game_level1; + levels.level[1].place = hh_game_level2; return levels; } diff --git a/src/engine/level_const.h b/src/engine/level_const.h index 7a4aac5..b86ae7b 100644 --- a/src/engine/level_const.h +++ b/src/engine/level_const.h @@ -3,27 +3,27 @@ #include #include #include -#include ` +#include "engine/maths.h" +#include "engine/entity.h" typedef enum { - hh_e_STATE_startingScreen, - hh_e_STATE_Shop, - hh_e_STATE_Gameplay, - hh_e_STATE_GameOver, - hh_e_STATE_HighScore -} hh_e_GameState; - + hh_e_state_starting_screen, + hh_e_state_shop, + hh_e_state_gameplay, + hh_e_state_game_over, + hh_e_state_high_score +} hh_e_game_state; +//entity array met enemeies typedef struct { - int x; - int y; + vec2 size; int hh_total_enemies; int* place; bool hh_level_completed; }hh_level_entity; typedef struct { - hh_level_entity level[1]; - int currentLevel; + hh_level_entity level[2]; + int current_level; }hh_g_all_levels; diff --git a/src/game_loop/game_over.c b/src/game_loop/game_over.c new file mode 100644 index 0000000..f5b70cf --- /dev/null +++ b/src/game_loop/game_over.c @@ -0,0 +1,28 @@ +#include "game_over.h" + + +void hh_game_over(hh_e_game_state* hh_game_state){ + static hh_e_game_over hh_e_states_game_over = hh_e_game_over_show; + + switch (hh_e_states_game_over) + { + case hh_e_game_over_show: + hh_clear_screen(); + hh_clear_sprite(); + // todo: make function to show game over + hh_e_states_game_over = hh_e_game_over_input; + break; + case hh_e_game_over_input: + if(g_hh_controller_p1.button_primary){ + hh_e_states_game_over = hh_e_game_over_end; + } + break; + case hh_e_game_over_end: + hh_e_states_game_over = hh_e_game_over_show; + *hh_game_state = hh_e_state_game_over; + break; + default: + hh_e_states_game_over = hh_e_game_over_show; + break; + } +} diff --git a/src/game_loop/game_over.h b/src/game_loop/game_over.h new file mode 100644 index 0000000..80db667 --- /dev/null +++ b/src/game_loop/game_over.h @@ -0,0 +1,18 @@ +#pragma once + +#include "input.h" +#include "engine/draw_screen.h" +#include "engine/level_const.h" + + +#include +#include + +typedef enum { + hh_e_game_over_show, + hh_e_game_over_input, + hh_e_game_over_end, +} hh_e_game_over; + + +void hh_game_over(hh_e_game_state*); diff --git a/src/game_loop/gameplay.c b/src/game_loop/gameplay.c new file mode 100644 index 0000000..295eb5d --- /dev/null +++ b/src/game_loop/gameplay.c @@ -0,0 +1,47 @@ +#include "gameplay.h" + +// player struct + + +void hh_gameplay(hh_g_all_levels game, hh_e_game_state* hh_game_state){ + static hh_e_gameplay gameplay = hh_e_setup_screen; + + switch (gameplay) + { + case hh_e_setup_screen: + hh_setup_screen(game.level[game.current_level]); + gameplay = hh_e_play_level; + break; + case hh_e_play_level: + // todo: here come all the different functions for the gameplay + hh_player_actions(); + + + + + + if(game.level[game.current_level].hh_level_completed){ + gameplay = hh_e_level_complete; + } + break; + case hh_e_level_complete: + if(game.current_level < 3){ + game.current_level++; + gameplay = hh_e_setup_screen; + } + else { + gameplay = hh_e_game_over; + } + break; + case hh_e_game_over: + // todo make reset levels + hh_reset_levels(); + gameplay = hh_e_setup_screen; + *hh_game_state = hh_e_state_game_over; + break; + default: + break; + } + +} +void hh_reset_levels(){} diff --git a/src/game_loop/gameplay.h b/src/game_loop/gameplay.h new file mode 100644 index 0000000..d309e78 --- /dev/null +++ b/src/game_loop/gameplay.h @@ -0,0 +1,17 @@ +#pragma once +#include "engine/draw_screen.h" +#include "engine/player_controller.h" +#include "engine/sprite_controller.h" +#include "game_loop/starting_screen.h" +#include "engine/level_const.h" + +typedef enum { + hh_e_setup_screen, + hh_e_play_level, + hh_e_level_complete, + hh_e_game_over, +}hh_e_gameplay; + +void hh_reset_levels(); +void hh_gameplay(hh_g_all_levels, hh_e_game_state*); + diff --git a/src/game_loop/shop.c b/src/game_loop/shop.c new file mode 100644 index 0000000..b3d2234 --- /dev/null +++ b/src/game_loop/shop.c @@ -0,0 +1,30 @@ +#include "shop.h" + + +void hh_shop(hh_e_game_state* hh_game_state){ + static hh_e_shop_states hh_e_shop = hh_e_shop_show; + + switch (hh_e_shop) + { + case hh_e_shop_show: + hh_clear_screen(); + hh_clear_sprite(); + // todo: make function to show shop + //hh_setup_shop(); + hh_e_shop = hh_e_shop_input; + break; + case hh_e_shop_input: + // todo: make it so that you can choose between shop + if(g_hh_controller_p1.button_primary){ + hh_e_shop = hh_e_shop_end; + } + break; + case hh_e_shop_end: + hh_e_shop = hh_e_shop_show; + *hh_game_state = hh_e_state_gameplay; + break; + default: + hh_e_shop = hh_e_shop_show; + break; + } +} diff --git a/src/game_loop/shop.h b/src/game_loop/shop.h new file mode 100644 index 0000000..7d01b7e --- /dev/null +++ b/src/game_loop/shop.h @@ -0,0 +1,18 @@ +#pragma once + +#include "input.h" +#include "engine/draw_screen.h" +#include "engine/level_const.h" + + +#include +#include + +typedef enum { + hh_e_shop_show, + hh_e_shop_input, + hh_e_shop_end, +} hh_e_shop_states; + + +void hh_shop(hh_e_game_state*); diff --git a/src/game_loop/starting_screen.c b/src/game_loop/starting_screen.c new file mode 100644 index 0000000..6ab0278 --- /dev/null +++ b/src/game_loop/starting_screen.c @@ -0,0 +1,32 @@ +#include "starting_screen.h"" +#include "input.h" +#include "engine/title_screen.h" +#include "engine/draw_screen.h" +// #include "engine/player_controller.h" + +bool hh_show_starting_screen(){ + static hh_e_screen_states hh_e_starting_screen = hh_e_state_show; + + switch (hh_e_starting_screen) + { + case hh_e_state_show: + hh_clear_screen(); + hh_init_title_screen(); + hh_e_starting_screen = hh_e_state_input; + return false; + break; + case hh_e_state_input: + if(g_hh_controller_p1.button_primary){ + hh_e_starting_screen = hh_e_state_end; + } + break; + case hh_e_state_end: + hh_e_starting_screen = hh_e_state_show; + return true; + break; + default: + hh_e_starting_screen = hh_e_state_show; + break; + } + return false; +} diff --git a/src/game_loop/starting_screen.h b/src/game_loop/starting_screen.h new file mode 100644 index 0000000..4228f38 --- /dev/null +++ b/src/game_loop/starting_screen.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +typedef enum { + hh_e_state_show, + hh_e_state_input, + hh_e_state_end +} hh_e_screen_states; + + +bool hh_show_starting_screen(); + diff --git a/src/makefile b/src/makefile index d00b0ee..4dc84e6 100644 --- a/src/makefile +++ b/src/makefile @@ -41,10 +41,10 @@ LOCAL_SRCS += main.c \ engine/bullet.c \ engine/title_screen.c \ engine/level_const.c \ - GameLoop/shop.c \ - GameLoop/gameplay.c \ - GameLoop/game_over.c \ - GameLoop/startingScreen.c + game_loop/shop.c \ + game_loop/gameplay.c \ + game_loop/game_over.c \ + game_loop/starting_screen.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) -- cgit v1.2.3