Class: Box

Inherits:
GameObject show all
Defined in:
lib/entities/box.rb

Instance Attribute Summary collapse

Attributes inherited from GameObject

#components, #location, #x, #y

Instance Method Summary collapse

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

#angleObject (readonly)

Returns the value of attribute angle.



2
3
4
# File 'lib/entities/box.rb', line 2

def angle
  @angle
end

#graphicsObject (readonly)

Returns the value of attribute graphics.



2
3
4
# File 'lib/entities/box.rb', line 2

def graphics
  @graphics
end

#healthObject (readonly)

Returns the value of attribute health.



2
3
4
# File 'lib/entities/box.rb', line 2

def health
  @health
end

Instance Method Details

#boxObject



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