Hello,
I need very big help with figuring out how to jump onto a sprite and being able to jump off the sprite as well. it's a simple mario game test but when i jump on top of the brick, it will be on top of it, but it wont jump again. some one help!!
#include "DarkGDK.h"
const int REFRESH_RATE = 60;
const int BACK_IMAGE_NUMBER = 1;
const int BACK_SPRITE_NUMBER = 1;
const int MARIO_IMAGE_NUMBER = 2;
const int MARIO_SPRITE_NUMBER = 2;
const int MARIO_START_X = 400;
const int MARIO_START_Y = 405;
const int STARTY = 405;
const int STARTY2 = 385;
int xSpeed = 2;
int ySpeed = 0;
const int GRAVITY = 1;
bool Jumping = false;
int brickX = 335;
int brickY = 400;
int levelX = 0;
int levelY = 0;
void createSprites();
void getMARIOcoordinates(int &, int &);
void DarkGDK(void)
{
dbSetWindowTitle("Mario Fun");
int marioX = MARIO_START_X;
int marioY = MARIO_START_Y;
int colorDepth = dbScreenDepth();
dbSyncOn();
dbSyncRate(REFRESH_RATE);
dbSetDisplayMode(640, 431, colorDepth);
dbMaximizeWindow();
dbHideMouse();
createSprites();
while ( LoopGDK() )
{
dbSprite(MARIO_SPRITE_NUMBER, marioX, marioY, MARIO_IMAGE_NUMBER);
getMARIOcoordinates(marioX, marioY);
if(levelX < 0)
{
levelX = 0;
dbRotateSprite(2, 90);
dbMoveSprite(2,1);
dbRotateSprite(2,0);
}
if(dbSpaceKey() && ! Jumping)
{
dbPlaySound(5);
Jumping = true;
ySpeed = 15;
}
if(Jumping)
{
ySpeed -= GRAVITY;
marioY -= ySpeed;
if(marioY > STARTY)
{
marioY = STARTY;
Jumping = false;
}
if(dbSpriteCollision(MARIO_SPRITE_NUMBER, 3))
{
marioY = dbSpriteY(3) - dbSpriteHeight(2);
Jumping = false;
dbPlaySound(6);
}
if(dbSpaceKey() && ! Jumping)
{
Jumping = true;
ySpeed = 15;
}
}
dbSync();
}
return;
}
void createSprites()
{
dbSetImageColorKey(0, 0, 255);
dbLoadImage("level1.png", BACK_IMAGE_NUMBER);
dbCreateAnimatedSprite(MARIO_SPRITE_NUMBER, "smw.png", 3, 3, MARIO_IMAGE_NUMBER);
dbLoadImage("BrickBlockBrown.bmp", 3);
dbLoadSound("jump.wav", 5);
dbLoadSound("1-UP.wav", 6);
dbSprite(BACK_SPRITE_NUMBER, levelX, levelY, BACK_IMAGE_NUMBER);
dbSprite(MARIO_SPRITE_NUMBER, MARIO_START_X, MARIO_START_Y, MARIO_IMAGE_NUMBER);
dbSprite(3, brickX, brickY, 3);
dbSetSpritePriority(2,1);
dbSetSpritePriority(3,2);
}
void getMARIOcoordinates(int &x, int &y)
{
if( dbLeftKey() ==1 )
{
dbPlaySprite(MARIO_SPRITE_NUMBER, 1, 3, 100);
dbRotateSprite(1, 90);
dbMoveSprite(1, 1);
dbRotateSprite(1,0);
dbRotateSprite(3, 90);
dbMoveSprite(3,1);
dbRotateSprite(3,0);
}
if( dbRightKey()==1 )
{
dbPlaySprite(MARIO_SPRITE_NUMBER, 4, 6, 100);
dbRotateSprite(1, 270);
dbMoveSprite(1,1);
dbRotateSprite(1,0);
dbRotateSprite(3, 270);
dbMoveSprite(3,1);
dbRotateSprite(3,0);
}
//barrier around Map
if (x < 0)
{
x++;
}
if (y <0)
{
y++;
}
if (y > 445)
{
y--;
}
if (x > 1007)
{
x--;
}
}
w00t! ^_^