I am using darkGDK to complete an asignment where I am to create a sprite with a moon background and to make a rocket ship move up with the spacebar pressed and come back down agian when it is released. I can't figure out what I don't have in my code to keep my rocket from floating off the bottom of the screen. Here is what I have so far.
#include "DarkGDK.h"
// set the refresh rate.
const int REFRESH_RATE = 60;
// assign image numbers
const int ROCKET_IMAGE_NUMBER = 1;
const int MOON_IMAGE_NUMBER = 2;
// Rocket sprite number
const int ROCKET_SPRITE_NUMBER = 1;
// Rocket starting coordinates
const int ROCKET_STARTING_X = 300;
const int ROCKET_STARTING_Y = 300;
// text coordinates
const int TEXT_X = 319;
const int TEXT_Y = 20;
// set prototypes
void moveUp();
void getROCKETcoordinates(int &, int &);
void DarkGDK()
{
// Variables for the Rocket's x and y coordinates.
int rocketX = ROCKET_STARTING_X;
int rocketY = ROCKET_STARTING_Y;
moveUp();
// Game loop
while ( LoopGDK() )
{
dbPasteImage(MOON_IMAGE_NUMBER, 0, 0);
dbCenterText(TEXT_X, TEXT_Y,
"Use the spacebar to move the Rocket");
getROCKETcoordinates(rocketX, rocketY);
dbSprite(ROCKET_SPRITE_NUMBER, rocketX, rocketY,ROCKET_IMAGE_NUMBER);
// Refresh the screen.
dbSync();
}
}
void moveUp()
{
// Set the key color to green.
dbSetImageColorKey(0, 255, 0);
// Load images.
dbLoadImage("moon.bmp", MOON_IMAGE_NUMBER);
dbLoadImage("rocket.bmp", ROCKET_IMAGE_NUMBER);
// Create the Rocket sprite and display it at its
// starting coordinates.
dbSprite(ROCKET_SPRITE_NUMBER, ROCKET_STARTING_X,
ROCKET_STARTING_Y, ROCKET_IMAGE_NUMBER);
dbSyncOn();
dbSyncRate(REFRESH_RATE);
}
void getROCKETcoordinates(int &x, int &y)
{
if ( dbSpaceKey() )
{
y--;
}
if (!dbSpaceKey() )
{
y++;
}
}