Class: RoadToRubykaigi::Sprite::Enemy
- Inherits:
-
RoadToRubykaigi::Sprite
- Object
- RoadToRubykaigi::Sprite
- RoadToRubykaigi::Sprite::Enemy
- 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
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #activate_with_offset(offset_x) ⇒ Object
- #active? ⇒ Boolean
- #bounding_box ⇒ Object
- #characters ⇒ Object
- #height ⇒ Object
- #move ⇒ Object
- #reset_last_update_time ⇒ Object
- #reverse_direction ⇒ Object
- #width ⇒ Object
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
98 99 100 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 98 def direction @direction end |
#x ⇒ Object
Returns the value of attribute x.
97 98 99 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 97 def x @x end |
#y ⇒ Object (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
136 137 138 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 136 def active? @active end |
#bounding_box ⇒ Object
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 |
#characters ⇒ Object
104 105 106 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 104 def characters super { [CHARACTER[@character]] } end |
#height ⇒ Object
122 123 124 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 122 def height 1 end |
#move ⇒ Object
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_time ⇒ Object
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_direction ⇒ Object
126 127 128 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 126 def reverse_direction @direction *= -1 end |
#width ⇒ Object
118 119 120 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 118 def width 2 end |