Hey, i've decided to make 3D Pong as my first Dark GDK program, and i'm having some trouble.
Here's the code -
#include "DarkGDK.h"
void SetupCamera();
void CreateObjects();
void PositionObjects();
void StartGame();
void CheckKeys1();
void CheckKeys2();
bool CheckPosT(int objectn);
bool CheckPosB(int objectn);
void MoveBall(int BallSpeed);
bool BallOut();
void RestartGame();
void Reset();
float BallHit();
void DarkGDK ( void )
{
dbSyncOn();
dbSyncRate(60);
StartGame();
bool gamestart = 1;
float BallSpeed = 1.0;
dbCLS();
while(gamestart)
{
CheckKeys1();
CheckKeys2();
dbSync();
MoveBall(BallSpeed);
RestartGame();
BallSpeed = BallSpeed + BallHit();
if (dbEscapeKey())
break;
}
}
void SetupCamera()
{
dbMakeCamera(1);
dbPositionCamera(1,0,0,80);
dbPointCamera(1,0,0,0);
dbSetCurrentCamera(1);
dbAutoCamOff();
}
void CreateObjects()
{
dbMakeObjectBox(1, 3, 20, 5);
dbMakeObjectBox(2, 3, 20, 5);
dbMakeObjectSphere(3,3);
}
void PositionObjects()
{
dbPositionObject(1,38,0,0);
dbPositionObject(2,-38,0,0);
dbPositionObject(3,0,0,0);
dbZRotateObject(3,dbRND(360));
}
void StartGame()
{
SetupCamera();
CreateObjects();
PositionObjects();
}
void CheckKeys2()
{
if(dbUpKey() && CheckPosT(2))
{
dbPositionObject(2,dbObjectPositionX(2),dbObjectPositionY(2)+2,dbObjectPositionZ(2));
}
if(dbDownKey() && CheckPosB(2))
{
dbPositionObject(2,dbObjectPositionX(2),dbObjectPositionY(2)-2,dbObjectPositionZ(2));
}
}
void CheckKeys1()
{
if (dbKeyState(17) && CheckPosT(1))
{
dbPositionObject(1,dbObjectPositionX(1),dbObjectPositionY(1)+2,dbObjectPositionZ(1));
}
if(dbKeyState(31) && CheckPosB(1))
{
dbPositionObject(1,dbObjectPositionX(1),dbObjectPositionY(1)-2,dbObjectPositionZ(1));
}
}
bool CheckPosT(int objectn)
{
if (dbObjectPositionY(objectn) > 25)
{
return 0;
}
else
{
return 1;
}
}
bool CheckPosB(int objectn)
{
if (dbObjectPositionY(objectn) < -25)
{
return 0;
}
else
{
return 1;
}
}
void MoveBall(int BallSpeed)
{
if (CheckPosB(3) && CheckPosT(3))
{
dbMoveObjectUp(3,BallSpeed);
}
if (!CheckPosB(3))
{
dbZRotateObject(3,180-dbObjectAngleZ(3));
dbMoveObjectUp(3,1);
}
if (!CheckPosT(3))
{
dbZRotateObject(3,180-dbObjectAngleZ(3));
dbMoveObjectUp(3,1);
}
}
bool BallOut()
{
if (dbObjectPositionX(3) > 40 || dbObjectPositionX(3) < -40)
return 1;
else
return 0;
}
void RestartGame()
{
if (BallOut())
Reset();
}
void Reset()
{
PositionObjects();
dbPrint("Press any key to restart...");
dbSync();
dbWaitKey();
dbWait(100);
dbCLS();
}
float BallHit()
{
if (dbObjectHit(2,3) == 1)
{
dbZRotateObject(3,90-dbObjectAngleZ(3));
return 0.3;
}
if (dbObjectHit(1,3) == 1)
{
dbZRotateObject(3,90+dbObjectAngleZ(3));
return 0.3;
}
return 0;
}
Anyway, the problem is, that some time through the game (pretty early, maybe after hitting the ball 10 times) the ball starts sticking to the edges and vibrating. If you compile the program, you'll see. I think the problem may have something to do with the "MoveBall", "CheckPosB" and "CheckPosT" functions, but it may not be. Anyway, all help will be appreciated, and just ignore all the warnings when compiling.