|
|
|
@ -4,7 +4,7 @@ load "gosu_plugin.rb" |
|
|
|
|
GRAV_CONSTANT = 1e+1 |
|
|
|
|
|
|
|
|
|
class PhysObj |
|
|
|
|
attr_accessor :world, :saved_pos, :pos, :vel, :accel, :x, :y |
|
|
|
|
attr_accessor :world, :saved_pos, :pos, :vel, :accel, :x, :y, :show_info, :angle |
|
|
|
|
attr_reader :name |
|
|
|
|
def initialize(name, world) |
|
|
|
|
@name = name |
|
|
|
@ -14,6 +14,8 @@ class PhysObj |
|
|
|
|
@accel = Vector.zero(2) |
|
|
|
|
@x, @y = 0, 0 |
|
|
|
|
@saved_pos = [] |
|
|
|
|
@show_info = false |
|
|
|
|
@angle = 0 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def tick |
|
|
|
@ -34,26 +36,14 @@ class PhysObj |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PhysCube < PhysObj |
|
|
|
|
attr_reader :width, :height |
|
|
|
|
def initialize(name, world, width, height, color=0xff_ffffff, ela=-0.8) |
|
|
|
|
super name, world |
|
|
|
|
|
|
|
|
|
@width, @height = width, height |
|
|
|
|
@color = Gosu::Color.argb(color) |
|
|
|
|
@ela = ela |
|
|
|
|
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) |
|
|
|
|
private def debug_string |
|
|
|
|
return "\n#{self.name}\nVel: #{self.vel.magnitude.round(1)} #{self.vel.round(4)}\nAccel: #{self.accel.magnitude.round(4)} #{self.accel.round(4)}\nPos: #{self.pos.round(4)}\nAngle: #{self.angle.round(1)} deg\n" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def physics |
|
|
|
|
self.tick |
|
|
|
|
def render(x_offset=0, y_offset=0, color=Gosu::Color.argb(0xaa_2222ff)) |
|
|
|
|
if( @show_info ) then |
|
|
|
|
self.world.fonts[:normal].draw(self.debug_string, self.pos[0] + x_offset, self.pos[1] + y_offset, 1, 1.0, 1.0, color) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def draw_vector(vec, scale=2, color=0xaf_ffaaaa) |
|
|
|
@ -75,6 +65,32 @@ class PhysCube < PhysObj |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def draw_direction |
|
|
|
|
rads = (self.angle * Math::PI) / 180 |
|
|
|
|
dir_vec = Vector[Math::cos(rads), Math::sin(rads)] |
|
|
|
|
self.draw_vector(dir_vec, 25, 0xaf_aaaaff) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PhysCube < PhysObj |
|
|
|
|
attr_reader :width, :height |
|
|
|
|
def initialize(name, world, width, height, color=0xff_ffffff) |
|
|
|
|
super name, world |
|
|
|
|
|
|
|
|
|
@width, @height = width, height |
|
|
|
|
@color = Gosu::Color.argb(color) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def render |
|
|
|
|
super 0, 0, @color |
|
|
|
|
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) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def physics |
|
|
|
|
self.tick |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -107,7 +123,28 @@ class Planet < PhysObj |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
private def debug_string |
|
|
|
|
return "\n#{self.name}\nPos: #{self.pos.round(4)}\nMass: #{self.mass.round(4)}\nRadius: #{self.radius.round(4)} p\nGravity: #{(self.mass*GRAV_CONSTANT).round(2)} p/r^2" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def render |
|
|
|
|
super @radius*3, @radius*3, Gosu::Color.argb(0xff_ffffff) |
|
|
|
|
Gosu.draw_circle(self.pos[0], self.pos[1], @radius, @color, 0, @circle_thickness) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Player < PhysCube |
|
|
|
|
def initialize(name, world, width, height, color=0xff_aaaaaa) |
|
|
|
|
super name, world, width, height, color |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def button_up(id) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def button_down(id) |
|
|
|
|
if( id == Gosu::KbDown ) then |
|
|
|
|
puts("DOWN") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|