|
|
|
@ -96,7 +96,7 @@ static uint8_t check_collision(const CollideEntity_t* ent, TileGrid_t* grid, boo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: This should be a point collision check, not an AABB check
|
|
|
|
|
static bool check_collision_at(
|
|
|
|
|
static bool check_collision_offset(
|
|
|
|
|
Entity_t* p_ent, Vector2 pos, Vector2 bbox_sz,
|
|
|
|
|
TileGrid_t* grid, Vector2 offset
|
|
|
|
|
)
|
|
|
|
@ -202,7 +202,7 @@ static bool check_collision_and_move(
|
|
|
|
|
Vector2 point_to_test = {0};
|
|
|
|
|
point_to_test.x = p_ct->position.x;
|
|
|
|
|
point_to_test.y = other_pos->y - p_bbox->size.y + 1;
|
|
|
|
|
if (!check_collision_at(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
|
|
|
|
|
if (!check_collision_offset(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
|
|
|
|
|
{
|
|
|
|
|
p_ct->position = point_to_test;
|
|
|
|
|
goto collision_end;
|
|
|
|
@ -210,7 +210,7 @@ static bool check_collision_and_move(
|
|
|
|
|
|
|
|
|
|
point_to_test.x = other_pos->x - p_bbox->size.x + 1;
|
|
|
|
|
point_to_test.y = p_ct->position.y;
|
|
|
|
|
if (!check_collision_at(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
|
|
|
|
|
if (!check_collision_offset(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
|
|
|
|
|
{
|
|
|
|
|
p_ct->position = point_to_test;
|
|
|
|
|
goto collision_end;
|
|
|
|
@ -218,7 +218,7 @@ static bool check_collision_and_move(
|
|
|
|
|
|
|
|
|
|
point_to_test.x = other_pos->x + other_bbox.x - 1;
|
|
|
|
|
point_to_test.y = p_ct->position.y;
|
|
|
|
|
if (!check_collision_at(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
|
|
|
|
|
if (!check_collision_offset(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
|
|
|
|
|
{
|
|
|
|
|
p_ct->position = point_to_test;
|
|
|
|
|
goto collision_end;
|
|
|
|
@ -226,7 +226,7 @@ static bool check_collision_and_move(
|
|
|
|
|
|
|
|
|
|
point_to_test.x = p_ct->position.x;
|
|
|
|
|
point_to_test.y = other_pos->y + other_bbox.y - 1;
|
|
|
|
|
if (!check_collision_at(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
|
|
|
|
|
if (!check_collision_offset(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
|
|
|
|
|
{
|
|
|
|
|
p_ct->position = point_to_test;
|
|
|
|
|
goto collision_end;
|
|
|
|
@ -353,6 +353,22 @@ static Vector2 shift_bbox(Vector2 bbox, Vector2 new_bbox, AnchorPoint_t anchor)
|
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void player_respawn_system(Scene_t* scene)
|
|
|
|
|
{
|
|
|
|
|
Entity_t* p_player;
|
|
|
|
|
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_player)
|
|
|
|
|
{
|
|
|
|
|
if (!p_player->m_alive)
|
|
|
|
|
{
|
|
|
|
|
p_player->m_alive = true;
|
|
|
|
|
CTransform_t* p_ctransform = get_component(p_player, CTRANSFORM_COMP_T);
|
|
|
|
|
memset(&p_ctransform->position, 0, sizeof(p_ctransform->position));
|
|
|
|
|
memset(&p_ctransform->velocity, 0, sizeof(p_ctransform->velocity));
|
|
|
|
|
memset(&p_ctransform->accel, 0, sizeof(p_ctransform->accel));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void player_dir_reset_system(Scene_t* scene)
|
|
|
|
|
{
|
|
|
|
|
CPlayerState_t* p_pstate;
|
|
|
|
@ -390,15 +406,10 @@ void player_movement_input_system(Scene_t* scene)
|
|
|
|
|
p_ctransform->position.y + p_bbox->half_size.y,
|
|
|
|
|
data->tilemap.width
|
|
|
|
|
);
|
|
|
|
|
if (tilemap.tiles[tile_idx].tile_type == LADDER)
|
|
|
|
|
if (tilemap.tiles[tile_idx].tile_type == LADDER && p_ctransform->velocity.y >= 0)
|
|
|
|
|
{
|
|
|
|
|
p_pstate->ladder_state = true;
|
|
|
|
|
|
|
|
|
|
//p_ctransform->position.x = (tile_idx % tilemap.width) * TILE_SIZE;
|
|
|
|
|
if (p_mstate->ground_state & 1)
|
|
|
|
|
{
|
|
|
|
|
p_ctransform->position.y--;
|
|
|
|
|
}
|
|
|
|
|
p_ctransform->position.y--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (p_pstate->player_dir.y > 0)
|
|
|
|
@ -424,11 +435,7 @@ void player_movement_input_system(Scene_t* scene)
|
|
|
|
|
if (tile_idx < tilemap.n_tiles && tilemap.tiles[tile_idx].tile_type == LADDER)
|
|
|
|
|
{
|
|
|
|
|
p_pstate->ladder_state = true;
|
|
|
|
|
//p_ctransform->position.x = (tile_idx % tilemap.width) * TILE_SIZE;
|
|
|
|
|
if (p_mstate->ground_state & 1)
|
|
|
|
|
{
|
|
|
|
|
p_ctransform->position.y += TILE_SIZE / 2;
|
|
|
|
|
}
|
|
|
|
|
p_ctransform->position.y++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -451,6 +458,10 @@ void player_movement_input_system(Scene_t* scene)
|
|
|
|
|
{
|
|
|
|
|
p_ctransform->velocity.y = p_pstate->player_dir.y * 150;
|
|
|
|
|
p_ctransform->velocity.x = p_pstate->player_dir.x * 40;
|
|
|
|
|
if (p_pstate->player_dir.y != 0)
|
|
|
|
|
{
|
|
|
|
|
p_ctransform->position.x = tile_x * TILE_SIZE + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -582,7 +593,7 @@ void player_bbox_update_system(Scene_t* scene)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!check_collision_at(
|
|
|
|
|
!check_collision_offset(
|
|
|
|
|
p_player, p_ctransform->position, new_bbox,
|
|
|
|
|
&tilemap, offset
|
|
|
|
|
)
|
|
|
|
@ -617,15 +628,44 @@ void player_crushing_system(Scene_t* scene)
|
|
|
|
|
.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_x2 = (p_ctransform->position.x) / TILE_SIZE,
|
|
|
|
|
.tile_y2 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
if (check_collision(&ent, &tilemap, false) == 1)
|
|
|
|
|
|
|
|
|
|
// Mostly identical to edge check function
|
|
|
|
|
// Except we want collision instead of just touching
|
|
|
|
|
uint8_t detected = 0;
|
|
|
|
|
// Left
|
|
|
|
|
detected |= (check_collision(&ent, &tilemap, false) ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
//Right
|
|
|
|
|
ent.area.tile_x1 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE;
|
|
|
|
|
ent.area.tile_x2 = ent.area.tile_x1;
|
|
|
|
|
detected |= (check_collision(&ent, &tilemap, false) ? 1 : 0) << 1;
|
|
|
|
|
|
|
|
|
|
if (detected == 0b11)
|
|
|
|
|
{
|
|
|
|
|
memset(&p_ctransform->position, 0, sizeof(p_ctransform->position));
|
|
|
|
|
memset(&p_ctransform->velocity, 0, sizeof(p_ctransform->velocity));
|
|
|
|
|
memset(&p_ctransform->accel, 0, sizeof(p_ctransform->accel));
|
|
|
|
|
p_player->m_alive = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
detected = 0;
|
|
|
|
|
// Up
|
|
|
|
|
ent.area.tile_x1 = (p_ctransform->position.x) / TILE_SIZE,
|
|
|
|
|
ent.area.tile_y1 = (p_ctransform->position.y - 1) / TILE_SIZE,
|
|
|
|
|
ent.area.tile_y2 = ent.area.tile_y1;
|
|
|
|
|
detected |= (check_collision(&ent, &tilemap, false) ? 1 : 0) << 1;
|
|
|
|
|
|
|
|
|
|
// Down
|
|
|
|
|
ent.area.tile_y1 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE,
|
|
|
|
|
ent.area.tile_y2 = ent.area.tile_y1;
|
|
|
|
|
detected |= (check_collision(&ent, &tilemap, true) ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
//if (check_collision(&ent, &tilemap, false) == 1)
|
|
|
|
|
if (detected == 0b11)
|
|
|
|
|
{
|
|
|
|
|
p_player->m_alive = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|