I am trying to teach myself to code with DarkDGK. It is the first time I've used any non-BASIC language so it is an uphill struggle. I thought the best method would be to write some code in DBPro and then try to replicate it in C++ (DarkGDK) but I am having problems.
Perhaps someone would be good enough to point out what the problem is with these bit of code?
DBP:
`Add Thrust
if mouseclick( ) = 1
x# = sin( Ship.Angle + 180 ) * 1.1
y# = cos( Ship.Angle ) * 1.1
phy add rigid body force Ship.oNum, x#, y#, 0, 2
endif
The same thing in DarkDGK:
//Add Thrust
int mc;
mc = dbMouseClick( );
if ( mc == 1 );
{
float x = dbSin( Ship.Angle + 180 ) * 1.1;
float y = dbCos( Ship.Angle ) * 1.1;
dbPhyAddRigidBodyForce( Ship.oNum, x, y, 0, 2);
}
As far as I can tell, they should perform the same function, which is to apply a small amount of thrust to the Physics object
Ship.oNum when the left mouse button is clicked. However, in the DarkGDK version the thrust is applied constantly. Any suggestions?
Later in the code I have this:
DBP:
`===================
` UPDATE WORLD
`===================
function UpdateWorld()
Ship.x = object position x( Ship.oNum )
Ship.y = object position y( Ship.oNum )
Ship.Angle = object angle z( Ship.oNum )
`Position camera
position camera Ship.x, Ship.y, -200
point camera Ship.x, Ship.y, 0
`Constrain 2D angles
phy set rigid body rotation Ship.oNum, -90, 0, Ship.Angle
`Constrain 2D Co-ords
phy set rigid body position Ship.oNum, Ship.x, Ship.y, 0
endfunction
DarkGDK:
//======================
// UPDATE WORLD
//======================
void UpDateWorld( void )
{
Ship.x = dbObjectPositionX( Ship.oNum );
Ship.y = dbObjectPositionY( Ship.oNum );
Ship.Angle = dbObjectAngleZ( Ship.oNum );
//Position Camera
dbPositionCamera( Ship.x, Ship.y, -200 );
dbPointCamera( Ship.x, Ship.y, 0 );
//Constrain 2D Angles
dbPhySetRigidBodyRotation( Ship.oNum, -90, 0, Ship.Angle );
//Constrain 2D Co-ords
dbPhySetRigidBodyPosition( Ship.oNum, Ship.x, Ship.y, 0 );
return;
}
Again, I think it should perform the same function but the ship remains stationary, completely unaffected by gravity or thrust unless I comment out the line that constrains the 2D angle.
This C++ stuff isn't proving easy ... any help is always appreciated.
Thanks
[Edit] Perhaps I should point out that the DBP code works perfectly.
[Edit 2]I've worked the first one out!
It's those bloody semi-colons! I hade one in the wrong place, it should be:
//Add Thrust
int mc;
mc = dbMouseClick( );
if ( mc == 1 )
{
float x = dbSin( Ship.Angle + 180 ) * 1.1;
float y = dbCos( Ship.Angle ) * 1.1;
dbPhyAddRigidBodyForce( Ship.oNum, x, y, 0, 2);
};
Still no idea about the other one though