Update moveable movement system
Changelog: - Before entering grid movement, check if any solid entities exist. - This allow rolling over the player, who is not solidscene_man
parent
8bc14b17b1
commit
c84ef5d5ee
|
@ -815,63 +815,92 @@ void moveable_update_system(Scene_t* scene)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (p_ctransform->prev_velocity.y <= 0) continue;
|
if (p_ctransform->prev_velocity.y <= 0) continue;
|
||||||
//if (p_ctransform->prev_position.y < p_ctransform->position.y) continue;
|
|
||||||
|
|
||||||
TileGrid_t tilemap = (CONTAINER_OF(scene, LevelScene_t, scene)->data).tilemap;
|
TileGrid_t tilemap = (CONTAINER_OF(scene, LevelScene_t, scene)->data).tilemap;
|
||||||
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||||
Vector2 point_to_check = p_ctransform->position;
|
|
||||||
int tile_x = (p_ctransform->position.x + p_bbox->half_size.x) / TILE_SIZE;
|
int tile_x = (p_ctransform->position.x + p_bbox->half_size.x) / TILE_SIZE;
|
||||||
int tile_y = (p_ctransform->position.y + p_bbox->size.y) / TILE_SIZE;
|
int tile_y = (p_ctransform->position.y + p_bbox->size.y) / TILE_SIZE;
|
||||||
if (tile_y >= tilemap.height) continue;
|
if (tile_y >= tilemap.height) continue;
|
||||||
|
|
||||||
int tile_idx = tile_y * tilemap.width + tile_x;
|
int tile_idx = tile_y * tilemap.width + tile_x;
|
||||||
unsigned int other_ent_idx;
|
unsigned int other_ent_idx;
|
||||||
|
bool can_move = false;
|
||||||
|
int tile_y2 = tile_y - 1;
|
||||||
sc_map_foreach_key(&tilemap.tiles[tile_idx].entities_set, other_ent_idx)
|
sc_map_foreach_key(&tilemap.tiles[tile_idx].entities_set, other_ent_idx)
|
||||||
{
|
{
|
||||||
if (other_ent_idx == ent_idx) continue;
|
if (other_ent_idx == ent_idx) continue;
|
||||||
sc_map_get_64v(&scene->ent_manager.component_map[CMOVEABLE_T], other_ent_idx);
|
sc_map_get_64v(&scene->ent_manager.component_map[CMOVEABLE_T], other_ent_idx);
|
||||||
if (sc_map_found(&scene->ent_manager.component_map[CMOVEABLE_T]))
|
if (!sc_map_found(&scene->ent_manager.component_map[CMOVEABLE_T])) continue;
|
||||||
|
|
||||||
|
tile_x = (p_ctransform->position.x) / TILE_SIZE - 1;
|
||||||
|
|
||||||
|
if (tile_x >= 0 && tile_x < tilemap.width)
|
||||||
{
|
{
|
||||||
tile_x = (p_ctransform->position.x) / TILE_SIZE - 1;
|
unsigned int tile_idx1 = tile_y * tilemap.width + tile_x;
|
||||||
int tile_y2 = tile_y - 1;
|
unsigned int tile_idx2 = tile_y2 * tilemap.width + tile_x;
|
||||||
|
if (
|
||||||
if (tile_x >= 0 && tile_x < tilemap.width)
|
tilemap.tiles[tile_idx1].tile_type == EMPTY_TILE
|
||||||
|
&& tilemap.tiles[tile_idx2].tile_type == EMPTY_TILE
|
||||||
|
)
|
||||||
{
|
{
|
||||||
unsigned int tile_idx1 = tile_y * tilemap.width + tile_x;
|
bool any_solid = false;
|
||||||
unsigned int tile_idx2 = tile_y2 * tilemap.width + tile_x;
|
unsigned int idx_to_check;
|
||||||
if (tilemap.tiles[tile_idx1].tile_type == EMPTY_TILE
|
sc_map_foreach_key(&tilemap.tiles[tile_idx1].entities_set, idx_to_check)
|
||||||
&& sc_map_size_64(&tilemap.tiles[tile_idx1].entities_set) == 0
|
|
||||||
&& tilemap.tiles[tile_idx2].tile_type == EMPTY_TILE
|
|
||||||
&& sc_map_size_64(&tilemap.tiles[tile_idx2].entities_set) == 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
p_moveable->gridmove = true;
|
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
|
||||||
p_moveable->prev_pos = p_ctransform->position;
|
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
|
||||||
p_moveable->target_pos = p_ctransform->position;
|
any_solid |= p_other_bbox->solid;
|
||||||
p_moveable->target_pos.x -= TILE_SIZE;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
sc_map_foreach_key(&tilemap.tiles[tile_idx2].entities_set, idx_to_check)
|
||||||
|
|
||||||
tile_x += 2;
|
|
||||||
if (tile_x >= 0 && tile_x < tilemap.width)
|
|
||||||
{
|
|
||||||
unsigned int tile_idx1 = tile_y * tilemap.width + tile_x;
|
|
||||||
unsigned int tile_idx2 = tile_y2 * tilemap.width + tile_x;
|
|
||||||
if (tilemap.tiles[tile_idx1].tile_type == EMPTY_TILE
|
|
||||||
&& sc_map_size_64(&tilemap.tiles[tile_idx1].entities_set) == 0
|
|
||||||
&& tilemap.tiles[tile_idx2].tile_type == EMPTY_TILE
|
|
||||||
&& sc_map_size_64(&tilemap.tiles[tile_idx2].entities_set) == 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
p_moveable->gridmove = true;
|
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
|
||||||
p_moveable->prev_pos = p_ctransform->position;
|
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
|
||||||
p_moveable->target_pos = p_ctransform->position;
|
any_solid |= p_other_bbox->solid;
|
||||||
p_moveable->target_pos.x += TILE_SIZE;
|
}
|
||||||
continue;
|
if (!any_solid)
|
||||||
|
{
|
||||||
|
can_move = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tile_x += 2;
|
||||||
|
if (tile_x >= 0 && tile_x < tilemap.width)
|
||||||
|
{
|
||||||
|
unsigned int tile_idx1 = tile_y * tilemap.width + tile_x;
|
||||||
|
unsigned int tile_idx2 = tile_y2 * tilemap.width + tile_x;
|
||||||
|
if (tilemap.tiles[tile_idx1].tile_type == EMPTY_TILE
|
||||||
|
&& tilemap.tiles[tile_idx2].tile_type == EMPTY_TILE
|
||||||
|
)
|
||||||
|
{
|
||||||
|
bool any_solid = false;
|
||||||
|
unsigned int idx_to_check;
|
||||||
|
sc_map_foreach_key(&tilemap.tiles[tile_idx1].entities_set, idx_to_check)
|
||||||
|
{
|
||||||
|
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
|
||||||
|
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
|
||||||
|
any_solid |= p_other_bbox->solid;
|
||||||
|
}
|
||||||
|
sc_map_foreach_key(&tilemap.tiles[tile_idx2].entities_set, idx_to_check)
|
||||||
|
{
|
||||||
|
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
|
||||||
|
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
|
||||||
|
any_solid |= p_other_bbox->solid;
|
||||||
|
}
|
||||||
|
if (!any_solid)
|
||||||
|
{
|
||||||
|
can_move = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (can_move)
|
||||||
|
{
|
||||||
|
p_moveable->gridmove = true;
|
||||||
|
p_moveable->prev_pos = p_ctransform->position;
|
||||||
|
p_moveable->target_pos = Vector2Scale((Vector2){tile_x,tile_y2}, TILE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue