1
General / Re: Collision issue
« on: November 02, 2013, 01:25:14 pm »
Thanks and i found that peice of code on an example of a pong implementation in SFML.
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.
bool player::isCollidingSide(gameBall& gameball)
{
if(right > gameball.left|| left < gameball.right ||
top > gameball.bottom || bottom < gameball.top)
{
return false;
}
return true;
}
void game::update(float &deltatime)
{
sf::Vector2f movement(0.f, 0.f);
if (mIsMovingUp)
movement.y -= 0.01f;
if (mIsMovingDown)
movement.y += 0.01f;
player.rect.move(movement*playerspeed);
float factor=ballspeed*deltatime;
balll.ballShape.move(xvel*ballspeed, yvel*ballspeed);
if(player.isCollidingSide(balll))
{
xvel = -xvel;
std::cout<<"Collision x";
}
}
void Ball::accelerate(Paddle PLAYER)
{
currentSpeed.y = (ballObject.getGlobalBounds().top
+ ballObject.getGlobalBounds().height / 2
- PLAYER.getRect().top
- PLAYER.getRect().height / 2) / 100;
}