Allow urchin to be crushed

LIMITATION
- Urchin can be crushed by wooden crates.
main
En Yi 2024-09-29 17:58:07 +08:00
parent d3db15a018
commit 3520715655
5 changed files with 50 additions and 23 deletions

View File

@ -14,6 +14,7 @@ enum ComponentEnum {
CWATERRUNNER_T,
CAIRTIMER_T,
CEMITTER_T,
CSQUISHABLE_T
};
typedef struct _CMovementState_t {
@ -171,3 +172,7 @@ typedef struct _CEmitter_t
EmitterHandle handle;
Vector2 offset;
} CEmitter_t;
typedef struct _CSquishable_t {
bool active; //< Dummy variable
} CSquishable_t;

View File

@ -15,6 +15,7 @@ DEFINE_COMP_MEMPOOL_BUF(CLifeTimer_t, MAX_COMP_POOL_SIZE)
DEFINE_COMP_MEMPOOL_BUF(CWaterRunner_t, 32)
DEFINE_COMP_MEMPOOL_BUF(CAirTimer_t, 8)
DEFINE_COMP_MEMPOOL_BUF(CEmitter_t, 32)
DEFINE_COMP_MEMPOOL_BUF(CSquishable_t, MAX_COMP_POOL_SIZE)
// Component mempools are added in the order of the component enums
BEGIN_DEFINE_COMP_MEMPOOL
@ -30,4 +31,5 @@ BEGIN_DEFINE_COMP_MEMPOOL
ADD_COMP_MEMPOOL(CWaterRunner_t)
ADD_COMP_MEMPOOL(CAirTimer_t)
ADD_COMP_MEMPOOL(CEmitter_t)
ADD_COMP_MEMPOOL(CSquishable_t)
END_DEFINE_COMP_MEMPOOL

View File

@ -583,13 +583,16 @@ void player_crushing_system(Scene_t* scene)
{
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
Entity_t* p_player;
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_player)
//sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_player)
CSquishable_t* p_squish;
unsigned int ent_idx;
sc_map_foreach(&scene->ent_manager.component_map[CSQUISHABLE_T], ent_idx, p_squish)
{
CBBox_t* p_bbox = get_component(p_player, CBBOX_COMP_T);
Entity_t* p_ent = get_entity(&scene->ent_manager, ent_idx);
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
uint8_t edges = check_bbox_edges(
&data->tilemap, p_player,
&data->tilemap, p_ent,
p_bbox->size, true
);
@ -601,14 +604,14 @@ void player_crushing_system(Scene_t* scene)
uint8_t collide = 0;
CollideEntity_t ent =
{
.p_ent = p_player,
.bbox = (Rectangle){p_player->position.x, p_player->position.y, p_bbox->size.x, 1},
.prev_bbox = (Rectangle){p_player->position.x, p_player->position.y, p_bbox->size.x, p_bbox->size.y},
.p_ent = p_ent,
.bbox = (Rectangle){p_ent->position.x, p_ent->position.y, p_bbox->size.x, 1},
.prev_bbox = (Rectangle){p_ent->position.x, p_ent->position.y, p_bbox->size.x, p_bbox->size.y},
.area = (TileArea_t){
.tile_x1 = (p_player->position.x) / TILE_SIZE,
.tile_y1 = (p_player->position.y) / TILE_SIZE,
.tile_x2 = (p_player->position.x + p_bbox->size.x - 1) / TILE_SIZE,
.tile_y2 = (p_player->position.y + p_bbox->size.y - 1) / TILE_SIZE,
.tile_x1 = (p_ent->position.x) / TILE_SIZE,
.tile_y1 = (p_ent->position.y) / TILE_SIZE,
.tile_x2 = (p_ent->position.x + p_bbox->size.x - 1) / TILE_SIZE,
.tile_y2 = (p_ent->position.y + p_bbox->size.y - 1) / TILE_SIZE,
}
};
@ -619,7 +622,7 @@ void player_crushing_system(Scene_t* scene)
collide |= 1 << 1;
}
ent.bbox.y = p_player->position.y + p_bbox->size.y;
ent.bbox.y = p_ent->position.y + p_bbox->size.y;
collide_type = check_collision_line(&ent, &data->tilemap, true);
if (collide_type == 1)
{
@ -628,7 +631,14 @@ void player_crushing_system(Scene_t* scene)
if (collide != 0)
{
p_player->m_alive = false;
if (p_ent->m_tag == PLAYER_ENT_TAG)
{
p_ent->m_alive = false;
}
else
{
destroy_entity(scene, &data->tilemap, p_ent);
}
return;
}
}
@ -638,14 +648,14 @@ void player_crushing_system(Scene_t* scene)
uint8_t collide = 0;
CollideEntity_t ent =
{
.p_ent = p_player,
.bbox = (Rectangle){p_player->position.x, p_player->position.y, 1, p_bbox->size.y},
.prev_bbox = (Rectangle){p_player->position.x, p_player->position.y, p_bbox->size.x, p_bbox->size.y},
.p_ent = p_ent,
.bbox = (Rectangle){p_ent->position.x, p_ent->position.y, 1, p_bbox->size.y},
.prev_bbox = (Rectangle){p_ent->position.x, p_ent->position.y, p_bbox->size.x, p_bbox->size.y},
.area = (TileArea_t){
.tile_x1 = (p_player->position.x) / TILE_SIZE,
.tile_y1 = (p_player->position.y) / TILE_SIZE,
.tile_x2 = (p_player->position.x + p_bbox->size.x - 1) / TILE_SIZE,
.tile_y2 = (p_player->position.y + p_bbox->size.y - 1) / TILE_SIZE,
.tile_x1 = (p_ent->position.x) / TILE_SIZE,
.tile_y1 = (p_ent->position.y) / TILE_SIZE,
.tile_x2 = (p_ent->position.x + p_bbox->size.x - 1) / TILE_SIZE,
.tile_y2 = (p_ent->position.y + p_bbox->size.y - 1) / TILE_SIZE,
}
};
@ -657,7 +667,7 @@ void player_crushing_system(Scene_t* scene)
}
//Right
ent.bbox.x = p_player->position.x + p_bbox->size.x; // 2 to account for the previous subtraction
ent.bbox.x = p_ent->position.x + p_bbox->size.x; // 2 to account for the previous subtraction
collide_type = check_collision_line(&ent, &data->tilemap, false);
if (collide_type == 1)
{
@ -666,7 +676,14 @@ void player_crushing_system(Scene_t* scene)
if (collide != 0)
{
p_player->m_alive = false;
if (p_ent->m_tag == PLAYER_ENT_TAG)
{
p_ent->m_alive = false;
}
else
{
destroy_entity(scene, &data->tilemap, p_ent);
}
return;
}
}

View File

@ -268,12 +268,13 @@ Entity_t* create_urchin(EntityManager_t* ent_manager)
CHitBoxes_t* p_hitbox = add_component(p_urchin, CHITBOXES_T);
p_hitbox->n_boxes = 1;
p_hitbox->boxes[0] = (Rectangle){3, 3, 26, 26};
p_hitbox->atk = 1;
p_hitbox->atk = 2;
CSprite_t* p_cspr = add_component(p_urchin, CSPRITE_T);
p_cspr->sprites = item_sprite_map;
p_cspr->current_idx = 21;
add_component(p_urchin, CSQUISHABLE_T);
return p_urchin;
}

View File

@ -115,6 +115,8 @@ Entity_t* create_player(EntityManager_t* ent_manager)
CEmitter_t* p_emitter = add_component(p_ent, CEMITTER_T);
p_emitter->offset = (Vector2){7,0};
add_component(p_ent, CSQUISHABLE_T);
return p_ent;
}