Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Help with my sprites not showing up

Author
Message
LadyCataluna
11
Years of Service
User Offline
Joined: 8th Oct 2012
Location: Florida
Posted: 8th Dec 2012 23:29 Edited at: 11th Dec 2012 14:06
So I have been working on this assignment that calls for the creation of a rock, paper, scissor game. Yet, when I run the debug I get a blank screen. Any ideas on what I am doing wrong?



[#include "DarkGDK.h"

int choice2 = 3;
int choice1 = 4;
bool mouseFullClick(int &, int &);
bool onSprite(int, int, int);
void DetermineWinner(int choice1, int choice2);

void DarkGDK()
{
dbRandomize( dbTimer() );
int mouseX, mouseY;

dbLoadImage("scissors.png",1);
dbLoadImage("rock.png",1);
dbLoadImage("paper.png",1);
dbLoadImage("pointer.png",1);

dbSyncOn ();
dbSyncRate (60);

while ( LoopGDK () )
{
dbSprite(10, 100, 100, 1);
dbSprite(11, 200, 100, 2);
dbSprite(12, 300, 100, 3);
dbSprite(7, dbMouseX(), dbMouseY(), 4);
dbSetSpritePriority(4, 1);
dbHideMouse();

if ( mouseFullClick(mouseX, mouseY) )
{
// Determine whether the user clicked on the scissors.
if ( onSprite(1, mouseX, mouseY) )
{
dbSprite(1, 200, 200, 1);
dbHideSprite(2);
dbHideSprite(3);
choice1 = 1;
}
if ( onSprite(2, mouseX, mouseY) )
{
dbHideSprite(1);
dbSprite(2, 200, 200, 2);
dbHideSprite(3);
choice1 = 2;
}
if ( onSprite(3, mouseX, mouseY) )
{
dbHideSprite(1);
dbHideSprite(2);
dbSprite(3, 200, 200, 3);
choice1 = 3;
}

if ( choice2 == 0 )
{
dbSprite(5, 400, 400, 1);
}
if ( choice2 == 1 )
{
dbSprite(6, 400, 400, 2);
}
if ( choice2 == 2 )
{
dbSprite(7, 400, 400, 3);
}
DetermineWinner(choice1, choice2);

dbSync();
}
}
}

bool mouseFullClick(int &x, int &y)
{
// Variable to hold the return value.
bool buttonClick = false;

// If the mouse button is pressed, process
// a full clicking action.
if ( dbMouseClick() == 1 )
{
// Get the mouse pointer coordinates.
x = dbMouseX();
y = dbMouseY();

choice2 = dbRND(2);
return choice2;

// Wait for the user to release the
// mouse button.
while ( dbMouseClick() == 1)
{
// Do nothing in this loop.
}

// Set buttonClick to true.
buttonClick = true;
}

// Return true or false to indicate whether the
// mouse was clicked.
return buttonClick;
}

bool onSprite(int spriteNum, int pointX, int pointY)
{
// Variable 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;
}

void DetermineWinner(int choice1, int choice2)
{
int comppoints = 0;
int playerpoints = 0;

dbLoadImage("win.bmp",15);
dbLoadImage("lose.bmp",16);
dbLoadImage("tie.bmp",17);

if (choice1 == 1)
{
if (choice2 == 0)
{
dbPasteImage(17, 300, 300);
}
else if (choice2 == 1)
{
dbPasteImage(16, 300, 300);
comppoints ++;
}
else if (choice2 == 2)
{
dbPasteImage(15, 300, 300);
playerpoints ++;
}
}
if (choice1 == 2)
{
if (choice2 == 0)
{
dbPasteImage(15, 300, 300);
playerpoints ++;
}
else if (choice2 == 1)
{
dbPasteImage(17, 300, 300);
}
else if (choice2 == 2)
{
dbPasteImage(16, 300, 300);
comppoints ++;
}
}
if (choice1 == 3)
{
if (choice2 == 0)
{
dbPasteImage(16, 300, 300);
comppoints ++;
}
else if (choice2 == 1)
{
dbPasteImage(15, 300, 300);
playerpoints ++;
}
else if (choice2 == 2)
{
dbPasteImage(17, 300, 300);
}
}

if (playerpoints == comppoints)
{
dbPrint("It's a Tie!");
}
if (playerpoints < comppoints)
{
dbPrint("You Lose!");
}
if (playerpoints > comppoints)
{
dbPrint("You Win!");
}
}]

Any help at all would be appreciated. Thank you.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 9th Dec 2012 15:03
There is a lot of code there. It's hard to read without indentions. Use the "code" button when adding code to your posts.

Now about your problem. It looks like you are only calling dbSync() when "if ( mouseFullClick(mouseX, mouseY) )" is true. You need to sync each frame or the screen will blank out.

The fastest code is the code never written.
LadyCataluna
11
Years of Service
User Offline
Joined: 8th Oct 2012
Location: Florida
Posted: 14th Dec 2012 22:45


Sorry about the lack of indentation.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 18th Dec 2012 19:14
Move dbSync() outside of "if ( mouseFullClick(mouseX, mouseY) )"

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-04-16 09:16:02
Your offset time is: 2024-04-16 09:16:02