Class TVisibleObject (unit Visible)

Inherits from

TStateAware

****** * * Module: Visible * Author: Joe Kessler * IntegrationWare - A New Generation of Extraordinary PC Solutions * www.integrationware.com * * Purpose: * * This module defines TVisibleObject, the base class for all objects that * eppear on the screen. This is one of the more complicated classes in * the application, encapsulating all of the core behvaior required by * objects in the universe. *

Constructors


constructor Create(lstUniverse: TList; { List of ALL objects. } iCollisionID: Integer);

Constructor and destructor.


Functions

procedure BeginFlashing;

Methods to begin and end random color flashing.

function bIsObjectColliding(objObject: TVisibleObject): Boolean;

Method to check if the given object is colliding with this one.

function bIsRectSafe(rectArea: TRect): Boolean;

Method to check if the given screen rectangle is large enough for this object to appear in without colliding with object objects.

procedure ClearShape;


destructor Destroy;

Collision ID to be used.

procedure Draw;

Method to draw and erase this polygon.

function edgeDefineNewEdge(vtxOne, vtxTwo: TVertex; clrColor: TColor; bIncludeInCollisions: Boolean): TEdge;

Add the vertex to the current list.

procedure EndFlashing;

Begin a color flashing sequence.

procedure EnterState(pCommand: PState);

Inherited methods that allow the visible object to respond to commands embedded in a state queue.

procedure Erase;

If the edge is part of the given shape, set is visibility.

procedure HandleCollision(objOtherObject: TVisibleObject);

Method providing default behavior in response to collisions.

function IncludeShape(szShapeFile: String; iRelativeX, iRelativeY: Integer; clrEdge: TColor; bIncludeInCollisions: Boolean): Integer;

Method to declare a defined shape as a part of the object structure.

procedure KillObject(bShatter: Boolean; iDuration: Integer; fMaxScatter: Real; fMaxSpin: Real; fFragmentationRate: Real);

Methods to signal the death of an object.

procedure Move;

Default movement behavior for visible objects.

procedure ProcessState(pstCurrent: PState);

If requested, exit the current state automatically.

function rectGetBoundingRect: TRect;

Method to get a rectangle that bounds the entire object at run-time.

procedure SetShapeVisible(m_iShapeID: Integer; bNewState: Boolean);

Methods to get and set the polygon's visible state.

procedure ShatterVertices(fDirection: Real; iDuration: Integer; fMaxScatter: Real; fMaxSpin: Real; fFragmentationRate: Real);

This method is called to disintegrate the object into flying shards of twisted metal or rock.

function vtxDefineNewVertex(fLocalX, fLocalY: Real): TVertex;

Functions for defining new edges and vertices.

procedure Wrap;

This method determines if the object is off the screen and, if so, wraps it around to the other side.

procedure DumpUnusedVertices;

Method to trim unused vertices from the object, in order to save execution time when transforming vertices.

procedure ProgressFlashing;

Method to process an object that is flashing wildly.

procedure TransformAndTranslate;

Method to compute the vertex positions based upon the object's current position and orientation.

Properties

property bCanCollide : Boolean


property bObjectDead : Boolean


property bVisible : Boolean

Exposed properties.

property devVideo : TVideoDevice


property iCollisionID : Integer


property iGroupID : Integer


property lstEdges : TList


property lstUniverse : TList


property lstVertices : TList


property mtrxTransform : TTemporalMatrix2D


Events

Variables

m_bCanCollide : Boolean;

TRUE if the object is currently on the screen.

m_bCurrentlyDrawn : Boolean;

TRUE if the object has been drawn at least once.

m_bCurrentlyFlashing : Boolean;

ID of control group this object belongs to.

m_bDrawnBefore : Boolean;

TRUE of the object is currently visible.

m_bObjectDead : Boolean;

TRUE if the object is eligible for collisions.

m_bShapeChanged : Boolean;

TRUE when the object can be released.

m_bVisible : Boolean;

ID to be associated with the next shape defined.

m_devVideo : TVideoDevice;


m_fLastColorChange : Real;

Current flash color from a random set.

m_iCollisionID : Integer;

List of all objects in the universe.

m_iGroupID : Integer;

Master tranformation matrix.

m_iNextShapeID : Integer;

List of edges between vertices.

m_lstEdges : TList;

List of vertices that define the object's shape.

m_lstUniverse : TList;

Current video output object.

m_lstVertices : TList;

Collision ID, determines who can hit me.

m_mtrxTransform : TTemporalMatrix2D;

TRUE if the object shape has changed recently.

m_rgbCurrentFlashColor : TColor;

TRUE if the object is flashing wildly.


Constructors


constructor Create(lstUniverse: TList; { List of ALL objects. } iCollisionID: Integer);

Constructor and destructor.


Functions


procedure BeginFlashing;

Methods to begin and end random color flashing. This looks great when used to highlight text items like bonuses, etc..

Clear our edge and vertex lists.


function bIsObjectColliding(objObject: TVisibleObject): Boolean;

Method to check if the given object is colliding with this one. This method implements a polygon intersection algorithm to determine this.

Upon collision, shatter the object violently.


function bIsRectSafe(rectArea: TRect): Boolean;

Method to check if the given screen rectangle is large enough for this object to appear in without colliding with object objects.

If the object is in a clearing then exiting the wait state.


procedure ClearShape;


destructor Destroy;

Collision ID to be used.

Set up a transformation matrix for processing vertices in real-time.


procedure Draw;

Method to draw and erase this polygon.

Connect the two edges using a line.


function edgeDefineNewEdge(vtxOne, vtxTwo: TVertex; clrColor: TColor; bIncludeInCollisions: Boolean): TEdge;

Add the vertex to the current list.


procedure EndFlashing;

Begin a color flashing sequence.


procedure EnterState(pCommand: PState);

Inherited methods that allow the visible object to respond to commands embedded in a state queue.

If the vertex is unused then free it.


procedure Erase;

If the edge is part of the given shape, set is visibility.


procedure HandleCollision(objOtherObject: TVisibleObject);

Method providing default behavior in response to collisions.

Compute the direction of movement of the next scrap.


function IncludeShape(szShapeFile: String; iRelativeX, iRelativeY: Integer; clrEdge: TColor; bIncludeInCollisions: Boolean): Integer;

Method to declare a defined shape as a part of the object structure.

This method is called by inherited object types such as TAlien and TBart to define their shape. The shape name that is passed in must be defined in the global shape library.


procedure KillObject(bShatter: Boolean; iDuration: Integer; fMaxScatter: Real; fMaxSpin: Real; fFragmentationRate: Real);

Methods to signal the death of an object. The death can be made more dramatic by having the object shatter into a billion shards.

This method gets called when the program wants to explicitly kill the object. The object can just disappear, or shatter violently. These parameters control the varacity of the explosion.


procedure Move;

Default movement behavior for visible objects.

Add the edge to the current list, and return a reference to it.


procedure ProcessState(pstCurrent: PState);

If requested, exit the current state automatically.


function rectGetBoundingRect: TRect;

Method to get a rectangle that bounds the entire object at run-time.

This method will calculate the bounding screen rectangle that contains the object in its current state. This logic works no matter how the object has been scaled or rotated.


procedure SetShapeVisible(m_iShapeID: Integer; bNewState: Boolean);

Methods to get and set the polygon's visible state. An object can be constructed from multiple polygons, each of which has its own state.

Since an object can consist of multiple combined shapes, this method allows an object to make an individual shape visible or invisible. A perfect example is TBart's engine flame, which is visible ONLY when the player is firing the thrusters.


procedure ShatterVertices(fDirection: Real; iDuration: Integer; fMaxScatter: Real; fMaxSpin: Real; fFragmentationRate: Real);

This method is called to disintegrate the object into flying shards of twisted metal or rock. Essentially, each edge of the object is converted to a separate TScrap object, and allowed to float independently in space.


function vtxDefineNewVertex(fLocalX, fLocalY: Real): TVertex;

Functions for defining new edges and vertices.

Record the current state of the matrix.


procedure Wrap;

This method determines if the object is off the screen and, if so, wraps it around to the other side.


procedure DumpUnusedVertices;

Method to trim unused vertices from the object, in order to save execution time when transforming vertices.

If enough time has passed, change the flash-color of the text.


procedure ProgressFlashing;

Method to process an object that is flashing wildly.

Stop the object from flashing.


procedure TransformAndTranslate;

Method to compute the vertex positions based upon the object's current position and orientation.

Record that we've been drawn before.


Properties


property bCanCollide : Boolean


property bObjectDead : Boolean


property bVisible : Boolean

Exposed properties.


property devVideo : TVideoDevice


property iCollisionID : Integer


property iGroupID : Integer


property lstEdges : TList


property lstUniverse : TList


property lstVertices : TList


property mtrxTransform : TTemporalMatrix2D


Events


Variables


m_bCanCollide : Boolean;

TRUE if the object is currently on the screen.


m_bCurrentlyDrawn : Boolean;

TRUE if the object has been drawn at least once.


m_bCurrentlyFlashing : Boolean;

ID of control group this object belongs to. } { Values used to control color flashing.


m_bDrawnBefore : Boolean;

TRUE of the object is currently visible.


m_bObjectDead : Boolean;

TRUE if the object is eligible for collisions.


m_bShapeChanged : Boolean;

TRUE when the object can be released.


m_bVisible : Boolean;

ID to be associated with the next shape defined.


m_devVideo : TVideoDevice;


m_fLastColorChange : Real;

Current flash color from a random set.


m_iCollisionID : Integer;

List of all objects in the universe.


m_iGroupID : Integer;

Master tranformation matrix.


m_iNextShapeID : Integer;

List of edges between vertices.


m_lstEdges : TList;

List of vertices that define the object's shape.


m_lstUniverse : TList;

Current video output object.


m_lstVertices : TList;

Collision ID, determines who can hit me.


m_mtrxTransform : TTemporalMatrix2D;

TRUE if the object shape has changed recently.


m_rgbCurrentFlashColor : TColor;

TRUE if the object is flashing wildly.