summaryrefslogtreecommitdiffhomepage
path: root/samples/04_physics_and_collisions/08_bouncing_on_collision/app/block.rb
diff options
context:
space:
mode:
Diffstat (limited to 'samples/04_physics_and_collisions/08_bouncing_on_collision/app/block.rb')
-rw-r--r--samples/04_physics_and_collisions/08_bouncing_on_collision/app/block.rb20
1 files changed, 10 insertions, 10 deletions
diff --git a/samples/04_physics_and_collisions/08_bouncing_on_collision/app/block.rb b/samples/04_physics_and_collisions/08_bouncing_on_collision/app/block.rb
index 9254ee4..ca0cb3a 100644
--- a/samples/04_physics_and_collisions/08_bouncing_on_collision/app/block.rb
+++ b/samples/04_physics_and_collisions/08_bouncing_on_collision/app/block.rb
@@ -1,14 +1,14 @@
DEGREES_TO_RADIANS = Math::PI / 180
-class Block
+class Block
def initialize(x, y, block_size, rotation)
@x = x
- @y = y
+ @y = y
@block_size = block_size
@rotation = rotation
#The repel velocity?
- @velocity = {x: 2, y: 0}
+ @velocity = {x: 2, y: 0}
horizontal_offset = (3 * block_size) * Math.cos(rotation * DEGREES_TO_RADIANS)
vertical_offset = block_size * Math.sin(rotation * DEGREES_TO_RADIANS)
@@ -36,7 +36,7 @@ class Block
@imaginary_line = [ @x1, @y1, @x2, @y2 ]
end
-
+
end
def draw args
@@ -80,7 +80,7 @@ class Block
collision = false
if @rotation >= 0
- if (current_area < min_area &&
+ if (current_area < min_area &&
current_area > 0 &&
args.state.ball.center.y > @y1 &&
args.state.ball.center.x < @x2)
@@ -88,7 +88,7 @@ class Block
collision = true
end
else
- if (current_area < min_area &&
+ if (current_area < min_area &&
current_area > 0 &&
args.state.ball.center.y > @y2 &&
args.state.ball.center.x > @x1)
@@ -96,7 +96,7 @@ class Block
collision = true
end
end
-
+
return collision
end
@@ -117,7 +117,7 @@ class Block
x:args.state.ball.center.x-args.state.ball.velocity.x,
y:args.state.ball.center.y-args.state.ball.velocity.y
}
-
+
velocityMag = (args.state.ball.velocity.x**2 + args.state.ball.velocity.y**2)**0.5 # the current velocity magnitude of the ball
theta_ball = Math.atan2(args.state.ball.velocity.y, args.state.ball.velocity.x) #the angle of the ball's velocity
theta_repel = (180 * DEGREES_TO_RADIANS) - theta_ball + (@rotation * DEGREES_TO_RADIANS)
@@ -139,7 +139,7 @@ class Block
dampener = 0.3
ynew *= dampener * 0.5
-
+
#If the bounce is very low, that means the ball is rolling and we don't want to dampenen the X velocity
if ynew > -0.1
xnew *= dampener
@@ -148,7 +148,7 @@ class Block
#Add the sine component of gravity back in (X component)
gravity_x = 4 * Math.sin(@rotation * DEGREES_TO_RADIANS)
xnew += gravity_x
-
+
args.state.ball.velocity.x = -xnew
args.state.ball.velocity.y = -ynew