So here is my issue. I am trying to create a scoreboard where the King (player 1) score - Queen (Player 2) score will display after the first goal is score. This is my first complete game. I am very confused as to how to get the return values to show up on the scoreboard. This is what I have so far. The more I look at it the more my eyes are getting crossed.
I think part of my problem is that when one player scores I dont believe it is registering the score.
I have attached all the pictures and sounds. If you dont like vuvuzelas you can comment out the vuvuzela sound.
#include "DarkGDK.h"
//Function prototype
void loadImages(); //This function is used to load all the images that
//are being used in this program.
void loadSounds();
void getData();
//Initiate Variables.
int ballXvelocity = 5; //This will hold the velocity of the ball's x motion.
int ballYvelocity = 5; //This will hold the velocity of the ball's y motion.
int ballXcoord; //This holds the ball's x coordinate.
int ballYcoord; //This holds the ball's y coordinate.
int kingX = 0; //This holds player 1's x coordinate.
int kingY; //This holds player 1's y coordinate.
int queenX = 590; //This holds player 2's x coordinate.
int queenY; //This holds player 2's y coordinate.
//Initiate and declare Constants.
const int KINGSCORE = 0 ; //This holds the King's guard score.
const int QUEENSCORE = 0; //This holds the Queen's guard score.
const int SIZE1 = 12;
const int SIZE2 = 12;
//Return Value return functions.
int getKingScore(); //This value return function will return the King's guard score.
int getQueenScore(); //This value return function will return the Queen's guard score.
// DarkGDK function
void DarkGDK ( )
{
//Set Window title to Medieval Soccer.
dbSetWindowTitle("Medieval Soccer");
//Instructions set on top of Medieval Castle Background.
loadImages();
loadSounds();
dbPlayMusic(1);
dbPasteImage(5, 0, 0);
dbSetTextFont("Times New Roman");
dbSetTextSize(48);
dbSetTextToOpaque();
dbCenterText(300, 40, "Welcome to Medieval Soccer.");
dbSetTextSize(24);
dbCenterText(300, 150, "This is a two player game.");
dbCenterText(300, 170, "Player one can use the enter");
dbCenterText(300, 190, "key to move his player up");
dbCenterText(300, 210, "and the shift key to move down.");
dbCenterText(300, 230, "Player two can move his player");
dbCenterText(300, 250, "with the up and down keys.");
dbCenterText(300, 150, "Press Space bar when you are ready to start.");
dbWaitKey();
dbDeleteImage(5);
dbCLS();
dbWait(3000);
if (dbMusicPlaying(1) )
{
dbStopMusic(1);
dbDeleteMusic(1);
}
//Scoreboard
dbSetTextToOpaque();
dbSetTextSize(48);
dbCenterText(200, 15, dbStr(KINGSCORE));
dbCenterText(215, 15, "-");
dbCenterText(220, 15, dbStr(QUEENSCORE));
//Create Sprites for all the images needed for the game.
dbSprite(4, 0, 0, 4);
dbSprite(1, 300, 200, 1);
dbSprite(2, 0, 150, 2);
dbSprite(3, 590, 150, 3);
dbLoopSound(1, 25);
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
// Game loop
while ( LoopGDK ( ) )
{
//move the ball
ballXcoord = dbSpriteX(1) + ballXvelocity;
ballYcoord = dbSpriteY(1) + ballYvelocity;
dbSprite(1, ballXcoord, ballYcoord, 1);
getData();
if (ballYcoord <= 0 || ballYcoord >= 400)
{
ballYvelocity = ballYvelocity* - 1;
}
if (ballXcoord <= 0 || ballXcoord >= 600)
{
ballXvelocity = ballXvelocity* - 1;
if (ballXcoord > 599)
{
dbDeleteSprite (1);
dbWait(3000);
for ( int KINGSCORE = 0; KINGSCORE < 5; KINGSCORE++ )
{
KINGSCORE++;
}
}
if (ballXcoord < 1)
{
dbDeleteSprite (1);
dbWait(3000);
for ( int QUEENSCORE = 0; QUEENSCORE < 5; QUEENSCORE++ )
{
QUEENSCORE++;
}
}
}
//check sprite collission
if (dbSpriteHit(1, 2) == 1)
{
ballXvelocity = ballXvelocity* - 1;
}
if (dbSpriteHit(1, 3) == 1)
{
ballXvelocity = ballXvelocity* - 1;
}
//moves king up and down to block shot
if (dbReturnKey() == 1)
{
kingY = dbSpriteY(2) - 5;
dbSprite(2, kingX, kingY, 2);
}
if (dbShiftKey() == 1)
{
kingY = dbSpriteY(2) + 5;
dbSprite(2, kingX, kingY, 2);
}
//moves queen's guard
if (dbUpKey() == 1)
{
queenY = dbSpriteY(3) - 5;
dbSprite(3, queenX, queenY, 3);
}
if (dbDownKey()== 1)
{
queenY = dbSpriteY(3) + 5;
dbSprite(3, queenX, queenY, 3);
}
// update the screen
dbSync ( );
}
for ( int i = 1; i < 6; i++ )
{
dbDeleteSprite ( i );
dbDeleteImage ( 1 );
}
// return back to windows
return;
}
void loadImages()
{
dbSetImageColorKey(0, 255, 0);
dbLoadImage("soccerball.bmp",1);
dbLoadImage("King's Guard.bmp",2);
dbLoadImage("Queen's Guard.bmp",3);
dbLoadImage("Grass.bmp", 4);
dbLoadImage("castle.jpg", 5);
dbLoadImage("game_over.bmp",6);
}
void loadSounds()
{
dbLoadSound("Vuvuzela.wav",1);
dbLoadMusic("Fanfare.mp3",1);
}
void getData()
{
if ( QUEENSCORE == 5)
{
//Display game over Queens Guard wins.
dbSetTextFont("Arial");
dbSetTextSize(48);
dbCLS();
dbPasteImage(5, 0, 0);
dbCenterText(300, 239, "Queen's Guard wins!!!");
dbWaitKey();
}
else
{
//continue game and add to the previous queen score.
for ( int QUEENSCORE = 0; QUEENSCORE < 5; QUEENSCORE++ )
{
QUEENSCORE++;
}
}
if ( KINGSCORE == 5)
{
//Display game over Queens Guard wins.
dbSetTextFont("Arial");
dbSetTextSize(48);
dbCLS();
dbPasteImage(5, 0, 0);
dbCenterText(300, 239, "King's Guard wins!!!");
dbWaitKey();
}
else
{
//continue game and add to the previous king score.
for ( int KINGSCORE = 0; KINGSCORE < 5; KINGSCORE++ )
{
KINGSCORE++;
}
}
getQueenScore();
getKingScore();
}
int getKingScore()
{
//Get the King's guard score.
return KINGSCORE;
}
int getQueenScore()
{
//Get the Queen's guard score.
return QUEENSCORE;
}
Carlos