diff options
| author | _Tradam <[email protected]> | 2021-12-16 19:22:26 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-16 19:22:26 -0500 |
| commit | 5954b9beb4d4a3b4f248d72d1851195f030558a8 (patch) | |
| tree | fecd8aa840a25afdb502915b0fdb4d03b7ed339a /samples/04_physics_and_collisions/08_bouncing_on_collision | |
| parent | 2f845281f133849256b57bb08fd3e9ae57600784 (diff) | |
| parent | eaa29e72939f5edf61735ccbb73c36ee89369f65 (diff) | |
| download | dragonruby-game-toolkit-contrib-master.tar.gz dragonruby-game-toolkit-contrib-master.zip | |
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.rb | 20 | ||||
| -rw-r--r-- | samples/04_physics_and_collisions/08_bouncing_on_collision/docs/LinearCollider.md | 26 |
2 files changed, 23 insertions, 23 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 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/> |
