pull/1/head
E. Almqvist 3 years ago
parent 13ef9957ea
commit 1a908eb656
  1. 77
      app.rb
  2. 3
      config.rb
  3. 31
      ui.rb

@ -3,13 +3,14 @@ require "matrix"
require "gosu"
load "gosu_plugin.rb"
load "ui.rb"
load "config.rb"
load "physobj.rb"
load "objects.rb"
load "controller.rb"
class Window < Gosu::Window
attr_accessor :freeze, :caption, :physobjs, :planets, :controller, :camera
attr_accessor :freeze, :caption, :physobjs, :planets, :controller, :camera, :ui
attr_reader :width, :height, :fonts
def initialize(title, width, height, physobjs = [], planets = [])
@ -28,10 +29,44 @@ class Window < Gosu::Window
big: @font2
}
@freeze = false
@freeze = true
@controller = nil
@camera = Vector[0, 0]
@ui = []
end
def start_game
cube = Player.new("Alpha", self, 8, 8)
cube.show_info = false
cube.thrust = 0.0075
cube.pos = Vector[800, 450 + 500]
cube.vel = Vector[1, 0]
self.controller = cube
cube2 = PhysCube.new("Beta", self, 8, 8)
cube2.pos = Vector[800, 450 + 300]
cube2.vel = Vector[2, 0]
cube2.show_info = true
sol = Planet.new("Sol", self, 0xff_ffffaa, 1e2, 15, 1)
sol.pos = Vector[800, 450]
planet = Planet.new("Planet", self, 0xff_cccccc, 1e1, 8, 1)
planet.pos = Vector[800, 450 + 300]
planet.vel = Vector[-2, 0]
planet.show_info = true
sol_orbiters = [cube, cube2, planet]
sol.orbit(sol_orbiters)
self.planets << sol
self.planets << planet
self.planets << cube
self.physobjs << cube
self.physobjs << cube2
self.physobjs << planet
end
def button_up(id)
@ -91,12 +126,15 @@ class Window < Gosu::Window
end
def draw
@ui.each do |u|
u.render
end
if( @controller != nil ) then
@camera = Vector[self.width/2, self.height/2] - @controller.pos
@font.draw_text(@controller.debug_string, 0, 32, 1, 1.0, 1.0, Gosu::Color::WHITE)
end
camx, camy = @camera[0], @camera[1]
p @camera
@font2.draw_text("Frozen: #{@freeze}", 0, 0, 1, 1.0, 1.0, Gosu::Color::WHITE)
@ -115,36 +153,9 @@ class Window < Gosu::Window
end
window = Window.new("Physics!", 1600, 900)
cube = Player.new("Alpha", window, 8, 8)
cube.show_info = false
cube.thrust = 0.0075
cube.pos = Vector[800, 450 + 500]
cube.vel = Vector[1, 0]
window.controller = cube
cube2 = PhysCube.new("Beta", window, 8, 8)
cube2.pos = Vector[800, 450 + 300]
cube2.vel = Vector[2, 0]
cube2.show_info = true
sol = Planet.new("Sol", window, 0xff_ffffaa, 1e2, 15, 1)
sol.pos = Vector[800, 450]
planet = Planet.new("Planet", window, 0xff_cccccc, 1e1, 8, 1)
planet.pos = Vector[800, 450 + 300]
planet.vel = Vector[-2, 0]
planet.show_info = true
sol_orbiters = [cube, cube2, planet]
sol.orbit(sol_orbiters)
window.planets << sol
window.planets << planet
window = Window.new("Hohmann Miner", WINDOW_WIDTH, WINDOW_HEIGHT)
window.fullscreen = WINDOW_FULLSCREEN
window.physobjs << cube
window.physobjs << cube2
window.physobjs << planet
mainmenu = MainMenu.new(window, true)
window.show

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

31
ui.rb

@ -1,11 +1,14 @@
class UI
attr_accessor :x, :y
attr_reader :width, :height, :zindex, :uiscale
def initialize(x, y, width, height, zindex=1, uiscale=1)
attr_reader :window, :width, :height, :zindex, :uiscale
def initialize(window, x, y, width, height, zindex=1, uiscale=1)
@window = window
@x, @y = x, y
@width, @height = width, height
@zindex = zindex
@uiscale = uiscale
@window.ui << self
end
private def pos
@ -25,15 +28,29 @@ class UI
end
def draw_rect(x, y, width, height, color=0xff_ffffff, z=0, mode=:default)
v1 = Vector[0, 0, color] + self.pos + Vector[x, y]
v2 = Vector[width, 0, color] + self.pos + Vector[x, y]
v3 = Vector[0, height, color] + self.pos + Vector[x, y]
v4 = Vector[width, height, color] + self.pos + Vector[x, y]
v1 = Vector[x, y, color] + self.pos
v2 = Vector[width + x, y, color] + self.pos
v3 = Vector[x, height + y, color] + self.pos
v4 = Vector[width + x, height + y, color] + self.pos
self.draw_quad(v1, v2, v3, v4, z, mode)
end
def draw_circle(x, y, r, c, z = 0, thickness = 1, sides = nil, mode = :default)
Gosu::draw_circle(x, y, r, c z, thickness, sides, mode)
Gosu::draw_circle(x, y, r, c, z, thickness, sides, mode)
end
end
class MainMenu < UI
attr_accessor :show
def initialize(window, show=false)
super window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 99
@show = show
end
def render
if( @show ) then
self.draw_rect(0, 0, self.width, self.height, 0x99_aaaaaa)
self.draw_text("Hohmann Miner", self.window.fonts[:big], self.width/2, self.height/2)
end
end
end

Loading…
Cancel
Save