diff options
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/entity.c | 50 | ||||
-rw-r--r-- | src/engine/entity.h | 4 | ||||
-rw-r--r-- | src/engine/player_controller.c | 143 | ||||
-rw-r--r-- | src/engine/player_controller.h | 2 |
4 files changed, 72 insertions, 127 deletions
diff --git a/src/engine/entity.c b/src/engine/entity.c index 58b62c9..7b780cf 100644 --- a/src/engine/entity.c +++ b/src/engine/entity.c @@ -127,3 +127,53 @@ bool hh_distance_circles (vec2 object_1, vec2 object_2, int radius_1, int radius return false; } } + +void hh_jump_entity(hh_entity* object_1){ + if (object_1->is_grounded == true) {//JUMP + object_1->vel.y = -10; + object_1->is_grounded = false; + } +} +void hh_gravity_entity(hh_entity* object_1){ + if (object_1->is_grounded == false && object_1->vel.y < 6) { + object_1->vel.y += 1; //gravity + } +} +void hh_hit_entity(hh_entity* object_1, int8_t* hit_timer, int8_t* direction){ + if(object_1->is_hit == true){ + hit_timer = 9; + object_1->is_hit = false; + } + if(hit_timer > -10){ + hit_timer--; + } + + if(hit_timer <= 0){ + if(direction != 0){ + if(object_1->vel.x > -1 * object_1->speed && object_1->vel.x < object_1->speed) { + object_1->vel.x = object_1->vel.x + direction; + } else { + if (object_1->vel.x > 0) { + object_1->vel.x--; + } else if(object_1->vel.x < 0) { + object_1->vel.x++; + } + } + } else { + if (object_1->vel.x > 0) { + object_1->vel.x--; + } else if(object_1->vel.x < 0) { + object_1->vel.x++; + } + } + + } else { + if (object_1->vel.x > 0) { + object_1->vel.x--; + } else if(object_1->vel.x < 0) { + object_1->vel.x++; + } + object_1->vel.y++; + } + +} diff --git a/src/engine/entity.h b/src/engine/entity.h index 68b450d..b681bd8 100644 --- a/src/engine/entity.h +++ b/src/engine/entity.h @@ -43,4 +43,8 @@ hh_entity hh_enemy_collision(hh_entity temp_player, hh_entity temp_enemy); /// @return true if objects collids bool hh_distance_circles(vec2 object_1, vec2 object_2, int radius_1, int radius_2); +// TODO: comments on functions below +void hh_jump_entity(hh_entity* ); +void hh_gravity_entity(hh_entity* ); +void hh_hit_entity(hh_entity* object_1, int8_t* hit_timer, int8_t* direction); diff --git a/src/engine/player_controller.c b/src/engine/player_controller.c index cec28df..096243b 100644 --- a/src/engine/player_controller.c +++ b/src/engine/player_controller.c @@ -7,30 +7,8 @@ #include "engine/animator.h" #include "engine/bullet.h" -void hh_player_actions() { - static hh_entity player={ - .hp = 4, - .speed = 6, - .is_grounded = false, - .is_hit = false, - .radius = 8, - .pos = (vec2){128+16,32}, - .vel = (vec2){0,0}, - .size = (vec2){32,32}, - .render = { - .frame0 = 80, - .palette = 3, - .ppu_foreground_index = 0, - .fam = (hh_s_ppu_loc_fam_entry){ - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = 3, - .tilemap_index = 80, - } - } - }, player_new = {0}; - - static hh_entity bullet={ +void hh_player_actions(hh_entity* player, vec_cor cam_pos){ + static hh_entity bullet={ // .hp = 4, .speed = 6, .is_grounded = true, @@ -49,124 +27,37 @@ void hh_player_actions() { } } }; + static hh_entity player_new = {0}; + player_new = *player; - static hh_entity enemy={ - .hp = 4, - .speed = 6, - .is_grounded = false, - .is_hit = false, - .radius = 8, - .pos = (vec2){128,48}, - .vel = (vec2){0,0}, - .size = (vec2){16,16}, - .render = { - .frame0 = 20, - .palette = 7, - .ppu_foreground_index = 16, - .fam = (hh_s_ppu_loc_fam_entry){ - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = 7, - .tilemap_index = 1, - } - } - }; - 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 + hh_hit_entity(player,hit_timer,direction_x); + hh_gravity_entity(player); + if(g_hh_controller_p1.button_primary){ + hh_jump_entity(player); } - -/* - 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, + .x = player->vel.x, + .y = player->vel.y, }; - - player_new = hh_enemy_collision(player, enemy); - + player_new.pos = (vec2){ - .x = player.pos.x + player_new.vel.x, - .y = player.pos.y + player_new.vel.y, + .x = player->pos.x + player_new.vel.x, + .y = player->pos.y + player_new.vel.y, }; - player = hh_background_collision( player, player_new); + *player = hh_background_collision ( *player, player_new); - vec_cor cam_pos;//value in tiles - cam_pos = hh_draw_screen(player.pos); - hh_shoot_bullet(player.pos, cam_pos ,&bullet); + hh_shoot_bullet(player->pos, cam_pos ,&bullet); uint16_t idx = 16; - idx = hh_update_sprite(idx, &player, cam_pos); - idx = hh_update_sprite(idx, &enemy, cam_pos); + idx = hh_update_sprite(idx, player, cam_pos); + // idx = hh_update_sprite(idx, &enemy, cam_pos); idx =16; diff --git a/src/engine/player_controller.h b/src/engine/player_controller.h index 400c18e..4a325e8 100644 --- a/src/engine/player_controller.h +++ b/src/engine/player_controller.h @@ -4,4 +4,4 @@ #include "engine/entity.h" // inputs -void hh_player_actions(); +void hh_player_actions(hh_entity* player, vec_cor cam_pos); |