int x_lives; /* This program was written by Alexander Siegel in September of 1989 */ /* at Cornell University. It may may copied freely for private use or */ /* public dispersion provided that this comment is not removed. This */ /* program, any portion of this program, or any derivative of this */ /* program may not be sold or traded for financial gain. */ /* Modified by Josh Siegel to work with NeWS/X11 */ #include #include #include #include #include "golddig.h" #define EVMASK KeyPressMask | ExposureMask | ButtonMotionMask | ButtonPressMask /* Plug into original block type definitions in shared.c */ extern struct symbs_s symbs[]; /* Current drawing character */ char curchar = ' '; /* Redraw the entire level */ void redrawall() { draw_level(); XFlush(disp); } /* Set the score to be equal to the number of gold pieces */ void count_gold() { register int i,levsize; levsize = xsize*ysize; score = 0; for(i=0;i] [-w ] -l []\n"); exit(1); } } /* If it doesn't start with a dash, it must a the world name */ else { worldname = argv[i]; break; } } /* Make sure some value was chosen for the level number. This */ /* discourages everybody editing the same level all the time. */ if(levelnum == -1) { printf("usage: levelmake [-h ] [-w ] -l []\n"); exit(1); } /* Load in level data from file. */ load_level(); printf("Welcome. Type h for help.\n"); /* Start up X windows and create all graphics cursors */ xstart(EVMASK); /* Set the name of the output window */ XStoreName(disp,wind,"Gold Digger 2.0 Level Generator"); /* Main event loop */ do { /* Get the next X window event */ XWindowEvent(disp,wind,EVMASK,&xev); /* If it was an expose event, redraw everything */ if(xev.type == Expose) { /* Count the number of gold pieces in level */ count_gold(); /* Redraw the level */ redrawall(); } else if(xev.type == KeyPress) { keycount = XLookupString(&xev,buf,50,&keyhit,(XComposeStatus *) NULL); /* If the 'h', '?' or '/' key was hit, print out the text */ /* descriptions of each block type */ if(keyhit == XK_H || keyhit == XK_h || keyhit == XK_question || keyhit == XK_slash) { for(i=0;symbs[i].symb != '\0';++i) if(! (symbs[i].code & NODRAW)) printf("%c - draw %ss\n",symbs[i].symb,symbs[i].name); puts("Type ^W to finish editing and save the level."); puts("Type ^C to quit editing."); puts("Type ^E to erase level."); puts("Use the left mouse button to paint blocks."); puts("Use the right mouse button to erase blocks."); putchar('\n'); } /* A ^E erases the entire level */ else if((keyhit == XK_E || keyhit == XK_e) && (xev.xkey.state & ControlMask)) { /* Replice level contents with space */ for(i=0;i> 4,xev.xmotion.y >> 4,SPACE); else setchar(xev.xmotion.x >> 4,xev.xmotion.y >> 4,curchar); } else if(xev.type == ButtonPress) { if(xev.xbutton.button == Button3) setchar(xev.xbutton.x >> 4,xev.xbutton.y >> 4,SPACE); else setchar(xev.xbutton.x >> 4,xev.xbutton.y >> 4,curchar); } /* Flush the graphics commands out to the server */ XFlush(disp); /* Loop until a control key is pressed */ } while(xev.type != KeyPress || (keyhit != XK_C && keyhit != XK_c && keyhit != XK_W && keyhit != XK_w) || ! (xev.xkey.state & ControlMask)); /* Terminated X windows connection */ xend(); /* Save level to data file */ if(keyhit == XK_W || keyhit == XK_w) save_level(); exit(0); }