Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created September 16, 2009 11:10
Show Gist options
  • Save Mon-Ouie/187992 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/187992 to your computer and use it in GitHub Desktop.
module MapLoader
TYPES = [ GameMap::COL_FULL,
GameMap::COL_LEFT,
GameMap::COL_RIGHT,
GameMap::COL_UP,
GameMap::COL_DOWN,
GameMap::COL_NO,
GameMap::COL_LEFT_RIGHT,
GameMap::COL_LEFT_UP,
GameMap::COL_LEFT_DOWN,
GameMap::COL_RIGHT_UP,
GameMap::COL_RIGHT_DOWN,
GameMap::COL_UP_DOWN ]
COL_FULL = 0
COL_LEFT = 1
COL_RIGHT = 2
COL_UP = 3
COL_DOWN = 4
COL_NO = 5
COL_LEFT_RIGHT = 6
COL_LEFT_UP = 7
COL_LEFT_DOWN = 8
COL_RIGHT_UP = 9
COL_RIGHT_DOWN = 10
COL_UP_DOWN = 11
TILE_WIDTH = 32
TILE_HEIGHT = 32
COL_HEIGHT = 5
def self.load(name, point = Point.new(0, 0))
File.open(name, "r") { |file|
map = GameMap.new
map.centerOn(point.x, point.y)
map.setTileSize(TILE_WIDTH, TILE_HEIGHT)
map.collisionH = COL_HEIGHT
# The first line tells how much tilesets
# there are on the map.
file.gets.to_i.times {
map.addTileset(file.gets.delete("\n"))
}
line = file.get
while line != "END\n" # the last line is END :)
# The format of each line is very simple :
# (tileset id) (tileX) (tileY) (x) (y) (type)
# Exactly the constructor of tile, of course.
param = line.split
param.size.times { |i|
param[i] = param[i].to_i
}
map << Tile.new(param[0], param[1], param[2], param[3], param[4],
TYPES[param[5]])
line = file.gets
end
return map
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment