Refactor (again)

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

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

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

Loading…
Cancel
Save