diff options
author | UnavailableDev <ggwildplay@gmail.com> | 2023-03-13 17:10:11 +0100 |
---|---|---|
committer | UnavailableDev <ggwildplay@gmail.com> | 2023-03-13 17:10:11 +0100 |
commit | 30eca8d3bd03c1efe52f2432c4b6b0c842fffa2d (patch) | |
tree | 988cb8dc3f400d76fb659733f9d5236b927d747a | |
parent | 506b1d11e6006e44de5b888eb342eb9dbed58d2c (diff) |
demo.c clean up
-rw-r--r-- | src/demo.c | 197 | ||||
-rw-r--r-- | src/engine/entity.c | 12 | ||||
-rw-r--r-- | src/engine/entity.h | 33 | ||||
-rw-r--r-- | src/engine/player_controller.c | 166 |
4 files changed, 207 insertions, 201 deletions
@@ -9,11 +9,10 @@ #include "engine/camera.h" #include "engine/entity.h" #include "engine/draw_screen.h" +#include "engine/player_controller.h" #include "engine/sprite_controller.h" -#define HH_DEMO_BALL_COUNT 1 -hh_s_ppu_loc_fam_entry g_hh_demo_balls[HH_DEMO_BALL_COUNT]; hh_s_entity_player g_hh_player_1 = { .pos_x = 31000, // 0b0000 0001 0011 0110 @@ -47,207 +46,17 @@ typedef struct { hh_entity hh_g_player, hh_g_player_new; void hh_demo_setup() { -#if 0 - // load sprites - // hh_ppu_update_sprite(0, HH_DBG_SPRITE_BALL); - // hh_ppu_update_sprite(1, HH_DBG_SPRITE_CHECKERBOARD); - hh_ppu_update_sprite(1, HH_SQUARE); - // background pattern - hh_ppu_update_color(0, 1, (hh_ppu_rgb_color_t){0x4, 0x4, 0x4}); - for (unsigned i = 0; i < HH_PPU_BG_CANVAS_TILES_H * HH_PPU_BG_CANVAS_TILES_V; i++) { - hh_ppu_update_background(i, (hh_s_ppu_loc_bam_entry){ - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = 0, - .tilemap_index = 1, - }); - } - - // cool colors - // hh_ppu_update_color(1, 1, (hh_ppu_rgb_color_t){0xf, 0x0, 0xf}); - // hh_ppu_update_color(2, 1, (hh_ppu_rgb_color_t){0xf, 0xf, 0xf}); - // hh_ppu_update_color(3, 1, (hh_ppu_rgb_color_t){0xf, 0x0, 0x0}); - // hh_ppu_update_color(4, 1, (hh_ppu_rgb_color_t){0x0, 0xf, 0xf}); - // hh_ppu_update_color(5, 1, (hh_ppu_rgb_color_t){0x0, 0x0, 0xf}); - - for (int i = 0; i < 8; i++) - { - hh_ppu_update_color(1,i,HH_SLIME[i]); - } - - - // balls -#else - hh_g_player = (hh_entity){ - .pos = {32,32}, - .vec = {0,0}, - .hp = 1, - .speed = 1, - .is_grounded = false - }; - - for (unsigned i = 0; i < HH_DEMO_BALL_COUNT; i++) { - g_hh_demo_balls[i].horizontal_flip = false; - g_hh_demo_balls[i].vertical_flip = false; - g_hh_demo_balls[i].palette_index = 7; - g_hh_demo_balls[i].tilemap_index = 20; - } hh_setup_palettes(); hh_setup_screen(); -#endif + } void hh_demo_loop(unsigned long frame) { // hh_player_movement(); - // adjust map size - // g_hh_pos_x = g_hh_player_1.pos_x / 100; - // g_hh_pos_y = g_hh_player_1.pos_y / 100; - - // input testing (no hitbox stuff) - // g_hh_pos_x += (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right); // -1 = L || 1 == R - // g_hh_pos_y += (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down); // -1 = D || 1 == U - - - - hh_g_player.vec = (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) { - // hh_g_player.vec.x += mbb; - // // g_hh_demo_balls[0].horizontal_flip = true; - // } - // if (g_hh_controller_p1.dpad_right) { - // hh_g_player.vec.x += maa; - // // g_hh_demo_balls[0].horizontal_flip = true; - // } - if (g_hh_controller_p1.button_primary /*&& hh_g_player.is_grounded*/) //JUMP - hh_g_player.vec.y += -6; - // // if (g_hh_controller_p1.button_secondary) - - - hh_g_player.vec.y += 1; //gravity - - - //END OF VECTOR CHANGES - // hh_g_player.vec.y = CLAMP(hh_g_player.vec.y,-32,32); - // hh_g_player.vec.x = CLAMP(hh_g_player.vec.x,-32,32); - - hh_g_player_new.pos = (vec2){ - .x = hh_g_player.pos.x + hh_g_player.vec.x, - .y = hh_g_player.pos.y + hh_g_player.vec.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(hh_g_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, &hh_g_player); - // } - // } - - hh_g_player_new.is_grounded = false; - - // solves x collision - if (hh_g_player.vec.x <= 0) { - if (hh_colidable(hh_world_to_tile((vec2){.x=hh_g_player_new.pos.x + 0, .y=hh_g_player.pos.y + 0})) || - hh_colidable(hh_world_to_tile((vec2){.x=hh_g_player_new.pos.x + 0, .y=hh_g_player.pos.y + 15}))) { - hh_g_player_new.pos.x = (hh_g_player_new.pos.x & ~15) + 16, - hh_g_player_new.vec.x = 0; - } - } else { - if (hh_colidable(hh_world_to_tile((vec2){.x=hh_g_player_new.pos.x + 16, .y=hh_g_player.pos.y + 0})) || - hh_colidable(hh_world_to_tile((vec2){.x=hh_g_player_new.pos.x + 16, .y=hh_g_player.pos.y + 15}))) { - hh_g_player_new.pos.x = hh_g_player_new.pos.x & ~15, // <-- magic comma, NOT TOUCHY - hh_g_player_new.vec.x = 0; - } - } - - //solves y collision - if (hh_g_player.vec.y <= 0) { - if (hh_colidable(hh_world_to_tile((vec2){.x=hh_g_player_new.pos.x + 0, .y=hh_g_player_new.pos.y + 0})) || - hh_colidable(hh_world_to_tile((vec2){.x=hh_g_player_new.pos.x + 0, .y=hh_g_player_new.pos.y + 15}))) { - hh_g_player_new.pos.y = (hh_g_player_new.pos.y & ~15) + 16, - hh_g_player_new.vec.y = 0; - } - } else { - if (hh_colidable(hh_world_to_tile((vec2){.x=hh_g_player_new.pos.x + 0, .y=hh_g_player_new.pos.y + 16})) || - hh_colidable(hh_world_to_tile((vec2){.x=hh_g_player_new.pos.x + 16, .y=hh_g_player_new.pos.y + 15}))) { - hh_g_player_new.pos.y = hh_g_player_new.pos.y & ~15, - hh_g_player_new.vec.y = 0; - hh_g_player_new.is_grounded = true; - } - } - - hh_g_player = hh_g_player_new; - - - - vec_cor cam_pos;//value in tiles - // cam_pos = (vec2){0,0}; - cam_pos = hh_update_camera(hh_g_player.pos,(vec2){0,0},(vec2){.x=20*16,.y=30*16});//TODO: remove magic number(s) - printf("%i, %i:%i, %i\n",hh_g_player.pos.x,hh_g_player.pos.y,cam_pos.x,cam_pos.y); - hh_draw_screen(cam_pos); - // update player sprite on ppu - g_hh_demo_balls[0].position_x = (hh_g_player.pos.x-cam_pos.x); - g_hh_demo_balls[0].position_y = hh_g_player.pos.y-cam_pos.y; - hh_ppu_update_foreground(0, g_hh_demo_balls[0]); - - // for (int i = 0; i < HH_DEMO_BALL_COUNT; i++){ - // g_hh_demo_balls[i].position_x = hh_g_player.pos.x +16*i; - // g_hh_demo_balls[i].position_y = hh_g_player.pos.y; - // hh_ppu_update_foreground(i, g_hh_demo_balls[i]); - - // } - + hh_player_actions(); - // set background pattern position - // hh_ppu_update_aux((hh_s_ppu_loc_aux){ - // .bg_shift_x = (frame / 2) % HH_PPU_SPRITE_WIDTH, - // .bg_shift_y = (frame / 8) % HH_PPU_SPRITE_HEIGHT, - // .fg_fetch = 0, - // .sysreset = 0, - // }); } // void sendData(uint8_t address, uint16_t data) { diff --git a/src/engine/entity.c b/src/engine/entity.c index 152cf1d..153e7e1 100644 --- a/src/engine/entity.c +++ b/src/engine/entity.c @@ -28,19 +28,19 @@ void hh_solve_collision(vec2 pos_environment, hh_entity* entity){ return; printf("BONK!/n"); - // if (entity->vec.y > 0){ + // if (entity->vel.y > 0){ // entity->pos.y = MAX(entity->pos.y,pos_environment.y); - // entity->vec.y = 0; + // entity->vel.y = 0; // } else { // entity->pos.y = MIN(entity->pos.y,pos_environment.y); - // entity->vec.y = 0; + // entity->vel.y = 0; // } - // if (entity->vec.x <= 0){ + // if (entity->vel.x <= 0){ // entity->pos.x = MIN(entity->pos.x,pos_environment.x-16); - // entity->vec.x = 0; + // entity->vel.x = 0; // } else { // entity->pos.x = MAX(entity->pos.x,pos_environment.x+16); - // entity->vec.x = 0; + // entity->vel.x = 0; // } } diff --git a/src/engine/entity.h b/src/engine/entity.h index dee4aed..f45dae2 100644 --- a/src/engine/entity.h +++ b/src/engine/entity.h @@ -3,16 +3,47 @@ #include <stdint.h> #include <stdbool.h> +#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, vec; + 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 diff --git a/src/engine/player_controller.c b/src/engine/player_controller.c index 27e522e..6735620 100644 --- a/src/engine/player_controller.c +++ b/src/engine/player_controller.c @@ -1 +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 <stdio.h> + +#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); + +} + |