here's my source code its pretty messy right now i cant find out what the problem is
#include "DarkGDK.h"
#include "player.h"
#include "enemy.h"
cPlayer player( 10, 256, 2, 4 );
cEnemy enemy( 320, 288, 2 );
void title();
void gameOver();
void scrollMap();
void collision();
enum cGameState {TITLE, GAME_SETUP, GAME, EXIT};
cGameState GAME_STATE = TITLE;
static int level = 1;
// 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 );
dbSetDisplayMode( 640, 480, 32 );
// our main loop
while ( LoopGDK ( ) )
{
switch( GAME_STATE )
{
case TITLE:
dbCLS( dbRGB( 0, 0, 0 ) );
title();
player.lives = 4;
break;
case GAME_SETUP:
dbCLS( dbRGB( 0, 0, 0 ) );
if( level == 1 )
{
dbLoadImage( "ground1.png", 1 );
dbLoadImage( "sky1.png", 2 );
dbSprite( 1, 0, 320, 1 );
dbSprite( 2, 0, 0, 2 );
enemy.makeEnemy();
enemy.drawEnemy();
GAME_STATE = GAME;
}
break;
case GAME:
scrollMap();
player.makePlayer();
player.updatePlayer();
player.playerLives();
enemy.updateEnemy();
collision();
if( player.xpos == 440 )
{
dbSprite( 2, 0 - player.speed, 0, 2 );
}
break;
case EXIT:
break;
}
// update the screen
dbSync ( );
}
// return back to windows
return;
}
void cPlayer::makePlayer()
{
dbCreateAnimatedSprite ( 3, "player.png", 2, 1, 3 );
}
void cPlayer::drawPlayer()
{
dbSprite( 3, player.xpos, player.ypos, 3 );
}
void cPlayer::movePlayer()
{
int height = player.ypos;
static int jump = 0;
int jumpHeight = 200;
int gravity = 8;
static bool keyState = false;
if( dbKeyState( 30 ) && player.xpos >= 0 )
{
player.xpos -= player.speed;
dbPlaySprite( 3, 1, 2, 1 );
}
if( dbKeyState( 32 ) && player.xpos <= 440 )
{
player.xpos += player.speed;
dbPlaySprite( 3, 1, 2, 1 );
}
if( dbKeyState( 33 ) && jump == 0 && keyState == false )
{
jump = 1;
keyState = true;
}
if( jump == 1 )
{
player.ypos -= 8;
if( player.ypos == jumpHeight )
{
jump = 2;
}
}
if( jump == 2)
{
player.ypos += gravity;
if( player.ypos == 256 )
{
jump = 0;
keyState = false;
}
}
}
void cPlayer::playerLives()
{
}
void cPlayer::updatePlayer()
{
cPlayer::drawPlayer();
cPlayer::movePlayer();
if( player.ypos <= 0 )
{
player.ypos = 0;
}
}
cPlayer::cPlayer( int xpos_c, int ypos_c, int speed_c, int lives_c )
{
xpos = xpos_c;
ypos = ypos_c;
speed = speed_c;
lives = lives_c;
}
void title()
{
dbSetTextFont( "Arial" );
dbSetTextSize( 75 );
dbInk( dbRGB( 100, 0, 0 ), dbRGB( 100, 0, 0 ) );
dbCenterText( 320, 10, "Sidescroller" );
dbInk( dbRGB( 180, 0, 0 ), dbRGB( 100, 0, 0 ) );
dbCenterText( 330, 20, "Sidescroller" );
dbInk( dbRGB( 0, 100, 0 ), dbRGB( 0, 100, 0 ) );
dbCenterText( 320, 100, "By Patrick987" );
dbInk( dbRGB( 0, 180, 0 ), dbRGB( 0, 100, 0 ) );
dbCenterText( 330, 110, "By Patrick987" );
dbInk( dbRGB( 0, 0, 100 ), dbRGB( 0, 0, 100 ) );
dbCenterText( 320, 250, "Press enter to begin" );
dbInk( dbRGB( 0, 0, 180 ), dbRGB( 0, 0, 180 ) );
dbCenterText( 330, 260, "Press enter to begin" );
if( dbKeyState( 28 ) )
{
GAME_STATE = GAME_SETUP;
}
}
void gameOver()
{
if( player.lives == 0 )
{
GAME_STATE = TITLE;
}
}
void cEnemy::makeEnemy()
{
dbLoadImage( "enemy1.png", 4 );
}
void cEnemy::drawEnemy()
{
dbSprite( 4, enemy.xpos, enemy.ypos, 4 );
}
void cEnemy::updateEnemy()
{
moveEnemy();
}
cEnemy::cEnemy( int xpos_c, int ypos_c, int speed_c )
{
xpos = xpos_c;
ypos = ypos_c;
speed = speed_c;
}
void scrollMap()
{
}
void cEnemy::moveEnemy()
{
}
void collision()
{
if( player.xpos + 28 == enemy.xpos && player.ypos + dbSpriteHeight(3) == enemy.ypos + dbSpriteHeight(4) )
{
player.xpos = 10;
player.lives -= 1;
}
if( player.ypos >= 256 )
{
player.ypos = 256;
}
if( (player.ypos + dbSpriteHeight( 3 ) == enemy.ypos) && (player.xpos == enemy.xpos + dbSpriteWidth( 4 ) ) )
{
dbDeleteSprite( 4 );
enemy.xpos = 500;
enemy.ypos = 500;
}
}
and any other help or tips would be appreciated. and also does anyone know if there is a plug in for 2d collision?