module GamespacePersistence
Module used by classes as a mixin for collision checking with the gamespace so that they do not get out of bounds.
Public Instance Methods
correct_coords(entity, gamespace)
click to toggle source
A method determining game object coordinations in case they are out of bounds.
# 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)
click to toggle source
A method determining whether a gamespace fully
contains a certain game object.
# File lib/prkwars/modules.rb, line 25 def in_bounds(entity, gamespace) return true if gamespace.bounding_box.contain?(entity.bounding_box) false end