home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume5
/
landmine
/
land_mine.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-09-21
|
7KB
|
266 lines
/******************************************************************************/
/*** ***/
/** LAND MINE **/
/* */
/* This program randomly generates NUM_MINES number of points on a */
/* SunView monitor. When the mouse on the Sun Workstation comes within */
/* PIXEL_AREA pixels of one of the "land mines", an animated sequence of */
/* icons are generated to simulate an explosion at that location. A new */
/* set of coordinates are generated to replace the "exploded" location. */
/* The number of "mines" to set is up to the person that compiles the */
/* program, the more "mines" that are present the greater the occurrance */
/* of "explosions", however, the greater the number of "mines", more CPU */
/* time will be wasted on checking the mouse location. */
/* */
/* I make no waranty, have no responsibility, and have no regrets in */
/* distributing this software. If you use it, it's your problem! */
/* Just to make sure its legal (Thanks to the legal department): */
/* */
/* Copyright (C) 1988 Rick Schneider */
/* */
/* Even though this code is mine, the algorithm for setting up the sun was */
/* was lifted from "eyecon" developed by Chuck Musciano of Harris so his */
/* copyright notice and disclaimer appear here as well: */
/* */
/* Copyright 1988 by Chuck Musciano and Harris Corporation */
/* */
/* Permission to use, copy, modify, and distribute this software */
/* and its documentation for any purpose and without fee is */
/* hereby granted, provided that the above copyright notice */
/* appear in all copies and that both that copyright notice and */
/* this permission notice appear in supporting documentation, and */
/* that the name of Chuck Musciano and Harris Corporation not be */
/* used in advertising or publicity pertaining to distribution */
/* of the software without specific, written prior permission. */
/* Chuck Musciano and Harris Corporation make no representations */
/* about the suitability of this software for any purpose. It is */
/* provided "as is" without express or implied warranty. */
/** **/
/*** ***/
/******************************************************************************/
#include <stdio.h>
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <suntool/fullscreen.h>
#include <sys/file.h>
#include <sys/time.h>
#define NUM_MINES 10
#define PIXEL_AREA 5
#define OR ( PIX_SRC | PIX_DST )
#define XOR ( PIX_SRC ^ PIX_DST )
#define SLEEP_TIME 250000
#define DEFAULT_DEVICE "/dev/fb"
static short broken1_bits[] =
{
#include "broken_window1.i"
};
static short broken2_bits[] =
{
#include "broken_window2.i"
};
static short broken3_bits[] =
{
#include "broken_window3.i"
};
static short broken4_bits[] =
{
#include "broken_window4.i"
};
mpr_static( broken1, 64, 64, 1, broken1_bits );
mpr_static( broken2, 64, 64, 1, broken2_bits );
mpr_static( broken3, 64, 64, 1, broken3_bits );
mpr_static( broken4, 64, 64, 1, broken4_bits );
char *device = NULL;
struct pixrect *background;
static struct pixrect *broken;
static int desktop_fd;
int last_x = -1;
int last_y = -1;
typedef struct s_loc
{
short x;
short y;
} loc;
loc *mine_list;
loc
*init_mine_list( )
{
loc *list;
loc *list_ptr;
int i;
/* allocate list array structure */
list = ( loc * )calloc( NUM_MINES, sizeof(*list) );
if ( list == NULL )
{
fprintf( stderr, "unable to allocate land mine list\n" );
exit(0);
}
list_ptr = list;
srand( getpid( ) );
for ( i = 0; i < NUM_MINES; i++ )
{
list_ptr->x = ( rand( ) % 1100 );
list_ptr->y = ( rand( ) % 900 );
list_ptr++;
}
return( list );
}
int
found_land_mine( x, y, list )
short x;
short y;
loc *list;
{
int i;
/* search the land mine list for an occurance of this location */
for ( i = 0; i < NUM_MINES; i++ )
{
if ( ( ( x - PIXEL_AREA <= list[i].x ) &&
( y - PIXEL_AREA <= list[i].y ) ) &&
( ( list[i].x <= x + PIXEL_AREA ) &&
( list[i].y <= y + PIXEL_AREA ) ) )
{
/* found a mine, generate a new (x,y) and return TRUE */
list[i].x = ( rand( ) % 1100 );
list[i].y = ( rand( ) % 900 );
return( TRUE );
}
}
/* no mine found at current possition, return FALSE */
return( FALSE );
}
void
mine_proc( )
{
int x;
int y;
x = win_get_vuid_value( desktop_fd, LOC_X_ABSOLUTE );
y = win_get_vuid_value( desktop_fd, LOC_Y_ABSOLUTE );
if ( ( x != last_x ) || ( y != last_y ) )
{
if ( found_land_mine( x,y,mine_list ) )
{
pr_rop( background,
x - ( broken1.pr_width/2 ),
y - ( broken1.pr_height/2 ),
broken1.pr_width,
broken1.pr_height,
OR,
&broken1,
0,
0 );
usleep( SLEEP_TIME );
pr_rop( background,
x - ( broken2.pr_width/2 ),
y - ( broken2.pr_height/2 ),
broken2.pr_width,
broken2.pr_height,
OR,
&broken2,
0,
0 );
usleep( SLEEP_TIME );
pr_rop( background,
x - ( broken3.pr_width/2 ),
y - ( broken3.pr_height/2 ),
broken3.pr_width,
broken3.pr_height,
OR,
&broken3,
0,
0 );
usleep( SLEEP_TIME );
pr_rop( background,
x - ( broken4.pr_width/2 ),
y - ( broken4.pr_height/2 ),
broken4.pr_width,
broken4.pr_height,
XOR,
&broken4,
0,
0 );
}
last_x = x;
last_y = y;
}
}
main( argc, argv )
int argc;
char **argv;
{
char *parent;
char *program;
char *getenv( );
strcpy( program = ( char * )malloc( strlen( argv[0] ) + 1 ),
argv[0] );
if ( ( parent = ( char * ) getenv( "WINDOW_PARENT" ) ) == NULL )
{
fprintf( stderr,
"The Sun must be running Suntools inorder to run this program\n");
exit( 1 );
}
if ( ( desktop_fd = open( parent, O_RDWR ) ) == -1 )
{
fprintf( stderr,
"%s: could not access desktop window device: %s\n",
program, parent);
exit( 1 );
}
if ( !( device ) && !( device = getenv( "DEV_FB" ) ) )
device = DEFAULT_DEVICE;
if ( ! ( background = pr_open( device ) ) )
exit(1);
we_setparentwindow( "/dev/win0" );
we_setgfxwindow( "/dev/win3" );
mine_list = init_mine_list( );
while( 1 )
{
mine_proc( );
}
}