From d5ccd4ea0d174c733d3fb57f520d261aeccfb8dc Mon Sep 17 00:00:00 2001 From: tradam Date: Mon, 16 Aug 2021 06:53:20 -0400 Subject: . --- run.rb | 67 +++++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/run.rb b/run.rb index 35f1860..5b56448 100644 --- a/run.rb +++ b/run.rb @@ -1,9 +1,11 @@ require 'ruby2d' require 'ruby2d/camera' +#DEBUG: used to colour all debug lines unique colours $colors = ['blue', 'teal', 'green', 'lime', 'yellow', 'orange', 'red', 'fuchsia'] +#DEBUG: used to draw, store and update debug lines class DebugLines class < amax @@ -77,6 +94,7 @@ def hitbox_check(shape_a, shape_b) end end + # Determine max and min of b_shape shape_b.each_with_index do |vertex, vertex_index| dot = vecDotProd(vertex, line) if dot > bmax @@ -86,6 +104,9 @@ def hitbox_check(shape_a, shape_b) end end + #DEBUG: display the lines, transluscent if they are not "seperating" + # If all lines are transluscent then the logic believes the + # shapes are colliding if line_index < shape_a.length DebugLines[line_index].x1 = shape_a[line_index][0] DebugLines[line_index].y1 = shape_a[line_index][1] @@ -108,6 +129,8 @@ def hitbox_check(shape_a, shape_b) end end DebugLines[line_index].color = $colors[line_index % $colors.length] + + #DEBUG: print out line information if $i == 0 puts puts $colors[line_index % $colors.length] @@ -119,17 +142,20 @@ def hitbox_check(shape_a, shape_b) puts "(((#{amin} < #{bmax}) && (#{amin} > #{bmin})) || ((#{bmin} < #{amax}) && (#{bmin} > #{amin})))" end if (((amin <= bmax) && (amin >= bmin)) || ((bmin <= amax) && (bmin >= amin))) - DebugLines[line_index].color.a = 0.2# = 'red' - #next + DebugLines[line_index].color.a = 0.2 else - DebugLines[line_index].color.a = 1.0# = 'green' + DebugLines[line_index].color.a = 1.0 + + # The logic should end the calculations early once it detects lack of collision + # however for debug purposes this is disabled #return false end + + #DEBUG: make the debug lines effectively infinitly long tempx1 = DebugLines[line_index].x1 tempx2 = DebugLines[line_index].x2 tempy1 = DebugLines[line_index].y1 tempy2 = DebugLines[line_index].y2 - DebugLines[line_index].x1 = (tempx1 *(1+1000)/2) + (tempx2 * (1-1000)/2) DebugLines[line_index].y1 = (tempy1 *(1+1000)/2) + (tempy2 * (1-1000)/2) DebugLines[line_index].x2 = (tempx2 *(1+1000)/2) + (tempx1 * (1-1000)/2) @@ -138,9 +164,7 @@ def hitbox_check(shape_a, shape_b) true end -#puts "should be false: #{hitbox(@sqr1, @tri1)}" -#puts "should be true: #{hitbox(@sqr2, @tri2)}" - +# Move camera on :key_held do |event| if event.key == 'w' Camera.y -= 5 @@ -156,18 +180,23 @@ on :key_held do |event| end end +# Initialize frame counter +# resets to 0 periodically by a set amount $i = 0 -#$line = Camera::Line.new(color: 'red', -# width: 5, z: 99) - +# "Game" loop update do + # Advance frame $i += 1 + + # Reset every 5 frames $i %= 5 + + # Update shape 1 position to mouse s1.x = Camera.coordinate_to_worldspace(get(:mouse_x),0)[0] s1.y = Camera.coordinate_to_worldspace(0, get(:mouse_y))[1] - $x = s1.x - $y = s1.y + + # Check hitboxes a = hitbox_check( [[s2.x1, s2.y1], [s2.x2, s2.y2], @@ -178,11 +207,8 @@ update do [s1.x3 + s1.x, s1.y3 + s1.y], [s1.x4 + s1.x, s1.y4 + s1.y]], ) - if a - #s1.color = 'orange' - else - s1.color = 'aqua' - end + + #DEBUG if $i == 0 pp [[s2.x1, s2.y1], [s2.x2, s2.y2], @@ -192,7 +218,6 @@ update do [s1.x2 + s1.x, s1.y2 + s1.y], [s1.x3 + s1.x, s1.y3 + s1.y], [s1.x4 + s1.x, s1.y4 + s1.y]] - puts a end end -- cgit v1.2.3