I need help with stopping my side scrolling with my code.
#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;
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(dbSpaceKey() && ! Jumping)
{
dbPlaySound(5);
Jumping = true;
ySpeed = 15;
}
if(Jumping)
{
ySpeed -= GRAVITY;
marioY -= ySpeed;
dbSprite(MARIO_SPRITE_NUMBER, marioX, marioY, MARIO_IMAGE_NUMBER);
if(marioY > STARTY)
{
marioY = STARTY;
Jumping = false;
}
if(dbSpriteCollision(MARIO_SPRITE_NUMBER, 3))
{
marioY = dbSpriteY(3) - dbSpriteHeight(2);
Jumping = false;
dbPlaySound(6);
}
if(dbSpriteCollision(MARIO_SPRITE_NUMBER, 4))
{
marioY = dbSpriteY(4) - dbSpriteHeight(2);
Jumping = false;
dbPlaySound(6);
}
if(dbSpriteCollision(MARIO_SPRITE_NUMBER, 5))
{
marioY = dbSpriteY(5) - dbSpriteHeight(2);
Jumping = false;
}
}
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);
dbLoadImage("groundtile1.png", 4);
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);
dbSprite(4, 350, 400, 3);
dbSprite(5, 500, 415, 4);
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);
dbRotateSprite(4, 90);
dbMoveSprite(4,1);
dbRotateSprite(4,0);
dbRotateSprite(5, 90);
dbMoveSprite(5,1);
dbRotateSprite(5,0);
//need help here
if(levelX < MARIO_START_X)
{
dbRotateSprite(1, 270);
dbMoveSprite(1,1);
dbRotateSprite(1,0);
dbRotateSprite(3, 270);
dbMoveSprite(3,1);
dbRotateSprite(3,0);
dbRotateSprite(4, 270);
dbMoveSprite(4,1);
dbRotateSprite(4,0);
dbRotateSprite(5, 270);
dbMoveSprite(5,1);
dbRotateSprite(5,0);
x--;
}
}
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);
dbRotateSprite(4, 270);
dbMoveSprite(4,1);
dbRotateSprite(4,0);
dbRotateSprite(5, 270);
dbMoveSprite(5,1);
dbRotateSprite(5,0);
if(levelX > MARIO_START_X)
{
dbRotateSprite(1, 90);
dbMoveSprite(1, 1);
dbRotateSprite(1,0);
dbRotateSprite(3, 90);
dbMoveSprite(3,1);
dbRotateSprite(3,0);
dbRotateSprite(4, 90);
dbMoveSprite(4,1);
dbRotateSprite(4,0);
dbRotateSprite(5, 90);
dbMoveSprite(5,1);
dbRotateSprite(5,0);
x++;
}
}
//barrier around Map
if (x < 0)
{
x++;
}
if (y <0)
{
y++;
}
if (y > 445)
{
y--;
}
if (x > 1007)
{
x--;
}
}
thank you to all who will help me
w00t! ^_^