From 611c4ceefdc94fbd4a4bd15ad65309d64cac8a8a Mon Sep 17 00:00:00 2001 From: tradam Date: Sun, 15 Aug 2021 12:28:21 -0400 Subject: . --- Gemfile | 11 ++++ Gemfile.lock | 16 +++++ run.rb | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 227 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 run.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..94ab5da --- /dev/null +++ b/Gemfile @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } + +# gem "rails" + +gem "ruby2d", "~> 0.10.0" + +gem "ruby2d-camera", "~> 1.1" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..8b212cb --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,16 @@ +GEM + remote: https://rubygems.org/ + specs: + ruby2d (0.10.0) + ruby2d-camera (1.1.0) + ruby2d (~> 0.10) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + ruby2d (~> 0.10.0) + ruby2d-camera (~> 1.1) + +BUNDLED WITH + 2.2.22 diff --git a/run.rb b/run.rb new file mode 100644 index 0000000..35f1860 --- /dev/null +++ b/run.rb @@ -0,0 +1,200 @@ +require 'ruby2d' +require 'ruby2d/camera' + +$colors = ['blue', 'teal', 'green', 'lime', + 'yellow', 'orange', 'red', 'fuchsia'] + +class DebugLines + class < amax + amax = dot + elsif dot < amin + amin = dot + end + end + + shape_b.each_with_index do |vertex, vertex_index| + dot = vecDotProd(vertex, line) + if dot > bmax + bmax = dot + elsif dot < bmin + bmin = dot + end + end + + if line_index < shape_a.length + DebugLines[line_index].x1 = shape_a[line_index][0] + DebugLines[line_index].y1 = shape_a[line_index][1] + if shape_a[line_index].nil? + DebugLines[line_index].x2 = shape_a[line_index + 1][0] + DebugLines[line_index].y2 = shape_a[line_index + 1][1] + else + DebugLines[line_index].x2 = shape_a[0][0] + DebugLines[line_index].y2 = shape_a[0][1] + end + else + DebugLines[line_index].x1 = shape_b[line_index - shape_a.length][0] + DebugLines[line_index].y1 = shape_b[line_index - shape_a.length][1] + if shape_a[line_index - shape_a.length + 1].nil? + DebugLines[line_index].x2 = shape_b[0][0] + DebugLines[line_index].y2 = shape_b[0][1] + else + DebugLines[line_index].x2 = shape_b[line_index - shape_a.length + 1][0] + DebugLines[line_index].y2 = shape_b[line_index - shape_a.length + 1][1] + end + end + DebugLines[line_index].color = $colors[line_index % $colors.length] + if $i == 0 + puts + puts $colors[line_index % $colors.length] + puts line_index + puts "x1 #{DebugLines[line_index].x1}" + puts "y1 #{DebugLines[line_index].y1}" + puts "x2 #{DebugLines[line_index].x2}" + puts "y2 #{DebugLines[line_index].y2}" + 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 + else + DebugLines[line_index].color.a = 1.0# = 'green' + #return false + end + 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) + DebugLines[line_index].y2 = (tempy2 *(1+1000)/2) + (tempy1 * (1-1000)/2) + end + true +end + +#puts "should be false: #{hitbox(@sqr1, @tri1)}" +#puts "should be true: #{hitbox(@sqr2, @tri2)}" + +on :key_held do |event| + if event.key == 'w' + Camera.y -= 5 + end + if event.key == 's' + Camera.y += 5 + end + if event.key == 'a' + Camera.x -= 5 + end + if event.key == 'd' + Camera.x += 5 + end +end + +$i = 0 + +#$line = Camera::Line.new(color: 'red', +# width: 5, z: 99) + +update do + $i += 1 + $i %= 5 + 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 + a = hitbox_check( + [[s2.x1, s2.y1], + [s2.x2, s2.y2], + [s2.x3, s2.y3], + [s2.x4, s2.y4]], + [[s1.x1 + s1.x, s1.y1 + s1.y], + [s1.x2 + s1.x, s1.y2 + s1.y], + [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 + if $i == 0 + pp [[s2.x1, s2.y1], + [s2.x2, s2.y2], + [s2.x3, s2.y3], + [s2.x4, s2.y4]] + pp [[s1.x1 + s1.x, s1.y1 + s1.y], + [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 + +show -- cgit v1.2.3