module RubyMan::LevelLoader

mixin for loading levels from files required method - add_object, level_loaded

Public Class Methods

object_from_char(char) click to toggle source
# File lib/ruby_man/level_loader.rb, line 38
def self.object_from_char(char)
  case char.downcase
  when 'p' then return Player.new
  when '.' then return Food.new
  when ':' then return SuperFood.new
  when 'g' then return Ghost.new
  when '_' then return Door.new
  end
  Wall.from_char(char) unless Wall.chars.index(char).nil?
end

Public Instance Methods

load_level_file(level_name, restart) click to toggle source
# File lib/ruby_man/level_loader.rb, line 33
def load_level_file(level_name, restart)
  f = File.open(ResourceManager.media(level_name))
  load_level_string(f.read, restart)
end
load_level_string(level_string, restart) click to toggle source
# File lib/ruby_man/level_loader.rb, line 13
def load_level_string(level_string, restart)
  y = 0
  level_string.lines do |line|
    x = -1
    line.each_char do |char|
      x += 1
      obj = LevelLoader.object_from_char(char)
      next unless obj
      next if restart && obj.class.persistent == true
      obj.set_pos(x, y)
      add_object(obj)
    end
    y += 1
  end

  add_object(Hud.new)

  level_loaded
end