#include \"DarkGDK.h\"
// image constants
const int playerSprite = 1;
const int cave3floor = 2;
const int cave3wall1 = 3;
const int itembox = 4;
const int rockslide = 5;
const int rockgoblin = 6;
const int cave3wall2 = 7;
//character constants
bool life = true;
bool item = true;
bool cave3win = true;
bool debugEnabled = true;
//function prototypes
void playerMovement(int &playerX, int &playerY, const int playerSpeed, int ¤tDirection);
void LoadFiles(int &playerX,int &playerY);
void debug(int &playerX,int &playerY);
void screen1(int &playerX, int &playerY, const int playerSpeed);
void SetupScreen();
void DarkGDK ( void )
{
// Variables
const int playerSpeed = 2;
int playerX = 10;
int playerY = 10;
int currentDirection = 0;
// Set up Game Screen
dbSyncOn ();
dbSyncRate (60);
dbSetWindowTitle(\"Nightmare Island\");
dbSetDisplayMode(1000,690,0);
dbMaximizeWindow();
dbDisableEscapeKey();
LoadFiles(playerX,playerY);
while( LoopGDK ())
{
dbPasteImage(cave3floor,0,0,cave3floor);
// Control player movement. Do it here to be behind fringe.
playerMovement(playerX,playerY,playerSpeed,currentDirection);
// Debug
debug(playerX,playerY);
if((playerX == 960)&&(playerY == 10))
{
cave3win = false;
}//end if
if((dbEscapeKey()==1)||(cave3win == false))
{
break;
}
dbSync();
}//end game loop
//delete all images and sprites
for( int count=1; count<10; count++)
{
dbDeleteImage(count);
dbDeleteSprite(count);
}
return;
}//end function dark gdk
void playerMovement(int &playerX, int &playerY, const int playerSpeed, int ¤tDirection)
{
int walkAnimationSpeed = 150;
// Standard Movement
if(dbLeftKey() && dbDownKey() == 0 && dbUpKey() == 0)
{
if( currentDirection != 1)
{
dbSetSpriteFrame(playerSprite,5);
}
currentDirection = 1;
dbPlaySprite(playerSprite,5,8,walkAnimationSpeed);
playerX -= playerSpeed;
}
if(dbRightKey() && dbDownKey() == 0 && dbUpKey() == 0)
{
if( currentDirection != 2)
{
dbSetSpriteFrame(playerSprite,9);
}
currentDirection = 2;
dbPlaySprite(playerSprite,9,12,walkAnimationSpeed);
playerX += playerSpeed;
}
if(dbUpKey() && dbLeftKey() == 0 && dbRightKey() == 0)
{
if( currentDirection != 3)
{
dbSetSpriteFrame(playerSprite,13);
}
currentDirection = 3;
dbPlaySprite(playerSprite,13,16,walkAnimationSpeed);
playerY -= playerSpeed;
}
if(dbDownKey() && dbLeftKey() == 0 && dbRightKey() == 0)
{
if( currentDirection != 4)
{
dbSetSpriteFrame(playerSprite,1);
}
currentDirection = 4;
dbPlaySprite(playerSprite,1,4,walkAnimationSpeed);
playerY += playerSpeed;
}
// Diagonal Movement
if(dbLeftKey() && dbUpKey())
{
if( currentDirection != 5)
{
dbSetSpriteFrame(playerSprite,5);
}
currentDirection = 5;
dbPlaySprite(playerSprite,5,8,walkAnimationSpeed);
playerX -= playerSpeed;
playerY -= playerSpeed;
}
if(dbRightKey() && dbUpKey())
{
if( currentDirection != 6)
{
dbSetSpriteFrame(playerSprite,9);
}
currentDirection = 6;
dbPlaySprite(playerSprite,9,12,walkAnimationSpeed);
playerX += playerSpeed;
playerY -= playerSpeed;
}
if(dbLeftKey() && dbDownKey())
{
if( currentDirection != 7)
{
dbSetSpriteFrame(playerSprite,5);
}
currentDirection = 7;
dbPlaySprite(playerSprite,5,8,walkAnimationSpeed);
playerX -= playerSpeed;
playerY += playerSpeed;
}
if(dbRightKey() && dbDownKey())
{
if( currentDirection != 8)
{
dbSetSpriteFrame(playerSprite,9);
}
currentDirection = 8;
dbPlaySprite(playerSprite,9,12,walkAnimationSpeed);
playerX += playerSpeed;
playerY += playerSpeed;
}
// Check to prevent players leaving screen
if (playerX > 970)
{
dbPasteSprite(playerSprite,970,playerY);
playerX = 970;
}
if (playerX < 0)
{
dbPasteSprite(playerSprite,0,playerY);
playerX = 0;
}
if (playerY < 0)
{
dbPasteSprite(playerSprite,playerX,0);
playerY = 0;
}
if (playerY > 640)
{
dbPasteSprite(playerSprite,playerX,640);
playerY = 640;
}
// Teleport helps to debug
if(dbShiftKey() && dbMouseClick() == 1 && debugEnabled == true)
{
playerX = dbMouseX();
playerY = dbMouseY();
}
// Update screen position.
dbPasteSprite(playerSprite,playerX,playerY);
}//end function player movement
void LoadFiles(int &playerX,int &playerY)
{
// Set Transparency
dbSetImageColorKey ( 0, 0, 0 );
dbLoadImage(\"cave3floor.png\",cave3floor);
dbLoadImage(\"cave3wall1.png\",cave3wall1);
dbLoadImage(\"Player.png\",playerSprite);
// Load Player Sprite
dbCreateAnimatedSprite(playerSprite,\"Player.png\",4,4,playerSprite);
dbSprite(playerSprite,playerX,playerY,playerSprite);
dbHideSprite(playerSprite);
dbSprite(cave3wall1,330,0,cave3wall1);
dbSprite(cave3wall2,660,0,cave3wall1);
}//end function Load Objects
void debug(int &playerX,int &playerY)
{
if (debugEnabled == true)
{
// Debug Display
dbInk(dbRGB(255,0,0),1);
dbText(770,0,dbStr(dbScreenFPS()));
dbText(770,15,dbStr(dbScanCode()));
dbText(770,30,dbStr(playerX));
dbText(770,45,dbStr(playerY));
dbText(770,60,dbStr(dbMouseX()));
dbText(770,75,dbStr(dbMouseY()));
}//end if
}//end function debug
Ok Guys and Gal\'s, i need some help, my problem :
I have tried multiple ways of getting collision into this small 2d game in progress, both functions dbSpriteCollision() and dbSpriteHit() and had no joy getting it to work, if someone could help me get it to work just once i\'m sure i could finish my game, i have tried to upload the code and media which is 5.85mb but the uploader tells me the file is larger than 50mb so if you want i could email it to you if it helps, thanks.