Module: GamespacePersistence
- Included in:
- Bullet, BulletTurret, ExplosionParticle, Play, Player, Stalker
- Defined in:
- lib/prkwars/modules.rb
Overview
Module used by classes as a mixin for collision checking with the gamespace so that they do not get out of bounds.
Instance Method Summary collapse
-
#correct_coords(entity, gamespace) ⇒ Object
A method determining game object coordinations in case they are out of bounds.
-
#in_bounds(entity, gamespace) ⇒ Object
A method determining whether a gamespace
fullycontains a certain game object.
Instance Method Details
#correct_coords(entity, gamespace) ⇒ Object
A method determining game object coordinations in case they are out of bounds.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/prkwars/modules.rb', line 34 def correct_coords(entity, gamespace) if entity.bounding_box.top < gamespace.bounding_box.top # ceiling entity.y += gamespace.bounding_box.top - entity.bounding_box.top elsif entity.bounding_box.bottom > gamespace.bounding_box.bottom # floor entity.y -= entity.bounding_box.bottom - gamespace.bounding_box.bottom end if entity.bounding_box.left < gamespace.bounding_box.left # left side entity.x += gamespace.bounding_box.left - entity.bounding_box.left elsif entity.bounding_box.right > gamespace.bounding_box.right # right side entity.x -= entity.bounding_box.right - gamespace.bounding_box.right end end |
#in_bounds(entity, gamespace) ⇒ Object
A method determining whether a gamespace fully contains a certain game object.
25 26 27 28 |
# File 'lib/prkwars/modules.rb', line 25 def in_bounds(entity, gamespace) return true if gamespace.bounding_box.contain?(entity.bounding_box) false end |