1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include "DarkGDK.h"
class Die
{
private:
int imageNumber;
int spriteNumber;
public:
Die(int, int );
~Die();
void toss() const;
};
Die::~Die()
{
}
Die::Die(int x, int y )
{
dbLoadImage("C:\\temp\\1Die.bmp", 1 );
dbLoadImage("C:\\temp\\2Die.bmp", 2 );
dbLoadImage("C:\\temp\\3Die.bmp", 3 );
dbLoadImage("C:\\temp\\4Die.bmp", 4 );
dbLoadImage("C:\\temp\\5Die.bmp", 5 );
dbLoadImage("C:\\temp\\6Die.bmp", 6 );
dbRandomize( dbTimer() );
int randomSprite = dbRND( 6 );
if ( randomSprite == 0 )
{
randomSprite = dbRND( 6 );
}
imageNumber = randomSprite;
spriteNumber = randomSprite;
// Display the sprite.
dbSprite( randomSprite, x, y, randomSprite );
}
void Die::toss() const
{
int randomSprite = dbRND( 6 );
if ( randomSprite == 0 )
{
randomSprite = dbRND( 6 );
}
int x = dbRND( dbScreenWidth() );
int y = dbRND( dbScreenHeight() );
dbSprite( randomSprite, x, y, randomSprite );
}
// main entry point for the application
void DarkGDK()
{
dbSetWindowTitle("Dice Simulator");
dbRandomize( dbTimer() );
dbSetImageColorKey(0, 255, 0);
dbSyncOn();
dbSyncRate(60);
Die dieOne(40,40);// first die screen coordinates are (40,40)
Die dieTwo(200,200); //second die screen coordinates are (200, 200)
while ( LoopGDK() )
{
dbCenterText(320, 320,
"Press spacebar to roll dice.");
if ( dbSpaceKey() )
{
dieOne.toss();
dieTwo.toss();
}
dbSync();
}
}
|