lib/fantasy/global.rb in fantasy-0.1.3 vs lib/fantasy/global.rb in fantasy-0.1.5
- old
+ new
@@ -1,10 +1,10 @@
require "ostruct"
module Global
class << self
- attr_accessor :actors, :hud_texts, :hud_images, :backgrounds, :clocks
+ attr_accessor :actors, :hud_texts, :hud_images, :backgrounds, :tile_maps, :clocks
attr_accessor :debug
attr_accessor :setup_proc, :loop_proc, :button_proc
attr_accessor :presentation_proc, :game_proc, :end_proc
attr_accessor :space_bar_proc
@@ -24,18 +24,20 @@
puts "Global.initialize"
@actors = []
@hud_texts = []
@hud_images = []
@backgrounds = []
+ @tile_maps = []
@clocks = []
@last_frame_at = Time.now
@debug = false
@pixel_font = Gosu::Font.new(20, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
@d_key_pressed = false
@references = OpenStruct.new
@camera = Camera.new(position: Coordinates.zero)
@game_state = Global.presentation_proc.nil? ? "game" : "presentation"
+ @game_started_at = Time.now
if @presentation_proc.nil?
on_presentation { Global.default_on_presentation }
end
@@ -102,14 +104,24 @@
def clear_state_elements
@actors.clear
@hud_texts.clear
@hud_images.clear
@backgrounds.clear
+ @tile_maps.clear
@clocks.reject(&:persistent?).each(&:stop)
@background = Color.new(r: 0, g: 0, b: 0)
end
def mouse_position
Coordinates.new(Global.game.mouse_x, Global.game.mouse_y)
+ end
+
+ def setup
+ Sound.preload_sounds
+ Image.preload_images
+ end
+
+ def seconds_in_game
+ Time.now - @game_started_at
end
end
end