From 41054e7046c0872fd5b45258d247584bbe7b98f4 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 11 Oct 2021 22:53:57 +0200 Subject: [PATCH] Dumb vector --- app.rb | 2 +- physobj.rb | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app.rb b/app.rb index 3285280..65ae1a2 100755 --- a/app.rb +++ b/app.rb @@ -34,7 +34,7 @@ planet = PhysCube.new(window, 16, 16, 0xff_aaffaa) cube = PhysCube.new(window, 8, 8) cube.accel = Vector[0, 0.1] -cube.vel = Vector[0.01, 0] +cube.vel = Vector[2, -2] window.physobjs << cube window.show diff --git a/physobj.rb b/physobj.rb index 2f9369b..ad240ad 100644 --- a/physobj.rb +++ b/physobj.rb @@ -34,18 +34,10 @@ class PhysCube < PhysObj @ela = ela end - def draw_vector(vec, scale=0.1, color=0xaf_ffaaaa) - clr = Gosu::Color.argb(color) - dx, dy = vec[0], vec[1] - xx, yy = @x + @width/2, @y + @height/2 - Gosu.draw_line(xx, yy, clr, (xx + dx).round(1) * scale, (yy + dy).round(1) * scale, clr) - puts("#{dx} #{dy} #{[xx - (xx + dx), yy - (yy + dy)]}") - end - def render x, y = self.pos[0], self.pos[1] Gosu.draw_quad(x, y, @color, x + self.width, y, @color, x, y + self.height, @color, x + self.width, y + self.height, @color) - self.draw_vector(@accel, 10, 0xff_00ff00) + self.draw_vector(@vel, 2) end def physics @@ -56,7 +48,20 @@ class PhysCube < PhysObj y_max = world.height - self.height if( x > x_max ) then self.pos[0] = x_max end - if( y > y_max ) then self.pos[1] = y_max end + if( y > y_max ) then + self.pos[1] = y_max + self.vel[1] = -2 + self.vel[0] = 1 + end end + + def draw_vector(vec, scale=0.1, color=0xaf_ffaaaa) + clr = Gosu::Color.argb(color) + dx, dy = vec[0], vec[1] + xx, yy = @x + @width/2, @y + @height/2 + Gosu.draw_line(xx, yy, clr, (xx + dx).round(1) * scale, (yy + dy).round(1) * scale, clr) + puts("#{dx} #{dy} #{[xx - (xx + dx), yy - (yy + dy)]}") + end + end