collision.cpp File Reference

#include "stdafx.h"

Include dependency graph for collision.cpp:

Go to the source code of this file.

Functions

void DoCollisions (CWorld *ThisWorld)
 check for collisions
void Collide (CWorld *ThisWorld, CObject *ObjA, CObject *ObjB)
 process collision results
int InitCollision (void)
 initialize collision detection system
int loadInteractionMatrix (int *matrix, const char *filename)
 load interaction matrix from disk
int getInteraction (int matrixID, int typeID_A, int typeID_B)
 get object interaction response code
void ProcessTileCollisions (CWorld *ThisWorld)
 check for collisions between players and tile objects

Variables

int collisionInteract [INTERACTION_MATRIX_SIZE *INTERACTION_MATRIX_SIZE]
int damageInteract [INTERACTION_MATRIX_SIZE *INTERACTION_MATRIX_SIZE]
int effectInteract [INTERACTION_MATRIX_SIZE *INTERACTION_MATRIX_SIZE]


Function Documentation

void Collide ( CWorld ThisWorld,
CObject ObjA,
CObject ObjB 
)

Process the results of a collision between two objects passed in as references. This function uses a matrix-lookup approach to determine the appropriate response to any particular collision, examining each object's 'iType' member variable and using it as an index in to the interaction matrix. This scheme is used three times in order to retrieve the appropriate responses for collision, damage, and effects (such as equipping the player with a certain weapon).

Definition at line 102 of file collision.cpp.

References GameLogicDamage(), GameLogicEquip(), getInteraction(), CObject::iHealth, CObject::iType, MATRIXID_COLLISION, MATRIXID_DAMAGE, MATRIXID_EFFECT, PhysicsDampedCollision(), PhysicsElasticCollision(), PhysicsReflect(), PhysicsStop(), PlaySound(), RESPONSE_COL_DAMPED, RESPONSE_COL_ELASTIC, RESPONSE_COL_REFLECT_A, RESPONSE_COL_REFLECT_B, RESPONSE_COL_REFLECT_BOTH, RESPONSE_COL_STOP_A, RESPONSE_COL_STOP_B, RESPONSE_COL_STOP_BOTH, RESPONSE_DMG_A, RESPONSE_DMG_B, RESPONSE_DMG_BOTH, RESPONSE_DMG_KILL_A, RESPONSE_DMG_KILL_B, RESPONSE_DMG_KILL_BOTH, RESPONSE_EFF_EQUIP_A, RESPONSE_EFF_EQUIP_B, RESPONSE_NULL, and SOUNDID_BOUNCE.

Referenced by DoCollisions().

Here is the call graph for this function:

Here is the caller graph for this function:

void DoCollisions ( CWorld ThisWorld  ) 

Check the game world's objects for object pairs which are colliding with each other. If they are, pass the objects as references to a routine which will process the interaction between the two objects.

Todo:
Currently this function performs only simple bounding-box collision detection. Update this to recurse in to a more accurate collision detection method once the objects bounding boxes are found to be touching.

Definition at line 43 of file collision.cpp.

References CObject::bCheckedForCollision, Collide(), CObject::fBBBottom, CObject::fBBLeft, CObject::fBBRight, CObject::fBBTop, CWorld::iNumCollisions, CObject::Next, CWorld::Objects, CObject::Position, Vector::x, and Vector::y.

Referenced by PlayGame().

Here is the call graph for this function:

Here is the caller graph for this function:

int getInteraction ( int  matrixID,
int  typeID_A,
int  typeID_B 
)

This function looks up the interaction response code in a matrix structure for a given game object pair. The matrixID parameter specifies which type of response should be retrieved; collision, damage, and effect responses.

Definition at line 276 of file collision.cpp.

References collisionInteract, damageInteract, DAS_ERROR, effectInteract, INTERACTION_MATRIX_SIZE, MATRIXID_COLLISION, MATRIXID_DAMAGE, and MATRIXID_EFFECT.

Referenced by Collide().

Here is the caller graph for this function:

int InitCollision ( void   ) 

Initialize the collision detection system. Loads the object interaction matrices from disk, and performs any needed setup on the collision detection engine.

Definition at line 212 of file collision.cpp.

References collisionInteract, damageInteract, DAS_ERROR, effectInteract, and loadInteractionMatrix().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

int loadInteractionMatrix ( int *  matrix,
const char *  filename 
)

Load data from an interaction matrix file stored on disk. The interaction matrix can hold information about collision response, damage taken, and other effects that occur when two objects come in contact with each other.

Definition at line 230 of file collision.cpp.

References DAS_ERROR, and INTERACTION_MATRIX_SIZE.

Referenced by InitCollision().

Here is the caller graph for this function:

void ProcessTileCollisions ( CWorld ThisWorld  ) 

This function check all players against the tile objects they're 'standing' on and processes collision events based on the particular type of tile the player is on. This function employs a timer routine in order to only periodically apply the collision effect.

Definition at line 303 of file collision.cpp.

References CWorld::AddEffect(), CELL_SIZE, EFFECTID_PSYSTEM, CObject::fBBBottom, CObject::fBBLeft, CObject::fBBRight, CObject::fBBTop, CTile::iDamage, CObject::iHealth, CTile::iTileEffect, MAP_SIZE, NUM_PLAYERS, PI, CWorld::Player, PlaySound(), CObject::Position, CEffect::PSys, PSystem::SetColor(), SOUNDID_BURNING, TILE_EFFECT_DAMAGE, TILE_EFFECT_TIMER, TILE_SOUND_TIMER, CWorld::tiles, Vector::x, and Vector::y.

Referenced by PlayGame().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int collisionInteract[INTERACTION_MATRIX_SIZE *INTERACTION_MATRIX_SIZE]

Definition at line 27 of file collision.cpp.

Referenced by getInteraction(), and InitCollision().

int damageInteract[INTERACTION_MATRIX_SIZE *INTERACTION_MATRIX_SIZE]

Definition at line 28 of file collision.cpp.

Referenced by getInteraction(), and InitCollision().

int effectInteract[INTERACTION_MATRIX_SIZE *INTERACTION_MATRIX_SIZE]

Definition at line 29 of file collision.cpp.

Referenced by getInteraction(), and InitCollision().

 

Copyright Windsor Schmidt 2006 - All rights reserved.