1
Graphics / Re: Quad and mouse click collisions are consistently 3 tiles off.
« on: December 23, 2022, 08:39:48 pm »
That was it, thanks!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
for (auto& tileMap : renderAfterPlayerTM) {
tileMap->tileMap->update(player, &movement, &this->frameItem, &zoneInfo, deltaTime);
playerUpdate = movement.ghostMove(deltaTime, currentPlayerPosition, *tileMap->tileMap->getTilesGroupVector());
}
player->update(deltaTime, playerUpdate.newPosition, playerUpdate.playerPosition);
for (auto& tileMap : renderBeforePlayerTM) {
tileMap->tileMap->update(player, &movement, &this->frameItem, &zoneInfo, deltaTime);
playerUpdate = movement.ghostMove(deltaTime, currentPlayerPosition, *tileMap->tileMap->getTilesGroupVector());
}
player->update(deltaTime, playerUpdate.newPosition, playerUpdate.playerPosition);
MovePlayerResponse Movement::ghostMove(sf::Time deltaTime, sf::Vector2f playerPosition, std::vector<TileGroup*> tileGroupsVector) {
MovePlayerResponse mpr;
AnimatedSprite ghost;
ghost.setPosition(playerPosition);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
ghost.move(sf::Vector2f((-1 * speed), 0.0f));
LL::MapUpdateResponseObject collideResponse = LL::Collision::collide(ghost.getPosition(), tileGroupsVector);
mpr.playerPosition = LL::PlayerPosition::Left;
if (collideResponse.collided) {
mpr.newPosition = sf::Vector2f(speed, 0.0f);
mpr.tileNumber = collideResponse.tileNumber;
return mpr;
}
mpr.newPosition = sf::Vector2f((-1 * speed), 0.0f);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
ghost.move(sf::Vector2f((speed), 0.0f));
LL::MapUpdateResponseObject collideResponse = LL::Collision::collide(sf::Vector2f(ghost.getPosition().x, ghost.getPosition().y), tileGroupsVector);
mpr.playerPosition = LL::PlayerPosition::Right;
if (collideResponse.collided) {
mpr.newPosition = sf::Vector2f(-1 * (speed), 0.0f);
mpr.tileNumber = collideResponse.tileNumber;
return mpr;
}
mpr.newPosition = sf::Vector2f((speed), 0.0f);
}
mpr.tileNumber = -1;
return mpr;
}