Class: Kawaii::PhysicsManager

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/physics_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePhysicsManager

Returns a new instance of PhysicsManager.



8
9
10
11
# File 'lib/kawaii/physics_manager.rb', line 8

def initialize
	@space = CP::Space.new
	@entities = []
end

Instance Attribute Details

#entitiesObject

Returns the value of attribute entities.



6
7
8
# File 'lib/kawaii/physics_manager.rb', line 6

def entities
  @entities
end

#spaceObject

Returns the value of attribute space.



6
7
8
# File 'lib/kawaii/physics_manager.rb', line 6

def space
  @space
end

Instance Method Details

#add_physics_entity(entity) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/kawaii/physics_manager.rb', line 13

def add_physics_entity entity
	if entity.class == PhysicsEntity
		@entities.push entity
		entity.add_to_space @space
	else
		raise WrongTypeError, "Only PhysicsEntity and derivatives are accepted"
	end 
end

#remove_physics_entity(entity) ⇒ Object



22
23
24
25
# File 'lib/kawaii/physics_manager.rb', line 22

def remove_physics_entity entity
	@entities.delete entity
	entity.remove_from_space @space
end