So, I'm new to both c++ and DarkGDK and I have a question.
I've just started to make my first game, some kind of platformer.
The gravity and collition is handled like this (inside the While LoopGDK)
ycord += 2;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
while(dbSpriteCollision(3,2) == 1)
{
ycord -= 2;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
}
This works great except that the dbSpriteCollision returns 1 as soon as the Sprites touch each other, but I want the sprite 3 (player) to stop a little inside the sprite 2 (ground). Soo it looks like both feet are on the ground. (See the
image and you will understand the problem)
So is there any way to make the dbSpriteCollision check a box smaller then the image itself?[img]null[/img]
HEre's the whole code if that helps.
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSetDisplayMode(800, 600, 0);
dbSyncOn ( );
dbSyncRate ( 60 );
dbDisableEscapeKey ( );
dbRandomize ( dbTimer ( ) );
dbLoadImage ( "backdrop.bmp", 1 );
dbSprite ( 1, 0, 0, 1 );
dbSetImageColorKey ( 255, 0, 255 );
dbLoadImage ( "ground.bmp", 2 );
dbSprite ( 2, 0, 450, 2 );
int xcord(100);
int ycord(170);
//If dir is 2 it's faceing right, 1 = left
int dir(2);
dbCreateAnimatedSprite(3, "Sprite.bmp", 4, 2, 3);
dbSprite(3, xcord, ycord, 3);
while ( LoopGDK ( ) )
{
ycord += 2;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
while(dbSpriteCollision(3,2) == 1)
{
ycord -= 2;
if(dir == 2) dbSprite(3, xcord, ycord, 3);
if(dir == 1) dbSprite(3, xcord, ycord, 5);
}
if(dbRightKey() != 0)
{
if(dir == 1)
{
dir = 2;
dbSetSpriteFrame(3, 1);
}
dbPlaySprite(3, 1, 4, 150);
xcord += 3;
dbSprite(3, xcord, ycord, 3);
}
if(dbLeftKey() != 0)
{
if(dir == 2)
{
dir = 1;
dbSetSpriteFrame(3, 5);
}
dbPlaySprite(3, 5, 8, 150);
xcord -= 3;
dbSprite(3, xcord, ycord, 3);
}
if(dbLeftKey() == 0)
{
if(dbRightKey() == 0)
{
if(dir == 1)
{
dbSetSpriteFrame(3, 5);
}
else
{
dbSetSpriteFrame(3, 1);
}
}
}
if ( dbEscapeKey ( ) )
break;
dbSync ( );
}
// when the user presses escape the code will break out to this location
// and we can free up any previously allocated resources
// delete all the sprites
for ( int i = 1; i < 30; i++ )
dbDeleteSprite ( i );
// delete the backdrop image
dbDeleteImage (2);
// and now everything is ready to return back to Windows
return;
}