Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.goof

Class EM_GOOF_PHYSICS


Direct ancestors

EM_DRAWABLE, EM_SHARED_BITMAP_FACTORY

Creation

Features

Invariants

indexing

description

The main physics engine and the core of EM_GOOF. Processes and draws
all EM_GOOF_OBJECT and processes all EM_GOOF_FORCE. Coordinates
with EM_COLLISION_DETECTOR.

Use 'get_registered_object' and 'get_registered_forces' to get named
objects loaded from xml file.

You can add this to every scene as it is an EM_DRAWABLE.

date

$Date: 2005/10/23 09:37:18 $

revision

$Revision: 1.11 $

class

EM_GOOF_PHYSICS

inherit

EM_DRAWABLE

create

make (a_background_file: STRING a_level_size,a_level_position,a_screen_size,a_screen_position: EM_VECTOR_2D a_speed: DOUBLE collision_set_no: INTEGER)

-- Make physics

require
a_level_size_not_void: a_level_size /= void
a_level_position_not_void: a_level_position /= void
a_screen_size_not_void: a_screen_size /= void
a_screen_position_not_void: a_screen_position /= void
a_background_file_not_void: a_background_file /= void
collision_set_no_positive: collision_set_no > 0

feature -- Initialization

make (a_background_file: STRING a_level_size,a_level_position,a_screen_size,a_screen_position: EM_VECTOR_2D a_speed: DOUBLE collision_set_no: INTEGER)

-- Make physics

require
a_level_size_not_void: a_level_size /= void
a_level_position_not_void: a_level_position /= void
a_screen_size_not_void: a_screen_size /= void
a_screen_position_not_void: a_screen_position /= void
a_background_file_not_void: a_background_file /= void
collision_set_no_positive: collision_set_no > 0

feature {EM_GOOF_OBJECT, EM_GOOF_LOADER_NODE_PROCESSOR, EM_GOOF_LEVEL_SCENE} -- Access

get_registered_force (name: STRING): EM_GOOF_FORCE

-- Get a registered force

require
name_not_void: name /= void
ensure
result_not_void: result /= void
get_registered_object (name: STRING): EM_GOOF_OBJECT

-- Get a registered object

require
name_not_void: name /= void
ensure
result_not_void: result /= void

feature -- Status report

is_size_fixed: BOOLEAN

-- Should Current not scale when drawed?
-- True means that the object will be drawed unscaled
-- but its position (reference_point) will still be transformed correctly
-- if drawed on a transformed scaled coordinate system
-- (This is handled accordingly by draw_object of EM_SURFACE)

-- (From EM_DRAWABLE)

x: INTEGER

-- Horizontal position, distance in pixels from left

-- (From EM_DRAWABLE)

y: INTEGER

-- Vertical position, distance in pixels from top

-- (From EM_DRAWABLE)

feature -- Status setting

set_size_fixed (a_boolean: BOOLEAN)

-- Set is_size_fixed to a_boolean.

-- (From EM_DRAWABLE)

ensure
size_fixed_set: is_size_fixed = a_boolean
set_x (x_position: INTEGER)

-- Set x to x_position.

-- (From EM_DRAWABLE)

ensure
x_set: x = x_position
set_x_y (an_x, a_y: INTEGER)

-- Set x to an_x and y to a_y.

-- (From EM_DRAWABLE)

ensure
x_set: x = an_x
y_set: y = a_y
set_y (y_position: INTEGER)

-- Set y to y_position.

-- (From EM_DRAWABLE)

ensure
y_set: y = y_position

feature -- Drawing

draw (screen: EM_VIDEO_SURFACE)

-- Draw physic objects

-- (From EM_DRAWABLE)

require
a_surface_not_void: a_surface /= Void
draw_part (a_rect: EM_RECT; a_surface: EM_SURFACE)

-- Draw rectangular part of Current defined by a_rect to a_surface.
-- (Subclasses could redefine this feature for providing an implementation
-- with better performance, otherwise its just done per default by
-- transforming and clipping coordinates on a_surface before calling draw).

-- (From EM_DRAWABLE)

require
a_surface_not_void: a_surface /= Void
a_rect_not_void: a_rect /= Void

feature {EM_GOOF_OBJECT, EM_GOOF_LOADER_NODE_PROCESSOR, EM_GOOF_LEVEL_SCENE} -- Load

add_force (a_force: EM_GOOF_FORCE)

-- Add this object (used by loader)

require
a_force_not_void: a_force /= void
ensure
force_added: forces.has(a_force)
add_object (a_object: EM_GOOF_OBJECT)

-- Add this object (used by loader)

require
a_object_not_void: a_object /= void
ensure
object_added: objects.has(a_object)
register_force (name: STRING force: EM_GOOF_FORCE)

-- Register 'force' with 'name'

require
name_not_void: name /= void
force_not_void: force /= void
ensure
registered: registered_forces.has(name)
register_object (name: STRING object: EM_GOOF_OBJECT)

-- Register 'object' with 'name'

require
name_not_void: name /= void
object_not_void: object /= void
ensure
registered: registered_objects.has(name)
remove_force (a_force: EM_GOOF_FORCE)

-- Add this object (used by loader)

require
a_force_not_void: a_force /= void
remove_object (a_object: EM_GOOF_OBJECT)

-- Add this object (used by loader)

require
a_object_not_void: a_object /= void
unregister_force (name: STRING)

-- Register 'force' with 'name'

require
name_not_void: name /= void
ensure
unregistered: not registered_forces.has(name)
unregister_object (name: STRING)

-- Register 'object' with 'name'

require
name_not_void: name /= void
ensure
unregistered: not registered_objects.has(name)

feature {EM_GOOF_LOADER_NODE_PROCESSOR, EM_GOOF_LEVEL_SCENE, EM_GOOF_OBJECT} -- Properties

set_speed (a_speed: DOUBLE)

-- Set 'speed'

ensure
speed_set: speed = a_speed
speed: DOUBLE

-- How fast do things happen?

feature -- Operate

move_camera (by_x,by_y: DOUBLE)

-- Move the camera (internal_position)
-- No strict precondition but disallowed
-- values will do nothing

feature -- Processing

process (time_length: DOUBLE)

-- Process all physics

feature -- Mouse events

events_initialized: BOOLEAN

-- Have events been initialized?

-- (From EM_DRAWABLE)

initialize_events

-- Event initialization.
-- Needs to be called before subscribing for events.

-- (From EM_DRAWABLE)

require
not_yet_initialized: not events_initialized
ensure
events_initialized: events_initialized
mouse_button_down_event_initialized: mouse_button_down_event /= Void
mouse_button_up_event_initialized: mouse_button_up_event /= Void
mouse_motion_event_initialized: mouse_motion_event /= Void
mouse_button_down_event: EM_EVENT_TYPE [TUPLE [EM_MOUSE_EVENT]]

-- Mouse button down event,
-- gets published when the mouse button is pressed over Current,
-- an EM_MOUSEBUTTON_EVENT is passed as argument

-- (From EM_DRAWABLE)

mouse_button_up_event: EM_EVENT_TYPE [TUPLE [EM_MOUSE_EVENT]]

-- Mouse button up event,
-- gets published when the mouse button is released over Current,
-- an EM_MOUSEBUTTON_EVENT is passed as argument

-- (From EM_DRAWABLE)

mouse_motion_event: EM_EVENT_TYPE [TUPLE [EM_MOUSE_EVENT]]

-- Mouse button up event,
-- gets published when the mouse button is released over Current,
-- an EM_MOUSEMOTION_EVENT is passed as argument

-- (From EM_DRAWABLE)

publish_mouse_event (a_mouse_event: EM_MOUSE_EVENT)

-- Publish mouse event when a_mouse_event occured on Current.
-- Descendants should redefine this feature
-- for only catching and publishing their mouse events when mouse pointer
-- is realy inside object or for
-- distributing mouse events to child objects.

-- (From EM_DRAWABLE)

require
a_mouse_event_not_void: a_mouse_event /= Void

feature -- Queries

bounding_box: EM_ORTHOGONAL_RECTANGLE

-- Orthogonal rectangle surrounding Current; (i.e. usefull
-- for visibility testing if it intersects with
-- coordinate_area of EM_SURFACE) TODO: We create a new
-- one on each call. Maybe there is a more efficient way to
-- do that?

-- (From EM_DRAWABLE)

ensure
result_not_void: Result /= Void
reference_point: EM_VECTOR_2D

-- Reference point of Current relative to which it should be positioned.
-- (i.e. important when drawn on a scaled coordinate system and is_size_fixed is True)

-- (From EM_DRAWABLE)

ensure
result_not_void: Result /= Void

invariant

internal_size_not_void: internal_size /= void
internal_position_not_void: internal_position /= void
screen_size_not_void: screen_size /= void
screen_position_not_void: screen_position /= void
level_large_enough: internal_size.x >= screen_size.x and internal_size.x >= screen_size.x
level_position_positive: internal_position.x >= 0 and internal_position.y >= 0
level_position_alllowed: internal_position.x <= internal_size.x - screen_size.x and internal_position.y <= internal_size.y - screen_size.y
forces_not_void: forces /= void
objects_not_void: objects /= void
objects_deletor_not_void: objects_deletor /= void
forces_deletor_not_void: forces_deletor /= void
registered_objects_not_void: registered_objects /= void
registered_forces_not_void: registered_forces /= void

-- From EM_DRAWABLE
mouse_button_down_event_initialized: events_initialized implies mouse_button_down_event /= Void
mouse_button_up_event_initialized: events_initialized implies mouse_button_up_event /= Void
mouse_motion_event_initialized: events_initialized implies mouse_motion_event /= Void

-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

end