Class: RoadToRubykaigi::Sprite::Enemy

Inherits:
RoadToRubykaigi::Sprite show all
Defined in:
lib/road_to_rubykaigi/sprite/enemy.rb

Constant Summary collapse

CHARACTER =
{
  bee: "🐝",
  bug: "🐛",
  ladybug: "🐞",
  spider: "🕷️",
}
RIGHT =
1
LEFT =
-1

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



98
99
100
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 98

def direction
  @direction
end

#xObject

Returns the value of attribute x.



97
98
99
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 97

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



98
99
100
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 98

def y
  @y
end

Instance Method Details

#activate_with_offset(offset_x) ⇒ Object



130
131
132
133
134
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 130

def activate_with_offset(offset_x)
  if !@active && @x <= (offset_x + Map::VIEWPORT_WIDTH)
    @active = true
  end
end

#active?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 136

def active?
  @active
end

#bounding_boxObject



100
101
102
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 100

def bounding_box
  { x: @x, y: @y, width: width, height: height }
end

#charactersObject



104
105
106
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 104

def characters
  super { [CHARACTER[@character]] }
end

#heightObject



122
123
124
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 122

def height
  1
end

#moveObject



108
109
110
111
112
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 108

def move
  elapsed_time = Time.now - @last_update_time
  @last_update_time = Time.now
  @strategy.move(self, elapsed_time)
end

#reset_last_update_timeObject



114
115
116
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 114

def reset_last_update_time
  @last_update_time = Time.now
end

#reverse_directionObject



126
127
128
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 126

def reverse_direction
  @direction *= -1
end

#widthObject



118
119
120
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 118

def width
  2
end