I'm having difficulty creating random Green Balloons that appear along the Y axis and move from right to left. I've included the just this particuliar function of the game in hopes of narrowing down the possible errors.
Thanks for any help.
Inline Code Example Here
// This program simulates a green balloon appearing randomly
// and moving horizontally.
// Constants
const int GREEN_BALLOON_IMAGE = 1;
const int GREEN_BALLOON_SPRITE = 1;
const int REFRESH_RATE = 60;
const int X_MOVEMENT = 10;
const int distance = 10;
// Function prototype
void moveGreenBalloon();
//*****************************************************
// DarkGDK function *
//*****************************************************
void DarkGDK()
{
// Variables
int greenBalloonX, greenBalloonY;
// Perform setup operations.
moveGreenBalloon();
// Calculate the maximum Y coordinate for
// the greenBalloon sprite.
int maxY = dbScreenHeight() -
dbSpriteHeight(GREEN_BALLOON_SPRITE);
// Game loop
while ( LoopGDK() )
{
// Random Green Balloons
moveGreenBalloon(GreenBalloonX);
}
}
//*****************************************************
// The setUp function performs setup operations. *
//*****************************************************
void moveGreenBalloon(int & GreenBalloonY)
{
// Set the key color.
dbSetImageColorKey(0, 255, 0);
// Load the ball image.
dbLoadImage("greenBalloon.bmp", GREEN_BALLOON_IMAGE);
// Calculate the ball's X coordinate so we can
// place the ball at the right edge of the screen.
int greenBalloonX = dbScreenWidth() -
dbGetImageWidth(GREEN_BALLOON_IMAGE);
// The ball's Y coordinate is 0.
dbRandomize( dbTimer() );
int greenBalloonY = dbRND(dbScreenHeight()-
dbSpriteHeight(GREEN_BALLOON_SPRITE) );
// Create the ball sprite.
dbSprite(GREEN_BALLOON_SPRITE, greenBalloonX, greenBalloonY, GREEN_BALLOON_IMAGE);
// Disable auto refresh and set the maximum
// refresh rate.
dbSyncOn();
dbSyncRate(REFRESH_RATE);
}