I've got a task to create ludo in my programing class and because we was forced to only use c++, I decided to use DarkGDK (have used dbp for 1 year now).
Now my problem is that my game doesn't work and I have found out that it's (probably) because of that some of my variables is getting the same value
(Never had this problem with dbp
)
#include <cstdlib>
#include "DarkGDK.h"
#include <string>
#include <sstream>
using namespace std;
string PlayerName(int);
void Print(string,int,int);
int rnd(int);
void NextRound();
void EndRound(int);
void ShowRound(int);
void Movement(int,int);
void InitRound();
void Camera();
int NextMove(int);
int ObjectPlayer(int);
void PositionPlayerHome(int);
void EndGame(int);
// variables:
int temp2=0;
int i=0;
int j=0;
int riktning=1;
int xCam=0;
int cameraAngle=1;
int cameraAngle2=1;
int yCam=500;
int zCam=0;
int cameraCheck=0;
int dice=0;
int initCheck=0;
int playerNr;
int cantMoveCheck=0;
int mouseCheck=0;
int playerMoveCheck=0;
int pointObject=0;
int print_X=0;
int print_Y=0;
char* ctemp;
string str="";
string fstr="";
stringstream ss;
int victory[4];
int playerPos[4][4];
int playerMove[4][3];
int placeCheck[56];
int playerStart[4][2];
void DarkGDK ( void )
{
playerStart[1][1]=90;
playerStart[1][2]=416;
playerStart[2][1]=421;
playerStart[2][2]=-88;
playerStart[3][1]=-76;
playerStart[3][2]=-420;
playerStart[4][1]=-412;
playerStart[4][2]=82;
playerNr=(rnd(3)+1);
//initializing
srand(dbTimer());
dbSetDisplayMode (1280,800,32);
dbMaximizeWindow();
dbHideMouse();
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetTextFont("arial");
dbSetTextSize(22);
dbSetAmbientLight(60);
dbLoadImage("Blå.jpg",6);
dbLoadImage("Grön.jpg",7);
dbLoadImage("Röd.jpg",8);
dbLoadImage("Gul.jpg",9);
dbLoadImage("FiaMus1.png",1);
dbLoadImage("FiaMus2.png",2);
dbLoadImage("FiaMus3.png",3);
dbLoadImage("FiaMus4.png",4);
dbLoadImage("Ghost.png",5);
dbLoadObject("Banan.x",1);
dbPositionObject(1,0,0,0);
dbLoadObject("Spelare.x",2);
dbColorBackdrop(dbRgb(0,0,0));
for (i=3;i<19;i++)
{
dbCloneObject(i,2);
if (i>=3 && i<=6)
dbTextureObject(i,6);
if (i>=7 && i<=10)
dbTextureObject(i,7);
if (i>=11 && i<=14)
dbTextureObject(i,8);
if (i>=15 && i<=18)
dbTextureObject(i,9);
PositionPlayerHome(i);
}
dbTextureObject(2,5);
dbSetObjectTransparency(2,1);
dbHideObject(2);
dbMoveCamera(-50);
//main loop
while ( LoopGDK ( ) )
{
dbEnd();
pointObject=dbPickObject(dbMouseX(),dbMouseY(),3,18);
if (dbMouseClick()==0 && mouseCheck==1)
{
mouseCheck=0;
}
if (cantMoveCheck==1)
{
Print("Spelare "+PlayerName(playerNr)+" kan inte röra sig",640,100);
if (dbMouseClick()==1 && mouseCheck==0)
{
NextRound();
}
}
if (dbMouseClick()==1)
{
if (pointObject>=3+(playerNr-1)*4 && pointObject<=6+(playerNr-1)*4 && initCheck==1)
{
EndRound(pointObject);
}
mouseCheck=1;
}
if (initCheck==0)
{
InitRound();
}
if (initCheck==1 && pointObject>=3+(playerNr-1)*4 && pointObject<=6+(playerNr-1)*4)
{
ShowRound(pointObject);
}
else
{
if (dbObjectVisible(2)==1)
{
dbHideObject(2);
}
}
Print("Spelare "+PlayerName(playerNr)+":s Tur",100,100);
dbInk(dbRgb(255,255,255),0);
if(dice!=0)
{
ss.str("");
ss<<"Tärningen:"<<dice;
Print(ss.str(),100,150);
}
dbSprite(1,dbMouseX()-10,dbMouseY()-19,playerNr);
Camera();
dbSync();
//main loop end
}
return;
}
//functions
int rnd(int rnd)
{
return rand()%(rnd+1);
}
void PositionPlayerHome(int nr)
{
if(nr==3 || nr==7 || nr==11 || nr==15)
{
dbPositionObject(nr,254+(-254*2*(nr==15 || nr==11)),36,246+(-246*2*(nr==7 || nr==11)));
}
if(nr==4 || nr==8 || nr==12 || nr==16)
{
dbPositionObject(nr,254+(-254*2*(nr==16 || nr==12)),36,302+(-302*2*(nr==8 || nr==12)));
}
if(nr==5 || nr==9 || nr==13 || nr==17)
{
dbPositionObject(nr,312+(-312*2*(nr==17 || nr==13)),36,302+(-302*2*(nr==9 || nr==13)));
}
if(nr==6 || nr==10 || nr==14 || nr==18)
{
dbPositionObject(nr,312+(-312*2*(nr==18 || nr==14)),36,246+(-246*2*(nr==10 || nr==14)));
}
}
int ObjectPlayer(int nr)
{
int temp=0;
if(nr>=3 && nr<=6)
{
temp=1;
}
if(nr>=7 && nr<=10)
{
temp=2;
}
if(nr>=11 && nr<=14)
{
temp=3;
}
if(nr>=15 && nr<=18)
{
temp=4;
}
return temp;
}
int NextMove(int nr)
{
int temp=0;
if((nr>=1 && nr<=4) || nr==9 || (nr==10 && playerNr!=2) || (nr>=15 && nr<=18) || (nr>=41 && nr<=44) || (playerNr==1 && nr==40) || (nr==100 && playerNr==1))
{
temp=1;
}else
{
if((nr>=21 && nr<=24) || nr==29 || (nr==30 && playerNr!=4) || (nr>=35 && nr<=38) || (nr>=49 && nr<=52) || (playerNr==3 && nr==20) || (nr==100 && playerNr==3))
{
temp=3;
}else
{
if((nr>=11 && nr<=14) || nr==19 || (nr==20 && playerNr!=3) || (nr>=25 && nr<=28) || (nr>=45 && nr<=48) || (playerNr==2 && nr==10) || (nr==100 && playerNr==2))
{
temp=2;
}else
{
if((nr>=5 && nr<=8) || (nr>=39 && nr<=40) || (nr>=31 && nr<=34) || (nr>=53 && nr<=56) || (playerNr==4 && nr==30) || (nr==100 && playerNr==4))
temp=4;
}
}
}
return temp;
}
void Camera()
{
if(cameraCheck==0)
{
cameraAngle=cameraAngle+2*(dbRightKey()-dbLeftKey());
xCam=dbSin(cameraAngle)*1000;
zCam=dbCos(cameraAngle)*1000;
}
yCam=yCam+(dbUpKey()-dbDownKey())*15;
if(yCam>=801)
{
yCam=800;
cameraCheck=1;
xCam=0;
zCam=0;
}
if(yCam<=799)
{
cameraCheck=0;
}
if(yCam<=-401)
{
yCam=-400;
}
if(cameraAngle<=0)
{
cameraAngle=360;
}
if(cameraAngle>=361)
{
cameraAngle=1;
}
dbPositionCamera(xCam,yCam,zCam);
dbPointCamera(0,0,0);
}
void InitRound()
{
int temp;
playerMoveCheck=0;
dice=rnd(5)+1;
initCheck=1;
for(i=1;i<5;i++)
{
temp=playerPos[playerNr][i];
playerMove[i][1]=-1;
if(temp==0)
{
playerMove[i][2]=playerStart[playerNr][1];
playerMove[i][3]=playerStart[playerNr][2];
if(dice==1 && (placeCheck[1+(playerNr-1)*10]==0 || ObjectPlayer(placeCheck[1+(playerNr-1)*10])!=playerNr))
{
playerMove[i][1]=1+(playerNr-1)*10;
}
if(dice==6 && (placeCheck[6+(playerNr-1)*10]==0 || ObjectPlayer(placeCheck[6+(playerNr-1)*10])!=playerNr))
{
Movement(temp,i);
}
}else
{
if(temp!=100)
{
playerMove[i][2]=dbObjectPositionX(2+i+(playerNr-1)*4);
playerMove[i][3]=dbObjectPositionX(2+i+(playerNr-1)*4);
Movement(temp,i);
}
}
if(playerMove[i][1]==-1)
{
playerMoveCheck++;
}
}
if(playerMoveCheck==4)
{
cantMoveCheck=1;
}
}
void Movement(int temp,int nr)
{
playerMove[nr][1]=temp;
riktning=1;
for(j=0;j<dice+1;j++)
{
if(temp!=0)
{
if(playerMove[nr][1]==100)
{
riktning=-1;
}
temp2=NextMove(playerMove[nr][1]);
if(temp2==1)
{
playerMove[nr][3]=playerMove[nr][3]-84*riktning;
}
if(temp2==2)
{
playerMove[nr][2]=playerMove[nr][2]-84*riktning;
}
if(temp2==3)
{
playerMove[nr][3]=playerMove[nr][3]+84*riktning;
}
if(temp2==4)
{
playerMove[nr][2]=playerMove[nr][2]+84*riktning;
}
if(playerMove[nr][1]!=100)
{
playerMove[nr][1]=playerMove[nr][1]+riktning;
}else
{
playerMove[nr][1]=44+(playerNr-1)*4;
}
//Man kan inte gå förbi en själv (avstängd)
// if ObjectPlayer(placeCheck(playerMove(nr,1)))=playerNr and 0 then playerMove(nr,1)=-1
/////////////////////////////////////////
if(playerMove[nr][1]==41 && playerNr!=1)
{
playerMove[nr][1]=1;
}
if(playerMove[nr][1]==1+(playerNr-1)*10)
{
playerMove[nr][1]=41+(playerNr-1)*4;
}
if(riktning==-1 && playerMove[nr][1]==40+(playerNr-1)*4 && playerNr!=1)
{
playerMove[nr][1]=(playerNr-1)*10;
}
if(playerMove[nr][1]>=43+(playerNr-1)*4)
{
playerMove[nr][1]=100;
}else
{
playerMove[nr][1]=1+(playerNr-1)*10;
}
temp=playerMove[nr][1];
}
}
if(ObjectPlayer(placeCheck[playerMove[nr][1]])==playerNr)
{
playerMove[nr][1]=-1;
}
}
void ShowRound(int nr)
{
if(playerMove[nr-2-(playerNr-1)*4][1]!=-1)
{
if(dbObjectVisible(2)==0)
{
dbShowObject(2);
}
dbPositionObject(2,playerMove[nr-2-(playerNr-1)*4][2],41,playerMove[nr-2-(playerNr-1)*4][3]);
}
}
void EndRound(int nr)
{
int temp=nr-2-(playerNr-1)*4;
if(playerMove[temp][1]!=-1)
{
placeCheck[playerPos[playerNr][temp]]=0;
playerPos[playerNr][temp]=playerMove[temp][1];
if(playerMove[temp][1]!=100)
{
if(placeCheck[playerPos[playerNr][temp]]!=0)
{
playerPos[ObjectPlayer(placeCheck[playerMove[temp][1]])][placeCheck[playerMove[temp][1-2-(ObjectPlayer(placeCheck[playerMove[temp][1]])-1)*4]]]=0;
PositionPlayerHome(placeCheck[playerMove[temp][1]]);
}
dbPositionObject(nr,playerMove[temp][2],36,playerMove[temp][3]);
placeCheck[playerPos[playerNr][temp]]=nr;
}else
{
dbHideObject(nr);
victory[playerNr]=victory[playerNr]+1;
}
NextRound();
}
}
void NextRound()
{
for(i=1;i<5;i++)
{
if(victory[i]==4)
{
EndGame(i);
}
}
initCheck=0;
if(dice!=6 || cantMoveCheck==1)
{
playerNr=playerNr+1;
}
cantMoveCheck=0;
dice=0;
if(playerNr>4)
{
playerNr=1;
}
}
void EndGame(int player)
{
dbEnd();
}
string PlayerName(int player)
{
if(player==1)
{
fstr="Blå";
dbInk(dbRgb(0,0,255),0);
}
if(player==2)
{
fstr="Grön";
dbInk(dbRgb(0,255,0),0);
}
if(player==3)
{
fstr="Röd";
dbInk(dbRgb(255,0,0),0);
}
if(player==4)
{
fstr="Gul";
dbInk(dbRgb(255,255,0),0);
}
return fstr;
}
void Print(string fstr,int print_X,int print_Y)
{
ctemp = new char[fstr.length() + 1];
strcpy(ctemp, fstr.c_str());
dbCenterText(print_X,print_Y,ctemp);
delete []ctemp;
}
Any help would be great
(Have included the game, both the working made in dbp and the non working in c++)