hey again,
I've been strugling with the same problem for ages now, and i can't get it fixed.
when two spheres collide it should make a new one that behaves the same as the others. all it does is create a new one which just sits there.
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
int Sid = 1;
// the place in the array - the object number
int Sx [100];
// the X co-ordinates of each sphere
int Sz [100];
// the Z co-ordinates of each sphere
int Sg [100];
// the gender of each sphere - 0 for female, 1 for male
int SBo;
// the amount of blue in a sphere, dependant on its gender
int SRo;
// the amount of red in a sphere, dependant on its gender
int Sm = 2;
// how many spheres there are
int Sidc = 1;
// a counter to go through all the spheres to check if they colide
int Smx [100];
// how fast the sphere is going left or right
int Smz [100];
// how fast the sphere is going up or down
int Nx = 0;
// the x co-ordinates of a new sphere
int Nz = 0;
// the z co-ordinates of a new sphere
Sg[1] = 0;
Sg[2] = 1;
// make the first sphere female, and the seccond male
int Setup = 1;
int MN = 0;
dbSetAmbientLight ( 0 );
dbRandomize ( 2 );
// using this to change the starting positions
// make the floor
dbMakeObjectCube (201, 100);
dbPositionObject (201, 0, 0, 0);
dbScaleObject (201, 1000, 0.5, 1000);
dbColorObject (201, dbRGB ( 0, 0, 0 ));
// make the walls
dbMakeObjectCube (202, 100);
dbPositionObject (202, 500, 0, 0);
dbScaleObject (202, 40, 50, 1000);
dbMakeObjectCube (203, 100);
dbPositionObject (203, -500, 0, 0);
dbScaleObject (203, 40, 50, 1000);
dbMakeObjectCube (204, 100);
dbPositionObject (204, 0, 0, 500 );
dbScaleObject (204, 1040, 50, 40);
dbMakeObjectCube (205, 100);
dbPositionObject (205, 0, 0, -500 );
dbScaleObject (205, 1040, 50, 40);
// make the walls
while ( LoopGDK ( ) ) {
dbPositionCamera ( 0, 1000, 0 );
dbPointCamera ( 0, 0, 0 );
// Make initial spheres
if (Setup == 1) {
if (Sid <= 2) {
// reset the colours
SBo = 0;
SRo = 0;
// set the x and z values to random
Sx[Sid] = dbRND ( 500 );
Sz[Sid] = dbRND ( 500 );
// the x movement equils a number between 1 and 10
Smx[Sid] = dbRND ( 10 );
// the z movement equils 10 - the x movement, so its at the same speed
Smz[Sid] = 10 - Smx[Sid];
// make and position a new sphere
dbMakeObjectSphere ( Sid, 50 );
dbPositionObject ( Sid, Sx[Sid], 0, Sz[Sid] );
// set the colours
if (Sg[Sid] == 0){SRo = 1000;}
if (Sg[Sid] == 1){SBo = 1000;}
dbColorObject ( Sid, dbRGB ( SRo, 0, SBo ));
Sid = Sid + 1;
Sm = Sm + 1;
}}
if (Sid > 2) {
Setup = 0;
Sm = 2;
Sid = 1;
}
// Make initial spheres
//////////////////////////////////////////////////////////////////////////////////////
// Run the spheres
if ( Setup == 0 ) {
if (Sid <= Sm) {
// check for collisions with walls, if so reverse direction
if (dbObjectCollision ( Sid, 202 )) {
Smx[Sid] = Smx[Sid] * -1;
Smz[Sid] = Smz[Sid] * 1;
}
if (dbObjectCollision ( Sid, 203 )) {
Smx[Sid] = Smx[Sid] * -1;
Smz[Sid] = Smz[Sid] * 1;
}
if (dbObjectCollision ( Sid, 204 )) {
Smx[Sid] = Smx[Sid] * 1;
Smz[Sid] = Smz[Sid] * -1;
}
if (dbObjectCollision ( Sid, 205 )) {
Smx[Sid] = Smx[Sid] * 1;
Smz[Sid] = Smz[Sid] * -1;
}
Sx[Sid] = dbObjectPositionX ( Sid );
Sz[Sid] = dbObjectPositionZ ( Sid );
// reposition the object
dbPositionObject ( Sid, ( Sx[Sid] + Smx[Sid] ), 0,( Sz[Sid] + Smz[Sid] ) );
// this checks for collision with sid and sidc
for (Sidc; Sidc < Sm; Sidc++) {
if ( dbObjectCollision ( Sidc, Sid ) ) {
MN = 1;
Smx[Sidc] = Smx[Sidc] * - 1;
Smx[Sidc] = Smz[Sidc] * - 1;
Smz[Sid] = Smx[Sid] * - 1;
Smz[Sid] = Smx[Sid] * - 1;
Nz = Sz[Sid] - 30;
Nx = Sx[Sid];
}}
Sid = Sid + 1;
}}
// make a new sphere
if (MN == 1) {
Sm = Sm + 1;
Sid = Sm;
SBo = 0;
SRo = 0;
Sx[Sid] = Nx;
Sz[Sid] = Nz;
Smx[Sid] = dbRND ( 10 );
Smz[Sid] = 10 - Smx[Sid];
Sg[Sid] = dbRND ( 1 );
dbMakeObjectSphere ( Sid, 50 );
dbPositionObject ( Sid, Sx[Sid], 0, Sz[Sid] );
if (Sg[Sid] == 0){SRo = 1000;}
if (Sg[Sid] == 1){SBo = 1000;}
dbColorObject ( Sid, dbRGB ( SRo, 0, SBo ));
MN = 0;
}
// Run the spheres
dbSync();
}
return;
}
Please help,
David
True geeks live forever, or die trying.