hi, I just started learning gdk about 2 days ago. so far i can move my character forward and backwards. But i dont now how to make him jump.
here is my code for forward and backwards. plz help me out with jump. remember i just start 2 days ago so i cant understant hard code like classess, functions... etc. i want to keep it really basic. i want t use dbUpKey() function.
#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(2,400,50,2);
dbSprite(3,250,50,3);
dbSprite(4,200,250,4);
//keep looping through until user enter escape key
while (LoopGDK())
{
//move image forward
if(dbRightKey() == 1)
{
dbRotateSprite(1, 90); //rotate image right
dbMoveSprite(1, 20); //image#, move 20 space right
dbRotateSprite(1,0); //rotate back to normal
//collision with all numbers greater than 0. but not 3
if(dbSpriteCollision(1, 0) > 0 && dbSpriteCollision(1, 0) != 3)
{
dbRotateSprite(1, 270); //roate image left
dbMoveSprite(1,20); //image#, move 20 space left
dbRotateSprite(1,0); //rotate back to normal
}
if(dbSpriteCollision(1, 0) == 3) //del coin
{
dbDeleteSprite(3);
}
}
//move image left
if(dbLeftKey() == 1)
{
dbRotateSprite(1, 270); //roate image left
dbMoveSprite(1,20); //image#, move one space up
dbRotateSprite(1,0); //rotate back to normal
if(dbSpriteCollision(1, 0) > 0 && dbSpriteCollision(1, 0) != 3)
{
dbRotateSprite(1, 90); //rotate image right
dbMoveSprite(1, 20); //image#, move 20 space right
dbRotateSprite(1, 0); //rotate back to normal
}
if(dbSpriteCollision(1, 0) == 3) //del coin
{
dbDeleteSprite(3);
}
}
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;
}