Compare commits

..

No commits in common. "b5790ef00bab75b4b37890ad0aa61b3943d848fd" and "c7ef3f473f93c70753bf0ba5480ad869bbecb689" have entirely different histories.

2 changed files with 18 additions and 89 deletions

View File

@ -369,23 +369,17 @@ static void toggle_block_system(Scene_t* scene)
} }
if (tilemap.tiles[tile_idx].tile_type == SPIKES) if (tilemap.tiles[tile_idx].tile_type == SPIKES)
{ {
// Priority: Down, Up, Left, Right if (tile_idx - tilemap.width >= 0 && tilemap.tiles[tile_idx-tilemap.width].tile_type == SOLID_TILE)
if (tile_idx + tilemap.width < MAX_N_TILES && tilemap.tiles[tile_idx + tilemap.width].tile_type == SOLID_TILE)
{
tilemap.tiles[tile_idx].offset = (Vector2){0,16};
tilemap.tiles[tile_idx].size = (Vector2){32,16};
}
else if (tile_idx - tilemap.width >= 0 && tilemap.tiles[tile_idx - tilemap.width].tile_type == SOLID_TILE)
{ {
tilemap.tiles[tile_idx].offset = (Vector2){0,0}; tilemap.tiles[tile_idx].offset = (Vector2){0,0};
tilemap.tiles[tile_idx].size = (Vector2){32,16}; tilemap.tiles[tile_idx].size = (Vector2){32,16};
} }
else if (tile_idx % tilemap.width != 0 && tilemap.tiles[tile_idx - 1].tile_type == SOLID_TILE) else if (tile_idx % tilemap.width != 0 && tile_idx > 0 && tilemap.tiles[tile_idx-1].tile_type == SOLID_TILE)
{ {
tilemap.tiles[tile_idx].offset = (Vector2){0,0}; tilemap.tiles[tile_idx].offset = (Vector2){0,0};
tilemap.tiles[tile_idx].size = (Vector2){16,32}; tilemap.tiles[tile_idx].size = (Vector2){16,32};
} }
else if ((tile_idx + 1) % tilemap.width != 0 && tilemap.tiles[tile_idx + 1].tile_type == SOLID_TILE) else if (tile_idx % tilemap.width + 1 != 0 && tile_idx < MAX_N_TILES - 1 && tilemap.tiles[tile_idx+1].tile_type == SOLID_TILE)
{ {
tilemap.tiles[tile_idx].offset = (Vector2){16,0}; tilemap.tiles[tile_idx].offset = (Vector2){16,0};
tilemap.tiles[tile_idx].size = (Vector2){16,32}; tilemap.tiles[tile_idx].size = (Vector2){16,32};

View File

@ -326,7 +326,6 @@ static uint8_t check_bbox_edges(
{ {
uint8_t detected = 0; uint8_t detected = 0;
// Too lazy to adjust the tile area to check, so just make a big one
CollideEntity_t ent = CollideEntity_t ent =
{ {
.p_ent = p_ent, .p_ent = p_ent,
@ -341,6 +340,7 @@ static uint8_t check_bbox_edges(
}; };
// TODO: Handle one-way platform
// Left // Left
uint8_t collide_type = check_collision_line(&ent, tilemap, false); uint8_t collide_type = check_collision_line(&ent, tilemap, false);
if (collide_type == 1 || (collide_type == 2 && !ignore_fragile)) if (collide_type == 1 || (collide_type == 2 && !ignore_fragile))
@ -350,6 +350,8 @@ static uint8_t check_bbox_edges(
//Right //Right
ent.bbox.x = pos.x + bbox.x + 1; // 2 to account for the previous subtraction ent.bbox.x = pos.x + bbox.x + 1; // 2 to account for the previous subtraction
//ent.area.tile_x1 = (pos.x + bbox.x) / TILE_SIZE;
//ent.area.tile_x2 = ent.area.tile_x1;
collide_type = check_collision_line(&ent, tilemap, false); collide_type = check_collision_line(&ent, tilemap, false);
if (collide_type == 1 || (collide_type == 2 && !ignore_fragile)) if (collide_type == 1 || (collide_type == 2 && !ignore_fragile))
{ {
@ -361,6 +363,10 @@ static uint8_t check_bbox_edges(
ent.bbox.y = pos.y - 1; ent.bbox.y = pos.y - 1;
ent.bbox.width = bbox.x; ent.bbox.width = bbox.x;
ent.bbox.height = 1; ent.bbox.height = 1;
//ent.area.tile_x1 = (pos.x) / TILE_SIZE,
//ent.area.tile_x2 = (pos.x + bbox.x - 1) / TILE_SIZE,
//ent.area.tile_y1 = (pos.y - 1) / TILE_SIZE,
//ent.area.tile_y2 = ent.area.tile_y1;
collide_type = check_collision_line(&ent, tilemap, false); collide_type = check_collision_line(&ent, tilemap, false);
if (collide_type == 1 || (collide_type == 2 && !ignore_fragile)) if (collide_type == 1 || (collide_type == 2 && !ignore_fragile))
{ {
@ -369,7 +375,9 @@ static uint8_t check_bbox_edges(
// Down // Down
ent.bbox.y = pos.y + bbox.y + 1; ent.bbox.y = pos.y + bbox.y + 1;
collide_type = check_collision_line(&ent, tilemap, true); //ent.area.tile_y1 = (pos.y + bbox.y) / TILE_SIZE,
//ent.area.tile_y2 = ent.area.tile_y1;
collide_type = check_collision_line(&ent, tilemap, false);
if (collide_type == 1 || (collide_type == 2 && !ignore_fragile)) if (collide_type == 1 || (collide_type == 2 && !ignore_fragile))
{ {
detected |= 1; detected |= 1;
@ -716,85 +724,12 @@ void player_crushing_system(Scene_t* scene)
p_ctransform->position, p_ctransform->prev_position, p_bbox->size, true p_ctransform->position, p_ctransform->prev_position, p_bbox->size, true
); );
// There is a second check for to ensure that there is an solid entity/tile overlapping the player bbox if ((edges & 0b1100) == 0b1100 || (edges & 0b0011) == 0b0011)
// This is to prevent crushing by perfectly fitting in a gap (imagine a size 32 player in between two tiles)
// or any scenario where the edge check is just fringing, not overlapping
if ((edges & 0b0011) == 0b0011)
{
uint8_t collide = 0;
CollideEntity_t ent =
{
.p_ent = p_player,
.bbox = (Rectangle){p_ctransform->position.x, p_ctransform->position.y, p_bbox->size.x, 1},
.prev_bbox = (Rectangle){p_ctransform->position.x, p_ctransform->position.y, p_bbox->size.x, p_bbox->size.y},
.area = (TileArea_t){
.tile_x1 = (p_ctransform->position.x) / TILE_SIZE,
.tile_y1 = (p_ctransform->position.y) / TILE_SIZE,
.tile_x2 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE,
.tile_y2 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE,
}
};
uint8_t collide_type = check_collision_line(&ent, &data->tilemap, false);
if (collide_type == 1)
{
collide |= 1 << 1;
}
ent.bbox.y = p_ctransform->position.y + p_bbox->size.y;
collide_type = check_collision_line(&ent, &data->tilemap, true);
if (collide_type == 1)
{
collide |= 1;
}
if (collide != 0)
{ {
p_player->m_alive = false; p_player->m_alive = false;
return; return;
} }
} }
if ((edges & 0b1100) == 0b1100)
{
uint8_t collide = 0;
CollideEntity_t ent =
{
.p_ent = p_player,
.bbox = (Rectangle){p_ctransform->position.x, p_ctransform->position.y, 1, p_bbox->size.y},
.prev_bbox = (Rectangle){p_ctransform->position.x, p_ctransform->position.y, p_bbox->size.x, p_bbox->size.y},
.area = (TileArea_t){
.tile_x1 = (p_ctransform->position.x) / TILE_SIZE,
.tile_y1 = (p_ctransform->position.y) / TILE_SIZE,
.tile_x2 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE,
.tile_y2 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE,
}
};
// Left
uint8_t collide_type = check_collision_line(&ent, &data->tilemap, false);
if (collide_type == 1)
{
collide |= 1 << 1;
}
//Right
ent.bbox.x = p_ctransform->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)
{
collide |= 1;
}
if (collide != 0)
{
p_player->m_alive = false;
return;
}
}
}
} }
void spike_collision_system(Scene_t* scene) void spike_collision_system(Scene_t* scene)
@ -867,8 +802,8 @@ void tile_collision_system(Scene_t* scene)
// exclude self // exclude self
// This has an extra pixel when gathering potential collision, just to avoid missing any // This has an extra pixel when gathering potential collision, just to avoid missing any
// This is only done here, collision methods do not have this // This is only done here, collision methods do not have this
unsigned int tile_x1 = (p_ctransform->position.x - 1) / TILE_SIZE; unsigned int tile_x1 = (p_ctransform->position.x) / TILE_SIZE;
unsigned int tile_y1 = (p_ctransform->position.y - 1) / TILE_SIZE; unsigned int tile_y1 = (p_ctransform->position.y) / TILE_SIZE;
unsigned int tile_x2 = (p_ctransform->position.x + p_bbox->size.x) / TILE_SIZE; unsigned int tile_x2 = (p_ctransform->position.x + p_bbox->size.x) / TILE_SIZE;
unsigned int tile_y2 = (p_ctransform->position.y + p_bbox->size.y) / TILE_SIZE; unsigned int tile_y2 = (p_ctransform->position.y + p_bbox->size.y) / TILE_SIZE;