Last active
August 29, 2015 14:02
-
-
Save Syntaf/de401a9689432474e9ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sf::Vector2f ball_current_speed(0,0); //ball starts with no movement, OK | |
// Lets say the game begun, we launch the ball in a random direction | |
// e.g. one program execution would make: ball_current_speed = (9,4) | |
// if you remember good' ol math, you can use the pythangorean theorem to find | |
// it's actual speed, which in this case is sqrt(9^2 + 4^2) | |
ball_current_speed += sf::Vector2f(rand()%10,rand()%10); | |
//stuff happends | |
// Now we saw it touched a paddle, so we want to deflect the ball in the opposite | |
// direction, meaning we want to reverse it's x & y speed vector. If you think | |
// about it this will simulate a paddle deflecting a ball | |
ball_current_speed.x = -ball_current_speed.x; | |
ball_current_speed.y = -ball_current_speed.y; | |
// It's important to realize this is the SPEED vector, not a POSITION vector. The | |
// position vector will be manipulated using the speed vector! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment