Permalink
Browse files

Angle in radians is better

  • Loading branch information...
1 parent 596f0b9 commit fa2621897d0bcb1923eda179fbb6ea1256afe22d @semaperepelitsa committed Dec 15, 2011
Showing with 5 additions and 5 deletions.
  1. +5 −5 lib/ball.rb
View
@@ -7,15 +7,15 @@ class Ball < GameObject
def reset
@x = 200
@y = 200
- @angle = 45
+ @angle = 0.25
end
def update(container, delta)
- @x += 0.3 * delta * Math.cos(@angle * Math::PI / 180)
- @y -= 0.3 * delta * Math.sin(@angle * Math::PI / 180)
+ @x += 0.3 * delta * Math.cos(@angle * Math::PI)
+ @y -= 0.3 * delta * Math.sin(@angle * Math::PI)
if (@x > container.width - width) || (@y < 0) || (@x < 0)
- @angle = (@angle + 90) % 360
+ @angle = (@angle + 0.5) % 2
end
if @y > container.height
@@ -25,7 +25,7 @@ def update(container, delta)
if @y + height > paddle.y and
@x < paddle.x + paddle.width and
@x + width > paddle.x
- @angle = (@angle + 80 + rand(20) - 10) % 360
+ @angle = (@angle + 0.5 + rand(0.2) - 0.1) % 2
end
end

0 comments on commit fa26218

Please sign in to comment.