int Scene::TileExists(glm::vec2 pos, int relativeCoordX, int relativeCoordY) { glm::vec2 position = glm::vec2(pos.x - (tileSize.x / 2), pos.y - (tileSize.y / 4)); glm::vec2 tileIndices = GetCurrentTile(position); return GetTileID((int)tileIndices.x + relativeCoordX, (int)tileIndices.y + relativeCoordY); }
bool Entity::DoFieldsEndOnRight(double dt, LevelPtr level) const { size_t curr_x_tile, curr_y_tile; GetCurrentTile(&curr_x_tile, &curr_y_tile); if (level->IsFieldNotCollidable(curr_x_tile + 1, curr_y_tile + 1) && level->GetFieldAabb(curr_x_tile + 1, curr_y_tile).IsOnRightOf(GetNextHorizontalAabb(dt))) { return true; } return false; }
bool Entity::DoFieldsEndOnLeft(double dt, LevelPtr level) const { size_t curr_x_tile, curr_y_tile; GetCurrentTile(&curr_x_tile, &curr_y_tile); // czy pole o jeden w lewo i w doł jest puste (None) // oraz czy jednostka jest przy krawędzi (IsOnLeftOf)... if (level->IsFieldNotCollidable(curr_x_tile - 1, curr_y_tile + 1) && level->GetFieldAabb(curr_x_tile - 1, curr_y_tile).IsOnLeftOf(GetNextHorizontalAabb(dt))) { return true; } return false; }
bool Entity::IsAnyFieldOnRight(double dt, LevelPtr level) const { size_t curr_x_tile, curr_y_tile; GetCurrentTile(&curr_x_tile, &curr_y_tile); for (int y = -1; y < 2; ++y) { if (level->IsFieldNotCollidable(curr_x_tile + 1, curr_y_tile + y)) { continue; } const Aabb field_aabb = level->GetFieldAabb(curr_x_tile + 1, curr_y_tile + y); if (GetNextHorizontalAabb(dt).IsOnLeftOf(field_aabb)) { return true; } } return false; }
bool Entity::IsAnyFieldAboveMe(double dt, LevelPtr level) const { size_t curr_x_tile, curr_y_tile; GetCurrentTile(&curr_x_tile, &curr_y_tile); for (int x = -1; x < 2; ++x) { if (level->IsFieldNotCollidable(curr_x_tile + x, curr_y_tile - 1)) { continue; } const Aabb field_aabb = level->GetFieldAabb(curr_x_tile + x, curr_y_tile - 1); if (GetNextVerticalAabb(dt).IsUnder(field_aabb)) { return true; } } return false; }
void Player::CheckCollisionsWithLevel(double dt, LevelPtr level) { size_t x_tile, y_tile; GetCurrentTile(&x_tile, &y_tile); // czy gracz wszedł w portal i należy mu się wygrana :) for (int i=-1; i<2; i++) { for (int j=-1; j<2; j++) { if (static_cast<int>(x_tile) + i < 0 || static_cast<int>(y_tile) + j < 0) continue; if (level->GetFieldAabb(x_tile + i, y_tile + j).Collides(GetNextAabb(dt)) && level->Field(x_tile + i, y_tile + j) == FT::EndOfLevel) { LevelCompleted(); } } } // czy postać koliduje z czymś od góry if (IsAnyFieldAboveMe(dt, level)) { Fall(); } // czy postać koliduje z czymś od dołu if (IsAnyFieldBelowMe(dt, level)) { PlayerOnGround(); } // czy postać koliduje z czymś po lewej stronie if (IsAnyFieldOnLeft(dt, level)) { ForbidGoingLeft(); } // czy postać koliduje z czymś po prawej stronie if (IsAnyFieldOnRight(dt, level)) { ForbidGoingRight(); } }
void Scene::SnapToY(glm::vec2 &pos, int offset) { glm::vec2 position = glm::vec2(pos.x - (tileSize.x / 2), pos.y); pos.y = (GetCurrentTile(position).y + offset) * tileSize.y + 3; }
void Scene::SnapToX(glm::vec2 &pos, int offset) { pos.x = (GetCurrentTile(pos).x + offset) * tileSize.x; }