Update hitbox-hurtbox system
Changelog: - Use atk and def values to determine whether a hitbox destroys a hurtboxscene_man
parent
fc2001e428
commit
63930fbe7d
|
@ -108,13 +108,13 @@ typedef struct _CContainer_t {
|
||||||
typedef struct _CHitBoxes_t {
|
typedef struct _CHitBoxes_t {
|
||||||
Rectangle boxes[2];
|
Rectangle boxes[2];
|
||||||
uint8_t n_boxes;
|
uint8_t n_boxes;
|
||||||
bool strong;
|
uint8_t atk;
|
||||||
} CHitBoxes_t;
|
} CHitBoxes_t;
|
||||||
|
|
||||||
typedef struct _CHurtbox_t {
|
typedef struct _CHurtbox_t {
|
||||||
Vector2 offset;
|
Vector2 offset;
|
||||||
Vector2 size;
|
Vector2 size;
|
||||||
bool fragile;
|
uint8_t def;
|
||||||
} CHurtbox_t;
|
} CHurtbox_t;
|
||||||
|
|
||||||
// Credits to bedroomcoders.co.uk for this
|
// Credits to bedroomcoders.co.uk for this
|
||||||
|
|
|
@ -1386,6 +1386,7 @@ void hitbox_update_system(Scene_t* scene)
|
||||||
if (p_other_hurtbox == NULL) continue;
|
if (p_other_hurtbox == NULL) continue;
|
||||||
CTransform_t* p_other_ct = get_component(p_other_ent, CTRANSFORM_COMP_T);
|
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);
|
Vector2 hurtbox_pos = Vector2Add(p_other_ct->position, p_other_hurtbox->offset);
|
||||||
|
if (p_hitbox->atk <= p_other_hurtbox->def) continue;
|
||||||
|
|
||||||
Vector2 overlap;
|
Vector2 overlap;
|
||||||
if (
|
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)
|
//if (p_other_ent->m_tag == CRATES_ENT_TAG)
|
||||||
{
|
{
|
||||||
|
|
||||||
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||||
CPlayerState_t* p_pstate = get_component(p_ent, CPLAYERSTATE_T);
|
CPlayerState_t* p_pstate = get_component(p_ent, CPLAYERSTATE_T);
|
||||||
if (
|
if (
|
||||||
// TODO: Check Material of the crates
|
|
||||||
p_ctransform->position.y + p_bbox->size.y <= p_other_ct->position.y
|
p_ctransform->position.y + p_bbox->size.y <= p_other_ct->position.y
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,7 @@ Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool meta
|
||||||
add_component(p_crate, CTILECOORD_COMP_T);
|
add_component(p_crate, CTILECOORD_COMP_T);
|
||||||
CHurtbox_t* p_hurtbox = add_component(p_crate, CHURTBOX_T);
|
CHurtbox_t* p_hurtbox = add_component(p_crate, CHURTBOX_T);
|
||||||
p_hurtbox->size = p_bbox->size;
|
p_hurtbox->size = p_bbox->size;
|
||||||
p_hurtbox->fragile = !metal;
|
p_hurtbox->def = metal ? 2 : 1;
|
||||||
return p_crate;
|
return p_crate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,6 @@ Entity_t* create_boulder(EntityManager_t* ent_manager, Assets_t* assets)
|
||||||
p_cmove->move_speed = 8;
|
p_cmove->move_speed = 8;
|
||||||
CHurtbox_t* p_hurtbox = add_component(p_boulder, CHURTBOX_T);
|
CHurtbox_t* p_hurtbox = add_component(p_boulder, CHURTBOX_T);
|
||||||
p_hurtbox->size = p_bbox->size;
|
p_hurtbox->size = p_bbox->size;
|
||||||
p_hurtbox->fragile = false;
|
p_hurtbox->def = 2;
|
||||||
return p_boulder;
|
return p_boulder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,7 @@ Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets)
|
||||||
.width = p_bbox->size.x + 2,
|
.width = p_bbox->size.x + 2,
|
||||||
.height = p_bbox->size.y - 1,
|
.height = p_bbox->size.y - 1,
|
||||||
};
|
};
|
||||||
|
p_hitbox->atk = 2;
|
||||||
CSprite_t* p_cspr = add_component(p_ent, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_ent, CSPRITE_T);
|
||||||
p_cspr->sprites = player_sprite_map;
|
p_cspr->sprites = player_sprite_map;
|
||||||
p_cspr->transition_func = &player_sprite_transition_func;
|
p_cspr->transition_func = &player_sprite_transition_func;
|
||||||
|
|
Loading…
Reference in New Issue