class Core::Game::MapLoader

Attributes

misc[R]
objects[R]
player[R]
xoff[RW]
yoff[RW]

Public Class Methods

new() click to toggle source
# File lib/game/map/map_loader.rb, line 10
def initialize
  @objects = []
  @maps = []
  @misc = []
  @player = Core::Game::Player.new(0, 0)
  @tonepic = Core.sprite("pixel", true)
  @box = Core::GUI::Textfield.new(256, 480, 512, 224, "", 24, :left)
  @message = false
  @xoff = 496
  @yoff = 360
end

Public Instance Methods

current() click to toggle source
# File lib/game/map/map_loader.rb, line 22
def current
  return @maps[4]
end
draw() click to toggle source
# File lib/game/map/map_loader.rb, line 152
def draw
  @maps.each { |map|
    map.draw(@xoff, @yoff) if map
  }
  @objects.each { |obj|
    obj.draw(@xoff, @yoff)
  }
  @misc.each { |m|
    m.draw
  }
  @fog.draw if @fog
  @tonepic.draw(0, 0, 500000, 1024, 768, @tone) if @tone
  if @message
    @box.draw
  end
end
left() click to toggle source
# File lib/game/map/map_loader.rb, line 26
def left
  return @maps[3]
end
load(file) click to toggle source

0 1 2 3 4 5 6 7 8

4 => current

# File lib/game/map/map_loader.rb, line 48
def load(file)
  @maps.clear
  map = Core::Parse.map(file)
  @objects = map.objects
  @objects.push(@player)
  @maps[4] = map
  if map.upper
    @maps[1] = Core::Parse.map(map.upper)
    @maps[1].yoff = -@maps[1].height*32
    if @maps[1].left
      @maps[0] = Core::Parse.map(@maps[1].left)
      @maps[0].xoff = -@maps[1].height*32
      @maps[0].yoff = -@maps[0].height*32
    end
    if @maps[1].right
      @maps[2] = Core::Parse.map(@maps[1].right)
      @maps[2].xoff = @maps[1].height*32
      @maps[2].yoff = -@maps[1].height*32
    end
  end
  if map.right
    @maps[5] = Core::Parse.map(map.right)
    @maps[5].xoff = @maps[4].width*32
    if @maps[5].upper
      @maps[2] = Core::Parse.map(@maps[5].upper)
      @maps[2].xoff = @maps[4].width*32
      @maps[2].yoff = -@maps[2].height*32
    end
    if @maps[5].lower
      @maps[8] = Core::Parse.map(@maps[5].lower)
      @maps[8].xoff = @maps[4].width*32
      @maps[8].yoff = @maps[4].height*32
    end
  end
  if map.left
    @maps[3] = Core::Parse.map(map.left)
    @maps[3].xoff = -@maps[3].width*32
    if !@maps[1].left and @maps[3].upper
      @maps[0] = Core::Parse.map(@maps[3].upper)
      @maps[0].xoff = -@maps[0].width*32
      @maps[0].yoff = -@maps[0].height*32
    end
  end
  if map.lower
    @maps[7] = Core::Parse.map(map.lower)
    @maps[7].yoff = @maps[7].height*32
    if @maps[7].left
      @maps[6] = Core::Parse.map(@maps[7].left)
      @maps[6].xoff = -@maps[7].height*32
      @maps[6].yoff = @maps[7].height*32
      if !@maps[6].left and @maps[3].lower
        @maps[6] = Core::Parse.map(@maps[3].lower)
        @maps[6].xoff = -@maps[6].width*32
        @maps[6].yoff = +@maps[6].height*32
      end
    end
    if @maps[7].right
      @maps[8] = Core::Parse.map(@maps[7].right)
      @maps[8].xoff = @maps[7].height*32
      @maps[8].yoff = @maps[7].height*32
    end
  end
  if map.properties[:music]
    if map.properties[:music] == "nil"
      @song.stop if @song
    else
      @song = Core::Song.new(map.properties[:music])
      @song.play(true)
    end
  end
  if map.properties[:fog]
    if map.properties[:fog] == "nil"
      @fog = nil
    else
      @fog = Core::Game::Fog.new(map.properties[:fog], map.properties[:fogx].to_f, map.properties[:fogy].to_f, map.properties[:foga].to_i, map.properties[:fogr].to_i, map.properties[:fogg].to_i, map.properties[:fogb].to_i)
    end
  end
  if map.properties[:tonea] or map.properties[:toner] or map.properties[:toneg] or map.properties[:toneb]
    @tone = Gosu::Color.new(map.properties[:tonea].to_i, map.properties[:toner].to_i, map.properties[:toneg].to_i, map.properties[:toneb].to_i)
  else
    @tone = nil
  end
end
lower() click to toggle source
# File lib/game/map/map_loader.rb, line 38
def lower
  return @maps[7]
end
message(str, x=256, y=480, w=512, h=224) click to toggle source
# File lib/game/map/map_loader.rb, line 169
def message(str, x=256, y=480, w=512, h=224)
  @box.text = str
  @message = true
  @box.x, @box.y = x, y
  @box.w, @box.h = w, h
end
right() click to toggle source
# File lib/game/map/map_loader.rb, line 30
def right
  return @maps[5]
end
update() click to toggle source
# File lib/game/map/map_loader.rb, line 132
def update
  if !@message
    @objects.each { |obj|
      obj.setup if obj.do_setup?
      obj.update
      if obj.dead?
        @objects.delete(obj)
      end
    }
    @misc.each { |obj|
      obj.update
    }
    @fog.update if @fog
  else
    if Core.window.pressed?(Gosu::KbSpace)
      @message = false
    end
  end
end
upper() click to toggle source
# File lib/game/map/map_loader.rb, line 34
def upper
  return @maps[1]
end