Class: DXRuby::Tiled::Tile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image, offset_x, offset_y, adjusted_offset_y, tileset = nil) ⇒ Tile

Returns a new instance of Tile.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dxruby_tiled/tile.rb', line 8

def initialize(image, offset_x, offset_y, adjusted_offset_y, tileset = nil)
  @image = @original_image = image
  @offset_x = offset_x
  @offset_y = offset_y
  @adjusted_offset_y = adjusted_offset_y
  @tileset = tileset
  @type = nil
  @anim_time_total = 1
  @anim_time = [0]
  @anim_tile = [self]
  @collision = nil
  @collision_enable = true
  @scale_x = 1
  @scale_y = 1
  @angle   = 0
end

Instance Attribute Details

#adjusted_offset_yObject (readonly)

Returns the value of attribute adjusted_offset_y.



4
5
6
# File 'lib/dxruby_tiled/tile.rb', line 4

def adjusted_offset_y
  @adjusted_offset_y
end

#angleObject (readonly)

Returns the value of attribute angle.



4
5
6
# File 'lib/dxruby_tiled/tile.rb', line 4

def angle
  @angle
end

#collisionObject

Returns the value of attribute collision.



6
7
8
# File 'lib/dxruby_tiled/tile.rb', line 6

def collision
  @collision
end

#collision_enableObject

Returns the value of attribute collision_enable.



6
7
8
# File 'lib/dxruby_tiled/tile.rb', line 6

def collision_enable
  @collision_enable
end

#imageObject (readonly)

Returns the value of attribute image.



4
5
6
# File 'lib/dxruby_tiled/tile.rb', line 4

def image
  @image
end

#offset_xObject (readonly)

Returns the value of attribute offset_x.



4
5
6
# File 'lib/dxruby_tiled/tile.rb', line 4

def offset_x
  @offset_x
end

#offset_yObject (readonly)

Returns the value of attribute offset_y.



4
5
6
# File 'lib/dxruby_tiled/tile.rb', line 4

def offset_y
  @offset_y
end

#original_imageObject (readonly)

Returns the value of attribute original_image.



4
5
6
# File 'lib/dxruby_tiled/tile.rb', line 4

def original_image
  @original_image
end

#scale_xObject (readonly)

Returns the value of attribute scale_x.



4
5
6
# File 'lib/dxruby_tiled/tile.rb', line 4

def scale_x
  @scale_x
end

#scale_yObject (readonly)

Returns the value of attribute scale_y.



4
5
6
# File 'lib/dxruby_tiled/tile.rb', line 4

def scale_y
  @scale_y
end

#tilesetObject (readonly)

Returns the value of attribute tileset.



4
5
6
# File 'lib/dxruby_tiled/tile.rb', line 4

def tileset
  @tileset
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/dxruby_tiled/tile.rb', line 6

def type
  @type
end

Instance Method Details

#animate(current_time) ⇒ Object



33
34
35
36
# File 'lib/dxruby_tiled/tile.rb', line 33

def animate(current_time)
  time = current_time % @anim_time_total
  @anim_tile[@anim_time.rindex { |t| time >= t } ]
end

#animate!(current_time) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/dxruby_tiled/tile.rb', line 38

def animate!(current_time)
  time = current_time % @anim_time_total
  tile = @anim_tile[@anim_time.rindex { |t| time >= t } ]
  @image    = tile.original_image
  @offset_x = tile.offset_x
  @offset_y = tile.offset_y
  @adjusted_offset_y = tile.adjusted_offset_y
end

#heightObject



26
# File 'lib/dxruby_tiled/tile.rb', line 26

def height; @image.height; end

#render(x, y, target = DXRuby::Window, z_index = 0) ⇒ Object Also known as: draw



28
29
30
# File 'lib/dxruby_tiled/tile.rb', line 28

def render(x, y, target = DXRuby::Window, z_index = 0)
  target.draw(x + @offset_x, y + @adjusted_offset_y, @image, z_index)
end

#set_animation(anim_time, anim_tile) ⇒ Object



47
48
49
50
51
# File 'lib/dxruby_tiled/tile.rb', line 47

def set_animation(anim_time, anim_tile)
  @anim_time = anim_time
  @anim_tile = anim_tile
  @anim_time_total = @anim_time.pop
end

#to_sprite(x, y) ⇒ Object



53
54
55
# File 'lib/dxruby_tiled/tile.rb', line 53

def to_sprite(x, y)
  TileObject.new(x: x, y: y, tile: self)
end

#widthObject



25
# File 'lib/dxruby_tiled/tile.rb', line 25

def width ; @image.width ; end