Basically I'm trying to make a little game (my first with the Dark GDK) that first displays a background and sprite (the starting screen)
and then, when the mouse is clicked, have the program execute some code. In my case its a starting screen telling the player to click to roll the dice, and when they player clicks, the random dice simulator will do its job.
here is my code:
#include "DarkGDK.h"
#include "windows.h"
#include <ctime>
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbDisableEscapeKey ( );
dbLoadImage ( "dicerollbd.bmp", 10 );
dbSprite ( 10, 0, 0, 10 );
dbSetImageColorKey ( 255, 0, 255 );
srand(time(0));
int roll1 = (rand() % 6) + 1;
int roll2 = (rand() % 6) + 1;
//dice roll start
if(dbMouseClick() == true)
{
if (roll1 == 1 && roll2 == 1)
{
dbLoadImage ( "dice1.bmp", 1);
dbSprite (1, 200, 100, 1);
dbLoadImage ( "dice12.bmp", 12);
dbSprite (12, 300, 100, 12);
}
if (roll1 == 2 && roll2 == 2)
{
dbLoadImage ( "dice2.bmp", 2);
dbSprite (2, 200, 100, 2);
dbLoadImage ( "dice22.bmp", 22);
dbSprite (22, 300, 100, 22);
}
if (roll1 == 3 && roll2 == 3)
{
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 200, 100, 3);
dbLoadImage( "dice32.bmp", 32);
dbSprite (32, 300, 100, 32);
}
if (roll2 == 4 && roll2 == 4)
{
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 200, 100, 4);
dbLoadImage( "dice42.bmp", 42);
dbSprite (42, 300, 100, 42);
}
if (roll1 == 5 && roll2 == 5)
{
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 200, 100, 5);
dbLoadImage( "dice52.bmp", 52);
dbSprite (52, 300, 100, 52);
}
if (roll1 == 6 && roll2 == 6)
{
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 200, 100, 6);
dbLoadImage( "dice62.bmp", 62);
dbSprite (62, 300, 100, 62);
}
if (roll1 == 1 && roll2 == 2)
{
dbLoadImage( "dice1.bmp", 1);
dbSprite (1, 200, 100, 1);
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 300, 100, 2);
}
if (roll1 == 1 && roll2 == 3)
{
dbLoadImage( "dice1.bmp", 1);
dbSprite (1, 200, 100, 1);
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 300, 100, 3);
}
if (roll1 == 1 && roll2 == 4)
{
dbLoadImage( "dice1.bmp", 1);
dbSprite (4, 200, 100, 4);
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 300, 100, 4);
}
if (roll1 == 1 && roll2 == 5)
{
dbLoadImage( "dice1.bmp", 1);
dbSprite (1, 200, 100, 1);
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 300, 100, 5);
}
if (roll1 == 1 && roll2 == 6)
{
dbLoadImage( "dice1.bmp", 1);
dbSprite (1, 200, 100, 1);
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 300, 100, 6);
}
if (roll1 == 2 && roll2 == 1)
{
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 200, 100, 2);
dbLoadImage( "dice1.bmp", 1);
dbSprite (1, 300, 100, 1);
}
if (roll1 == 2 && roll2 == 3)
{
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 200, 100, 2);
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 300, 100, 3);
}
if (roll1 == 2 && roll2 == 4)
{
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 200, 100, 2);
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 300, 100, 4);
}
if (roll1 == 2 && roll2 == 5)
{
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 200, 100, 2);
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 300, 100, 5);
}
if (roll1 == 2 && roll2 == 6)
{
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 200, 100, 2);
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 300, 100, 6);
}
if (roll1 == 3 && roll2 == 1)
{
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 200, 100, 3);
dbLoadImage( "dice1.bmp", 1);
dbSprite (1, 300, 100, 1);
}
if (roll1 == 3 && roll2 == 2)
{
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 200, 100, 3);
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 300, 100, 2);
}
if (roll1 == 3 && roll2 == 4)
{
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 200, 100, 3);
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 300, 100, 4);
}
if (roll1 == 3 && roll2 == 5)
{
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 200, 100, 3);
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 300, 100, 5);
}
if (roll1 == 3 && roll2 == 6)
{
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 200, 100, 3);
dbLoadImage( "dice1.bmp", 6);
dbSprite (6, 300, 100, 6);
}
if (roll1 == 4 && roll2 == 1)
{
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 200, 100, 4);
dbLoadImage( "dice1.bmp", 1);
dbSprite (1, 300, 100, 1);
}
if (roll1 == 4 && roll2 == 2)
{
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 200, 100, 4);
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 300, 100, 2);
}
if (roll1 == 4 && roll2 == 3)
{
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 200, 100, 4);
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 300, 100, 3);
}
if (roll1 == 4 && roll2 == 5)
{
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 200, 100, 4);
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 300, 100, 5);
}
if (roll1 == 4 && roll2 == 6)
{
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 200, 100, 4);
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 300, 100, 6);
}
if (roll1 == 5 && roll2 == 1)
{
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 200, 100, 5);
dbLoadImage( "dice1.bmp", 1);
dbSprite (1, 300, 100, 1);
}
if (roll1 == 5 && roll2 == 2)
{
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 200, 100, 5);
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 300, 100, 2);
}
if (roll1 == 5 && roll2 == 3)
{
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 200, 100, 5);
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 300, 100, 3);
}
if (roll1 == 5 && roll2 == 4)
{
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 200, 100, 5);
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 300, 100, 4);
}
if (roll1 == 5 && roll2 == 6)
{
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 200, 100, 5);
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 300, 100, 6);
}
if (roll1 == 6 && roll2 == 1)
{
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 200, 100, 6);
dbLoadImage( "dice1.bmp", 1);
dbSprite (1, 300, 100, 1);
}
if (roll1 == 6 && roll2 == 2)
{
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 200, 100, 6);
dbLoadImage( "dice2.bmp", 2);
dbSprite (2, 300, 100, 2);
}
if (roll1 == 6 && roll2 == 3)
{
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 200, 100, 6);
dbLoadImage( "dice3.bmp", 3);
dbSprite (3, 300, 100, 3);
}
if (roll1 == 6 && roll2 == 4)
{
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 200, 100, 6);
dbLoadImage( "dice4.bmp", 4);
dbSprite (4, 300, 100, 4);
}
if (roll1 == 6 && roll2 == 5)
{
dbLoadImage( "dice6.bmp", 6);
dbSprite (6, 200, 100, 6);
dbLoadImage( "dice5.bmp", 5);
dbSprite (5, 300, 100, 5);
}
//dice roll end
//dice roll addition
if (roll1 + roll2 == 2)
{
dbLoadImage ( "n2.bmp", 22);
dbSprite ( 22, 400, 115, 22);
}
if (roll1 + roll2 == 3)
{
dbLoadImage ( "n3.bmp", 33);
dbSprite ( 33, 400, 115, 33);
}
if (roll1 + roll2 == 4)
{
dbLoadImage ( "n4.bmp", 44);
dbSprite ( 44, 400, 115, 44);
}
if (roll1 + roll2 == 5)
{
dbLoadImage ( "n5.bmp", 55);
dbSprite ( 55, 400, 115, 55);
}
if (roll1 + roll2 == 6)
{
dbLoadImage ( "n6.bmp", 66);
dbSprite (66, 400, 115, 66);
}
if (roll1 + roll2 == 7)
{
dbLoadImage ( "n2.bmp", 77);
dbSprite ( 77, 400, 115, 77);
}
if (roll1 + roll2 == 8)
{
dbLoadImage ( "n8.bmp", 88);
dbSprite ( 88, 400, 115, 88);
}
if (roll1 + roll2 == 9)
{
dbLoadImage ( "n9.bmp", 99);
dbSprite ( 99, 400, 115, 99);
}
if (roll1 + roll2 == 10)
{
dbLoadImage ( "n10.bmp", 101);
dbSprite ( 101, 400, 115, 101);
}
if (roll1 + roll2 == 11)
{
dbLoadImage ( "n11.bmp", 111);
dbSprite ( 111, 400, 115, 111);
}
if (roll1 + roll2 == 12)
{
dbLoadImage ( "n12.bmp", 202);
dbSprite ( 202, 400, 115, 202);
}
}
//dice add end
while ( LoopGDK ( ) )
{
if ( dbEscapeKey ( ) )
break;
dbSync ( );
}
return;
}
The dice generator works great when it runs first thing, but when I want it to run after a mouse click, it doesn't work.
Any help would be great!
Thanks again
Learning C++
Proud member of www.codecall.com