Class: RedBird::EntityCollision
- Inherits:
-
Object
- Object
- RedBird::EntityCollision
- Defined in:
- lib/red_bird/entity_collision.rb
Overview
This class does collision tests between entities.
Instance Method Summary collapse
-
#call ⇒ Object
Loop over entities in the array and test if they collide.
-
#initialize(entities) ⇒ EntityCollision
constructor
A new instance of EntityCollision.
Constructor Details
#initialize(entities) ⇒ EntityCollision
Returns a new instance of EntityCollision.
8 9 10 |
# File 'lib/red_bird/entity_collision.rb', line 8 def initialize(entities) @entities = entities end |
Instance Method Details
#call ⇒ Object
Loop over entities in the array and test if they collide. In the case of collision, it calls the method collide
of the entity and sends the entity it collided to as a single argument.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/red_bird/entity_collision.rb', line 17 def call # Calculate entities rote @entities.each_with_index do |e1, i| @entities.drop(i + 1).each do |e2| if e1.collision_box.collide? e2.collision_box then e1.collide(e2) e2.collide(e1) # If an object responds to 'collision_box' then it is tested. end if e1.respond_to?('collision_box') end end end |