Class: Box
- Inherits:
-
GameObject
- Object
- GameObject
- Box
- Defined in:
- lib/entities/box.rb
Instance Attribute Summary collapse
-
#angle ⇒ Object
readonly
Returns the value of attribute angle.
-
#graphics ⇒ Object
readonly
Returns the value of attribute graphics.
-
#health ⇒ Object
readonly
Returns the value of attribute health.
Attributes inherited from GameObject
#components, #location, #x, #y
Instance Method Summary collapse
- #box ⇒ Object
-
#initialize(object_pool, x, y) ⇒ Box
constructor
A new instance of Box.
- #on_collision(object) ⇒ Object
Methods inherited from GameObject
#collide, #draw, #effect?, #mark_for_removal, #move, #removable?, #update
Constructor Details
#initialize(object_pool, x, y) ⇒ Box
Returns a new instance of Box.
4 5 6 7 8 9 |
# File 'lib/entities/box.rb', line 4 def initialize(object_pool, x, y) super @graphics = BoxGraphics.new(self) @health = Health.new(self, object_pool, 10, true) @angle = rand(-15..15) end |
Instance Attribute Details
#angle ⇒ Object (readonly)
Returns the value of attribute angle.
2 3 4 |
# File 'lib/entities/box.rb', line 2 def angle @angle end |
#graphics ⇒ Object (readonly)
Returns the value of attribute graphics.
2 3 4 |
# File 'lib/entities/box.rb', line 2 def graphics @graphics end |
#health ⇒ Object (readonly)
Returns the value of attribute health.
2 3 4 |
# File 'lib/entities/box.rb', line 2 def health @health end |
Instance Method Details
#box ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/entities/box.rb', line 17 def box return @box if @box w = @graphics.width / 2 h = @graphics.height / 2 # Bounding box adjusted to trim shadows @box = [x - w + 4, y - h + 8, x + w , y - h + 8, x + w , y + h, x - w + 4, y + h] @box = Utils.rotate(@angle, @x, @y, *@box) end |
#on_collision(object) ⇒ Object
11 12 13 14 15 |
# File 'lib/entities/box.rb', line 11 def on_collision(object) return unless object.physics.speed > 1.0 move(*Utils.point_at_distance(@x, @y, object.direction, 2)) @box = nil end |