IceDragon200

Tilemap Pseudocode

Apr 30th, 2011
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.14 KB | None | 0 0
  1. class Tilemap
  2.  
  3.   TILESIZE = 32
  4.  
  5.   def initialize(viewport, width, height, layer_count)
  6.     @viewport    = Viewport.new(0, 0, 544, 416) # // You probably don't need this...
  7.     @data        = Array.new(width).map! { Array.new(height).map! { Array.new(layer_count).map! { 0 } } }
  8.     @width       = width
  9.     @height      = height
  10.     @layer_count = layer_count
  11.     @layers      = []
  12.     @layer_count.times { |i|
  13.       @layers[i] = Plane.new( @viewport )  
  14.       @layers[i].bitmap = Bitmap.new(TILESIZE*width, TILESIZE*height) # // Normally wurks under 2000 x 2000 pixels
  15.     }
  16.  
  17.   end
  18.  
  19.   def draw_tile(layer, x, y, bitmap, sourcerect)
  20.     layer.bitmap.blt(x, y, bitmap, sourcerect)
  21.   end
  22.  
  23.   def update_tiles
  24.     for x in 0...@width
  25.       for y in 0...@height
  26.         for z in 0...@layer_count
  27.           tileid = @data[x][y][z]
  28.           draw_tile(@layers[z], x*TILESIZE, y*TILESIZE, tile_bitmap(tileid), tile_rect(tileid))
  29.         end
  30.       end
  31.     end
  32.   end
  33.  
  34.   def tile_bitmap(tileid)
  35.     return Bitmap.new # // Need to edit this
  36.   end
  37.  
  38.   def tile_rect(tileid)
  39.     return Rect.new() # // Need to edit this
  40.   end
  41.  
  42. end
Advertisement
Add Comment
Please, Sign In to add comment