Skip to content

Instantly share code, notes, and snippets.

@SpaceShot
Created August 13, 2012 12:22
Show Gist options
  • Save SpaceShot/3340138 to your computer and use it in GitHub Desktop.
Save SpaceShot/3340138 to your computer and use it in GitHub Desktop.
Calculate Bounce based on where the clown hits for breakout style returns
// calculate bounce based on distance from clown center to trampoline center
int angle = trampolineRectangle.Center.X - clownRectangle.Center.X + 90;
float newY = 800 * (float)Math.Sin(MathHelper.ToRadians((float)(angle)));
float newX = 800 * (float)Math.Cos(MathHelper.ToRadians((float)(angle)));
clown.Velocity.X = newX;
clown.Velocity.Y = newY;
clown.Velocity.Y *= -1;
clown.Position.Y = trampolinePosition.Y - clown.Texture.Height;
bounce.Play();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment