Hi, iam trying to make my rock.bmp jump. it kind of works fine but there are some problems.
1st my rock.bmp jumps too slow.
2nd my rock.bmp jump in mid air too.
i really dont know where to start fixing this problem. can any one take a look at my code.
left and right works find
#include "DarkGDK.h"
void DarkGDK(void)
{
dbSyncOn();
dbSyncRate(60);
dbDisableEscapeKey();
dbLoadImage("rock.bmp", 1);
int x = 10;
int y = 400;
int velx = 0; //how fast start with 0
int vely = 0; //how fast start with 0
const int gravity = 2; //gravit stay same
while(LoopGDK())
{
if(dbRightKey() == 1)
{
velx = 5;
dbRotateSprite(1, 90);
dbMoveSprite(1, velx);
dbRotateSprite(1,0);
}
else if(dbLeftKey() == 1)
{
velx = -5;
dbRotateSprite(1, 90);
dbMoveSprite(1, velx);
dbRotateSprite(1,0);
}
else
{
velx = 0;
}
if(dbUpKey() == 1 && y >= 310)
{
vely = -5;
dbMoveSprite(1, vely);
}
else
{
vely = 0;
}
vely += gravity;
x += velx;
y += vely;
dbSprite(1,x,y,1);
if(y >= 400) //ground height
{
y = 400; //stay at ground height
}
if(dbEscapeKey() == 1)
{
break;
}
dbSync();
}
}