Class: Tile

Inherits:
Object
  • Object
show all
Defined in:
lib/lib/user_interface/tile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, loaded_symbol, infopane) ⇒ Tile

Returns a new instance of Tile.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lib/user_interface/tile.rb', line 12

def initialize(x, y, loaded_symbol, infopane)
  dir_path = File.dirname(__FILE__)

  @x = x
  @y = y
  @infopane = infopane

  case(loaded_symbol)
  when SYMBOL_SEA then
    @terrain = TILE_SEA
    @image = Gosu::Image.new(dir_path + '/../../media/sea.png')
  when SYMBOL_GROUND then
    @terrain = TILE_GROUND
    @image = Gosu::Image.new(dir_path + '/../../media/ground.png')
  else
    abort("Tile.initialize(): Unknown terrain symbol (#{loaded_symbol})")
  end
end

Instance Attribute Details

#infopaneObject

Returns the value of attribute infopane.



10
11
12
# File 'lib/lib/user_interface/tile.rb', line 10

def infopane
  @infopane
end

#terrainObject

Returns the value of attribute terrain.



10
11
12
# File 'lib/lib/user_interface/tile.rb', line 10

def terrain
  @terrain
end

#unitObject

Returns the value of attribute unit.



10
11
12
# File 'lib/lib/user_interface/tile.rb', line 10

def unit
  @unit
end

Instance Method Details

#drawObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lib/user_interface/tile.rb', line 31

def draw
  # 1) terrain
  @image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZTILE)

  # 2) unit
  if @unit
    @unit.draw
  end

  # 3) axes
  draw_axis_tick(@x, @y, 0) if SetState.instance.settings['axis_top'] # TODO 0 -> viewport.y
  draw_axis_tick(@x, @y, MAPY) if SetState.instance.settings['axis_bottom']
  draw_axis_tick(@y, @x, 0) if SetState.instance.settings['axis_left'] # TODO 0 -> viewport.x
  draw_axis_tick(@y, @x, MAPX) if SetState.instance.settings['axis_right']
end

#draw_axis_tick(draw_coord, test_coord, test_against) ⇒ Object

Draw one tick of axis for appropriate tiles



48
49
50
51
52
53
54
55
# File 'lib/lib/user_interface/tile.rb', line 48

def draw_axis_tick(draw_coord, test_coord, test_against)
  # TODO appropriatness can be changed (show axes: no/top/left/bottom/right)
  if test_coord == test_against
    tick = Gosu::Image.from_text(draw_coord, 20)
    tick.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZTEXT)
    # ^^ TODO substract test_against of viewport from @x and @y here?
  end
end