Posted: 30th Nov 2013 09:17
I am trying to get a esp card game to work but I am having difficulties. Can anyone help?
// include the Dark GDK header file (http://forum.thegamecreators.com/?m=forum_read&i=22)
#include "DarkGDK.h"
//Constants to use for the image numbers
const int triangle = 1;
const int square = 2;
const int circle = 3;
//Other constants
const int refreshRate = 60;
const int textX = 319;
const int textY = 120;
const int backDrop = 4;
const int esp_backface = 5;
//Function Prototypes
void setUp();
void displayImages(int [], int);
void shuffle(int [], int);
void swap(int &, int &);
bool mouseFullClick(int &, int &);
bool onSprite(int, int, int);
//**DARK GDK FUNCTION**
void DarkGDK ()
{
//Variables to hold mouse coordinates.
int mouseX, mouseY;
//Create an array to hold the image numbers.
const int SIZE = 3;
int images[SIZE] = {triangle, square, circle};
//Perform setup operations.
setUp();
//Game Loop
while ( LoopGDK() )
{
//Get the mouse location.
mouseX = dbMouseX();
mouseY = dbMouseY();
//Display the images.
displayImages(images, SIZE);
//Prompt the user to click on a card.
dbCenterText( textX, textY,"Click on the card that you think is the triangle!");
//Refresh the screen.
dbSync();
}
}
//**The setUp function performs setup operations.**
void setUp()
{
//Load the images.
dbLoadImage("esp_triangle.png",triangle);
dbLoadImage("esp_square.png",square);
dbLoadImage("esp_circle.png",circle);
//Disable auto-refresh and set the refresh rate.
dbSyncOn();
dbSyncRate(refreshRate);
}
//**Display Image Function**
void displayImages(int images[], int size)
{
//Variables for the image XY coordinates
int x = 0;
int y = (dbScreenHeight() / 2) - (dbGetImageHeight(images[0]) / 2);
//Display the images.
for (int index = 0; index < size; index ++)
{
//Display an image
dbPasteImage( images[index], x, y );
//Increase x for the next image.
x+= dbGetImageWidth( images[index] );
}
}
//*Shuffle Function**
void shuffle(int numbers [], int size)
{
//Variables to hold a random subscript
int randomSub;
//Seed the random number generator.
dbRandomize(dbTimer() );
//Setup through the array, swapping each element with ar andom element.
for (int index = 0; index < size; index++)
{
//Get a random subscript.
randomSub = dbRND(size - 1);
//Swap two elements.
swap( numbers[index], numbers[randomSub] );
}
}
//**Swap Function**
void swap(int &a, int &b)
{
//Assign a to temp.
int temp = a;
//Assign b to a.
a = b;
//Assign temp to b.
b = temp;
}
//**mouseClick Funtion**
bool mouseFullClick(int &x, int &y)
{
//Variables to hold the return value.
bool buttonClick = false;
//If the mouse button is pressed, process a full clicking action.
if (dbMouseClick() ==1 )
{
//Get tte mouse pointer coordiantes.
x = dbMouseX();
y = dbMouseY();
//Wait for the user to release the mouse button.
while (dbMouseClick() ==1)
{
//Do nothing in this loop.
}
//Set the buttonClick to true.
buttonClick = true;
}
//Return true of false to indicate wheather the mouse was clicked.
return buttonClick;
}
//**onSprite Function**
bool onSprite(int spriteNum, int pointX, int pointY)
{
//Variables to hold the value to return.
bool insideSprite;
//Get the X coordinate of the sprite's upper-left corner.
int upperX = dbSpriteX(spriteNum) - dbSpriteOffsetX(spriteNum);
//Get the Y coordinate of the sprite's upper-left corner.
int upperY = dbSpriteY(spriteNum) - dbSpriteOffsetY(spriteNum);
//Get the X coordinate of the sprite's lower-right corner.
int lowerX = upperX + dbSpriteWidth(spriteNum);
//Get the Y coordinate of the sprite's lower-right corner.
int lowerY = upperY + dbSpriteHeight(spriteNum);
//Determine whether (pointX, pointY) is inside the sprite's bounding rectangle.
if (pointX >= upperX && pointY >= upperY && pointX <= lowerX && pointY <= lowerY)
{
insideSprite = true;
}
else
{
insideSprite = false;
}
//Return the value of insideSprite.
return insideSprite;
}