Refactor (again)

pull/1/head
E. Almqvist 4 years ago
parent 473af1b382
commit ab08202b58
  1. 10
      src/app.rb
  2. 7
      src/lib/ui.rb
  3. 2
      src/lib/world.rb

@ -14,7 +14,7 @@ require_relative "lib/controller.rb"
require_relative "lib/world.rb" require_relative "lib/world.rb"
class Window < Gosu::Window class Window < Gosu::Window
attr_accessor :caption, :ui, :world attr_accessor :caption, :ui, :world, :mainmenu
attr_reader :width, :height, :fonts attr_reader :width, :height, :fonts
def initialize(title, width, height) def initialize(title, width, height)
@ -22,10 +22,9 @@ class Window < Gosu::Window
@width, @height = width, height @width, @height = width, height
self.caption = "#{title}| #{width}x#{height}" self.caption = "#{title}| #{width}x#{height}"
#@physobjs = physobjs
#@planets = planets
@world = nil @world = nil
@ui = [] @ui = []
@mainmenu = nil
@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)
@ -73,6 +72,9 @@ class Window < Gosu::Window
@world.physobjs << ply @world.physobjs << ply
@world.physobjs << cube2 @world.physobjs << cube2
@world.physobjs << planet @world.physobjs << planet
@world.freeze = true
self.mainmenu.show = false
end end
def button_up(id) def button_up(id)
@ -132,6 +134,6 @@ end
window = Window.new("Hohmann Miner", WINDOW_WIDTH, WINDOW_HEIGHT) window = Window.new("Hohmann Miner", WINDOW_WIDTH, WINDOW_HEIGHT)
window.fullscreen = WINDOW_FULLSCREEN window.fullscreen = WINDOW_FULLSCREEN
mainmenu = MainMenu.new(window, true) window.mainmenu = MainMenu.new(window, true)
window.show window.show

@ -64,8 +64,8 @@ class Button < UI
default: 0xff_ff0000 default: 0xff_ff0000
}, },
background: { background: {
selected: 0xcc_ffffff, selected: 0xcc_cccccc,
default: 0xbb_ff0000 default: 0xaa_aaaaaa
} }
} }
end end
@ -73,14 +73,13 @@ class Button < UI
def hover? def hover?
inx = window.mouse_x >= self.x && window.mouse_x <= self.x + self.width inx = window.mouse_x >= self.x && window.mouse_x <= self.x + self.width
iny = window.mouse_y >= self.y && window.mouse_y <= self.y + self.height iny = window.mouse_y >= self.y && window.mouse_y <= self.y + self.height
p [inx, iny]
self.selected = inx && iny self.selected = inx && iny
end end
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(0, 0, 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

@ -21,7 +21,7 @@ class World
@planets.each do |planet| @planets.each do |planet|
orbiters = [] orbiters = []
orbiters += @physobjs orbiters += @physobjs # append each element
orbiters += @planets orbiters += @planets
orbiters.delete(planet) orbiters.delete(planet)
planet.orbit(planets) planet.orbit(planets)

Loading…
Cancel
Save