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.



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

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.



8
9
10
# File 'lib/lib/user_interface/tile.rb', line 8

def infopane
  @infopane
end

#terrainObject

Returns the value of attribute terrain.



8
9
10
# File 'lib/lib/user_interface/tile.rb', line 8

def terrain
  @terrain
end

#unitObject

Returns the value of attribute unit.



8
9
10
# File 'lib/lib/user_interface/tile.rb', line 8

def unit
  @unit
end

Instance Method Details

#drawObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lib/user_interface/tile.rb', line 29

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) # TODO 0 -> viewport.y
  draw_axis_tick(@y, @x, 0) # TODO 0 -> viewport.x
end

#draw_axis_tick(draw_coord, test_coord, test_against) ⇒ Object

Draw one tick of axis for appropriate tiles



44
45
46
47
48
49
50
51
# File 'lib/lib/user_interface/tile.rb', line 44

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