mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 21:23:41 +00:00
Hotfix only calculate for player
This commit is contained in:
parent
8ff81ace72
commit
0c1c9a7f84
18
src/Game.cpp
18
src/Game.cpp
@ -159,24 +159,6 @@ void Game::update()
|
|||||||
manager.refresh();
|
manager.refresh();
|
||||||
manager.update();
|
manager.update();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*for (auto cc : Game::collisionHandler->getColliders(GroupLabel::COLLIDERS))
|
|
||||||
{
|
|
||||||
if (cc->hasCollision &&
|
|
||||||
strcmp(cc->tag, "player") &&
|
|
||||||
SDL_HasIntersection(&player1.getComponent<ColliderComponent>().collider, &cc->collider))
|
|
||||||
{
|
|
||||||
player1.getComponent<TransformComponent>().position = playerPos;
|
|
||||||
}
|
|
||||||
if (cc->hasCollision &&
|
|
||||||
strcmp(cc->tag, "enemy") &&
|
|
||||||
SDL_HasIntersection(&player2.getComponent<ColliderComponent>().collider, &cc->collider))
|
|
||||||
{
|
|
||||||
player2.getComponent<TransformComponent>().position = enemyPos;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//checking if projectiles hit player1 or player2
|
//checking if projectiles hit player1 or player2
|
||||||
for (auto& p : projectiles) {
|
for (auto& p : projectiles) {
|
||||||
if(SDL_HasIntersection(&player2.getComponent<ColliderComponent>().collider, &p->getComponent<ColliderComponent>().collider)
|
if(SDL_HasIntersection(&player2.getComponent<ColliderComponent>().collider, &p->getComponent<ColliderComponent>().collider)
|
||||||
|
|||||||
@ -56,34 +56,40 @@ void TransformComponent::update()
|
|||||||
velocity.y * speed * multiplier
|
velocity.y * speed * multiplier
|
||||||
);
|
);
|
||||||
|
|
||||||
IntersectionBitSet intersectionsX = CollisionHandler::getIntersectionWithBounds(entity, positionChange);
|
// TODO: move to separate functions
|
||||||
for (auto& collider : Game::collisionHandler->getColliders(GroupLabel::MAPTILES)) {
|
|
||||||
intersectionsX |= CollisionHandler::getIntersection(entity, collider->entity, Vector2D(positionChange.x, 0), Vector2D(0, 0));
|
if (this->entity->hasGroup((size_t) GroupLabel::PLAYERS)) {
|
||||||
|
IntersectionBitSet intersectionsX = CollisionHandler::getIntersectionWithBounds(entity, positionChange);
|
||||||
|
for (auto& collider : Game::collisionHandler->getColliders(GroupLabel::MAPTILES)) {
|
||||||
|
intersectionsX |= CollisionHandler::getIntersection(entity, collider->entity, Vector2D(positionChange.x, 0), Vector2D(0, 0));
|
||||||
|
}
|
||||||
|
for (auto& collider : Game::collisionHandler->getColliders(GroupLabel::COLLIDERS)) {
|
||||||
|
intersectionsX |= CollisionHandler::getIntersection(entity, collider->entity, Vector2D(positionChange.x, 0), Vector2D(0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
IntersectionBitSet intersectionsY = CollisionHandler::getIntersectionWithBounds(entity, positionChange);
|
||||||
|
for (auto& collider : Game::collisionHandler->getColliders(GroupLabel::MAPTILES)) {
|
||||||
|
intersectionsY |= CollisionHandler::getIntersection(entity, collider->entity, Vector2D(0, positionChange.y), Vector2D(0, 0));
|
||||||
|
}
|
||||||
|
for (auto& collider : Game::collisionHandler->getColliders(GroupLabel::COLLIDERS)) {
|
||||||
|
intersectionsY |= CollisionHandler::getIntersection(entity, collider->entity, Vector2D(0, positionChange.y), Vector2D(0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->entity->hasGroup((size_t) GroupLabel::PLAYERS) && this->entity->getTeam() == TeamLabel::BLUE)
|
||||||
|
std::cout << intersectionsX << std::endl;
|
||||||
|
|
||||||
|
if (intersectionsX.test((size_t) direction::LEFT) && positionChange.x < 0)
|
||||||
|
positionChange.x = 0;
|
||||||
|
|
||||||
|
if (intersectionsX.test((size_t) direction::RIGHT) && positionChange.x > 0)
|
||||||
|
positionChange.x = 0;
|
||||||
|
|
||||||
|
if (intersectionsY.test((size_t) direction::UP) && positionChange.y < 0)
|
||||||
|
positionChange.y = 0;
|
||||||
|
|
||||||
|
if (intersectionsY.test((size_t) direction::DOWN) && positionChange.y > 0)
|
||||||
|
positionChange.y = 0;
|
||||||
}
|
}
|
||||||
for (auto& collider : Game::collisionHandler->getColliders(GroupLabel::COLLIDERS)) {
|
|
||||||
intersectionsX |= CollisionHandler::getIntersection(entity, collider->entity, Vector2D(positionChange.x, 0), Vector2D(0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
IntersectionBitSet intersectionsY = CollisionHandler::getIntersectionWithBounds(entity, positionChange);
|
|
||||||
for (auto& collider : Game::collisionHandler->getColliders(GroupLabel::MAPTILES)) {
|
|
||||||
intersectionsY |= CollisionHandler::getIntersection(entity, collider->entity, Vector2D(0, positionChange.y), Vector2D(0, 0));
|
|
||||||
}
|
|
||||||
for (auto& collider : Game::collisionHandler->getColliders(GroupLabel::COLLIDERS)) {
|
|
||||||
intersectionsY |= CollisionHandler::getIntersection(entity, collider->entity, Vector2D(0, positionChange.y), Vector2D(0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (intersectionsX.test((size_t) direction::LEFT) && positionChange.x < 0)
|
|
||||||
positionChange.x = 0;
|
|
||||||
|
|
||||||
if (intersectionsX.test((size_t) direction::RIGHT) && positionChange.x > 0)
|
|
||||||
positionChange.x = 0;
|
|
||||||
|
|
||||||
if (intersectionsY.test((size_t) direction::UP) && positionChange.y < 0)
|
|
||||||
positionChange.y = 0;
|
|
||||||
|
|
||||||
if (intersectionsY.test((size_t) direction::DOWN) && positionChange.y > 0)
|
|
||||||
positionChange.y = 0;
|
|
||||||
|
|
||||||
position += positionChange;
|
position += positionChange;
|
||||||
|
|
||||||
};
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user