home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / spyvsbob / part01 < prev    next >
Encoding:
Text File  |  1992-02-21  |  49.1 KB  |  1,846 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!think.com!mips!msi!dcmartin
  3. From: Dave Lemke <lupine!lemke@uunet.UU.NET>
  4. Subject: v16i094: Spy vs "BoB", Part01/01
  5. Message-ID: <1992Feb22.190436.4644@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Organization: Molecular Simulations, Inc.
  9. Date: Sat, 22 Feb 1992 19:04:36 GMT
  10. Approved: dcmartin@msi.com
  11.  
  12. [ a neat little game.. good to waste time during compiles! - dcm] 
  13.  
  14. Submitted-by: Dave Lemke <lupine!lemke@uunet.UU.NET>
  15. Posting-number: Volume 16, Issue 94
  16. Archive-name: spy.vs.bob/part01
  17.  
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  22. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  23. # If this archive is complete, you will see the following message at the end:
  24. #        "End of archive 1 (of 1)."
  25. # Contents:  README Imakefile Makefile score.c svb.man svs.c
  26. # Wrapped by dcmartin@fascet on Sat Feb 22 11:01:46 1992
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'README' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'README'\"
  30. else
  31. echo shar: Extracting \"'README'\" \(495 characters\)
  32. sed "s/^X//" >'README' <<'END_OF_FILE'
  33. XSpy vs "BoB" is a simple arcade game, based on Dodger by Bert Nelson
  34. Xand an Apple ][ game, Spy vs Spy.  Its been tested with SunOS 4.x, and
  35. Xshould run with minimal changes on any BSD-based UNIX.  Other OS's will
  36. Xneed to come up with another way to handle select().
  37. X
  38. XTo install, change the Imakefile to point to the proper scorefile,
  39. Xxmkmf and make.
  40. X
  41. XThe scorefile either needs to be mode 666 or the game should be setuid.
  42. X
  43. XSend any comments, bug fixes, enhancements to
  44. XDave Lemke
  45. Xlemke@ncd.com
  46. X
  47. END_OF_FILE
  48. if test 495 -ne `wc -c <'README'`; then
  49.     echo shar: \"'README'\" unpacked with wrong size!
  50. fi
  51. # end of 'README'
  52. fi
  53. if test -f 'Imakefile' -a "${1}" != "-c" ; then 
  54.   echo shar: Will not clobber existing file \"'Imakefile'\"
  55. else
  56. echo shar: Extracting \"'Imakefile'\" \(139 characters\)
  57. sed "s/^X//" >'Imakefile' <<'END_OF_FILE'
  58. XSRCS = score.c svs.c
  59. XOBJS = score.o svs.o
  60. XLOCAL_LIBRARIES = -lX11
  61. XDEFINES = -DSCOREFILE=\"/tmp/svb.scorefile\"
  62. X
  63. XComplexProgramTarget(svb)
  64. X
  65. END_OF_FILE
  66. if test 139 -ne `wc -c <'Imakefile'`; then
  67.     echo shar: \"'Imakefile'\" unpacked with wrong size!
  68. fi
  69. # end of 'Imakefile'
  70. fi
  71. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  72.   echo shar: Will not clobber existing file \"'Makefile'\"
  73. else
  74. echo shar: Extracting \"'Makefile'\" \(10299 characters\)
  75. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  76. X# Makefile generated by imake - do not edit!
  77. X# $XConsortium: imake.c,v 1.65 91/07/25 17:50:17 rws Exp $
  78. X#
  79. X# The cpp used on this machine replaces all newlines and multiple tabs and
  80. X# spaces in a macro expansion with a single space.  Imake tries to compensate
  81. X# for this, but is not always successful.
  82. X#
  83. X
  84. X# -------------------------------------------------------------------------
  85. X# Makefile generated from "Imake.tmpl" and <Imakefile>
  86. X# $XConsortium: Imake.tmpl,v 1.139 91/09/16 08:52:48 rws Exp $
  87. X#
  88. X# Platform-specific parameters may be set in the appropriate <vendor>.cf
  89. X# configuration files.  Site-specific parameters should be set in the file
  90. X# site.def.  Full rebuilds are recommended if any parameters are changed.
  91. X#
  92. X# If your C preprocessor does not define any unique symbols, you will need
  93. X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
  94. X# "make World" the first time).
  95. X#
  96. X
  97. X# -------------------------------------------------------------------------
  98. X# site-specific configuration parameters that need to come before
  99. X# the platform-specific parameters - edit site.def to change
  100. X
  101. X# site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  102. X
  103. X# -------------------------------------------------------------------------
  104. X# platform-specific configuration parameters - edit sun.cf to change
  105. X
  106. X# platform:  $XConsortium: sun.cf,v 1.68 91/07/30 11:34:39 rws Exp $
  107. X
  108. X# operating system:  SunOS 4.1.1
  109. X
  110. X# $XConsortium: sunLib.rules,v 1.6 91/03/24 17:55:58 rws Exp $
  111. X
  112. X# -------------------------------------------------------------------------
  113. X# site-specific configuration parameters that go after
  114. X# the platform-specific parameters - edit site.def to change
  115. X
  116. X# site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  117. X
  118. X            SHELL = /bin/sh
  119. X
  120. X              TOP = .
  121. X      CURRENT_DIR = .
  122. X
  123. X               AR = ar clq
  124. X  BOOTSTRAPCFLAGS =
  125. X               CC = cc
  126. X               AS = as
  127. X
  128. X         COMPRESS = compress
  129. X              CPP = /lib/cpp $(STD_CPP_DEFINES)
  130. X    PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
  131. X          INSTALL = install
  132. X               LD = ld
  133. X             LINT = lint
  134. X      LINTLIBFLAG = -C
  135. X         LINTOPTS = -axz
  136. X               LN = ln -s
  137. X             MAKE = make
  138. X               MV = mv
  139. X               CP = cp
  140. X
  141. X           RANLIB = ranlib
  142. X  RANLIBINSTFLAGS =
  143. X
  144. X               RM = rm -f
  145. X            TROFF = psroff
  146. X         MSMACROS = -ms
  147. X              TBL = tbl
  148. X              EQN = eqn
  149. X     STD_INCLUDES =
  150. X  STD_CPP_DEFINES =
  151. X      STD_DEFINES =
  152. X EXTRA_LOAD_FLAGS =
  153. X  EXTRA_LIBRARIES =
  154. X             TAGS = ctags
  155. X
  156. X    SHAREDCODEDEF = -DSHAREDCODE
  157. X         SHLIBDEF = -DSUNSHLIB
  158. X
  159. X    PROTO_DEFINES =
  160. X
  161. X     INSTPGMFLAGS =
  162. X
  163. X     INSTBINFLAGS = -m 0755
  164. X     INSTUIDFLAGS = -m 4755
  165. X     INSTLIBFLAGS = -m 0644
  166. X     INSTINCFLAGS = -m 0444
  167. X     INSTMANFLAGS = -m 0444
  168. X     INSTDATFLAGS = -m 0444
  169. X    INSTKMEMFLAGS = -m 4755
  170. X
  171. X      PROJECTROOT = /usr/X11/R5
  172. X
  173. X     TOP_INCLUDES = -I$(INCROOT)
  174. X
  175. X      CDEBUGFLAGS = -O
  176. X        CCOPTIONS = -pipe
  177. X
  178. X      ALLINCLUDES = $(INCLUDES) $(EXTRA_INCLUDES) $(TOP_INCLUDES) $(STD_INCLUDES)
  179. X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(DEFINES)
  180. X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
  181. X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
  182. X
  183. X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  184. X
  185. X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS) $(LOCAL_LDFLAGS) -L$(USRLIBDIR)
  186. X
  187. X   LDCOMBINEFLAGS = -X -r
  188. X      DEPENDFLAGS =
  189. X
  190. X        MACROFILE = sun.cf
  191. X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
  192. X
  193. X    IMAKE_DEFINES =
  194. X
  195. X         IRULESRC = $(CONFIGDIR)
  196. X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
  197. X
  198. X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
  199. X            $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
  200. X            $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
  201. X
  202. X# -------------------------------------------------------------------------
  203. X# X Window System Build Parameters
  204. X# $XConsortium: Project.tmpl,v 1.138 91/09/10 09:02:12 rws Exp $
  205. X
  206. X# -------------------------------------------------------------------------
  207. X# X Window System make variables; this need to be coordinated with rules
  208. X
  209. X          PATHSEP = /
  210. X        USRLIBDIR = /usr/X11/R5/lib
  211. X           BINDIR = /usr/X11/R5/bin
  212. X          INCROOT = /usr/X11/R5/include
  213. X     BUILDINCROOT = $(TOP)
  214. X      BUILDINCDIR = $(BUILDINCROOT)/X11
  215. X      BUILDINCTOP = ..
  216. X           INCDIR = $(INCROOT)/X11
  217. X           ADMDIR = /usr/adm
  218. X           LIBDIR = $(USRLIBDIR)/X11
  219. X        CONFIGDIR = $(LIBDIR)/config
  220. X       LINTLIBDIR = $(USRLIBDIR)/lint
  221. X
  222. X          FONTDIR = $(LIBDIR)/fonts
  223. X         XINITDIR = $(LIBDIR)/xinit
  224. X           XDMDIR = $(LIBDIR)/xdm
  225. X           TWMDIR = $(LIBDIR)/twm
  226. X          MANPATH = /usr/X11/R5/man
  227. X    MANSOURCEPATH = $(MANPATH)/man
  228. X        MANSUFFIX = n
  229. X     LIBMANSUFFIX = 3
  230. X           MANDIR = $(MANSOURCEPATH)$(MANSUFFIX)
  231. X        LIBMANDIR = $(MANSOURCEPATH)$(LIBMANSUFFIX)
  232. X           NLSDIR = $(LIBDIR)/nls
  233. X        PEXAPIDIR = $(LIBDIR)/PEX
  234. X      XAPPLOADDIR = $(LIBDIR)/app-defaults
  235. X       FONTCFLAGS = -t
  236. X
  237. X     INSTAPPFLAGS = $(INSTDATFLAGS)
  238. X
  239. X            IMAKE = imake
  240. X           DEPEND = makedepend
  241. X              RGB = rgb
  242. X
  243. X            FONTC = bdftopcf
  244. X
  245. X        MKFONTDIR = mkfontdir
  246. X        MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier
  247. X
  248. X        CONFIGSRC = $(TOP)/config
  249. X       DOCUTILSRC = $(TOP)/doc/util
  250. X        CLIENTSRC = $(TOP)/clients
  251. X          DEMOSRC = $(TOP)/demos
  252. X           LIBSRC = $(TOP)/lib
  253. X          FONTSRC = $(TOP)/fonts
  254. X       INCLUDESRC = $(TOP)/X11
  255. X        SERVERSRC = $(TOP)/server
  256. X          UTILSRC = $(TOP)/util
  257. X        SCRIPTSRC = $(UTILSRC)/scripts
  258. X       EXAMPLESRC = $(TOP)/examples
  259. X       CONTRIBSRC = $(TOP)/../contrib
  260. X           DOCSRC = $(TOP)/doc
  261. X           RGBSRC = $(TOP)/rgb
  262. X        DEPENDSRC = $(UTILSRC)/makedepend
  263. X         IMAKESRC = $(CONFIGSRC)
  264. X         XAUTHSRC = $(LIBSRC)/Xau
  265. X          XLIBSRC = $(LIBSRC)/X
  266. X           XMUSRC = $(LIBSRC)/Xmu
  267. X       TOOLKITSRC = $(LIBSRC)/Xt
  268. X       AWIDGETSRC = $(LIBSRC)/Xaw
  269. X       OLDXLIBSRC = $(LIBSRC)/oldX
  270. X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
  271. X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
  272. X      BDFTOSNFSRC = $(FONTSRC)/clients/bdftosnf
  273. X      BDFTOPCFSRC = $(FONTSRC)/clients/bdftopcf
  274. X     MKFONTDIRSRC = $(FONTSRC)/clients/mkfontdir
  275. X         FSLIBSRC = $(FONTSRC)/lib/fs
  276. X    FONTSERVERSRC = $(FONTSRC)/server
  277. X     EXTENSIONSRC = $(TOP)/extensions
  278. X         XILIBSRC = $(EXTENSIONSRC)/lib/xinput
  279. X      PHIGSLIBSRC = $(EXTENSIONSRC)/lib/PEX
  280. X
  281. X# $XConsortium: sunLib.tmpl,v 1.11 91/07/31 11:32:08 rws Exp $
  282. X
  283. XSHLIBLDFLAGS = -assert pure-text
  284. XPICFLAGS = -pic
  285. X
  286. X  DEPEXTENSIONLIB =
  287. X     EXTENSIONLIB = -lXext
  288. X
  289. X          DEPXLIB = $(DEPEXTENSIONLIB)
  290. X             XLIB = $(EXTENSIONLIB) -lX11
  291. X
  292. X        DEPXMULIB = $(USRLIBDIR)/libXmu.sa.$(SOXMUREV)
  293. X           XMULIB = -lXmu
  294. X
  295. X       DEPOLDXLIB =
  296. X          OLDXLIB = -loldX
  297. X
  298. X      DEPXTOOLLIB = $(USRLIBDIR)/libXt.sa.$(SOXTREV)
  299. X         XTOOLLIB = -lXt
  300. X
  301. X        DEPXAWLIB = $(USRLIBDIR)/libXaw.sa.$(SOXAWREV)
  302. X           XAWLIB = -lXaw
  303. X
  304. X        DEPXILIB =
  305. X           XILIB = -lXi
  306. X
  307. X        SOXLIBREV = 4.10
  308. X          SOXTREV = 4.10
  309. X         SOXAWREV = 5.0
  310. X        SOOLDXREV = 4.10
  311. X         SOXMUREV = 4.10
  312. X        SOXEXTREV = 4.10
  313. X      SOXINPUTREV = 4.10
  314. X
  315. X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
  316. X         XAUTHLIB =  -lXau
  317. X      DEPXDMCPLIB = $(USRLIBDIR)/libXdmcp.a
  318. X         XDMCPLIB =  -lXdmcp
  319. X
  320. X        DEPPHIGSLIB = $(USRLIBDIR)/libphigs.a
  321. X           PHIGSLIB =  -lphigs
  322. X
  323. X       DEPXBSDLIB = $(USRLIBDIR)/libXbsd.a
  324. X          XBSDLIB =  -lXbsd
  325. X
  326. X LINTEXTENSIONLIB = $(LINTLIBDIR)/llib-lXext.ln
  327. X         LINTXLIB = $(LINTLIBDIR)/llib-lX11.ln
  328. X          LINTXMU = $(LINTLIBDIR)/llib-lXmu.ln
  329. X        LINTXTOOL = $(LINTLIBDIR)/llib-lXt.ln
  330. X          LINTXAW = $(LINTLIBDIR)/llib-lXaw.ln
  331. X           LINTXI = $(LINTLIBDIR)/llib-lXi.ln
  332. X        LINTPHIGS = $(LINTLIBDIR)/llib-lphigs.ln
  333. X
  334. X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
  335. X
  336. X         DEPLIBS1 = $(DEPLIBS)
  337. X         DEPLIBS2 = $(DEPLIBS)
  338. X         DEPLIBS3 = $(DEPLIBS)
  339. X
  340. X# -------------------------------------------------------------------------
  341. X# Imake rules for building libraries, programs, scripts, and data files
  342. X# rules:  $XConsortium: Imake.rules,v 1.123 91/09/16 20:12:16 rws Exp $
  343. X
  344. X# -------------------------------------------------------------------------
  345. X# start of Imakefile
  346. X
  347. XSRCS = score.c svs.c
  348. XOBJS = score.o svs.o
  349. XLOCAL_LIBRARIES = -lX11
  350. XDEFINES = -DSCOREFILE=\"/tmp/svb.scorefile\"
  351. X
  352. X PROGRAM = svb
  353. X
  354. Xall:: svb
  355. X
  356. Xsvb: $(OBJS) $(DEPLIBS)
  357. X    $(RM) $@
  358. X    $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
  359. X
  360. Xsaber_svb:: $(SRCS)
  361. X    # load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  362. X
  363. Xosaber_svb:: $(OBJS)
  364. X    # load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  365. X
  366. Xinstall:: svb
  367. X    @if [ -d $(DESTDIR)$(BINDIR) ]; then set +x; \
  368. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(BINDIR)); fi
  369. X    $(INSTALL) -c $(INSTPGMFLAGS)  svb $(DESTDIR)$(BINDIR)
  370. X
  371. Xinstall.man:: svb.man
  372. X    @if [ -d $(DESTDIR)$(MANDIR) ]; then set +x; \
  373. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(MANDIR)); fi
  374. X    $(INSTALL) -c $(INSTMANFLAGS) svb.man $(DESTDIR)$(MANDIR)/svb.$(MANSUFFIX)
  375. X
  376. Xdepend::
  377. X    $(DEPEND) $(DEPENDFLAGS) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  378. X
  379. Xlint:
  380. X    $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
  381. Xlint1:
  382. X    $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
  383. X
  384. Xclean::
  385. X    $(RM) $(PROGRAM)
  386. X
  387. X# -------------------------------------------------------------------------
  388. X# common rules for all Makefiles - do not edit
  389. X
  390. Xemptyrule::
  391. X
  392. Xclean::
  393. X    $(RM_CMD) "#"*
  394. X
  395. XMakefile::
  396. X    -@if [ -f Makefile ]; then set -x; \
  397. X    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
  398. X    else exit 0; fi
  399. X    $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
  400. X
  401. Xtags::
  402. X    $(TAGS) -w *.[ch]
  403. X    $(TAGS) -xw *.[ch] > TAGS
  404. X
  405. Xsaber:
  406. X    # load $(ALLDEFINES) $(SRCS)
  407. X
  408. Xosaber:
  409. X    # load $(ALLDEFINES) $(OBJS)
  410. X
  411. X# -------------------------------------------------------------------------
  412. X# empty rules for directories that do not have SUBDIRS - do not edit
  413. X
  414. Xinstall::
  415. X    @echo "install in $(CURRENT_DIR) done"
  416. X
  417. Xinstall.man::
  418. X    @echo "install.man in $(CURRENT_DIR) done"
  419. X
  420. XMakefiles::
  421. X
  422. Xincludes::
  423. X
  424. X# -------------------------------------------------------------------------
  425. X# dependencies generated by makedepend
  426. X
  427. END_OF_FILE
  428. if test 10299 -ne `wc -c <'Makefile'`; then
  429.     echo shar: \"'Makefile'\" unpacked with wrong size!
  430. fi
  431. # end of 'Makefile'
  432. fi
  433. if test -f 'score.c' -a "${1}" != "-c" ; then 
  434.   echo shar: Will not clobber existing file \"'score.c'\"
  435. else
  436. echo shar: Extracting \"'score.c'\" \(7183 characters\)
  437. sed "s/^X//" >'score.c' <<'END_OF_FILE'
  438. X/*
  439. X * SvB score file
  440. X */
  441. X/*
  442. X * Copyright 1992 David Lemke and Network Computing Devices
  443. X *
  444. X * Permission to use, copy, modify, distribute, and sell this software and its
  445. X * documentation for any purpose is hereby granted without fee, provided that
  446. X * the above copyright notice appear in all copies and that both that
  447. X * copyright notice and this permission notice appear in supporting
  448. X * documentation, and that the name of Network Computing Devices not be
  449. X * used in advertising or publicity pertaining to distribution of the
  450. X * software without specific, written prior permission.  Network Computing
  451. X * Devices makes no representations about the suitability of this software
  452. X * for any purpose.  It is provided "as is" without express or implied
  453. X * warranty.
  454. X *
  455. X * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  456. X * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  457. X * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
  458. X * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  459. X * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  460. X * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  461. X * OR PERFORMANCE OF THIS SOFTWARE.
  462. X *
  463. X * Author:
  464. X *        Dave Lemke
  465. X *        lemke@ncd.com
  466. X *
  467. X *        Network Computing Devices, Inc
  468. X *        350 North Bernardo Ave
  469. X *        Mountain View, CA 94043
  470. X *
  471. X *    @(#)score.c    1.3    92/01/20
  472. X *
  473. X */
  474. X
  475. X#include    <stdio.h>
  476. X#include    <X11/Xos.h>
  477. X#include    <X11/Xlib.h>
  478. X#include    <X11/Xutil.h>
  479. X#include    <sys/file.h>
  480. X
  481. Xextern Display *dpy;
  482. Xextern Window game_win;
  483. Xextern GC   text_gc;
  484. X
  485. Xextern char user_name[];
  486. Xextern int  highscore;
  487. X
  488. Xextern char get_key();
  489. X
  490. Xstatic void find_personal_best();
  491. Xstatic void draw_scores();
  492. X
  493. Xvoid        update_scores();
  494. X
  495. X#define    NUM_TOP_SCORES    25
  496. X#define    SCORES_PER_USER    5
  497. X
  498. X#define    SCORE_Y_INC    15
  499. X#define    TOP_SCORE_Y    30
  500. X#define    PERSONAL_SCORE_Y    (3 * TOP_SCORE_Y + (NUM_TOP_SCORES * SCORE_Y_INC))
  501. X#define    SCORE_X        10
  502. X
  503. X#define    MESSAGE_Y    (PERSONAL_SCORE_Y + (SCORES_PER_USER + 1) * SCORE_Y_INC)
  504. X
  505. X#ifndef SCOREFILE
  506. X#define    SCOREFILE    "/tmp/svb.scores"
  507. X#endif
  508. X
  509. Xtypedef struct _score {
  510. X    char        name[40];
  511. X    int         score;
  512. X    int         ledge;
  513. X}           Score;
  514. X
  515. XScore       top_scores[NUM_TOP_SCORES];
  516. XScore       personal[SCORES_PER_USER];
  517. XBool        read_scores = False;
  518. X
  519. Xstatic void
  520. Xwait_for_key()
  521. X{
  522. X    XEvent      ev;
  523. X    char        c;
  524. X
  525. X    while (1) {
  526. X    XNextEvent(dpy, &ev);
  527. X    if (ev.type == Expose && ev.xexpose.count == 0)
  528. X        draw_scores();
  529. X    else if (ev.type == KeyPress) {
  530. X        c = get_key((XKeyPressedEvent *) & ev);
  531. X        if (c == 'q')
  532. X        exit(0);
  533. X        else if (c == 'h') {
  534. X        update_scores();
  535. X        draw_scores();
  536. X        } else if (c == ' ' || c == 's')
  537. X        return;
  538. X    }
  539. X    }
  540. X}
  541. X
  542. Xstatic void
  543. Xdraw_scores()
  544. X{
  545. X    int         i,
  546. X                y;
  547. X    char        scorebuf[256];
  548. X
  549. X    XClearWindow(dpy, game_win);
  550. X    sprintf(scorebuf, "%40s", "Top Scores");
  551. X    XDrawImageString(dpy, game_win, text_gc, SCORE_X, 15,
  552. X             scorebuf, strlen(scorebuf));
  553. X    y = TOP_SCORE_Y;
  554. X    for (i = 0; i < NUM_TOP_SCORES; i++) {
  555. X    sprintf(scorebuf, "          %2d  %30s  %7d   Ledge %3d",
  556. X        i + 1, top_scores[i].name, top_scores[i].score,
  557. X        top_scores[i].ledge);
  558. X    XDrawImageString(dpy, game_win, text_gc, SCORE_X, y,
  559. X             scorebuf, strlen(scorebuf));
  560. X    y += SCORE_Y_INC;
  561. X    }
  562. X    sprintf(scorebuf, "%40s", "Personal Top Scores");
  563. X    y = PERSONAL_SCORE_Y;
  564. X    XDrawImageString(dpy, game_win, text_gc, SCORE_X, y - 2 * SCORE_Y_INC,
  565. X             scorebuf, strlen(scorebuf));
  566. X    for (i = 0; i < SCORES_PER_USER; i++) {
  567. X    sprintf(scorebuf, "          %2d  %30s  %7d   Ledge %3d",
  568. X        i + 1, personal[i].name, personal[i].score,
  569. X        personal[i].ledge);
  570. X    XDrawImageString(dpy, game_win, text_gc, SCORE_X, y,
  571. X             scorebuf, strlen(scorebuf));
  572. X    y += SCORE_Y_INC;
  573. X    }
  574. X
  575. X    sprintf(scorebuf, "          'q' to Quit, 's' to Start");
  576. X    XDrawImageString(dpy, game_win, text_gc, SCORE_X, MESSAGE_Y,
  577. X             scorebuf, strlen(scorebuf));
  578. X}
  579. X
  580. Xstatic void
  581. Xfind_personal_best()
  582. X{
  583. X    int         i,
  584. X                j;
  585. X
  586. X    for (i = 0; i < SCORES_PER_USER; i++) {
  587. X    strcpy(personal[i].name, user_name);
  588. X    personal[i].score = 0;
  589. X    personal[i].ledge = 0;
  590. X    }
  591. X    for (i = 0, j = 0; i < NUM_TOP_SCORES; i++) {
  592. X    if (strcmp(top_scores[i].name, user_name) == 0) {
  593. X        personal[j].score = top_scores[i].score;
  594. X        personal[j].ledge = top_scores[i].ledge;
  595. X        j++;
  596. X        if (j == SCORES_PER_USER)
  597. X        return;;
  598. X    }
  599. X    }
  600. X}
  601. X
  602. X/*
  603. X * reads/inits score file
  604. X */
  605. Xvoid
  606. Xupdate_scores()
  607. X{
  608. X    FILE       *fp;
  609. X    int         i;
  610. X    char        buf[256];
  611. X
  612. X    fp = fopen(SCOREFILE, "r");
  613. X    if (fp) {
  614. X    flock(fileno(fp), LOCK_EX);
  615. X    i = 0;
  616. X    while (fgets(buf, 256, fp)) {
  617. X        sscanf(buf, "%s %d %d", top_scores[i].name, &top_scores[i].score,
  618. X           &top_scores[i].ledge);
  619. X        i++;
  620. X    }
  621. X    if (!read_scores)
  622. X        find_personal_best();
  623. X    fclose(fp);
  624. X    } else {
  625. X    /* do reinit if already running and unreadable file */
  626. X    if (read_scores)
  627. X        return;
  628. X    for (i = 0; i < NUM_TOP_SCORES; i++) {
  629. X        strcpy(top_scores[i].name, "Nobody");
  630. X        top_scores[i].score = 0;
  631. X        top_scores[i].ledge = 0;
  632. X    }
  633. X    for (i = 0; i < SCORES_PER_USER; i++) {
  634. X        strcpy(personal[i].name, user_name);
  635. X        personal[i].score = 0;
  636. X        personal[i].ledge = 0;
  637. X    }
  638. X    }
  639. X    read_scores = True;
  640. X    highscore = personal[0].score;
  641. X}
  642. X
  643. X/*
  644. X * displays all current scores
  645. X */
  646. Xvoid
  647. Xshow_scores()
  648. X{
  649. X    update_scores();
  650. X    draw_scores();
  651. X    wait_for_key();
  652. X}
  653. X
  654. Xstatic void
  655. Xwrite_scores()
  656. X{
  657. X    FILE       *fp;
  658. X    int         i;
  659. X
  660. X    fp = fopen(SCOREFILE, "w");
  661. X    if (fp) {
  662. X    flock(fileno(fp), LOCK_EX);
  663. X    for (i = 0; i < NUM_TOP_SCORES; i++)
  664. X        fprintf(fp, "%s %d %d\n", top_scores[i].name,
  665. X            top_scores[i].score, top_scores[i].ledge);
  666. X    fclose(fp);
  667. X    }
  668. X}
  669. X
  670. X/*
  671. X * adds score to table
  672. X */
  673. Xadd_score(sc, ledge)
  674. X    int         sc;
  675. X    int         ledge;
  676. X{
  677. X    int         i,
  678. X                j;
  679. X    int         user_count = 0;
  680. X    int         replace;
  681. X    int         low_user = 0;
  682. X
  683. X    update_scores();        /* make sure they're up-to-date */
  684. X    for (i = 0; i < NUM_TOP_SCORES; i++) {
  685. X    if (strcmp(top_scores[i].name, user_name) == 0) {
  686. X        user_count++;
  687. X        low_user = top_scores[i].score;
  688. X        replace = i;
  689. X    }
  690. X    }
  691. X
  692. X    /*
  693. X     * punt if we have the full number of scores && the new one is too low to
  694. X     * care about
  695. X     */
  696. X    if (user_count >= SCORES_PER_USER) {
  697. X    if (sc <= low_user) {
  698. X        return;
  699. X    }
  700. X    } else {
  701. X    replace = NUM_TOP_SCORES - 1;
  702. X    }
  703. X
  704. X    for (i = 0; i < NUM_TOP_SCORES; i++) {
  705. X    if (sc > top_scores[i].score) {
  706. X        for (j = replace; j > i; j--) {
  707. X        strcpy(top_scores[j].name, top_scores[j - 1].name);
  708. X        top_scores[j].score = top_scores[j - 1].score;
  709. X        top_scores[j].ledge = top_scores[j - 1].ledge;
  710. X        }
  711. X        strcpy(top_scores[i].name, user_name);
  712. X        top_scores[i].score = sc;
  713. X        top_scores[i].ledge = ledge;
  714. X        break;
  715. X    }
  716. X    }
  717. X    for (i = 0; i < SCORES_PER_USER; i++) {
  718. X    if (sc > personal[i].score) {
  719. X        for (j = SCORES_PER_USER - 1; j > i; j--) {
  720. X        personal[j].score = personal[j - 1].score;
  721. X        personal[j].ledge = personal[j - 1].ledge;
  722. X        }
  723. X        personal[i].score = sc;
  724. X        personal[i].ledge = ledge;
  725. X        break;
  726. X    }
  727. X    }
  728. X    highscore = personal[0].score;
  729. X    write_scores();
  730. X}
  731. END_OF_FILE
  732. if test 7183 -ne `wc -c <'score.c'`; then
  733.     echo shar: \"'score.c'\" unpacked with wrong size!
  734. fi
  735. # end of 'score.c'
  736. fi
  737. if test -f 'svb.man' -a "${1}" != "-c" ; then 
  738.   echo shar: Will not clobber existing file \"'svb.man'\"
  739. else
  740. echo shar: Extracting \"'svb.man'\" \(1149 characters\)
  741. sed "s/^X//" >'svb.man' <<'END_OF_FILE'
  742. X.\" @(#)svb.man    1.1E%
  743. X.TH svb 1 "11 Feb 1992"
  744. X.SH NAME
  745. Xsvb \- Spy vs "BoB"
  746. X.SH SYNOPSIS
  747. X.B svb
  748. X[
  749. X.BI \-display " display_name"
  750. X]
  751. X.SH DESCRIPTION
  752. XIn
  753. X.I svb,
  754. Xyou control the Spy (Pink) who is trying to escape the building.  The
  755. X"BoB"s in the elevators are trying to stop you.  The goal is to get
  756. Xacross the screen without being smashed by a "BoB" before time runs 
  757. Xout.  Any leftover time is added to your score as a bonus.
  758. XThe "BoB"s
  759. Xwill change speed each time they change direction.  On each ledge some
  760. X"SLACK" will appear after a random delay.  Picking this up is
  761. Xworth 500 bonus points.
  762. X.PP
  763. XOnce you reach the top, you start over at the bottom, one ledge higher.
  764. XThe "BoB"s also travel a shorter route, so they bounce faster.
  765. X.SH CONTROLS
  766. XYou can control your Pinks with either the keyboard
  767. Xor the mouse.  With the keyboard, 'j' and 'k' change your direction,
  768. Xand 'SPACE' stops you.  With the mouse, you run as long as the button
  769. Xis held down.  Button 1 makes you run left, and any other button 
  770. Xmakes you run right.
  771. X.SH SEE ALSO
  772. X    dodger(6)
  773. X.SH COPYRIGHT
  774. XCopyright (c) 1992 by David Lemke & Network Computing Devices, Inc.
  775. X.br
  776. X(lemke@ncd.com)
  777. END_OF_FILE
  778. if test 1149 -ne `wc -c <'svb.man'`; then
  779.     echo shar: \"'svb.man'\" unpacked with wrong size!
  780. fi
  781. # end of 'svb.man'
  782. fi
  783. if test -f 'svs.c' -a "${1}" != "-c" ; then 
  784.   echo shar: Will not clobber existing file \"'svs.c'\"
  785. else
  786. echo shar: Extracting \"'svs.c'\" \(25542 characters\)
  787. sed "s/^X//" >'svs.c' <<'END_OF_FILE'
  788. X/*
  789. X * Spy vs "Bob"
  790. X *
  791. X * Based on the Apple ][ game "Spy vs Spy", and 'dodger' by Bert Nelson
  792. X */
  793. X
  794. X/*
  795. X * Copyright 1992 David Lemke and Network Computing Devices
  796. X *
  797. X * Permission to use, copy, modify, distribute, and sell this software and its
  798. X * documentation for any purpose is hereby granted without fee, provided that
  799. X * the above copyright notice appear in all copies and that both that
  800. X * copyright notice and this permission notice appear in supporting
  801. X * documentation, and that the name of Network Computing Devices not be
  802. X * used in advertising or publicity pertaining to distribution of the
  803. X * software without specific, written prior permission.  Network Computing
  804. X * Devices makes no representations about the suitability of this software
  805. X * for any purpose.  It is provided "as is" without express or implied
  806. X * warranty.
  807. X *
  808. X * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  809. X * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  810. X * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
  811. X * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  812. X * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  813. X * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  814. X * OR PERFORMANCE OF THIS SOFTWARE.
  815. X *
  816. X * Author:
  817. X *        Dave Lemke
  818. X *        lemke@ncd.com
  819. X *
  820. X *        Network Computing Devices, Inc
  821. X *        350 North Bernardo Ave
  822. X *        Mountain View, CA 94043
  823. X *
  824. X *    @(#)svs.c    1.9    92/02/10
  825. X *
  826. X */
  827. X
  828. X#include    <stdio.h>
  829. X#include    <X11/Xos.h>
  830. X#include     <sys/types.h>
  831. X#include     <sys/time.h>
  832. X#include    <errno.h>
  833. X#include    <X11/Xlib.h>
  834. X#include    <X11/Xutil.h>
  835. X#include    <math.h>
  836. X
  837. Xextern char *getenv();
  838. X
  839. Xextern int  errno;
  840. Xchar       *progname;
  841. Xchar        user_name[40];
  842. XBool        debug = False;
  843. X
  844. X#define    rnd(x)    (random() % (x))
  845. X
  846. X/* game stuff */
  847. X#define    NUM_LEDGES        10
  848. X#define    NUM_VATORS        5
  849. X
  850. X#define    MIN_LEDGE        3    /* tightest it will get */
  851. X
  852. X#define    NUM_LIVES        5
  853. X#define    START_LEDGE        (NUM_LEDGES - 1)
  854. X#define    START_TIME        100
  855. X#define    DELAY_TIME        20000
  856. X#define    ROUNDS_PER_UPDATE    8
  857. X
  858. X#define    GIFT_SCORE        500
  859. X#define    GIFT_NOTYET        1
  860. X#define    GIFT_OUT        2
  861. X#define    GIFT_TAKEN        3
  862. X
  863. X
  864. Xextern void update_scores();
  865. Xextern void show_scores();
  866. X
  867. Xint         score = 0;
  868. Xint         highscore = 0;
  869. Xint         time_left;
  870. Xint         time_interval = ROUNDS_PER_UPDATE;
  871. Xint         lives = 0;
  872. Xint         ledge_num;
  873. Xint         ledge_side;
  874. Xint         level;
  875. Xint        ledge;
  876. Xint         vator_loc[NUM_VATORS];
  877. Xint         vator_speed[NUM_VATORS];
  878. Xint         vator_run;
  879. Xint         man_x,
  880. X            man_y;
  881. Xint         man_speed;
  882. Xint         man_delta;
  883. X
  884. Xint         gift_x,
  885. X            gift_y;
  886. Xint         gift_state;
  887. XBool        refresh_gift;
  888. Xint         gift_time;
  889. X
  890. X/* increase with each level */
  891. Xdouble      level_factor = 1.0;
  892. X
  893. X/* speeds */
  894. X#define    MIN_VATOR_SPEED        5
  895. X#define    VATOR_SPEED_RANGE    10
  896. X
  897. X#ifdef fast
  898. X#define    LEVEL_INCREASE        (0.2)
  899. X#else
  900. X#define    LEVEL_INCREASE        (0.0)
  901. X#endif
  902. X
  903. X/* X stuff */
  904. X
  905. XDisplay    *dpy;
  906. XWindow      game_win;
  907. XColormap    cmap;
  908. XGC          text_gc;
  909. XGC          vator_gc;
  910. XGC          draw_gc;
  911. Xunsigned long man_color,
  912. X            vator_color,
  913. X            vator_bg_color,
  914. X            timer_color,
  915. X            gift_color,
  916. X            splat_color,
  917. X            ledge_color;
  918. Xunsigned long text_color;
  919. Xunsigned long bg_color;
  920. XBool        paused = False;
  921. XPixmap      man_left,
  922. X            man_right,
  923. X            man_stand,
  924. X            splat_map,
  925. X            slack_map,
  926. X            vator_map;
  927. X
  928. X#define    MAN        0
  929. X#define    VATOR        1
  930. X#define    TIMER        2
  931. X#define    LEDGE        3
  932. X#define    TEXT        4
  933. X#define    BACKGROUND    5
  934. X#define    GIFT        6
  935. X#define    VATOR_BG    7
  936. X#define    SPLAT        8
  937. X
  938. Xstatic char *game_colors[] = {
  939. X    "pink",            /* MAN */
  940. X    "blue",            /* VATOR */
  941. X    "yellow",            /* TIMER */
  942. X    "brown",            /* LEDGE */
  943. X    "white",            /* TEXT */
  944. X    "black",            /* BACKGROUND */
  945. X    "green",            /* GIFT */
  946. X    "white",            /* VATOR_BG */
  947. X    "pink",            /* SPLAT */
  948. X};
  949. X
  950. X
  951. Xstatic char bob_vator_bits[] = {
  952. X    0xff, 0x01, 0x50, 0x25, 0x00, 0xfe, 0x03, 0x07, 0x00, 0xfc, 0xff, 0x03,
  953. X    0x80, 0x03, 0x03, 0x00, 0xff, 0x5e, 0x06, 0x00, 0x03, 0x03, 0xc0, 0x97,
  954. X    0x44, 0x0a, 0x00, 0x03, 0x03, 0xc0, 0x17, 0xa9, 0x1d, 0x00, 0x03, 0x03,
  955. X    0xe0, 0x7f, 0xdd, 0x7f, 0x00, 0x03, 0x03, 0xf0, 0xff, 0xff, 0xf3, 0x00,
  956. X    0x03, 0x03, 0xf0, 0xff, 0xdf, 0xf0, 0x00, 0x03, 0x03, 0xf0, 0xa5, 0x17,
  957. X    0xf0, 0x01, 0x03, 0x03, 0xf0, 0x00, 0x00, 0xf0, 0x00, 0x03, 0x03, 0xf8,
  958. X    0x00, 0x00, 0xe8, 0x00, 0x03, 0x03, 0xf0, 0x01, 0x00, 0xe8, 0x00, 0x03,
  959. X    0x03, 0xf0, 0x00, 0x00, 0xe4, 0x00, 0x03, 0x03, 0xf8, 0x00, 0x00, 0xe8,
  960. X    0x00, 0x03, 0x03, 0xf0, 0x09, 0x80, 0xfb, 0x00, 0x03, 0x03, 0xe8, 0x3e,
  961. X    0xe0, 0xee, 0x00, 0x03, 0x03, 0xf8, 0x68, 0x70, 0xfd, 0x00, 0x03, 0x03,
  962. X    0x30, 0xee, 0x78, 0xe3, 0x00, 0x03, 0x03, 0x30, 0xf2, 0xa8, 0x60, 0x00,
  963. X    0x03, 0x03, 0x30, 0xb4, 0xc0, 0x63, 0x00, 0x03, 0x03, 0x30, 0x98, 0x00,
  964. X    0x40, 0x00, 0x03, 0x03, 0x20, 0x80, 0x00, 0xa0, 0x00, 0x03, 0x03, 0xb0,
  965. X    0x40, 0x00, 0x60, 0x00, 0x03, 0x03, 0x80, 0xd1, 0x70, 0x18, 0x00, 0x03,
  966. X    0x03, 0xc0, 0xe9, 0x8e, 0x0d, 0x00, 0x03, 0x03, 0x80, 0xf7, 0x87, 0x3f,
  967. X    0x00, 0x03, 0x03, 0x80, 0xfa, 0xea, 0x0c, 0x00, 0x03, 0x03, 0x80, 0x32,
  968. X    0x49, 0x0c, 0x00, 0x03, 0x03, 0x00, 0x35, 0x35, 0x0c, 0x00, 0x03, 0x03,
  969. X    0x00, 0xf1, 0x0f, 0x06, 0x00, 0x03, 0x03, 0x00, 0xf6, 0x15, 0x02, 0x00,
  970. X    0x03, 0x03, 0x10, 0xda, 0x0b, 0x03, 0x00, 0x03, 0x03, 0x48, 0x4e, 0x00,
  971. X    0x01, 0x00, 0x03, 0x03, 0x58, 0x77, 0x80, 0x00, 0x00, 0x03, 0x03, 0xe2,
  972. X    0xf3, 0xc0, 0x00, 0x00, 0x03, 0x03, 0xcc, 0x41, 0x3f, 0x00, 0x00, 0x03,
  973. X    0x03, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0xdc, 0x00, 0x00, 0x00,
  974. X    0x00, 0x03, 0x07, 0x70, 0x00, 0x00, 0x00, 0x80, 0x03, 0xff, 0x01, 0x00,
  975. X0x00, 0x00, 0xfe, 0x03};
  976. X
  977. Xstatic char man_left_bits[] = {
  978. X    0x18, 0x01, 0x00, 0xf8, 0x00, 0x00, 0x7e, 0x00, 0x00, 0xfe, 0x00, 0x00,
  979. X    0xfc, 0x01, 0x00, 0xfa, 0x03, 0x00, 0xf1, 0xff, 0x01, 0x20, 0xff, 0x01,
  980. X    0x84, 0x1f, 0x01, 0x86, 0x3f, 0x01, 0xce, 0xff, 0x01, 0x78, 0xff, 0x03,
  981. X    0x20, 0xff, 0x01, 0x00, 0xff, 0x00, 0x80, 0x7f, 0x04, 0xc0, 0xfe, 0x0e,
  982. X0xc0, 0x9c, 0x0b, 0x80, 0x09, 0x09, 0x00, 0x03, 0x00, 0xc0, 0x01, 0x00};
  983. X
  984. Xstatic char man_right_bits[] = {
  985. X    0x00, 0x88, 0x01, 0x00, 0xf0, 0x01, 0x00, 0xe0, 0x07, 0x00, 0xf0, 0x07,
  986. X    0x00, 0xf8, 0x03, 0x00, 0xfc, 0x05, 0xf8, 0xff, 0x08, 0xf8, 0x4f, 0x00,
  987. X    0x88, 0x1f, 0x02, 0xc8, 0x1f, 0x06, 0xf8, 0x3f, 0x07, 0xfc, 0xef, 0x01,
  988. X    0xf8, 0x4f, 0x00, 0xf0, 0x0f, 0x00, 0xe2, 0x1f, 0x00, 0xf7, 0x37, 0x00,
  989. X0x9d, 0x33, 0x00, 0x09, 0x19, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x38, 0x00};
  990. X
  991. Xstatic char man_stand_bits[] = {
  992. X    0x80, 0x03, 0x00, 0xc0, 0x07, 0x00, 0xf0, 0x1f, 0x00, 0xc0, 0x07, 0x00,
  993. X    0x80, 0x03, 0x00, 0x00, 0x01, 0x00, 0x80, 0x03, 0x00, 0xf0, 0x0f, 0x00,
  994. X    0xfc, 0x1f, 0x00, 0xfe, 0xbf, 0x0f, 0xf3, 0x7f, 0x01, 0xf3, 0xff, 0x01,
  995. X    0xfe, 0x1f, 0x01, 0xfc, 0x1f, 0x00, 0xf8, 0x3f, 0x00, 0xf0, 0x3f, 0x00,
  996. X0xf0, 0x7f, 0x00, 0xc0, 0x0c, 0x00, 0xc0, 0x0c, 0x00, 0xf0, 0x3c, 0x00};
  997. X
  998. X
  999. Xstatic char slack_bits[] = {
  1000. X0xeb, 0x56, 0xa9, 0x32, 0xeb, 0x32, 0xaa, 0x52, 0xbb, 0x56};
  1001. X
  1002. Xstatic char splatter_bits[] = {
  1003. X    0x68, 0x20, 0x02, 0x00, 0x2b, 0x49, 0x31, 0x1e, 0x3e, 0x92, 0x88, 0x11,
  1004. X    0x26, 0x22, 0x45, 0x1e, 0x6e, 0xec, 0xe3, 0x07, 0xf8, 0xff, 0xff, 0x00,
  1005. X    0x00, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1006. X0x00, 0x00, 0x00, 0x00};
  1007. X
  1008. X#define    MAN_WIDTH    20
  1009. X#define    MAN_HEIGHT    20
  1010. X#define    MAN_DELTA    6    /* motion per step */
  1011. X#define    MIN_MAN_DELTA    4
  1012. X
  1013. X#define SPLAT_WIDTH    30
  1014. X#define SPLAT_HEIGHT    10
  1015. X
  1016. X#define    VATOR_WIDTH    50
  1017. X#define    VATOR_HEIGHT    40
  1018. X#define    VATOR_GAP    40    /* space between them */
  1019. X
  1020. X#define    GIFT_WIDTH    15
  1021. X#define    GIFT_HEIGHT    5
  1022. X
  1023. X#define    LEDGE_WIDTH    30
  1024. X#define    LEDGE_HEIGHT    4
  1025. X
  1026. X#define    LEDGE_GAP    ((int)(VATOR_HEIGHT * 1.2 + LEDGE_HEIGHT))
  1027. X
  1028. X#define    TIMER_HEIGHT    25
  1029. X#define    TIMER_SLICE    1    /* visual size of each tick */
  1030. X
  1031. X#define    INFO_HEIGHT    100    /* size of timer, score, etc */
  1032. X
  1033. X#define    DELIM_HEIGHT    10    /* bar between game and info */
  1034. X
  1035. X#define    WIN_WIDTH    (NUM_VATORS * VATOR_WIDTH + (NUM_VATORS - 1) * VATOR_GAP + 2 * LEDGE_WIDTH)
  1036. X#define    WIN_HEIGHT    (NUM_LEDGES * LEDGE_GAP + INFO_HEIGHT + DELIM_HEIGHT)
  1037. X
  1038. X/* range of y locs for elevators */
  1039. X#define    VATOR_RUN    (WIN_HEIGHT - (INFO_HEIGHT + DELIM_HEIGHT) - VATOR_HEIGHT)
  1040. X
  1041. X/* range of man */
  1042. X#define    MAN_MAX_X    (WIN_WIDTH - MAN_DELTA - MAN_WIDTH)
  1043. X
  1044. X#define    TIMER_Y        (WIN_HEIGHT - ((INFO_HEIGHT * 2) / 3))
  1045. X#define    EXTRA_MAN_X    (WIN_WIDTH - 2 * MAN_WIDTH)
  1046. X#define    STATUS_Y    (TIMER_Y + 15)
  1047. X#define    STATUS_X    (2 * TIMER_SLICE)
  1048. X
  1049. X#define    FONTNAME    "fixed"
  1050. X
  1051. X#define    COLLISION_FUDGE    4
  1052. X
  1053. X#define    vator_pos(i) (LEDGE_WIDTH + (i) * (VATOR_GAP + VATOR_WIDTH))
  1054. X#define    man_start_pos(i)    (MAN_DELTA + (i) * (WIN_WIDTH - MAN_WIDTH - (2 * MAN_DELTA)))
  1055. X#define    man_y_pos(l)    ((LEDGE_GAP * ((l) + 1)) - (LEDGE_HEIGHT + MAN_HEIGHT))
  1056. X
  1057. X#define    min(a, b)    (((a) < (b)) ? (a) : (b))
  1058. X#define    max(a, b)    (((a) > (b)) ? (a) : (b))
  1059. X
  1060. Xstatic void wait_for_start();
  1061. Xstatic void run();
  1062. Xstatic void finish_up();
  1063. X
  1064. Xstatic void draw_ledges();
  1065. Xstatic void draw_init_screen();
  1066. Xstatic void draw_scores();
  1067. Xstatic void draw_obj();
  1068. Xstatic void draw_timer();
  1069. Xstatic void draw_status();
  1070. Xstatic void draw_message();
  1071. Xstatic void draw_message2();
  1072. Xstatic void erase_obj();
  1073. Xstatic void new_man();
  1074. Xstatic void new_gift();
  1075. Xstatic void flush_keyboard();
  1076. X
  1077. Xstatic void
  1078. Xusage()
  1079. X{
  1080. X    fprintf(stderr, "Usage: %s [-display displayname]\n", progname);
  1081. X    exit(0);
  1082. X}
  1083. X
  1084. Xstatic unsigned long
  1085. Xget_color(cname)
  1086. X    char       *cname;
  1087. X{
  1088. X    XColor      col;
  1089. X
  1090. X    XParseColor(dpy, cmap, cname, &col);
  1091. X    XAllocColor(dpy, cmap, &col);
  1092. X    return col.pixel;
  1093. X}
  1094. X
  1095. Xstatic void
  1096. Xinit_display(ac, av, dname)
  1097. X    int         ac;
  1098. X    char      **av;
  1099. X    char       *dname;
  1100. X{
  1101. X    Bool        is_color = False;
  1102. X    int         screen;
  1103. X    unsigned long wmask,
  1104. X                gcmask;
  1105. X    XSetWindowAttributes wattr;
  1106. X    XGCValues   gcv;
  1107. X    XFontStruct *pfont;
  1108. X    int         x,
  1109. X                y;
  1110. X    XSizeHints  xsh;
  1111. X    XWMHints    wmhints;
  1112. X
  1113. X    dpy = XOpenDisplay(dname);
  1114. X    if (!dpy) {
  1115. X    fprintf(stderr, "%s: Couldn't open display \"%s\"\n", progname, dname);
  1116. X    exit(-1);
  1117. X    }
  1118. X    screen = DefaultScreen(dpy);
  1119. X
  1120. X    if (debug)
  1121. X    XSynchronize(dpy, 1);
  1122. X
  1123. X    if (DisplayCells(dpy, screen) > 2)
  1124. X    is_color = True;
  1125. X    cmap = DefaultColormap(dpy, screen);
  1126. X
  1127. X    /* set up colors */
  1128. X    if (is_color) {
  1129. X    man_color = get_color(game_colors[MAN]);
  1130. X    splat_color = get_color(game_colors[SPLAT]);
  1131. X    vator_color = get_color(game_colors[VATOR]);
  1132. X    vator_bg_color = get_color(game_colors[VATOR_BG]);
  1133. X    ledge_color = get_color(game_colors[LEDGE]);
  1134. X    timer_color = get_color(game_colors[TIMER]);
  1135. X    text_color = get_color(game_colors[TEXT]);
  1136. X    gift_color = get_color(game_colors[GIFT]);
  1137. X    bg_color = get_color(game_colors[BACKGROUND]);
  1138. X    } else {
  1139. X    man_color = WhitePixel(dpy, screen);
  1140. X    splat_color = WhitePixel(dpy, screen);
  1141. X    vator_color = BlackPixel(dpy, screen);
  1142. X    vator_bg_color = WhitePixel(dpy, screen);
  1143. X    ledge_color = WhitePixel(dpy, screen);
  1144. X    timer_color = WhitePixel(dpy, screen);
  1145. X    text_color = WhitePixel(dpy, screen);
  1146. X    gift_color = WhitePixel(dpy, screen);
  1147. X    bg_color = BlackPixel(dpy, screen);
  1148. X    }
  1149. X
  1150. X    x = 100;
  1151. X    y = 100;
  1152. X
  1153. X    wattr.background_pixel = bg_color;
  1154. X    wattr.event_mask = ExposureMask | KeyPressMask |
  1155. X    ButtonPressMask | ButtonReleaseMask;
  1156. X
  1157. X    wmask = CWEventMask | CWBackPixel;
  1158. X
  1159. X    game_win = XCreateWindow(dpy, RootWindow(dpy, screen), x, y, WIN_WIDTH,
  1160. X           WIN_HEIGHT, 0, CopyFromParent, CopyFromParent, CopyFromParent,
  1161. X                 wmask, &wattr);
  1162. X
  1163. X    xsh.flags = PSize | PMinSize | PMaxSize;
  1164. X    xsh.width = xsh.min_width = xsh.max_width = WIN_WIDTH;
  1165. X    xsh.height = xsh.min_height = xsh.max_height = WIN_HEIGHT;
  1166. X    XSetStandardProperties(dpy, game_win, "Spy vs \"Bob\"", "SvB", None,
  1167. X               av, ac, &xsh);
  1168. X
  1169. X    wmhints.input = True;
  1170. X    wmhints.flags = InputHint;
  1171. X    XSetWMHints(dpy, game_win, &wmhints);
  1172. X
  1173. X    pfont = XLoadQueryFont(dpy, FONTNAME);
  1174. X
  1175. X    gcmask = GCForeground | GCBackground;
  1176. X    gcv.foreground = text_color;
  1177. X    gcv.background = bg_color;
  1178. X    if (pfont) {
  1179. X    gcv.font = pfont->fid;
  1180. X    gcmask |= GCFont;
  1181. X    }
  1182. X    text_gc = XCreateGC(dpy, game_win, gcmask, &gcv);
  1183. X
  1184. X    gcmask = GCForeground | GCBackground | GCGraphicsExposures;
  1185. X    gcv.foreground = man_color;
  1186. X    gcv.background = bg_color;
  1187. X    gcv.graphics_exposures = False;
  1188. X    draw_gc = XCreateGC(dpy, game_win, gcmask, &gcv);
  1189. X
  1190. X    gcmask = GCForeground | GCBackground | GCGraphicsExposures;
  1191. X    gcv.foreground = vator_color;
  1192. X    gcv.background = vator_bg_color;
  1193. X    gcv.graphics_exposures = False;
  1194. X    vator_gc = XCreateGC(dpy, game_win, gcmask, &gcv);
  1195. X
  1196. X    /* make bitmaps */
  1197. X    vator_map = XCreateBitmapFromData(dpy, game_win, bob_vator_bits,
  1198. X                      VATOR_WIDTH, VATOR_HEIGHT);
  1199. X    man_left = XCreateBitmapFromData(dpy, game_win, man_left_bits,
  1200. X                     MAN_WIDTH, MAN_HEIGHT);
  1201. X    man_right = XCreateBitmapFromData(dpy, game_win, man_right_bits,
  1202. X                      MAN_WIDTH, MAN_HEIGHT);
  1203. X    man_stand = XCreateBitmapFromData(dpy, game_win, man_stand_bits,
  1204. X                      MAN_WIDTH, MAN_HEIGHT);
  1205. X    slack_map = XCreateBitmapFromData(dpy, game_win, slack_bits,
  1206. X                      GIFT_WIDTH, GIFT_HEIGHT);
  1207. X    splat_map = XCreateBitmapFromData(dpy, game_win, splatter_bits,
  1208. X                      SPLAT_WIDTH, SPLAT_HEIGHT);
  1209. X
  1210. X    XMapWindow(dpy, game_win);
  1211. X}
  1212. X
  1213. Xmain(argc, argv)
  1214. X    int         argc;
  1215. X    char      **argv;
  1216. X{
  1217. X    int         i;
  1218. X    char       *dname = NULL;
  1219. X
  1220. X    progname = argv[0];
  1221. X    for (i = 1; i < argc; i++) {
  1222. X    if (!strncmp(argv[i], "-d", 2)) {
  1223. X        if (argv[++i])
  1224. X        dname = argv[i];
  1225. X        else
  1226. X        usage();
  1227. X    }
  1228. X    }
  1229. X    strcpy(user_name, "Unknown");
  1230. X    if (getenv("USER"))
  1231. X    strcpy(user_name, getenv("USER"));
  1232. X    srandom(getpid());
  1233. X    init_display(argc, argv, dname);
  1234. X    update_scores();
  1235. X    draw_init_screen();
  1236. X    while (1) {
  1237. X    wait_for_start();
  1238. X    run();
  1239. X    finish_up();
  1240. X    }
  1241. X}
  1242. X
  1243. Xstatic void
  1244. Xrefresh_screen()
  1245. X{
  1246. X    int         i;
  1247. X
  1248. X    XClearWindow(dpy, game_win);
  1249. X
  1250. X    draw_ledges();
  1251. X
  1252. X    /* delimiter */
  1253. X    XFillRectangle(dpy, game_win, text_gc, 0, WIN_HEIGHT - INFO_HEIGHT,
  1254. X           WIN_WIDTH, DELIM_HEIGHT);
  1255. X
  1256. X    for (i = 0; i < NUM_VATORS; i++) {
  1257. X    draw_obj(vator_pos(i), vator_loc[i], VATOR);
  1258. X    }
  1259. X    draw_obj(man_x, man_y, MAN);
  1260. X    if (gift_state == GIFT_OUT)
  1261. X    draw_obj(gift_x, gift_y, GIFT);
  1262. X    draw_scores();
  1263. X    draw_message(NULL);
  1264. X    draw_message2(NULL);
  1265. X}
  1266. X
  1267. Xstatic void
  1268. Xdraw_init_screen()
  1269. X{
  1270. X    int         i;
  1271. X
  1272. X    XClearWindow(dpy, game_win);
  1273. X
  1274. X    /* place some random elevators */
  1275. X    for (i = 0; i < NUM_VATORS; i++) {
  1276. X    vator_loc[i] = rnd(VATOR_RUN);
  1277. X    }
  1278. X
  1279. X    /* and the man */
  1280. X    man_x = man_start_pos(rnd(2));
  1281. X    man_y = man_y_pos(rnd(NUM_LEDGES));
  1282. X
  1283. X    gift_state = GIFT_NOTYET;
  1284. X    new_gift();
  1285. X
  1286. X    draw_message("     Spy Vs \"Bob\"     Hit 's' to Start, 'q' to Quit, 'h' for Hi Scores");
  1287. X    draw_message2("    Use 'j', 'k', SPACE or Mouse buttons to move, 'p' to Pause");
  1288. X
  1289. X    refresh_screen();
  1290. X}
  1291. X
  1292. Xchar
  1293. Xget_key(kev)
  1294. X    XKeyPressedEvent *kev;
  1295. X{
  1296. X    char        buffer[10];
  1297. X    int         len;
  1298. X
  1299. X    len = XLookupString(kev, buffer, 10, NULL, NULL);
  1300. X    if (len)
  1301. X    return buffer[0];
  1302. X    else
  1303. X    return (char) -1;
  1304. X}
  1305. X
  1306. X/*
  1307. X * draws instructions, waits for 'q' or 's'
  1308. X */
  1309. Xstatic void
  1310. Xwait_for_start()
  1311. X{
  1312. X    XEvent      ev;
  1313. X    Bool        done = False;
  1314. X    char        c;
  1315. X
  1316. X    while (!done) {
  1317. X    XNextEvent(dpy, &ev);
  1318. X    switch (ev.type) {
  1319. X    case Expose:
  1320. X        if (ev.xexpose.count == 0)
  1321. X        refresh_screen();
  1322. X        break;
  1323. X    case KeyPress:
  1324. X        c = get_key((XKeyPressedEvent *) & ev);
  1325. X        switch (c) {
  1326. X        case 'q':
  1327. X        exit(0);
  1328. X        break;
  1329. X        case 's':
  1330. X        done = True;
  1331. X        break;
  1332. X        case 'h':
  1333. X        show_scores();
  1334. X                refresh_screen();
  1335. X        break;
  1336. X        default:
  1337. X        break;
  1338. X        }
  1339. X    }
  1340. X    }
  1341. X    score = 0;
  1342. X    draw_message("");
  1343. X    draw_message2("");
  1344. X}
  1345. X
  1346. Xstatic void
  1347. Xinit_vators()
  1348. X{
  1349. X    int         i;
  1350. X
  1351. X    for (i = 0; i < NUM_VATORS; i++) {
  1352. X    vator_loc[i] = rnd(vator_run);
  1353. X    vator_speed[i] = rnd(VATOR_SPEED_RANGE) + MIN_VATOR_SPEED;
  1354. X    }
  1355. X}
  1356. X
  1357. Xstatic void
  1358. Xgot_across()
  1359. X{
  1360. X    if (gift_state == GIFT_OUT)
  1361. X    erase_obj(gift_x, gift_y, GIFT);
  1362. X    man_speed = 0;
  1363. X    ledge_num--;
  1364. X    score += 200 + (time_left * 5);
  1365. X    ledge++;
  1366. X    if (ledge_num < 0) {    /* finished level */
  1367. X    /* shrink the game board */
  1368. X    if (level < (START_LEDGE - MIN_LEDGE)) {
  1369. X        /* don't drop it to 0, in case anyone's that good */
  1370. X        ledge_num = START_LEDGE - level;
  1371. X        vator_run -= LEDGE_GAP;
  1372. X    } else {
  1373. X        ledge_num = MIN_LEDGE;
  1374. X    }
  1375. X    lives++;
  1376. X    ledge_side = 0;
  1377. X    new_man();
  1378. X    level_factor += LEVEL_INCREASE;
  1379. X    level++;
  1380. X    time_interval--;    /* speed it up too */
  1381. X    if (time_interval < 1)
  1382. X        time_interval = 1;
  1383. X    man_delta--;
  1384. X    if (man_delta <= MIN_MAN_DELTA)
  1385. X        man_delta = MIN_MAN_DELTA;
  1386. X    }
  1387. X    man_y = man_y_pos(ledge_num);
  1388. X    time_left = START_TIME;
  1389. X    gift_time = START_TIME - rnd(START_TIME / 2);
  1390. X    gift_state = GIFT_NOTYET;
  1391. X    flush_keyboard();
  1392. X    draw_scores();
  1393. X}
  1394. X
  1395. Xstatic void
  1396. Xmove_man()
  1397. X{
  1398. X    erase_obj(man_x, man_y, MAN);
  1399. X    man_x += man_speed;
  1400. X    if (man_x < man_start_pos(0)) {
  1401. X    man_x = man_start_pos(0);
  1402. X    if (ledge_side == 1) {    /* made it across */
  1403. X        ledge_side = 0;
  1404. X        got_across();
  1405. X    }
  1406. X    }
  1407. X    if (man_x > man_start_pos(1)) {
  1408. X    man_x = man_start_pos(1);
  1409. X    if (ledge_side == 0) {
  1410. X        ledge_side = 1;
  1411. X        got_across();
  1412. X    }
  1413. X    }
  1414. X    draw_obj(man_x, man_y, MAN);
  1415. X}
  1416. X
  1417. Xstatic void
  1418. Xmove_vators()
  1419. X{
  1420. X    int         i;
  1421. X
  1422. X    for (i = 0; i < NUM_VATORS; i++) {
  1423. X    erase_obj(vator_pos(i), vator_loc[i], VATOR);
  1424. X    vator_loc[i] += vator_speed[i];
  1425. X    if (vator_loc[i] <= 0) {
  1426. X        vator_loc[i] = 0;
  1427. X        vator_speed[i] = level_factor *
  1428. X        (rnd(VATOR_SPEED_RANGE) + MIN_VATOR_SPEED);
  1429. X    } else if (vator_loc[i] >= vator_run) {
  1430. X        vator_loc[i] = vator_run;
  1431. X        vator_speed[i] = -level_factor *
  1432. X        (rnd(VATOR_SPEED_RANGE) + MIN_VATOR_SPEED);
  1433. X    }
  1434. X    draw_obj(vator_pos(i), vator_loc[i], VATOR);
  1435. X    }
  1436. X}
  1437. X
  1438. Xstatic void
  1439. Xnew_man()
  1440. X{
  1441. X    int         i;
  1442. X
  1443. X    erase_obj(man_x, man_y, MAN);
  1444. X    if (gift_state == GIFT_OUT)
  1445. X    erase_obj(gift_x, gift_y, GIFT);
  1446. X    for (i = 0; i < NUM_VATORS; i++)
  1447. X    erase_obj(vator_pos(i), vator_loc[i], VATOR);
  1448. X    time_left = START_TIME;
  1449. X    gift_time = START_TIME - rnd(START_TIME / 2);
  1450. X    init_vators();
  1451. X    man_speed = 0;
  1452. X    man_x = man_start_pos(ledge_side);
  1453. X    man_y = man_y_pos(ledge_num);
  1454. X    draw_obj(man_x, man_y, MAN);
  1455. X    draw_status();
  1456. X    flush_keyboard();
  1457. X}
  1458. X
  1459. Xstatic void
  1460. Xcheck_collision()
  1461. X{
  1462. X    int         i;
  1463. X
  1464. X    for (i = 0; i < NUM_VATORS; i++) {
  1465. X    if (((man_x + MAN_WIDTH - COLLISION_FUDGE) > vator_pos(i)) &&
  1466. X        (man_x < (vator_pos(i) + VATOR_WIDTH - COLLISION_FUDGE))) {
  1467. X        if ((man_y > vator_loc[i]) &&
  1468. X            (man_y < vator_loc[i] + VATOR_HEIGHT)) {
  1469. X        lives--;
  1470. X        draw_message("SPLAT!!!");
  1471. X        erase_obj(man_x, man_y, MAN);
  1472. X        draw_obj(vator_pos(i), vator_loc[i], VATOR);
  1473. X        draw_obj(man_x - 5, man_y + 10, SPLAT);
  1474. X        XSync(dpy, 0);
  1475. X        sleep(1);
  1476. X        refresh_screen();
  1477. X        new_man();
  1478. X        return;
  1479. X        }
  1480. X    }
  1481. X    }
  1482. X
  1483. X    if (gift_state == GIFT_OUT) {
  1484. X    if (((man_x + MAN_WIDTH) > gift_x) &&
  1485. X        (man_x < (gift_x + GIFT_WIDTH))) {
  1486. X        score += GIFT_SCORE;
  1487. X        gift_state = GIFT_TAKEN;
  1488. X        draw_scores();
  1489. X        return;
  1490. X    }
  1491. X    }
  1492. X}
  1493. X
  1494. Xstatic void
  1495. Xflush_keyboard()
  1496. X{
  1497. X    XEvent      ev;
  1498. X
  1499. X    while (XCheckTypedEvent(dpy, KeyPress, &ev));
  1500. X    while (XCheckTypedEvent(dpy, ButtonPress, &ev));
  1501. X    while (XCheckTypedEvent(dpy, ButtonRelease, &ev));
  1502. X}
  1503. X
  1504. Xstatic void
  1505. Xnew_gift()
  1506. X{
  1507. X    if (gift_state == GIFT_NOTYET) {
  1508. X    gift_y = man_y + GIFT_HEIGHT;
  1509. X    gift_x = rnd(WIN_WIDTH - 2 * LEDGE_WIDTH) + LEDGE_WIDTH;
  1510. X    draw_obj(gift_x, gift_y, GIFT);
  1511. X    gift_state = GIFT_OUT;
  1512. X    }
  1513. X}
  1514. X
  1515. Xstatic Bool
  1516. Xhandle_event()
  1517. X{
  1518. X    char        c = '\0';
  1519. X    XEvent      ev;
  1520. X    int         button;
  1521. X
  1522. X    XNextEvent(dpy, &ev);
  1523. X    switch (ev.type) {
  1524. X    case KeyPress:
  1525. X    c = get_key((XKeyPressedEvent *) & ev);
  1526. X    switch (c) {
  1527. X    case 'q':
  1528. X        return False;
  1529. X    case 'j':
  1530. X        man_speed = -man_delta;
  1531. X        break;
  1532. X    case 'k':
  1533. X        man_speed = man_delta;
  1534. X        break;
  1535. X    case ' ':
  1536. X        man_speed = 0;
  1537. X        break;
  1538. X    case 'p':
  1539. X        paused = !paused;
  1540. X        draw_status();
  1541. X        break;
  1542. X    default:
  1543. X        break;
  1544. X    }
  1545. X    break;
  1546. X    case Expose:
  1547. X    refresh_screen();
  1548. X    break;
  1549. X    case ButtonPress:
  1550. X    button = ev.xbutton.button;
  1551. X    if (button == 1) {
  1552. X        man_speed = -man_delta;
  1553. X    } else {
  1554. X        man_speed = man_delta;
  1555. X    }
  1556. X    break;
  1557. X    case ButtonRelease:
  1558. X    button = ev.xbutton.button;
  1559. X    man_speed = 0;
  1560. X    break;
  1561. X    }
  1562. X    return True;
  1563. X}
  1564. X
  1565. Xstatic void
  1566. Xinit_parms()
  1567. X{
  1568. X    ledge_num = START_LEDGE;
  1569. X    ledge_side = 0;
  1570. X    level = 1;
  1571. X    ledge = 0;
  1572. X    lives = NUM_LIVES;
  1573. X    man_delta = MAN_DELTA;
  1574. X    vator_run = VATOR_RUN;
  1575. X    erase_obj(gift_x, gift_y, GIFT);
  1576. X    gift_state = GIFT_NOTYET;
  1577. X    level_factor = 1.0;
  1578. X    time_interval = ROUNDS_PER_UPDATE;
  1579. X}
  1580. X
  1581. X/*
  1582. X * plays the game
  1583. X */
  1584. Xstatic void
  1585. Xrun()
  1586. X{
  1587. X    int         time = 0;
  1588. X    int         ret;
  1589. X    int         serverfd = XConnectionNumber(dpy);
  1590. X    fd_set      read_fds,
  1591. X                base;
  1592. X    struct timeval tval,
  1593. X               *tm;
  1594. X
  1595. X    FD_ZERO(&base);
  1596. X    FD_SET(serverfd, &base);
  1597. X    init_parms();
  1598. X    new_man();
  1599. X
  1600. X    tval.tv_sec = 0;
  1601. X    tval.tv_usec = DELAY_TIME;
  1602. X    while (1) {
  1603. X    if (XPending(dpy)) {
  1604. X        if (!handle_event())
  1605. X        return;
  1606. X        continue;
  1607. X    }
  1608. X    if (!paused)
  1609. X        tm = &tval;
  1610. X    else
  1611. X        tm = (struct timeval *) 0;
  1612. X    read_fds = base;
  1613. X    ret = select(serverfd + 1, &read_fds, (fd_set *) 0, (fd_set *) 0, tm);
  1614. X    if (ret == -1)
  1615. X        if (errno == EINTR)
  1616. X        continue;
  1617. X    if (ret == 1) {
  1618. X        if (!handle_event())
  1619. X        return;
  1620. X        continue;
  1621. X    }
  1622. X    if (paused)
  1623. X        continue;
  1624. X    if (time_left == 0) {
  1625. X        lives--;
  1626. X        draw_message("Time's Up");
  1627. X        XSync(dpy, 0);
  1628. X        sleep(1);
  1629. X        new_man();
  1630. X        time = 0;
  1631. X    }
  1632. X    if (lives == 0)
  1633. X        return;
  1634. X
  1635. X    time++;
  1636. X    if (time >= time_interval) {
  1637. X        time = 0;
  1638. X        time_left--;
  1639. X        if (gift_time <= time_left) {
  1640. X        new_gift();
  1641. X        gift_time = -1;
  1642. X        }
  1643. X        draw_timer();
  1644. X            /* XXX this shouldn't really be necessray, but on a slow display,
  1645. X             * output can get queueed enough that the action gets delayed
  1646. X             */
  1647. X        XSync(dpy, 0);
  1648. X    }
  1649. X    move_vators();
  1650. X    move_man();
  1651. X    check_collision();
  1652. X    if (gift_state == GIFT_OUT)
  1653. X        draw_obj(gift_x, gift_y, GIFT);
  1654. X    }
  1655. X}
  1656. X
  1657. X/*
  1658. X * cleans up screen, shows score
  1659. X */
  1660. Xstatic void
  1661. Xfinish_up()
  1662. X{
  1663. X    draw_message("     Spy Vs \"Bob\"     Hit 's' to Start, 'q' to Quit, 'h' for Hi Scores");
  1664. X    draw_message2("    Use 'j', 'k', SPACE or Mouse buttons to move, 'p' to Pause");
  1665. X    add_score(score, ledge);
  1666. X    draw_scores();
  1667. X    refresh_screen();
  1668. X}
  1669. X
  1670. Xstatic void
  1671. Xerase_obj(x, y, type)
  1672. X    int         x,
  1673. X                y,
  1674. X                type;
  1675. X{
  1676. X    switch (type) {
  1677. X    case VATOR:
  1678. X    XClearArea(dpy, game_win, x, y, VATOR_WIDTH, VATOR_HEIGHT, False);
  1679. X    break;
  1680. X    case GIFT:
  1681. X    XClearArea(dpy, game_win, x, y, GIFT_WIDTH, GIFT_HEIGHT, False);
  1682. X    break;
  1683. X    case MAN:
  1684. X    XClearArea(dpy, game_win, x, y, MAN_WIDTH, MAN_HEIGHT, False);
  1685. X    break;
  1686. X    }
  1687. X}
  1688. X
  1689. Xstatic void
  1690. Xdraw_obj(x, y, type)
  1691. X    int         x,
  1692. X                y,
  1693. X                type;
  1694. X{
  1695. X    Pixmap      mmap;
  1696. X
  1697. X    switch (type) {
  1698. X    case VATOR:
  1699. X    XCopyPlane(dpy, vator_map, game_win, vator_gc,
  1700. X           0, 0, VATOR_WIDTH, VATOR_HEIGHT, x, y, 1);
  1701. X    break;
  1702. X    case GIFT:
  1703. X    XSetForeground(dpy, draw_gc, gift_color);
  1704. X    XCopyPlane(dpy, slack_map, game_win, draw_gc,
  1705. X           0, 0, GIFT_WIDTH, GIFT_HEIGHT, x, y, 1);
  1706. X    break;
  1707. X    case MAN:
  1708. X    XSetForeground(dpy, draw_gc, man_color);
  1709. X    if (man_speed == 0)
  1710. X        mmap = man_stand;
  1711. X    else if (man_speed < 0)
  1712. X        mmap = man_left;
  1713. X    else
  1714. X        mmap = man_right;
  1715. X    XCopyPlane(dpy, mmap, game_win, draw_gc,
  1716. X           0, 0, MAN_WIDTH, MAN_HEIGHT, x, y, 1);
  1717. X    break;
  1718. X    case SPLAT:
  1719. X    XSetForeground(dpy, draw_gc, splat_color);
  1720. X    XCopyPlane(dpy, splat_map, game_win, draw_gc,
  1721. X           0, 0, SPLAT_WIDTH, SPLAT_HEIGHT, x, y, 1);
  1722. X    break;
  1723. X    case LEDGE:
  1724. X    XSetForeground(dpy, draw_gc, ledge_color);
  1725. X    XFillRectangle(dpy, game_win, draw_gc, x, y, LEDGE_WIDTH, LEDGE_HEIGHT);
  1726. X    break;
  1727. X    }
  1728. X}
  1729. X
  1730. Xstatic void
  1731. Xdraw_ledges()
  1732. X{
  1733. X    int         i;
  1734. X    int         y;
  1735. X
  1736. X    for (i = 0; i < NUM_LEDGES; i++) {
  1737. X    y = (i + 1) * LEDGE_GAP;
  1738. X    draw_obj(0, y, LEDGE);
  1739. X    draw_obj(WIN_WIDTH - LEDGE_WIDTH, y, LEDGE);
  1740. X    }
  1741. X}
  1742. X
  1743. Xstatic void
  1744. Xdraw_scores()
  1745. X{
  1746. X    char        score_buffer[256];
  1747. X
  1748. X    sprintf(score_buffer, "Time Left      Level %2d Best %7d Score %7d Lives %2d",
  1749. X        level, highscore, score, lives);
  1750. X    XDrawImageString(dpy, game_win, text_gc, STATUS_X, WIN_HEIGHT - 5,
  1751. X             score_buffer, strlen(score_buffer));
  1752. X}
  1753. X
  1754. Xstatic void
  1755. Xdraw_timer()
  1756. X{
  1757. X    if (paused) {
  1758. X    draw_message("PAUSED");
  1759. X    } else {
  1760. X    XClearArea(dpy, game_win, TIMER_SLICE,
  1761. X           TIMER_Y, TIMER_SLICE * START_TIME, TIMER_HEIGHT, False);
  1762. X    XSetForeground(dpy, draw_gc, timer_color);
  1763. X    XFillRectangle(dpy, game_win, draw_gc, TIMER_SLICE,
  1764. X               TIMER_Y, TIMER_SLICE * time_left, TIMER_HEIGHT);
  1765. X    }
  1766. X}
  1767. X
  1768. Xstatic void
  1769. Xdraw_status()
  1770. X{
  1771. X    int         i,
  1772. X                x,
  1773. X                y;
  1774. X    int         old_sp;
  1775. X
  1776. X    XClearArea(dpy, game_win, TIMER_SLICE * (START_TIME + 1), TIMER_Y,
  1777. X           10000, MAN_HEIGHT, False);
  1778. X    y = TIMER_Y;
  1779. X    x = EXTRA_MAN_X;
  1780. X    old_sp = man_speed;
  1781. X    man_speed = 0;        /* make sure they're standing */
  1782. X    for (i = 0; i < min(lives - 1, 7); i++) {
  1783. X    draw_obj(x, y, MAN);
  1784. X    x -= (int) (MAN_WIDTH * 1.5);
  1785. X    }
  1786. X    man_speed = old_sp;
  1787. X    draw_timer();
  1788. X    draw_scores();
  1789. X}
  1790. X
  1791. Xstatic void
  1792. Xdraw_message(str)
  1793. X    char       *str;
  1794. X{
  1795. X    static char msgbuf[256];
  1796. X
  1797. X    if (str)
  1798. X    strcpy(msgbuf, str);
  1799. X    XClearArea(dpy, game_win, TIMER_SLICE,
  1800. X           TIMER_Y, TIMER_SLICE * START_TIME, TIMER_HEIGHT, False);
  1801. X    XDrawImageString(dpy, game_win, text_gc, STATUS_X, STATUS_Y,
  1802. X             msgbuf, strlen(msgbuf));
  1803. X}
  1804. X
  1805. Xstatic void
  1806. Xdraw_message2(str)
  1807. X    char       *str;
  1808. X{
  1809. X    static char msgbuf2[256];
  1810. X
  1811. X    if (str)
  1812. X    strcpy(msgbuf2, str);
  1813. X    XClearArea(dpy, game_win, STATUS_X,
  1814. X           STATUS_Y + 10, 1000, 15, False);
  1815. X    XDrawImageString(dpy, game_win, text_gc, STATUS_X, STATUS_Y + 20,
  1816. X             msgbuf2, strlen(msgbuf2));
  1817. X}
  1818. END_OF_FILE
  1819. if test 25542 -ne `wc -c <'svs.c'`; then
  1820.     echo shar: \"'svs.c'\" unpacked with wrong size!
  1821. fi
  1822. # end of 'svs.c'
  1823. fi
  1824. echo shar: End of archive 1 \(of 1\).
  1825. cp /dev/null ark1isdone
  1826. MISSING=""
  1827. for I in 1 ; do
  1828.     if test ! -f ark${I}isdone ; then
  1829.     MISSING="${MISSING} ${I}"
  1830.     fi
  1831. done
  1832. if test "${MISSING}" = "" ; then
  1833.     echo You have the archive.
  1834.     rm -f ark[1-9]isdone
  1835. else
  1836.     echo You still need to unpack the following archives:
  1837.     echo "        " ${MISSING}
  1838. fi
  1839. ##  End of shell archive.
  1840. exit 0
  1841. -- 
  1842. --
  1843. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1844. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1845. Sunnyvale, California 94086            at&t: 408/522-9236
  1846.