Compare commits

..

No commits in common. "4414747c792fe7ebb5387873ed12b8b58e491f5d" and "256ea02d0b671154cc3d85c9f5ce934831b1f363" have entirely different histories.

4 changed files with 37 additions and 47 deletions

View File

@ -642,7 +642,6 @@ void init_level_scene(LevelScene_t* scene)
init_level_scene_data(&scene->data); init_level_scene_data(&scene->data);
// insert level scene systems // insert level scene systems
sc_array_add(&scene->scene.systems, &update_tilemap_system);
sc_array_add(&scene->scene.systems, &player_movement_input_system); sc_array_add(&scene->scene.systems, &player_movement_input_system);
sc_array_add(&scene->scene.systems, &player_bbox_update_system); sc_array_add(&scene->scene.systems, &player_bbox_update_system);
sc_array_add(&scene->scene.systems, &player_pushing_system); sc_array_add(&scene->scene.systems, &player_pushing_system);
@ -654,14 +653,14 @@ void init_level_scene(LevelScene_t* scene)
sc_array_add(&scene->scene.systems, &boulder_destroy_wooden_tile_system); sc_array_add(&scene->scene.systems, &boulder_destroy_wooden_tile_system);
sc_array_add(&scene->scene.systems, &update_tilemap_system); sc_array_add(&scene->scene.systems, &update_tilemap_system);
sc_array_add(&scene->scene.systems, &tile_collision_system); sc_array_add(&scene->scene.systems, &tile_collision_system);
//sc_array_add(&scene->scene.systems, &update_tilemap_system); sc_array_add(&scene->scene.systems, &update_tilemap_system);
sc_array_add(&scene->scene.systems, &hitbox_update_system); sc_array_add(&scene->scene.systems, &hitbox_update_system);
sc_array_add(&scene->scene.systems, &player_crushing_system); sc_array_add(&scene->scene.systems, &player_crushing_system);
sc_array_add(&scene->scene.systems, &spike_collision_system); sc_array_add(&scene->scene.systems, &spike_collision_system);
sc_array_add(&scene->scene.systems, &state_transition_update_system); sc_array_add(&scene->scene.systems, &state_transition_update_system);
sc_array_add(&scene->scene.systems, &player_ground_air_transition_system); sc_array_add(&scene->scene.systems, &player_ground_air_transition_system);
sc_array_add(&scene->scene.systems, &lifetimer_update_system);
sc_array_add(&scene->scene.systems, &container_destroy_system); sc_array_add(&scene->scene.systems, &container_destroy_system);
sc_array_add(&scene->scene.systems, &lifetimer_update_system);
sc_array_add(&scene->scene.systems, &sprite_animation_system); sc_array_add(&scene->scene.systems, &sprite_animation_system);
sc_array_add(&scene->scene.systems, &camera_update_system); sc_array_add(&scene->scene.systems, &camera_update_system);
sc_array_add(&scene->scene.systems, &player_dir_reset_system); sc_array_add(&scene->scene.systems, &player_dir_reset_system);

View File

@ -125,9 +125,6 @@ Entity_t* get_entity(EntityManager_t* p_manager, unsigned long id)
void* add_component(Entity_t* p_entity, ComponentEnum_t comp_type) void* add_component(Entity_t* p_entity, ComponentEnum_t comp_type)
{ {
if (p_entity->components[comp_type] == MAX_COMP_POOL_SIZE)
{
unsigned long comp_idx = 0; unsigned long comp_idx = 0;
void* p_comp = new_component_from_mempool(comp_type, &comp_idx); void* p_comp = new_component_from_mempool(comp_type, &comp_idx);
if (p_comp) if (p_comp)
@ -137,9 +134,6 @@ void* add_component(Entity_t* p_entity, ComponentEnum_t comp_type)
sc_queue_add_last(&p_entity->manager->to_update, evt); sc_queue_add_last(&p_entity->manager->to_update, evt);
} }
return p_comp; return p_comp;
}
return get_component(p_entity, comp_type);
} }
void* get_component(Entity_t *p_entity, ComponentEnum_t comp_type) void* get_component(Entity_t *p_entity, ComponentEnum_t comp_type)
@ -154,6 +148,5 @@ void remove_component(Entity_t *p_entity, ComponentEnum_t comp_type)
{ {
if (p_entity->components[comp_type] == MAX_COMP_POOL_SIZE) return; if (p_entity->components[comp_type] == MAX_COMP_POOL_SIZE) return;
struct EntityUpdateEventInfo evt = (struct EntityUpdateEventInfo){p_entity->m_id, comp_type, p_entity->components[comp_type] , COMP_DELETION}; struct EntityUpdateEventInfo evt = (struct EntityUpdateEventInfo){p_entity->m_id, comp_type, p_entity->components[comp_type] , COMP_DELETION};
p_entity->components[comp_type] = MAX_COMP_POOL_SIZE;
sc_queue_add_last(&p_entity->manager->to_update, evt); sc_queue_add_last(&p_entity->manager->to_update, evt);
} }

View File

@ -274,7 +274,7 @@ static uint8_t check_collision_line(const CollideEntity_t* ent, TileGrid_t* grid
// TODO: This should be a point collision check, not an AABB check // TODO: This should be a point collision check, not an AABB check
static uint8_t check_collision_offset( static bool check_collision_offset(
Entity_t* p_ent, Vector2 pos, Vector2 bbox_sz, Entity_t* p_ent, Vector2 pos, Vector2 bbox_sz,
TileGrid_t* grid, Vector2 offset TileGrid_t* grid, Vector2 offset
) )
@ -689,8 +689,17 @@ void player_movement_input_system(Scene_t* scene)
} }
} }
uint8_t collide_type = check_collision_offset(p_player, p_ctransform->position, p_bbox->size, &tilemap, (Vector2){0, -TILE_SIZE}); bool hit = false;
if (collide_type == 1) unsigned int tile_x1 = (p_ctransform->position.x) / TILE_SIZE;
unsigned int tile_x2 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE;
unsigned int tile_y = (p_ctransform->position.y) / TILE_SIZE;
if (p_bbox->size.y < TILE_SIZE && tile_y > 0) tile_y--; // hack to detect small bbox state
for(unsigned int tile_x = tile_x1; tile_x <= tile_x2; tile_x++)
{
hit |= tilemap.tiles[tile_y * tilemap.width + tile_x].tile_type == SOLID_TILE;
}
if (hit)
{ {
p_pstate->is_crouch |= 0b10; p_pstate->is_crouch |= 0b10;
} }
@ -1636,21 +1645,19 @@ void update_tilemap_system(Scene_t* scene)
void hitbox_update_system(Scene_t* scene) void hitbox_update_system(Scene_t* scene)
{ {
static bool checked_entities[MAX_COMP_POOL_SIZE] = {0}; //static bool checked_entities[MAX_COMP_POOL_SIZE] = {0};
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data); LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
TileGrid_t tilemap = data->tilemap; TileGrid_t tilemap = data->tilemap;
unsigned int ent_idx; unsigned int ent_idx;
CHitBoxes_t* p_hitbox; CHitBoxes_t* p_hitbox;
sc_map_foreach(&scene->ent_manager.component_map[CHITBOXES_T], ent_idx, p_hitbox) sc_map_foreach(&scene->ent_manager.component_map[CHITBOXES_T], ent_idx, p_hitbox)
{ {
bool hit = false;
Entity_t *p_ent = get_entity(&scene->ent_manager, ent_idx); Entity_t *p_ent = get_entity(&scene->ent_manager, ent_idx);
if (!p_ent->m_alive) continue; if (!p_ent->m_alive) continue;
CTransform_t* p_ctransform = get_component(p_ent, CTRANSFORM_COMP_T); CTransform_t* p_ctransform = get_component(p_ent, CTRANSFORM_COMP_T);
memset(checked_entities, 0, sizeof(checked_entities));
for (uint8_t i = 0; i < p_hitbox->n_boxes; ++i) for (uint8_t i = 0; i < p_hitbox->n_boxes; ++i)
{ {
Vector2 hitbox_pos = { Vector2 hitbox_pos = {
@ -1672,6 +1679,7 @@ void hitbox_update_system(Scene_t* scene)
unsigned int other_ent_idx; unsigned int other_ent_idx;
Entity_t* p_other_ent; Entity_t* p_other_ent;
Vector2 overlap; Vector2 overlap;
//memset(checked_entities, 0, sizeof(checked_entities));
if (tilemap.tiles[tile_idx].tile_type != EMPTY_TILE) if (tilemap.tiles[tile_idx].tile_type != EMPTY_TILE)
{ {
@ -1684,19 +1692,21 @@ void hitbox_update_system(Scene_t* scene)
) )
) )
{ {
hit = true;
if (p_hitbox->atk > tilemap.tiles[tile_idx].def) if (p_hitbox->atk > tilemap.tiles[tile_idx].def)
{ {
change_a_tile(&tilemap, tile_idx, EMPTY_TILE); change_a_tile(&tilemap, tile_idx, EMPTY_TILE);
continue; }
if (p_hitbox->one_hit)
{
remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_ent);
goto hitbox_done;
} }
} }
} }
sc_map_foreach(&tilemap.tiles[tile_idx].entities_set, other_ent_idx, p_other_ent) sc_map_foreach(&tilemap.tiles[tile_idx].entities_set, other_ent_idx, p_other_ent)
{ {
if (other_ent_idx == ent_idx) continue; if (other_ent_idx == ent_idx) continue;
if (checked_entities[other_ent_idx]) continue; //if (checked_entities[other_ent_idx]) continue;
Entity_t* p_other_ent = get_entity(&scene->ent_manager, other_ent_idx); Entity_t* p_other_ent = get_entity(&scene->ent_manager, other_ent_idx);
if (!p_other_ent->m_alive) continue; // To only allow one way collision check if (!p_other_ent->m_alive) continue; // To only allow one way collision check
@ -1714,7 +1724,6 @@ void hitbox_update_system(Scene_t* scene)
) )
) )
{ {
hit = true;
if (p_hitbox->atk > p_other_hurtbox->def) if (p_hitbox->atk > p_other_hurtbox->def)
{ {
p_other_hurtbox->damage_src = ent_idx; p_other_hurtbox->damage_src = ent_idx;
@ -1738,30 +1747,21 @@ void hitbox_update_system(Scene_t* scene)
} }
} }
} }
if (p_ent->m_tag != PLAYER_ENT_TAG)
{
remove_component(p_other_ent, CHURTBOX_T);
CLifeTimer_t* p_clifetimer = add_component(p_other_ent, CLIFETIMER_T);
p_clifetimer->life_time = 8;
}
else
{
// Need to remove immediately, otherwise will interfere with bomb spawning
remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_other_ent); remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_other_ent);
} }
}
} if (p_hitbox->one_hit)
}
}
}
}
if (p_hitbox->one_hit && hit)
{ {
remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_ent); remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_ent);
goto hitbox_done;
} }
} }
}
}
}
}
hitbox_done: continue;
}
} }
void boulder_destroy_wooden_tile_system(Scene_t* scene) void boulder_destroy_wooden_tile_system(Scene_t* scene)

View File

@ -18,7 +18,6 @@ Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool meta
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->def = metal ? 2 : 1; p_hurtbox->def = metal ? 2 : 1;
p_hurtbox->damage_src = -1;
if (item != CONTAINER_EMPTY) if (item != CONTAINER_EMPTY)
{ {
@ -48,7 +47,6 @@ Entity_t* create_boulder(EntityManager_t* ent_manager, Assets_t* assets)
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->def = 2; p_hurtbox->def = 2;
p_hurtbox->damage_src = -1;
return p_boulder; return p_boulder;
} }