class TiledMap
ANIMATIONTIME = 12
TILESIZE = 8
ANIMETILEFRAMES = [4]
attr_accessor :ox
attr_accessor :oy
def initialize
@tileset = RPG::Cache.tileset("Test")
@animetileset = RPG::Cache.tileset("AnimeTiles")
$screen.mapSize($gameMap.width, $gameMap.height)
@animeTiles = []
@ox = 0
@oy = 0
update
end
def update
if $gameMap.redraw
refresh
end
for i in 0..3
$screen.BG[i].realox = @ox
$screen.BG[i].realoy = @oy
end
if Graphics.frame_count % ANIMATIONTIME == 0
updateAnimeTiles
end
end
def refresh
$gameMap.redraw = false
@tileWidth = $gameMap.data.xsize
@tileHeight = $gameMap.data.ysize
for z in 0...$gameMap.data.zsize
for x in 0...$gameMap.data.xsize
for y in 0...$gameMap.data.ysize
id = $gameMap.data[x, y, z]
next if id == 0x0
id < 0xFF ? drawTile(x, y, z, id) : drawAnimeTile(x, y, z, id)
end
end
end
end
def drawTile(x, y, z, id)
rect = Rect.new((id % 0xF) * TILESIZE, (id / 0xF) * TILESIZE, TILESIZE, TILESIZE)
x *= TILESIZE
y *= TILESIZE
$screen.BG[z].bitmap.blt(x, y, @tileset, rect)
end
def drawAnimeTile(x, y, z, id)
rect = Rect.new(0, (id - 0x100) * TILESIZE, TILESIZE, TILESIZE)
x *= TILESIZE
y *= TILESIZE
$screen.BG[z].bitmap.blt(x, y, @animetileset, rect)
@animeTiles.push(AnimeTile.new(x, y, z, id))
end
def updateAnimeTiles
for tile in @animeTiles
rect = Rect.new(tile.frame * TILESIZE, (tile.id - 0x100) * TILESIZE, TILESIZE, TILESIZE)
$screen.BG[tile.z].bitmap.blt(tile.x, tile.y, @animetileset, rect)
frames = ANIMETILEFRAMES[tile.id - 0x100]
tile.frame = (tile.frame + 1) % frames
end
end
end
class AnimeTile
attr_reader :x
attr_reader :y
attr_reader :z
attr_reader :id
attr_accessor :frame
def initialize(x, y, z, id)
@x = x
@y = y
@z = z
@id = id
@frame = 0
end
end