pull/1/head
E. Almqvist 3 years ago
parent f067a830d2
commit 08e70ec3e4
  1. 1
      app.rb
  2. 33
      physobj.rb

@ -88,6 +88,7 @@ planet.show_info = true
cube = Player.new("Alpha", window, 8, 8)
cube.show_info = true
cube.thrust = 0.0075
cube.pos = Vector[800, 450 + 200]
cube.vel = Vector[2.5, 0]
window.controller = cube

@ -27,6 +27,7 @@ class PhysObj
@pos += @vel
end
@x, @y = @pos[0], @pos[1]
@angle %= 360
@saved_pos << @pos
end
@ -135,16 +136,42 @@ end
class Player < PhysCube
attr_accessor :engine, :thrust
def initialize(name, world, width, height, color=0xff_aaaaaa)
super name, world, width, height, color
@engine = false
@thrust = 0.001
end
private def get_angle_vec
rads = (self.angle * Math::PI) / 180
dir_vec = Vector[Math::cos(rads), Math::sin(rads)]
return dir_vec
end
def tick
super
if( @engine ) then
self.vel += self.get_angle_vec * @thrust
end
end
def button_up(id)
if( id == Gosu::KbSpace ) then
@engine = !@engine
end
if( id == Gosu::KbLeft ) then
self.angle -= 20
end
if( id == Gosu::KbRight ) then
self.angle += 20
end
end
def button_down(id)
if( id == Gosu::KbDown ) then
puts("DOWN")
end
end
end

Loading…
Cancel
Save