indexing description: "[ All data needed to check collisions with this object Be sure not to confuse this with EM_COLLIDABLE from the collision detection, althougt this class uses the collision detection and EM_COLLIDABLE. This class is intendet to be inherited by EM_GOOF_OBJECT witch need the collision detection functionality. Objects collide only with objects in other collision_group (or set). ]" date: "$Date$" revision: "$Revision$" class EM_GOOF_COLLIDABLE inherit EM_GOOF_OBJECT create make_rect, make_circle feature {EM_GOOF_OBJECT, EM_GOOF_LOADER_NODE_PROCESSOR, EM_GOOF_PHYSICS, EM_GOOF_LEVEL_SCENE}-- Initialization make_rect(x, y, width, height: DOUBLE a_group: INTEGER) is -- Make with a rect collidable -- With x/y position (NOT top/left) local a_position: EM_VECTOR_2D do collision_group := a_group create a_position.make(x, y) create {EM_RECTANGLE_COLLIDABLE}collidable.make_from_position_and_size(a_position, width, height) collidable.set_holder(current) ensure group_set: collision_group = a_group collidable_holder_set: collidable.holder = current end make_circle(x, y, radius: DOUBLE a_group: INTEGER) is -- Make with a cicle collidable local center: EM_VECTOR_2D do collision_group := a_group create center.make(x,y) create {EM_CIRCLE_COLLIDABLE}collidable.make(center,radius) collidable.set_holder(current) ensure group_set: collision_group = a_group collidable_holder_set: collidable.holder = current end feature {EM_GOOF_OBJECT, EM_GOOF_LOADER_NODE_PROCESSOR, EM_GOOF_PHYSICS, EM_GOOF_LEVEL_SCENE} -- Handler collide(a_collision: EM_COLLISION [EM_COLLIDABLE]) is -- It collides require a_collision_not_void: a_collision /= void do end feature {EM_GOOF_OBJECT, EM_GOOF_LOADER_NODE_PROCESSOR, EM_GOOF_PHYSICS, EM_GOOF_LEVEL_SCENE} -- Update update_position(a_position: EM_VECTOR_2D) is -- Update collidable position require a_position_not_void: a_position /= void do collidable.set_center(a_position) end update_angle(a_angle: DOUBLE) is -- Update collidable angle do collidable.rotate_to(a_angle) end update_group(detector: EM_COLLISION_DETECTOR [EM_COLLIDABLE] a_group: INTEGER) is -- Update collidable group do collision_group := a_group if detector /= void then detector.remove(collidable) detector.add(collidable, collision_group) end ensure group_set: collision_group = a_group detector /= void implies detector.has(collidable) end update_collidable(detector: EM_COLLISION_DETECTOR [EM_COLLIDABLE] is_collidable: BOOLEAN) is -- Is it collidable within detector require detector_not_void: detector /= void do if is_collidable then detector.add(collidable, collision_group) else detector.remove(collidable) end end feature {EM_GOOF_OBJECT, EM_GOOF_LOADER_NODE_PROCESSOR, EM_GOOF_PHYSICS, EM_GOOF_LEVEL_SCENE} -- Properties collidable: EM_COLLIDABLE -- Collidable for detector collision_group: INTEGER -- Group for collision (uncolliable within group) invariant -- TODO: Not satisfied when 'premake' is used (e.g. in EM_GOOF_BALL)! -- collision_group_positive: collision_group > 0 -- collidable_not_void: collidable /= void end