Compare commits
4 Commits
c7ef3f473f
...
b5790ef00b
Author | SHA1 | Date |
---|---|---|
|
b5790ef00b | |
|
491f0bcbef | |
|
7a670f85fc | |
|
e79fb249d2 |
|
@ -369,17 +369,23 @@ static void toggle_block_system(Scene_t* scene)
|
||||||
}
|
}
|
||||||
if (tilemap.tiles[tile_idx].tile_type == SPIKES)
|
if (tilemap.tiles[tile_idx].tile_type == SPIKES)
|
||||||
{
|
{
|
||||||
if (tile_idx - tilemap.width >= 0 && tilemap.tiles[tile_idx-tilemap.width].tile_type == SOLID_TILE)
|
// Priority: Down, Up, Left, Right
|
||||||
|
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 && tile_idx > 0 && tilemap.tiles[tile_idx-1].tile_type == SOLID_TILE)
|
else if (tile_idx % tilemap.width != 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 % tilemap.width + 1 != 0 && tile_idx < MAX_N_TILES - 1 && tilemap.tiles[tile_idx+1].tile_type == SOLID_TILE)
|
else if ((tile_idx + 1) % tilemap.width != 0 && 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};
|
||||||
|
|
|
@ -326,6 +326,7 @@ 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,
|
||||||
|
@ -340,7 +341,6 @@ 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,8 +350,6 @@ 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))
|
||||||
{
|
{
|
||||||
|
@ -363,10 +361,6 @@ 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))
|
||||||
{
|
{
|
||||||
|
@ -375,9 +369,7 @@ static uint8_t check_bbox_edges(
|
||||||
|
|
||||||
// Down
|
// Down
|
||||||
ent.bbox.y = pos.y + bbox.y + 1;
|
ent.bbox.y = pos.y + bbox.y + 1;
|
||||||
//ent.area.tile_y1 = (pos.y + bbox.y) / TILE_SIZE,
|
collide_type = check_collision_line(&ent, tilemap, true);
|
||||||
//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;
|
||||||
|
@ -724,12 +716,85 @@ 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
|
||||||
);
|
);
|
||||||
|
|
||||||
if ((edges & 0b1100) == 0b1100 || (edges & 0b0011) == 0b0011)
|
// There is a second check for to ensure that there is an solid entity/tile overlapping the player bbox
|
||||||
|
// 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)
|
||||||
|
@ -802,8 +867,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) / TILE_SIZE;
|
unsigned int tile_x1 = (p_ctransform->position.x - 1) / TILE_SIZE;
|
||||||
unsigned int tile_y1 = (p_ctransform->position.y) / TILE_SIZE;
|
unsigned int tile_y1 = (p_ctransform->position.y - 1) / 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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue