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.



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

def direction
  @direction
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#activate_with_offset(offset_x) ⇒ Object



137
138
139
140
141
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 137

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

#active?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 143

def active?
  @active
end

#bounding_boxObject



107
108
109
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 107

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

#charactersObject



111
112
113
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 111

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

#heightObject



129
130
131
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 129

def height
  1
end

#moveObject



115
116
117
118
119
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 115

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

#reset_last_update_timeObject



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

def reset_last_update_time
  @last_update_time = Time.now
end

#reverse_directionObject



133
134
135
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 133

def reverse_direction
  @direction *= -1
end

#widthObject



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

def width
  2
end