Refactoring

pull/1/head
E. Almqvist 3 years ago
parent d39127dea2
commit 5314974bd5
  1. 10
      src/app.rb
  2. 2
      src/config.rb
  3. 2
      src/lib/controller.rb
  4. 2
      src/lib/objects.rb
  5. 4
      src/lib/physobj.rb
  6. 6
      src/lib/world.rb

@ -21,15 +21,11 @@ class Window < Gosu::Window
@width, @height = width, height
self.caption = "#{title}| #{width}x#{height}"
@world = nil
@ui = []
@mainmenu = nil
@fonts = {
normal: Gosu::Font.new(self, MAIN_FONT, 18)
big: Gosu::Font.new(self, MAIN_FONT, 20)
title: Gosu::Font.new(self, MAIN_FONT, 64)
normal: Gosu::Font.new(self, MAIN_FONT, 18),
big: Gosu::Font.new(self, MAIN_FONT, 20),
title: Gosu::Font.new(self, MAIN_FONT, 64),
button: Gosu::Font.new(self, MAIN_FONT, 48)
}
end

@ -4,7 +4,7 @@ WORLD_SEED = 123456789
# UI
WINDOW_WIDTH = 1600
WINDOW_HEIGHT = 900
WINDOW_FULLSCREEN = false
WINDOW_FULLSCREEN = true
MAIN_FONT = "monospace"
# Keybinds

@ -52,7 +52,7 @@ class Player < PhysCube
def button_down?(id)
end
def debug_string
def inspect
return "\nName: #{self.name}\nOrbit of: #{self.parent_orbit.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\nEngine: #{self.engine}\nThrust: #{self.thrust}\naccel_vecs: #{self.accel_vecs}\n"
end
end

@ -35,7 +35,7 @@ class Planet < PhysObj
end
end
# def debug_string
# def inspect
# 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

@ -50,13 +50,13 @@ class PhysObj
end
end
def debug_string
def inspect
return "\n#{self.name} - #{self.parent_orbit.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 render(x_offset=0, y_offset=0, color=Gosu::Color.argb(0xaa_2222ff))
if( @show_info ) then
self.world.fonts[:normal].draw_text(self.debug_string, self.pos[0] + x_offset, self.pos[1] + y_offset, 1, 1.0, 1.0, color)
self.world.fonts[:normal].draw_text(self.inspect, self.pos[0] + x_offset, self.pos[1] + y_offset, 1, 1.0, 1.0, color)
end
end

@ -8,8 +8,6 @@ class World
@planets = []
@freeze = true
@controller = nil
@camera = Vector[0, 0]
end
@ -23,7 +21,7 @@ class World
orbiters = []
orbiters += @physobjs # append each element
orbiters += @planets
orbiters.delete(planet)
orbiters.delete(planet) # dont orbit yourself, it is bad for your health.
planet.orbit(planets)
end
end
@ -32,7 +30,7 @@ class World
def render
if( @controller != nil ) then
self.camera = Vector[self.width/2, self.height/2] - self.controller.pos
@font.draw_text(self.controller.debug_string, 0, 32, 1, 1.0, 1.0, Gosu::Color::WHITE)
@font.draw_text(self.controller.inspect, 0, 32, 1, 1.0, 1.0, Gosu::Color::WHITE)
end
camx, camy = self.camera[0], self.camera[1]

Loading…
Cancel
Save