Update hitbox-hurtbox system

Changelog:
- Use atk and def values to determine whether a hitbox destroys a
  hurtbox
scene_man
En Yi 2023-06-17 13:08:07 +08:00
parent fc2001e428
commit 63930fbe7d
4 changed files with 6 additions and 6 deletions

View File

@ -108,13 +108,13 @@ typedef struct _CContainer_t {
typedef struct _CHitBoxes_t {
Rectangle boxes[2];
uint8_t n_boxes;
bool strong;
uint8_t atk;
} CHitBoxes_t;
typedef struct _CHurtbox_t {
Vector2 offset;
Vector2 size;
bool fragile;
uint8_t def;
} CHurtbox_t;
// Credits to bedroomcoders.co.uk for this

View File

@ -1386,6 +1386,7 @@ void hitbox_update_system(Scene_t* scene)
if (p_other_hurtbox == NULL) continue;
CTransform_t* p_other_ct = get_component(p_other_ent, CTRANSFORM_COMP_T);
Vector2 hurtbox_pos = Vector2Add(p_other_ct->position, p_other_hurtbox->offset);
if (p_hitbox->atk <= p_other_hurtbox->def) continue;
Vector2 overlap;
if (
@ -1395,14 +1396,12 @@ void hitbox_update_system(Scene_t* scene)
)
)
{
if (!p_other_hurtbox->fragile) continue;
//if (p_other_ent->m_tag == CRATES_ENT_TAG)
{
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
CPlayerState_t* p_pstate = get_component(p_ent, CPLAYERSTATE_T);
if (
// TODO: Check Material of the crates
p_ctransform->position.y + p_bbox->size.y <= p_other_ct->position.y
)
{

View File

@ -16,7 +16,7 @@ Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool meta
add_component(p_crate, CTILECOORD_COMP_T);
CHurtbox_t* p_hurtbox = add_component(p_crate, CHURTBOX_T);
p_hurtbox->size = p_bbox->size;
p_hurtbox->fragile = !metal;
p_hurtbox->def = metal ? 2 : 1;
return p_crate;
}
@ -37,6 +37,6 @@ Entity_t* create_boulder(EntityManager_t* ent_manager, Assets_t* assets)
p_cmove->move_speed = 8;
CHurtbox_t* p_hurtbox = add_component(p_boulder, CHURTBOX_T);
p_hurtbox->size = p_bbox->size;
p_hurtbox->fragile = false;
p_hurtbox->def = 2;
return p_boulder;
}

View File

@ -83,6 +83,7 @@ Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets)
.width = p_bbox->size.x + 2,
.height = p_bbox->size.y - 1,
};
p_hitbox->atk = 2;
CSprite_t* p_cspr = add_component(p_ent, CSPRITE_T);
p_cspr->sprites = player_sprite_map;
p_cspr->transition_func = &player_sprite_transition_func;