home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
CENVIW.ZIP
/
PONGTIME.CMM
< prev
next >
Wrap
Text File
|
1993-12-07
|
3KB
|
87 lines
/*************************************************************
*** PongTime - Make a bouncy clock. Randomize speed after ***
*** each bounce, within limites ***
*************************************************************/
#define COL_AVERAGE_MOVE 3 // average column movement
#define ROW_AVERAGE_MOVE 3 // average row movement
#define COL_RANDOM_DELTA 1 // allowed change from average move to
#define ROW_RANDOM_DELTA 1 // randomize the bounces
#include <WinUtil.lib> // Lots of useful routines
#include <Message.lib> // Send messages to windows
window = spawn(P_NOWAIT,"CLOCK.EXE");
if ( window != NULL ) {
// Get size of the screen
ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
// will make window fill 1/4 of the screen height
WinWidth = WinHeight = ScreenHeight / 4;
// Get Initial position of the window
WindowCol = GetWindowRect(window).left;
WindowRow = GetWindowRect(window).top;
// determine maximum and minimum values for Col and Row before bouncing
MinCol = 0;
MinRow = 0;
MaxCol = ScreenWidth - WinWidth;
MaxRow = ScreenHeight - WinHeight;
// start random direction and delta
srand();
ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,rand() & 1);
RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,rand() & 1);
// Finally, keep bouncing the window around at every interval
while ( IsWindow(window) ) {
// move window to new Row and Col position
MoveWindow(window,WindowCol += ColSpeed,WindowRow += RowSpeed,
WinWidth,WinHeight,TRUE);
// check if needs to bounce back to to hitting desktop edge
if ( ColSpeed < 0 ) {
if ( WindowCol < MinCol )
ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,TRUE);
} else {
if ( MaxCol < WindowCol )
ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,FALSE);
}
if ( RowSpeed < 0 ) {
if ( WindowRow < MinRow )
RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,TRUE);
} else {
if ( MaxRow < WindowRow )
RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,FALSE);
}
}
}
//****** ROUTINES CALLED BY THE ABOVE CODE *******
GetRandomSpeed(average,deviation,positive) // if not positive then negative
{
// get a random deviation from average
deviate = (rand() % (2*deviation + 1)) - deviation;
if ( positive )
return( average + deviate );
else
return( -average - deviate );
}
IsWindow(WindowHandle)
{
return DynamicLink("USER","ISWINDOW",SWORD16,PASCAL,WindowHandle);
}