I was working on a game for a final project when i figured i would need some form of jumping and I came to a halt in the programming and the teacher is of no help because she tells us to figure it out on our own. So i have been trying for 2 days now to figure it out and nothing i try is working. here is my code
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetWindowTitle("Final");
//load images
dbLoadImage("brick.png",2);
dbLoadImage("grass.png",3);
dbLoadImage("grass2.png",4);
dbLoadImage("grass2dirt.png",5);
//sprite info
int movex;
int movey;
movex=50;
movey=350;
int coinx;
coinx=150;
//gravity int
const int GRAVITY = 1;
const int STARTY = 350;
int yPos = STARTY;
int xPos = 50;
int xSpeed = 2;
int ySpeed = 0;
int Persony = 0;
//load sound
dbLoadSound("smw_coin.wav",1);
dbLoadMusic("XSONG.wav",2);
dbSetMusicVolume(2,50);
//coins stuff
dbCreateAnimatedSprite(8,"coin.png",4,1,8);
dbSprite(8,coinx,movey,8);
dbCreateAnimatedSprite(11,"coin.png",4,1,8);
dbSprite(11,coinx+coinx,movey,8);
dbCreateAnimatedSprite(12,"coin.png",4,1,8);
dbSprite(12,coinx+coinx+coinx,movey,8);
dbCreateAnimatedSprite(13,"coin.png",4,1,8);
dbSprite(13,coinx+coinx+coinx+coinx,movey,8);
dbCreateAnimatedSprite(14,"coin.png",4,1,8);
dbSprite(14,coinx+coinx+coinx+coinx+coinx,movey,8);
//makes jump
dbCreateAnimatedSprite(9,"xjump.png",7,1,9);
dbSprite(9,xPos,yPos,9);
dbCreateAnimatedSprite(10,"xjump.png",7,1,10);
dbSprite(10,xPos,yPos,10);
//makes movement
dbCreateAnimatedSprite(6,"xrun.png",13,1,6);
dbSprite(6,xPos,yPos,6);
dbCreateAnimatedSprite(7,"xrun.png",13,1,7);
dbSprite(7,xPos,yPos,7);
dbMirrorSprite(7);
dbMirrorSprite(10);
dbHideSprite(7);
dbHideSprite(10);
dbHideSprite(9);
//variables and tile map for level
int x;
int y;
int MapTile;
int Front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1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1},
};
int FrontScrollX=0;
int FrontScrollY=0;
// our main loop
while ( LoopGDK ( ) )
{
//play sound
// dbPlayMusic(2);
//animate non charcter
dbPlaySprite(8,1,4,200);
dbPlaySprite(11,1,4,200);
dbPlaySprite(12,1,4,200);
dbPlaySprite(13,1,4,200);
dbPlaySprite(14,1,4,200);
if(dbRightKey())
{
xPos = 5;
dbHideSprite(7);
dbHideSprite(9);
dbShowSprite(6);
//FrontScrollX -=5;
dbRotateSprite(8,90);
dbMoveSprite(8,-5.0);
dbRotateSprite(8,0);
dbRotateSprite(11,90);
dbMoveSprite(11,-5.0);
dbRotateSprite(11,0);
dbRotateSprite(12,90);
dbMoveSprite(12,-5.0);
dbRotateSprite(12,0);
dbRotateSprite(13,90);
dbMoveSprite(13,-5.0);
dbRotateSprite(13,0);
dbRotateSprite(14,90);
dbMoveSprite(14,-5.0);
dbRotateSprite(14,0);
dbPlaySprite(6,2,11,50);
}
else if(dbLeftKey())
{
xPos = -5;
dbHideSprite(6);
dbHideSprite(10);
dbHideSprite(9);
dbShowSprite(7);
//FrontScrollX +=5;
dbRotateSprite(8,90);
dbMoveSprite(8,5.0);
dbRotateSprite(8,0);
dbRotateSprite(11,90);
dbMoveSprite(11,5.0);
dbRotateSprite(11,0);
dbRotateSprite(12,90);
dbMoveSprite(12,5.0);
dbRotateSprite(12,0);
dbRotateSprite(13,90);
dbMoveSprite(13,5.0);
dbRotateSprite(13,0);
dbRotateSprite(14,90);
dbMoveSprite(14,5.0);
dbRotateSprite(14,0);
dbPlaySprite(7,2,11,50);
}
//jump
else if(dbKeyState(0x39))
{
xSpeed-=GRAVITY;
yPos -=xSpeed;
dbPlaySprite(9,1,7,50);
dbHideSprite(7);
dbHideSprite(6);
dbShowSprite(9);
}
else{
xPos = 0;
dbSetSpriteFrame(6,1);
dbSetSpriteFrame(7,1);
}
if(dbSpriteExist(8))
{
if(dbSpriteHit(7,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
if(dbSpriteHit(6,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
if(dbSpriteHit(9,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
if(dbSpriteHit(10,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
}
if(dbSpriteExist(11))
{
if(dbSpriteHit(7,11))
{
dbDeleteSprite(11);
dbPlaySound(1);
}
if(dbSpriteHit(6,11))
{
dbDeleteSprite(11);
dbPlaySound(1);
}
if(dbSpriteHit(9,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
if(dbSpriteHit(10,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
}
if(dbSpriteExist(12))
{
if(dbSpriteHit(7,12))
{
dbDeleteSprite(12);
dbPlaySound(1);
}
if(dbSpriteHit(6,12))
{
dbDeleteSprite(12);
dbPlaySound(1);
}
if(dbSpriteHit(9,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
if(dbSpriteHit(10,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
}
if(dbSpriteExist(13))
{
if(dbSpriteHit(7,13))
{
dbDeleteSprite(13);
dbPlaySound(1);
}
if(dbSpriteHit(6,13))
{
dbDeleteSprite(13);
dbPlaySound(1);
}
if(dbSpriteHit(9,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
if(dbSpriteHit(10,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
}
if(dbSpriteExist(14))
{
if(dbSpriteHit(7,14))
{
dbDeleteSprite(14);
dbPlaySound(1);
}
if(dbSpriteHit(6,14))
{
dbDeleteSprite(14);
dbPlaySound(1);
}
if(dbSpriteHit(9,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
if(dbSpriteHit(10,8))
{
dbDeleteSprite(8);
dbPlaySound(1);
}
}
for (y=0; y<20; y++)
{
for (x=0; x<80; x++) //tiles across
{
MapTile = FrontMap[x][y]; // this depends on how you get/make your data
dbPasteImage(1+MapTile, (x*32)+FrontScrollX,(y*32)+FrontScrollY, 1);
}
}
// update the screen
dbSync ( );
}
// return back to windows
return;
}