so this program is really simply. my player(ch1,bmp) just move right and left. on my map there are wall and coin. if player hit a wall it should stop. but if it hit a coin, coin should get delete.
problem iam having is that for some reason player(ch.bmp) is display as a coin.
i think its bc iam not using sprite right.
#include "DarkGDK.h"
void DarkGDK (void)
{
dbSyncOn(); // dbSyncOn() = turn sync on, this means we control when the screen is updated
dbSyncRate(60); //maximum frame rate will be set at 60 frames per second
dbDisableEscapeKey(); // to exit from main while loop and stop the game
dbSetImageColorKey(255,255,255); //igore color
dbLoadImage("ch1.bmp",1); //load image to memory
dbLoadImage("wall.bmp",2);
dbLoadImage("coin.bmp",3);
dbSprite(1,100,50,1); //mage#,x,y,image# -display image
dbSprite(1,400,50,2);
dbSprite(1,250,50,3);
// keep looping through until user enter escape key
while (LoopGDK())
{
//move image forward
if(dbRightKey() == 1)
{
dbRotateSprite(1, 90); //rotate image
dbMoveSprite(1,1); //image#, move one space up
dbRotateSprite(1,0); //rotate back to normal
if(dbSpriteCollision(1,3) == 1) //del coin
{
dbDeleteSprite(3);
}
if(dbSpriteCollision(1, 2) == 1)
{
dbRotateSprite(1, 270); //rotate image
dbMoveSprite(1,1); //image#, move one space up
dbRotateSprite(1,0); //rotate back to normal
}
}
//move image left
if(dbLeftKey() == 1)
{
dbRotateSprite(1, 270); //roate image
dbMoveSprite(1,1); //image#, move one space up
dbRotateSprite(1,0); //rotate back to normal
if(dbSpriteCollision(1,3) == 1) //del coin
{
dbDeleteSprite(3);
}
if(dbSpriteCollision(1, 2) == 1)
{
dbRotateSprite(1, 90); //rotate image
dbMoveSprite(1,1); //image#, move one space up
dbRotateSprite(1,0); //rotate back to normal
}
}
if (dbEscapeKey() == 1) //if the ecape key is pressed, the program will exit
{
break;
}
dbSync(); //update the screen
}//end of main while loop
for(int i = 1; i < 10; i++)
{
dbDeleteImage(i); //delete
dbDeleteSprite(i); //delete
}
return;
}