Skip to content

Commit

Permalink
variable angle of ball after bat
Browse files Browse the repository at this point in the history
  • Loading branch information
silvansky committed Aug 1, 2012
1 parent 58973ed commit a0202a5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions SimpleArkanoid/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,14 @@ - (void)update
[self endGameWithWin:NO];
}

// player got it
// player strikes!
if (CGRectIntersectsRect(self.ball.boundingRect, self.playerBat.boundingRect))
{
self.ball.moveVelocity = GLKVector2Make(self.ball.moveVelocity.x, -self.ball.moveVelocity.y);
float angleCoef = (self.ball.position.x - self.playerBat.position.x) / (self.playerBat.contentSize.width / 2);
float newAngle = 90.f - angleCoef * 80.f;
GLKVector2 ballDirection = GLKVector2Normalize(GLKVector2Make(1 / tanf(GLKMathDegreesToRadians(newAngle)), 1));
float ballSpeed = GLKVector2Length(self.ball.moveVelocity);
self.ball.moveVelocity = GLKVector2MultiplyScalar(ballDirection, ballSpeed);
self.ball.position = GLKVector2Make(self.ball.position.x, self.ball.position.y + (self.playerBat.boundingRect.origin.y + self.playerBat.boundingRect.size.height - self.ball.boundingRect.origin.y));
}

Expand Down

0 comments on commit a0202a5

Please sign in to comment.