Dumb vector

pull/1/head
E. Almqvist 3 years ago
parent 9e96d4735c
commit 41054e7046
  1. 2
      app.rb
  2. 25
      physobj.rb

@ -34,7 +34,7 @@ planet = PhysCube.new(window, 16, 16, 0xff_aaffaa)
cube = PhysCube.new(window, 8, 8) cube = PhysCube.new(window, 8, 8)
cube.accel = Vector[0, 0.1] cube.accel = Vector[0, 0.1]
cube.vel = Vector[0.01, 0] cube.vel = Vector[2, -2]
window.physobjs << cube window.physobjs << cube
window.show window.show

@ -34,18 +34,10 @@ class PhysCube < PhysObj
@ela = ela @ela = ela
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
def render def render
x, y = self.pos[0], self.pos[1] 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) 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 end
def physics def physics
@ -56,7 +48,20 @@ class PhysCube < PhysObj
y_max = world.height - self.height y_max = world.height - self.height
if( x > x_max ) then self.pos[0] = x_max end 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 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 end

Loading…
Cancel
Save