summaryrefslogtreecommitdiffhomepage
path: root/samples/04_physics_and_collisions/08_bouncing_on_collision
diff options
context:
space:
mode:
authorAmir Rajan <[email protected]>2021-08-07 00:13:33 -0500
committerAmir Rajan <[email protected]>2021-08-07 00:13:33 -0500
commita503afe87619ff82201c0a43818fa1c3f070a548 (patch)
tree0b228a6456d17f6d0c6ea54c9ecd6a045ddbdf59 /samples/04_physics_and_collisions/08_bouncing_on_collision
parentbea150381f495630f92f89d23d5f3445ec289b2d (diff)
downloaddragonruby-game-toolkit-contrib-a503afe87619ff82201c0a43818fa1c3f070a548.tar.gz
dragonruby-game-toolkit-contrib-a503afe87619ff82201c0a43818fa1c3f070a548.zip
Samples folder synced.
Diffstat (limited to 'samples/04_physics_and_collisions/08_bouncing_on_collision')
-rw-r--r--samples/04_physics_and_collisions/08_bouncing_on_collision/app/block.rb8
-rw-r--r--samples/04_physics_and_collisions/08_bouncing_on_collision/app/main.rb2
-rw-r--r--samples/04_physics_and_collisions/08_bouncing_on_collision/app/peg.rb18
-rw-r--r--samples/04_physics_and_collisions/08_bouncing_on_collision/app/vector2d.rb2
-rw-r--r--samples/04_physics_and_collisions/08_bouncing_on_collision/docs/LinearCollider.md26
5 files changed, 28 insertions, 28 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 db6687a..9254ee4 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
@@ -110,8 +110,8 @@ class Block
#Find the vector that is perpendicular to the slope
perpVect = { x: x, y: y }
- mag = (perpVect.x**2 + perpVect.y**2)**0.5 # find the magnitude of the perpVect
- perpVect = {x: perpVect.x/(mag), y: perpVect.y/(mag)} # divide the perpVect by the magnitude to make it a unit vector
+ mag = (perpVect.x**2 + perpVect.y**2)**0.5 # find the magniude of the perpVect
+ perpVect = {x: perpVect.x/(mag), y: perpVect.y/(mag)} # divide the perpVect by the magniude to make it a unit vector
previousPosition = { # calculate an ESTIMATE of the previousPosition of the ball
x:args.state.ball.center.x-args.state.ball.velocity.x,
@@ -140,7 +140,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 dampen the X velocity
+ #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
end
@@ -152,7 +152,7 @@ class Block
args.state.ball.velocity.x = -xnew
args.state.ball.velocity.y = -ynew
- #Set the position of the ball to the previous position so it doesn't warp through the block
+ #Set the position of the ball to the previous position so it doesn't warp throught the block
args.state.ball.center.x = previousPosition.x
args.state.ball.center.y = previousPosition.y
end
diff --git a/samples/04_physics_and_collisions/08_bouncing_on_collision/app/main.rb b/samples/04_physics_and_collisions/08_bouncing_on_collision/app/main.rb
index 22d3711..f5883ad 100644
--- a/samples/04_physics_and_collisions/08_bouncing_on_collision/app/main.rb
+++ b/samples/04_physics_and_collisions/08_bouncing_on_collision/app/main.rb
@@ -60,7 +60,7 @@ begin :default_methods
center = args.grid.w / 2
for i in (0...5)
- #Create a ramp of blocks. Not going to be perfect because of the float to integer conversion and anisotropic to isotropic conversion
+ #Create a ramp of blocks. Not going to be perfect because of the float to integer conversion and anisotropic to isotropic coversion
args.state.blocks.append(Block.new((center + 100 + (i * horizontal_offset)).to_i, 100 + (vertical_offset * i) + (i * block_size), block_size, rotation))
args.state.blocks.append(Block.new((center - 100 - (i * horizontal_offset)).to_i, 100 + (vertical_offset * i) + (i * block_size), block_size, -rotation))
end
diff --git a/samples/04_physics_and_collisions/08_bouncing_on_collision/app/peg.rb b/samples/04_physics_and_collisions/08_bouncing_on_collision/app/peg.rb
index daf95ec..52045de 100644
--- a/samples/04_physics_and_collisions/08_bouncing_on_collision/app/peg.rb
+++ b/samples/04_physics_and_collisions/08_bouncing_on_collision/app/peg.rb
@@ -1,11 +1,11 @@
class Peg
def initialize(x, y, block_size)
- @x = x # x coordinate of the LEFT side of the peg
- @y = y # y coordinate of the RIGHT side of the peg
+ @x = x # x cordinate of the LEFT side of the peg
+ @y = y # y cordinate of the RIGHT side of the peg
@block_size = block_size # diameter of the peg
@radius = @block_size/2.0 # radius of the peg
- @center = { # coordinatees of the CENTER of the peg
+ @center = { # cordinatees of the CENTER of the peg
x: @x+@block_size/2.0,
y: @y+@block_size/2.0
}
@@ -116,8 +116,8 @@ class Peg
}
perpVect = {x: pointB.x - pointA.x, y:pointB.y - pointA.y} # perpVect is to be VECTOR of the perpendicular tangent
- mag = (perpVect.x**2 + perpVect.y**2)**0.5 # find the magnitude of the perpVect
- perpVect = {x: perpVect.x/(mag), y: perpVect.y/(mag)} # divide the perpVect by the magnitude to make it a unit vector
+ mag = (perpVect.x**2 + perpVect.y**2)**0.5 # find the magniude of the perpVect
+ perpVect = {x: perpVect.x/(mag), y: perpVect.y/(mag)} # divide the perpVect by the magniude to make it a unit vector
perpVect = {x: -perpVect.y, y: perpVect.x} # swap the x and y and multiply by -1 to make the vector perpendicular
args.state.display_value = perpVect
if perpVect.y > 0 #ensure perpVect points upward
@@ -130,12 +130,12 @@ class Peg
}
yInterc = pointA.y + -slope*pointA.x
- if slope == INFINITY # the perpVect presently either points in the correct direction or it is 180 degrees off we need to correct this
+ if slope == INFINITY # the perpVect presently either points in the correct dirrection or it is 180 degrees off we need to correct this
if previousPosition.x < pointA.x
perpVect = {x: perpVect.x*-1, y: perpVect.y*-1}
yInterc = -INFINITY
end
- elsif previousPosition.y < slope*previousPosition.x + yInterc # check if ball is below or above the collider to determine if perpVect is - or +
+ elsif previousPosition.y < slope*previousPosition.x + yInterc # check if ball is bellow or above the collider to determine if perpVect is - or +
perpVect = {x: perpVect.x*-1, y: perpVect.y*-1}
end
@@ -148,7 +148,7 @@ class Peg
fbx = velocityMag * Math.cos(theta_ball) #the x component of the ball's velocity
fby = velocityMag * Math.sin(theta_ball) #the y component of the ball's velocity
- repelMag = getRepelMagnitude( # the magnitude of the collision vector
+ repelMag = getRepelMagnitude( # the magniude of the collision vector
args,
fbx,
fby,
@@ -173,7 +173,7 @@ class Peg
if args.state.ball.center.y > @center.y # if the ball is above the middle of the peg we need to temporarily ignore some of the gravity
args.state.ball.velocity.y = ynew + GRAVITY * 0.01
else
- args.state.ball.velocity.y = ynew - GRAVITY * 0.01 # if the ball is below the middle of the peg we need to temporarily increase the power of the gravity
+ args.state.ball.velocity.y = ynew - GRAVITY * 0.01 # if the ball is bellow the middle of the peg we need to temporarily increase the power of the gravity
end
args.state.ball.center.x+= args.state.ball.velocity.x # update the position of the ball so it never looks like the ball is intersecting the circle
diff --git a/samples/04_physics_and_collisions/08_bouncing_on_collision/app/vector2d.rb b/samples/04_physics_and_collisions/08_bouncing_on_collision/app/vector2d.rb
index 0b302f3..9cb1954 100644
--- a/samples/04_physics_and_collisions/08_bouncing_on_collision/app/vector2d.rb
+++ b/samples/04_physics_and_collisions/08_bouncing_on_collision/app/vector2d.rb
@@ -42,7 +42,7 @@ class Vector2d
Vector2d.new(@x/mag, @y/mag)
end
- #TODO delete?
+ #TODO delet?
def distABS vect
(((vect.x-@x)**2+(vect.y-@y)**2)**0.5).abs()
end
diff --git a/samples/04_physics_and_collisions/08_bouncing_on_collision/docs/LinearCollider.md b/samples/04_physics_and_collisions/08_bouncing_on_collision/docs/LinearCollider.md
index 41227a2..315ecf8 100644
--- a/samples/04_physics_and_collisions/08_bouncing_on_collision/docs/LinearCollider.md
+++ b/samples/04_physics_and_collisions/08_bouncing_on_collision/docs/LinearCollider.md
@@ -1,13 +1,13 @@
-<br/>
-<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_1.png?raw=true" width="300" height="271">
-<br/>
-<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_2.png?raw=true" width="300" height="271">
-<br/>
-<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_3.png?raw=true" width="300" height="271">
-<br/>
-<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_4.png?raw=true" width="634" height="72">
-<br/>
-<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_5.png?raw=true" width="1226" height="92">
-<br/>
-<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_6.png?raw=true" width="300" height="271">
-<br/>
+<br/>
+<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_1.png?raw=true" width="300" height="271">
+<br/>
+<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_2.png?raw=true" width="300" height="271">
+<br/>
+<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_3.png?raw=true" width="300" height="271">
+<br/>
+<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_4.png?raw=true" width="634" height="72">
+<br/>
+<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_5.png?raw=true" width="1226" height="92">
+<br/>
+<img src="https://github.com/DragonRuby/dragonruby-game-toolkit-physics/blob/master/docs/docImages/LinearCollider_6.png?raw=true" width="300" height="271">
+<br/>