Independent Software Solutions 

CONTENTS

  Entities


Index

Collision

Introduction

This section deals with one of the most commonly asked questions.... Collision.  There are now several options available to the DarkBASIC Professional user in helping with object collision, but for this discussion, I will refer to using only the Nuclear Glory collision system.  It will be apparent from the example that if you know what object identifier to use for your collision, you can adapt the code to suite your collision system based on this object identifier.

When the Cartography Shop map file is loaded, it is up to you, the programmer, to determine what groups which contain an object, are going to be used for collision.  Typically, you would want to use all of the map file.  This is fine for simple games, but you may only want to setup collision events for specific groups of meshes   Following is an example piece of code that will cause all groups that have a collision property to be used by Nuclear Glory.

#Constant ELLIP_2_POLY=2
#Constant RESP_SLIDE=2
#Constant DYN_NO_RESP=0

#Constant TYPE_CAM = 10
#Constant TYPE_WORLD = 11

Global nGroupCount As Integer
Global nPropertyCount As Integer
Global nProperty As Integer
Global strUseMe As String
Global nGroup As Integer
Global nObjID As Integer

Rem Startup Nuclear Glory's collision system
StartCollisionDebugPRO()

Rem Setup a collision event for the specified collision types
SetCollisionsPro( TYPE_CAM, TYPE_WORLD, ELLIP_2_POLY, RESP_SLIDE, DYN_NO_RESP )

CSM INITIAL OBJECT 1000
CSM INITIAL IMAGE 1000
nErr = Load CSM( "MyMap.csm", CSM_LIGHTMAP_MULTITEX )

Rem Now itterate through the Cartography Shop map to setup world
Rem collision for all groups. Although this can be refined to
Rem certain groups that meet a specific property criteria

Rem Obtain total number of CSM groups
nGroupCount = CSM COUNT( CSM_GROUP )
For nGroup = 0 To nGroupCount - 1

    Rem First we must test that this group is an object holder, because it could may well be that this
    Rem group is a child group of a collection of meshes, in which case it would not contain an object identifier
    nObjID = CSM Group To Object( nGroup )

    If nObjID > 0
        Rem Obtain total number of properties for this group
        nPropertyCount = CSM Property Count( CSM_GROUP, nGroup )

        For nProperty = 0 To nPropertyCount - 1
            Rem If group requires collision testing
            If CSM Property By Key( CSM_GROUP, nGroup, "Collision" ) = "Yes"
                CollisionTypePRO( nObjID, TYPE_WORLD )
            EndIf
        Next nProperty
    EndIf
Next nGroup

Rem ...
Rem ...
Rem ... Game loop here
Rem ...
Rem ...

Now, when a collision occurs, Nuclear Glory will return you a DarkBASIC object media identifier based on the collision event.  Pass this value to the function CSM OBJECT TO GROUP function which will return you the group index for the collided object.

This way, you can then query any properties or values for that group, and then perform game logic based on those properties.

 

 

(C) Paul S. J. Millard 2006