Compare commits
No commits in common. "06dd1d8be98d171034246733198b7a48b119ef54" and "5bbbaa19e2b1780654dd40277ecd04ad93433b17" have entirely different histories.
06dd1d8be9
...
5bbbaa19e2
|
@ -154,14 +154,10 @@ static inline void remove_entity_from_tilemap(EntityManager_t *p_manager, TileGr
|
||||||
// Do not subtract one for the size for any collision check, just pass normally. The extra one is important for AABB test
|
// Do not subtract one for the size for any collision check, just pass normally. The extra one is important for AABB test
|
||||||
static uint8_t check_collision(const CollideEntity_t* ent, TileGrid_t* grid, bool check_oneway)
|
static uint8_t check_collision(const CollideEntity_t* ent, TileGrid_t* grid, bool check_oneway)
|
||||||
{
|
{
|
||||||
unsigned int tile_x1 = (ent->area.tile_x1 < 0) ? 0 : ent->area.tile_x1;
|
for(unsigned int tile_y = ent->area.tile_y1; tile_y <= ent->area.tile_y2; tile_y++)
|
||||||
unsigned int tile_x2 = (ent->area.tile_x2 >= grid->width) ? grid->width - 1 : ent->area.tile_x2;
|
|
||||||
unsigned int tile_y1 = (ent->area.tile_y1 < 0) ? 0 : ent->area.tile_y1;
|
|
||||||
unsigned int tile_y2 = (ent->area.tile_y2 >= grid->height) ? grid->height - 1 : ent->area.tile_y2;
|
|
||||||
|
|
||||||
for(unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
|
|
||||||
{
|
{
|
||||||
for(unsigned int tile_x = tile_x1; tile_x <= tile_x2; tile_x++)
|
if (tile_y >= grid->height) return 0;
|
||||||
|
for(unsigned int tile_x = ent->area.tile_x1; tile_x <= ent->area.tile_x2; tile_x++)
|
||||||
{
|
{
|
||||||
if (tile_x >= grid->width) return 0;
|
if (tile_x >= grid->width) return 0;
|
||||||
unsigned int tile_idx = tile_y*grid->width + tile_x;
|
unsigned int tile_idx = tile_y*grid->width + tile_x;
|
||||||
|
@ -225,17 +221,12 @@ static uint8_t check_collision(const CollideEntity_t* ent, TileGrid_t* grid, boo
|
||||||
|
|
||||||
static uint8_t check_collision_line(const CollideEntity_t* ent, TileGrid_t* grid, bool check_oneway)
|
static uint8_t check_collision_line(const CollideEntity_t* ent, TileGrid_t* grid, bool check_oneway)
|
||||||
{
|
{
|
||||||
unsigned int tile_x1 = (ent->area.tile_x1 < 0) ? 0 : ent->area.tile_x1;
|
|
||||||
unsigned int tile_x2 = (ent->area.tile_x2 >= grid->width) ? grid->width - 1 : ent->area.tile_x2;
|
|
||||||
unsigned int tile_y1 = (ent->area.tile_y1 < 0) ? 0 : ent->area.tile_y1;
|
|
||||||
unsigned int tile_y2 = (ent->area.tile_y2 >= grid->height) ? grid->height - 1 : ent->area.tile_y2;
|
|
||||||
|
|
||||||
Vector2 p1 = {ent->bbox.x, ent->bbox.y};
|
Vector2 p1 = {ent->bbox.x, ent->bbox.y};
|
||||||
Vector2 p2 = {ent->bbox.x + ent->bbox.width - 1, ent->bbox.y + ent->bbox.height - 1};
|
Vector2 p2 = {ent->bbox.x + ent->bbox.width - 1, ent->bbox.y + ent->bbox.height - 1};
|
||||||
for(unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
|
for(unsigned int tile_y = ent->area.tile_y1; tile_y <= ent->area.tile_y2; tile_y++)
|
||||||
{
|
{
|
||||||
if (tile_y >= grid->height) return 0;
|
if (tile_y >= grid->height) return 0;
|
||||||
for(unsigned int tile_x = tile_x1; tile_x <= tile_x2; tile_x++)
|
for(unsigned int tile_x = ent->area.tile_x1; tile_x <= ent->area.tile_x2; tile_x++)
|
||||||
{
|
{
|
||||||
if (tile_x >= grid->width) return 0;
|
if (tile_x >= grid->width) return 0;
|
||||||
unsigned int tile_idx = tile_y*grid->width + tile_x;
|
unsigned int tile_idx = tile_y*grid->width + tile_x;
|
||||||
|
@ -709,10 +700,7 @@ void player_movement_input_system(Scene_t* scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t collide_type = check_collision_offset(
|
uint8_t collide_type = check_collision_offset(p_player, p_ctransform->position, p_bbox->size, &tilemap, (Vector2){0, -TILE_SIZE});
|
||||||
p_player, p_ctransform->position, p_bbox->size,
|
|
||||||
&tilemap, (Vector2){0, p_bbox->size.y - PLAYER_HEIGHT}
|
|
||||||
);
|
|
||||||
if (collide_type == 1)
|
if (collide_type == 1)
|
||||||
{
|
{
|
||||||
p_pstate->is_crouch |= 0b10;
|
p_pstate->is_crouch |= 0b10;
|
||||||
|
@ -885,6 +873,7 @@ void player_crushing_system(Scene_t* scene)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Left
|
// Left
|
||||||
uint8_t collide_type = check_collision_line(&ent, &data->tilemap, false);
|
uint8_t collide_type = check_collision_line(&ent, &data->tilemap, false);
|
||||||
if (collide_type == 1)
|
if (collide_type == 1)
|
||||||
|
@ -924,12 +913,6 @@ void spike_collision_system(Scene_t* scene)
|
||||||
unsigned int tile_y1 = (p_ctransform->position.y) / TILE_SIZE;
|
unsigned int tile_y1 = (p_ctransform->position.y) / TILE_SIZE;
|
||||||
unsigned int tile_x2 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE;
|
unsigned int tile_x2 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE;
|
||||||
unsigned int tile_y2 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE;
|
unsigned int tile_y2 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE;
|
||||||
|
|
||||||
tile_x1 = (tile_x1 < 0) ? 0 : tile_x1;
|
|
||||||
tile_x2 = (tile_x2 >= tilemap.width) ? tilemap.width - 1 : tile_x2;
|
|
||||||
tile_y1 = (tile_y1 < 0) ? 0 : tile_y1;
|
|
||||||
tile_y2 = (tile_y2 >= tilemap.height) ? tilemap.height - 1 : tile_y2;
|
|
||||||
|
|
||||||
Vector2 overlap;
|
Vector2 overlap;
|
||||||
for (unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
|
for (unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
|
||||||
{
|
{
|
||||||
|
@ -991,11 +974,6 @@ void tile_collision_system(Scene_t* scene)
|
||||||
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;
|
||||||
|
|
||||||
tile_x1 = (tile_x1 < 0) ? 0 : tile_x1;
|
|
||||||
tile_x2 = (tile_x2 >= tilemap.width) ? tilemap.width - 1 : tile_x2;
|
|
||||||
tile_y1 = (tile_y1 < 0) ? 0 : tile_y1;
|
|
||||||
tile_y2 = (tile_y2 >= tilemap.height) ? tilemap.height - 1 : tile_y2;
|
|
||||||
|
|
||||||
for (unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
|
for (unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
|
||||||
{
|
{
|
||||||
for (unsigned int tile_x = tile_x1; tile_x <= tile_x2; tile_x++)
|
for (unsigned int tile_x = tile_x1; tile_x <= tile_x2; tile_x++)
|
||||||
|
|
Loading…
Reference in New Issue