diff options
author | UnavailableDev <ggwildplay@gmail.com> | 2023-03-22 10:29:24 +0100 |
---|---|---|
committer | UnavailableDev <ggwildplay@gmail.com> | 2023-03-22 10:29:24 +0100 |
commit | cd9f96be0d1ca49f269d8dc7c801479ef382d21b (patch) | |
tree | d3768b4d9a8ef8cb1c6ee5e6dcea785adb902d5c /src/engine/player_controller.c | |
parent | 439be80c80498586a299c28ce1be3ea765b414a9 (diff) | |
parent | 746b9a43b745e6f7cbac4cbe529d3f5f719d1eea (diff) |
Merge branch 'dev' of https://github.com/heavydemon21/avans-arcade into game-engine
Diffstat (limited to 'src/engine/player_controller.c')
-rw-r--r-- | src/engine/player_controller.c | 182 |
1 files changed, 142 insertions, 40 deletions
diff --git a/src/engine/player_controller.c b/src/engine/player_controller.c index 22f6eb6..647b00c 100644 --- a/src/engine/player_controller.c +++ b/src/engine/player_controller.c @@ -6,29 +6,143 @@ #include "input.h" +#include "engine/bullet.h" void hh_player_actions() { + static Bullet bullet ={ + .isActive=false, + }; static hh_entity player={ .hp = 4, .speed = 6, .is_grounded = false, + .is_hit = false, + .radius = 8, .pos = (vec2){32,32}, .vel = (vec2){0,0}, .vec = (vec2){0,0}, .render = { + .frame0 = 80, + .palette = 3, + .fam = (hh_s_ppu_loc_fam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = 2, + .tilemap_index = 60, + } + } + }, player_new = {0}; + + + static hh_entity enemy={ + .hp = 4, + .speed = 6, + .is_grounded = false, + .is_hit = false, + .radius = 8, + .pos = (vec2){128,48}, + .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, + .tilemap_index = 1, } } - }, player_new = {0}; - + }; + player_new = player; // hh_input_read(); + static uint8_t hit = 0; + int8_t hit_timer = 0; + int8_t direction_x = (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right); + int8_t direction_y = (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down); + + if(player.is_hit == true){ + hit_timer = 9; + player.is_hit = false; + } + if(hit_timer > -10){ + hit_timer--; + } + + if(hit_timer <= 0){ + if(direction_x != 0){ + if(player.vel.x > -1 * player.speed && player.vel.x < player.speed) { + player.vel.x = player.vel.x + direction_x; + } else { + if (player.vel.x > 0) { + player.vel.x--; + } else if(player.vel.x < 0) { + player.vel.x++; + } + } + } else { + if (player.vel.x > 0) { + player.vel.x--; + } else if(player.vel.x < 0) { + player.vel.x++; + } + } + + /* // movement Y (w-s) disable gravity to use this + if(direction_y != 0){ + if(player.vel.y > -4 && player.vel.y < 4 ) { + player.vel.y = player.vel.y + direction_y; + } + } else { + if (player.vel.y > 0) { + player.vel.y--; + } else if(player.vel.y < 0) { + player.vel.y++; + } + } + + */ + } else { + if (player.vel.x > 0) { + player.vel.x--; + } else if(player.vel.x < 0) { + player.vel.x++; + } + player.vel.y++; + } + + + if (g_hh_controller_p1.button_primary && player.is_grounded == true) {//JUMP + player.vel.y = -10; + player.is_grounded = false; + } else if (player.vel.y < 6){ + player.vel.y += 1; //gravity + } + + if(g_hh_controller_p1.button_secondary==true){ + shootBullet(player.pos,&bullet); + } + updateBullet(&bullet,5); + + + +/* 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) }; + + player_new.vel = (vec2){ + .x = player.vel.x, + .y = player.vel.y, + }; +*/ + + player_new.vel = (vec2){ + .x = player.vel.x, + .y = player.vel.y, + }; + + player_new = hh_enemy_collision(player, enemy); + + // const int8_t maa = 3; // const int8_t mbb = -3; // if (g_hh_controller_p1.dpad_up) @@ -55,8 +169,8 @@ void hh_player_actions() { // 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, + .x = player.pos.x + player_new.vel.x, + .y = player.pos.y + player_new.vel.y, }; @@ -97,40 +211,9 @@ void hh_player_actions() { // } // } - 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; + player = hh_background_collision ( player, player_new); + + //player = player_new; vec_cor cam_pos;//value in tiles // cam_pos = (vec2){0,0}; @@ -141,10 +224,29 @@ void hh_player_actions() { player.render.fam.position_x = (player.pos.x-cam_pos.x); player.render.fam.position_y = (player.pos.y-cam_pos.y); + enemy.render.fam.position_x = (enemy.pos.x-cam_pos.x); + enemy.render.fam.position_y = (enemy.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_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(4, enemy.render.fam); } + + |