File restruc & refactor

pull/1/head
E. Almqvist 3 years ago
parent 9c5cff8631
commit 559d0c7dea
  1. 2
      README.md
  2. 0
      media/preview.png
  3. 29
      src/app.rb
  4. 0
      src/config.rb
  5. 0
      src/lib/controller.rb
  6. 0
      src/lib/gosu_plugin.rb
  7. 0
      src/lib/objects.rb
  8. 0
      src/lib/physobj.rb
  9. 10
      src/lib/ui.rb
  10. 16
      src/lib/universe.rb

@ -1,3 +1,3 @@
# Hohmann Miner # Hohmann Miner
Mine stuff and then get more stuff but in space. Mine stuff and then get more stuff but in space.
![](preview.png) ![](media/preview.png)

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

@ -10,16 +10,17 @@ load "objects.rb"
load "controller.rb" load "controller.rb"
class Window < Gosu::Window class Window < Gosu::Window
attr_accessor :freeze, :caption, :physobjs, :planets, :controller, :camera, :ui attr_accessor :caption,
attr_reader :width, :height, :fonts attr_reader :width, :height, :fonts
def initialize(title, width, height, physobjs = [], planets = []) def initialize(title, width, height, universe)
super width, height super width, height
@width, @height = width, height @width, @height = width, height
self.caption = "#{title}| #{width}x#{height}" self.caption = "#{title}| #{width}x#{height}"
@physobjs = physobjs #@physobjs = physobjs
@planets = planets #@planets = planets
@universe = universe
@font = Gosu::Font.new(self, MAIN_FONT, 18) @font = Gosu::Font.new(self, MAIN_FONT, 18)
@font2 = Gosu::Font.new(self, MAIN_FONT, 20) @font2 = Gosu::Font.new(self, MAIN_FONT, 20)
@ -33,20 +34,15 @@ class Window < Gosu::Window
button: @font_button button: @font_button
} }
@freeze = true
@controller = nil
@camera = Vector[0, 0]
@ui = []
end end
def start_game def start_game
cube = Player.new("Alpha", self, 8, 8) ply = Player.new("Player", self, 8, 8)
cube.show_info = false ply.show_info = false
cube.thrust = 0.0075 ply.thrust = 0.0075
cube.pos = Vector[800, 450 + 500] ply.pos = Vector[800, 450 + 500]
cube.vel = Vector[1, 0] ply.vel = Vector[1, 0]
self.controller = cube self.controller = ply
cube2 = PhysCube.new("Beta", self, 8, 8) cube2 = PhysCube.new("Beta", self, 8, 8)
cube2.pos = Vector[800, 450 + 300] cube2.pos = Vector[800, 450 + 300]
@ -66,9 +62,8 @@ class Window < Gosu::Window
self.planets << sol self.planets << sol
self.planets << planet self.planets << planet
self.planets << cube
self.physobjs << cube self.physobjs << ply
self.physobjs << cube2 self.physobjs << cube2
self.physobjs << planet self.physobjs << planet
end end

@ -80,7 +80,7 @@ class Button < UI
def render def render
sel = self.hover? ? :selected : :default sel = self.hover? ? :selected : :default
# self.draw_rect(self.x, self.y, self.width, self.height, self.colors[:background][sel]) self.draw_rect(self.x, self.y, self.width, self.height, self.colors[:background][sel])
self.draw_text(self.text, self.font, self.width/2 - self.text_width/2, self.height/2 - self.text_height/2, self.colors[:text][sel]) self.draw_text(self.text, self.font, self.width/2 - self.text_width/2, self.height/2 - self.text_height/2, self.colors[:text][sel])
end end
@ -102,12 +102,12 @@ class MainMenu < UI
self.draw_text(titletext, self.window.fonts[:title], self.width/2 - titlewidth/2, self.height/4) self.draw_text(titletext, self.window.fonts[:title], self.width/2 - titlewidth/2, self.height/4)
playbtn = Button.new(self.window, self, "Play", self.window.fonts[:button]) playbtn = Button.new(self.window, self, "Play", self.window.fonts[:button])
#playbtn.x, playbtn.y = self.width/2 - playbtn.width/2, self.height/2 - playbtn.height/2 playbtn.x, playbtn.y = self.width/2 - playbtn.width/2, self.height/2 - playbtn.height/2
playbtn.render playbtn.render
# quitbtn = Button.new(self.window, self, "Quit", self.window.fonts[:button]) quitbtn = Button.new(self.window, self, "Quit", self.window.fonts[:button])
# quitbtn.x, quitbtn.y = self.width/2 - quitbtn.width/2, quitbtn.height + playbtn.y + 16 quitbtn.x, quitbtn.y = self.width/2 - quitbtn.width/2, quitbtn.height + playbtn.y + 16
# quitbtn.render quitbtn.render
end end
end end
end end

@ -0,0 +1,16 @@
class Universe
attr_accessor :freeze, :physobjs, :planets, :controller, :camera, :ui
def initialize(seed, window)
@seed = seed
@window = window
@physobjs = []
@planets = []
@freeze = true
@controller = nil
@camera = Vector[0, 0]
@ui = []
end
end
Loading…
Cancel
Save