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.
105 106 107 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 105 def direction @direction end |
#x ⇒ Object
Returns the value of attribute x.
104 105 106 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 104 def x @x end |
#y ⇒ Object (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
143 144 145 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 143 def active? @active end |
#bounding_box ⇒ Object
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 |
#characters ⇒ Object
111 112 113 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 111 def characters super { [CHARACTER[@character]] } end |
#height ⇒ Object
129 130 131 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 129 def height 1 end |
#move ⇒ Object
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_time ⇒ Object
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_direction ⇒ Object
133 134 135 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 133 def reverse_direction @direction *= -1 end |
#width ⇒ Object
125 126 127 |
# File 'lib/road_to_rubykaigi/sprite/enemy.rb', line 125 def width 2 end |