Class: Xibe::Tilemap

Inherits:
Layer
  • Object
show all
Defined in:
lib/xibe.rb

Instance Attribute Summary collapse

Attributes inherited from Layer

#height, #visible, #width, #x, #y, #z

Instance Method Summary collapse

Methods inherited from Layer

#bottom, #hide, #left, #pos, #right, #show, #top

Constructor Details

#initialize(tiles, obstacle = false) ⇒ Tilemap

Returns a new instance of Tilemap.



524
525
526
527
528
529
530
531
532
533
534
# File 'lib/xibe.rb', line 524

def initialize(tiles, obstacle = false)
  super()
  @tiles = tiles
  @obstacle = obstacle
  @width = 0
  @height = 0
  @map = [[]]
  if @obstacle == true
    @collide_id = $bg_cmap.length
  end
end

Instance Attribute Details

#obstacleObject

Returns the value of attribute obstacle.



523
524
525
# File 'lib/xibe.rb', line 523

def obstacle
  @obstacle
end

Instance Method Details

#drawObject

Draw tilemap



552
553
554
555
556
557
558
559
560
# File 'lib/xibe.rb', line 552

def draw
  if @visible == true
    for i in 0..@height -1
      for j in 0..@width - 1
        draw_tile(@tiles[@map[i][j]], j*@tiles[@map[i][j]].w+@x, i*@tiles[@map[i][j]].h+@y)
      end
    end
  end
end

#load_map(map, width, height) ⇒ Object

Load map from array



537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/xibe.rb', line 537

def load_map(map, width, height)
  @map = map
  @width = width
  @height = height
  if @obstacle == true
    $bg_cmap[@collide_id] = []
    for i in 0..@height - 1
      for j in 0..@width - 1
        $bg_cmap[@collide_id] << {:map => @tiles[@map[i][j]].make_collision_map, :x => j*@tiles[@map[i][j]].w+@x, :y => i*@tiles[@map[i][j]].h+@y}
      end
    end
  end
end