module Core
Main entrance point of the engine
TODO floats for position and speeds
Gosu::Image wrapper
Constants
- CURSOR_Z
- DEFAULT_CONFIG
- DEFAULT_FONT
- FOG_Z
- GUI_Z
- HOME_PATH
For storing saves and updates in case the source folder is write protected
- LIBRARY_PATH
Source locations
- MAPOBJECT_Z
- MAP_Z
- PARTICLE_Z
- RELEASE
- SAVE_DIR
- VERSION
Public Class Methods
anim(anim)
click to toggle source
# File lib/animation.rb, line 12 def self.anim(anim) return animations[anim].clone end
animations()
click to toggle source
# File lib/animation.rb, line 4 def self.animations return @animations end
animations=(hsh)
click to toggle source
# File lib/animation.rb, line 8 def self.animations=(hsh) @animations = hsh end
between?(a, b, c)
click to toggle source
a between b and c
# File lib/core.rb, line 66 def self.between?(a, b, c) if a > b and a < c return true end return false end
config()
click to toggle source
# File lib/core.rb, line 113 def self.config return @config.hash end
exit(int)
click to toggle source
Graceful exit
# File lib/core.rb, line 137 def self.exit(int) @config.save puts("INFO: Shutting down") Kernel.exit(int) end
font(name, size)
click to toggle source
Returns a cached font instance
# File lib/core.rb, line 101 def self.font(name, size) if @@fonts["#{name}-#{size}".to_sym] return @@fonts["#{name}-#{size}".to_sym] else @@fonts["#{name}-#{size}".to_sym] = Gosu::Font.new(Core.window, name, size) end end
inside?(x, y, startx, starty, endx, endy)
click to toggle source
# File lib/core.rb, line 54 def self.inside?(x, y, startx, starty, endx, endy) if x >= startx && x < endx && y >= starty && y < endy return true end return false end
load_game(name="autosave")
click to toggle source
# File lib/load.rb, line 4 def self.load_game(name="autosave") f = File.open("#{Core::SAVE_DIR}#{name}.esf") inflate = Zlib::Inflate.new str = Base64.decode64(inflate.inflate(f.read)) inflate.close f.close map_obj = [] map_misc = [] lines = str.lines.to_a puts Core::States.constants.inspect state = Core::States.const_get("#{lines.shift.sub("\n", "")}".to_sym) lines.each do |line| line.sub!("\n", "") puts line.inspect end party = nil Core.window.advance(state.new(Core.window, party)) end
mouse_inside?(x, y, ex, ey)
click to toggle source
# File lib/core.rb, line 61 def self.mouse_inside?(x, y, ex, ey) return inside?(Core.window.mouse_x, Core.window.mouse_y, x, y, ex, ey) end
multiline(text, width, font)
click to toggle source
# File lib/core.rb, line 73 def self.multiline(text, width, font) ret = [] lines = text.split("\n") lines.each { |line| ary = line.split(" ") str = "" ary.each { |word| if font.text_width(str + word) < width - 18 str += "#{word} " else str.rstrip! if str != "" ret.push(str) end str = "#{word} " end if word == ary.last str.rstrip! ret.push(str) end } } return ret end
particles()
click to toggle source
# File lib/particles.rb, line 5 def self.particles return @particles end
particles=(hsh)
click to toggle source
# File lib/particles.rb, line 8 def self.particles=(hsh) @particles = hsh end
save_game(name="autosave")
click to toggle source
# File lib/save.rb, line 7 def self.save_game(name="autosave") state = Core.window.state if state.class == States::GameState map = state.map party = state.party else map = Core.window.saved.map party = Core.window.saved.party end map_obj = map.objects map_misc = map.misc map_file = map.current.properties[:file] f = File.open("#{Core::SAVE_DIR}#{name}.esf", "wb") str = "#{state.class.to_s.split("::").last}\n" str += "#{map_file}\n" str += "#{party}" str += "START_MAP_OBJ\n" map_obj.each do |obj| next if obj.dead? str += "#{obj.to_save}\n" end str += "END_MAP_OBJ\n" # TODO is this actually used? str += "START_MAP_MISC\n" map_misc.each do |misc| str += "#{misc.class}\n" #str += "#{misc.to_save}\n" end str += "END_MAP_MISC\n" deflate = Zlib::Deflate.new(Zlib::BEST_COMPRESSION) # take that, script kiddies! comp = deflate.deflate(Base64.encode64(str), Zlib::FINISH) deflate.close f.puts(comp) f.close end
silently(&block)
click to toggle source
# File lib/core.rb, line 36 def self.silently(&block) lvl = $VERBOSE $VERBOSE = nil result = block.call $VERBOSE = lvl return result end
sprite(file, tile=false)
click to toggle source
# File lib/sprite.rb, line 7 def self.sprite(file, tile=false) if @@cache[file] return @@cache[file] end begin raise if !File.exist?("#{Core::LIBRARY_PATH}/graphics/#{file}.png") img = Gosu::Image.new(window, "#{Core::LIBRARY_PATH}/graphics/#{file}.png", tile) @@cache.store(file, img) return img rescue RuntimeError warn("ERROR: Failed to open graphic #{file}") file = "missing" retry end end
tiles(file, tx, ty, tile=false)
click to toggle source
TODO cache
# File lib/sprite.rb, line 24 def self.tiles(file, tx, ty, tile=false) begin ary = Gosu::Image.load_tiles(window, "#{Core::LIBRARY_PATH}/graphics/#{file}.png", tx, ty, tile) return ary rescue RuntimeError warn("ERROR: Failed to open graphic #{file}") file = "missing" retry end end
window()
click to toggle source
Returns the global Gosu::Window instance
# File lib/core.rb, line 46 def self.window return @window end
window=(w)
click to toggle source
Globally sets the Gosu::Window instance
# File lib/core.rb, line 50 def self.window=(w) @window = w end
Private Class Methods
map_misc(line)
click to toggle source
# File lib/load.rb, line 28 def self.map_misc(line) end
map_object(line)
click to toggle source
# File lib/load.rb, line 25 def self.map_object(line) end