I've made my first game with c++ n' DarkGDK.
Download it at
http://wikisend.com/download/438600/FallNow.zip
What do you think?
I would love some feedback. And post your highscores!
Here's the source, it's only one script and probably ugly written, but hey, it's my first!
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSetDisplayMode(800, 600, 0);
dbSyncOn();
dbSyncRate(60);
dbDisableEscapeKey();
dbRandomize (dbTimer());
dbSetImageColorKey(255, 0, 255);
dbDrawSpritesFirst();
dbLoadImage("screen1.bmp", 45);
dbSprite(45, 0, 0, 45);
while(dbControlKey() == 0)
{
dbSync();
}
dbDeleteSprite(45);
start:
int score = 0;
//music stuff
dbLoadImage("backdrop.bmp", 1000);
dbSprite(1000, 0, 0, 1000);
dbLoadMusic("popcorn.mid", 1);
dbSetMusicSpeed(1, 110);
dbPlayMusic(1);
//can't jump
int jump = 0;
//0 can't jump, 1 = can jump, 2 or more = jumping)
int scount = 0;
int count = 0;
int speed = 1;
//Let's create
int xcord;
int ycord;
char text[200];
int r1;
int r2 = 300;
int sp_num;
int bonusx;
int bonusy;
int random;
for(sp_num = 4; sp_num < 8; sp_num ++)
{
r1 = dbRND(800);
r1 -= 100;
dbLoadImage("ground.bmp", sp_num);
dbSprite(sp_num, r1, r2, sp_num);
r2 += 150;
}
xcord = 200;
ycord = 200;
int platform(0);
//If dir is 2 it's faceing right, 1 = left
int dir(2);
dbCreateAnimatedSprite(42, "score.bmp", 3, 1, 42);
dbSprite(42, 1400, 1300, 42);
bonusx = dbRND(2);
bonusx += 1;
dbSetSpriteFrame(42, bonusx);
dbCreateAnimatedSprite(3, "Sprite.bmp", 4, 2, 3);
dbSprite(3, xcord, ycord, 3);
dbPasteSprite ( 1000,0,0);
while ( LoopGDK ( ) )
{
scount ++;
if(scount > 29)
{
score ++;
dbSync();
scount = 0;
}
sprintf_s( text, 200, "Score: %d", score );
dbText (50, 10, text );
if(jump > 1)
{
ycord -= 10;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
jump ++;
if(jump > 20)
{
jump = 0;
}
}
else
{
jump = 0;
}
count ++;
if(count > 299)
{
speed += 1;
count = 0;
random = dbRND(10);
if(random < 3)
{
bonusx = dbRND(770);
bonusy = dbRND(570);
dbSprite(42, bonusx, bonusy, 42);
bonusx = dbRND(2);
bonusx += 1;
dbSetSpriteFrame(42, bonusx);
}
}
//is the character outside the screen?
if((ycord < -50) || (ycord > 600))
{
break;
}
if(xcord < 1)
xcord = 1;
if(xcord > 720)
xcord = 720;
//First we let gravity move the player down!
ycord += 5;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
//collision check
sp_num = 4;
while(sp_num < 10)
{
if(dbSpriteY(sp_num) > ycord)
{
while(dbSpriteCollision(3, sp_num)!= 0)
{
ycord -= 2;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
//enable jumping!
jump = 1;
}
}
else
{
while(dbSpriteCollision(3, sp_num)!= 0)
{
ycord += 2;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
}
}
sp_num ++;
}
// time to move the platforms up
for(sp_num = 4; sp_num < 8; sp_num ++)
{
dbMoveSprite(sp_num, speed);
if(dbSpriteY(sp_num) < -10)
{
r2 = 700;
r1 = dbRND(800);
r1 -= 100;
dbSprite(sp_num, r1, r2, sp_num);
}
}
//Now we check collision with all platforms again!
sp_num = 4;
while(sp_num < 10)
{
if(dbSpriteY(sp_num) > ycord)
{
while(dbSpriteCollision(3, sp_num)!= 0)
{
ycord -= 2;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
jump = 1;
}
}
else
{
while(dbSpriteCollision(3, sp_num)!= 0)
{
ycord += 2;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
}
}
sp_num ++;
}
//This checks if we touch a bonus!
if(dbSpriteCollision(3, 42)!= 0)
{
dbSprite(42, 1000, 1000, 42);
if(bonusx == 1)
{
score += 10;
}
if(bonusx == 2)
{
score += 25;
}
if(bonusx == 3)
{
score += 15;
}
}
//Now let's write what happens when we press right arrow key.
if(dbRightKey() != 0)
{
if(dir == 1)
{
dir = 2;
dbSetSpriteFrame(3, 1);
}
dbPlaySprite(3, 1, 4, 150);
xcord += 5;
dbSprite(3, xcord, ycord, 3);
}
//n' left...
if(dbLeftKey() != 0)
{
if(dir == 2)
{
dir = 1;
dbSetSpriteFrame(3, 5);
}
dbPlaySprite(3, 5, 8, 150);
xcord -= 5;
dbSprite(3, xcord, ycord, 3);
}
//If no key is pressed we better make player stand still
//in his current direction
if(dbLeftKey() == 0)
{
if(dbRightKey() == 0)
{
if(dir == 1)
{
dbSetSpriteFrame(3, 5);
}
else
{
dbSetSpriteFrame(3, 1);
}
}
}
if(dbUpKey() != 0)
{
if(jump == 1)
{
jump = 2;
}
}
if(dbEscapeKey() != 0)
{
break;
}
dbSync ( );
}
dbStopMusic(1);
for(sp_num = 0; sp_num < 8; sp_num ++)
{
dbDeleteSprite(sp_num);
dbSync();
}
dbDeleteSprite(42);
dbDeleteSprite(1000);
dbSync();
dbLoadImage ("screen.bmp", 1010);
dbSprite (1001, 0, 0, 1010);
dbSync();
while(dbEscapeKey() == 0)
{
sprintf_s( text, 200, "Score: %d", score );
dbText (350, 300, text );
if(dbControlKey() == 1)
{
dbDeleteSprite(1010);
goto start;
}
dbSync();
}
dbDeleteSprite(1010);
return;
}