|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 8713 (0x2209) Types: TextFile Names: »main.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/X/Xrobots/main.c«
/* * main.c -- xrobots v1.0 * * Author: Brian Warkentine, 1989. * * Permission to use, copy, modify and distribute (without charge) this * software, documentation, images, etc. is granted, provided that this * comment and the author's name is retained. The author assumes no * responsibility for lost sleep as a consequence of use of this software. * * Send comments, bug reports, etc. to bwarkent@polyslo.CalPoly.EDU. * (Soon to be at @Sun.COM, so if the previous address doesn't work, * try brian@csufres.CSUFresno.EDU.) * * Portions of this code generated by wedgimatic on Jan 21 14:24:10 PST 1989. * */ #include <X11/X.h> #include <X11/Intrinsic.h> #include <X11/StringDefs.h> #include <X11/cursorfont.h> #include <X11/Core.h> #include <X11/Label.h> #include <X11/Command.h> #include <X11/Box.h> #include "callbacks.h" #include "graphics.h" #include "game.h" #include "score.h" #include "help.h" /*----------------------------------------------------------------------*/ Widget top_shell, top_widget, playfield_widget, score_widget, sonic_command; Display *display; Window playfield; GC gc; GC cleargc; /*----------------------------------------------------------------------*/ static XtCallbackRec teleport_callbackList[] = { { (XtCallbackProc)teleport_callback, NULL }, { NULL, NULL } }; static XtCallbackRec wait_callbackList[] = { { (XtCallbackProc)wait_callback, NULL }, { NULL, NULL } }; static XtCallbackRec sonic_callbackList[] = { { (XtCallbackProc)sonic_callback, NULL }, { NULL, NULL } }; static XtCallbackRec quitList[] = { { (XtCallbackProc)quit_callback, NULL }, { NULL, NULL } }; static XtCallbackRec new_gameList[] = { { (XtCallbackProc)new_game_callback, NULL }, { NULL, NULL } }; static XtCallbackRec show_helpList[] = { { (XtCallbackProc)show_help_callback, NULL }, { NULL, NULL } }; /*----------------------------------------------------------------------*/ static Arg arglistplayfield[] = { { XtNheight, (XtArgVal) pos_to_coord(MAXY) }, { XtNwidth, (XtArgVal) pos_to_coord(MAXX) }, { XtNborderWidth, (XtArgVal) 4 }, }; static Arg arglistteleport_command[] = { { XtNlabel, (XtArgVal) "Teleport" }, { XtNcallback, (XtArgVal) teleport_callbackList } }; static Arg arglistwait_command[] = { { XtNlabel, (XtArgVal) "Wait" }, { XtNcallback, (XtArgVal) wait_callbackList } }; static Arg arglistsonic_command[] = { { XtNlabel, (XtArgVal) "Sonic Screwdriver" }, { XtNcallback, (XtArgVal) sonic_callbackList } }; static Arg arglistquit_command[] = { { XtNlabel, (XtArgVal) "Quit" }, { XtNcallback, (XtArgVal) quitList } }; static Arg arglistnew_game[] = { { XtNlabel, (XtArgVal) "New Game" }, { XtNcallback, (XtArgVal) new_gameList } }; static Arg arglistscore_widget[] = { { XtNlabel, (XtArgVal) "Score: 0" }, }; static Arg arglisthelp_button[] = { { XtNlabel, (XtArgVal) "Help" }, { XtNcallback, (XtArgVal) show_helpList } }; /*----------------------------------------------------------------------*/ /* these can be overriden -- of course */ static char translations_str[] = "<Btn1Down>: do_nothing() \n\ <Btn2Down>: do_nothing() \n\ <Btn3Down>: do_nothing() \n\ <Btn1Up>: move() \n\ <Key>u: move(right, up) \n\ <Key>l: move(right) \n\ <Key>n: move(right, down) \n\ <Key>y: move(left, up) \n\ <Key>h: move(left) \n\ <Key>b: move(left, down) \n\ <Key>k: move(up) \n\ <Key>j: move(down) \n\ <Key>.: move(nowhere) \n\ <Key>\\ : move(nowhere) \n\ <Btn2Up>: go_here() \n\ <Btn3Up>: wait() \n\ <Key>s: sonic() \n\ <Key>t: teleport() \n\ <Key>w: wait() \n\ <Key>z: new_game() "; /* <Key>q: quit() "; */ Pixel fg, bg; Boolean spiffy; XtTranslations translations; static XtResource application_resources[] = { {"foreground", "Foreground", XtRPixel, sizeof(Pixel), (Cardinal)&fg, XtRString, (caddr_t) "Black"}, {"background", "Background", XtRPixel, sizeof(Pixel), (Cardinal)&bg, XtRString, (caddr_t) "White"}, {"spiffy", "Spiffy", XtRBoolean, sizeof(Boolean), (Cardinal)&spiffy, XtRString, (caddr_t) "True"}, {"translations","Translations", XtRTranslationTable, sizeof(XtTranslations), (Cardinal)&translations, XtRString, (caddr_t)translations_str}, }; /*----------------------------------------------------------------------*/ main(argc, argv) unsigned int argc; char **argv; { Arg args[1]; XGCValues gcv; srandom(getpid()); top_shell = XtInitialize(argv[0], "xrobots", 0, 0, &argc, argv); init_actions(); XtGetApplicationResources(top_shell, 0, application_resources, XtNumber(application_resources), NULL, 0 ); top_widget = XtCreateManagedWidget( "top_widget", boxWidgetClass, top_shell, 0,0); playfield_widget = XtCreateManagedWidget( "playfield", widgetClass, top_widget, arglistplayfield, XtNumber(arglistplayfield)); XtAugmentTranslations(playfield_widget,translations); (void) XtCreateManagedWidget( "teleport_button", commandWidgetClass, top_widget, arglistteleport_command, XtNumber(arglistteleport_command)); (void) XtCreateManagedWidget( "wait_button", commandWidgetClass, top_widget, arglistwait_command, XtNumber(arglistwait_command)); sonic_command= XtCreateManagedWidget( "sonic_button", commandWidgetClass, top_widget, arglistsonic_command, XtNumber(arglistsonic_command)); (void) XtCreateManagedWidget( "quit_button", commandWidgetClass, top_widget, arglistquit_command, XtNumber(arglistquit_command)); (void) XtCreateManagedWidget( "new_game_button", commandWidgetClass, top_widget, arglistnew_game, XtNumber(arglistnew_game)); (void) XtCreateManagedWidget( "help_button", commandWidgetClass, top_widget, arglisthelp_button, XtNumber(arglisthelp_button)); score_widget = XtCreateManagedWidget( "score_button", labelWidgetClass, top_widget, arglistscore_widget, XtNumber(arglistscore_widget)); create_high_score_popup(top_widget); create_help_popup(top_widget); XtRealizeWidget(top_shell); display = XtDisplay(playfield_widget); playfield = XtWindow(playfield_widget); gcv.foreground = fg; gcv.background = bg; gcv.function = GXcopy; gc = XCreateGC(display, playfield, GCForeground | GCBackground | GCFunction, &gcv); gcv.foreground = bg; cleargc = XCreateGC(display, playfield, GCForeground | GCBackground | GCFunction, &gcv); XtAddEventHandler(playfield_widget, ExposureMask, 0, redisplay_level, 0); XtAddEventHandler(playfield_widget, PointerMotionMask, 0, pointer_moved, 0); init_pixmaps(top_shell); new_game(); XtMainLoop(); } void quit_game() { free_pixmaps(); XtDestroyWidget(top_shell); XFreeGC(display,gc); XFreeGC(display,cleargc); /* XtDestroyApplicationContext(); */ exit(0); } void update_score(score) int score; { char text[13]; (void)sprintf(text,"Score: %4d",score); XtSetArg(arglistscore_widget[0],XtNlabel,text); XtSetValues(score_widget,arglistscore_widget,1); }