home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume13 / jetpack / part02 < prev    next >
Encoding:
Internet Message Format  |  1992-04-09  |  54.9 KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v13i074:  jetpack - an arcade action game for X, Part02/04
  5. Message-ID: <2646@master.CNA.TEK.COM>
  6. Date: 23 Mar 92 22:31:55 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1868
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: meb2@cec2.wustl.edu (Mark Edward Bradley)
  12. Posting-number: Volume 13, Issue 74
  13. Archive-name: jetpack/Part02
  14. Environment: X11, Xlib
  15.  
  16.  
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 2 (of 4)."
  25. # Contents:  Makefile.sample bitmap.c copyright.h draw.c message.c
  26. #   scores.c
  27. # Wrapped by billr@saab on Mon Mar 23 14:29:26 1992
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'Makefile.sample' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'Makefile.sample'\"
  31. else
  32. echo shar: Extracting \"'Makefile.sample'\" \(10733 characters\)
  33. sed "s/^X//" >'Makefile.sample' <<'END_OF_FILE'
  34. X# Makefile generated by imake - do not edit!
  35. X# $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
  36. X#
  37. X# The cpp used on this machine replaces all newlines and multiple tabs and
  38. X# spaces in a macro expansion with a single space.  Imake tries to compensate
  39. X# for this, but is not always successful.
  40. X#
  41. X
  42. X###########################################################################
  43. X# Makefile generated from "Imake.tmpl" and </tmp/IIf.a05645>
  44. X# $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
  45. X#
  46. X# Platform-specific parameters may be set in the appropriate .cf
  47. X# configuration files.  Site-wide parameters may be set in the file
  48. X# site.def.  Full rebuilds are recommended if any parameters are changed.
  49. X#
  50. X# If your C preprocessor doesn't define any unique symbols, you'll need
  51. X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
  52. X# "make Makefile", "make Makefiles", or "make World").
  53. X#
  54. X# If you absolutely can't get imake to work, you'll need to set the
  55. X# variables at the top of each Makefile as well as the dependencies at the
  56. X# bottom (makedepend will do this automatically).
  57. X#
  58. X
  59. X###########################################################################
  60. X# platform-specific configuration parameters - edit sun.cf to change
  61. X
  62. X# platform:  $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $
  63. X# operating system:  SunOS 4.1.1
  64. X
  65. X###########################################################################
  66. X# site-specific configuration parameters - edit site.def to change
  67. X
  68. X# site:  $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
  69. X
  70. X            SHELL = /bin/sh
  71. X
  72. X              TOP = .
  73. X      CURRENT_DIR = .
  74. X
  75. X               AR = ar cq
  76. X  BOOTSTRAPCFLAGS =
  77. X               CC = cc
  78. X
  79. X         COMPRESS = compress
  80. X              CPP = /lib/cpp $(STD_CPP_DEFINES)
  81. X    PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
  82. X          INSTALL = install
  83. X               LD = ld
  84. X             LINT = lint
  85. X      LINTLIBFLAG = -C
  86. X         LINTOPTS = -axz
  87. X               LN = ln -s
  88. X             MAKE = make
  89. X               MV = mv
  90. X               CP = cp
  91. X           RANLIB = ranlib
  92. X  RANLIBINSTFLAGS =
  93. X               RM = rm -f
  94. X     STD_INCLUDES =
  95. X  STD_CPP_DEFINES =
  96. X      STD_DEFINES =
  97. X EXTRA_LOAD_FLAGS =
  98. X  EXTRA_LIBRARIES =
  99. X             TAGS = ctags
  100. X
  101. X    SHAREDCODEDEF = -DSHAREDCODE
  102. X         SHLIBDEF = -DSUNSHLIB
  103. X
  104. X    PROTO_DEFINES =
  105. X
  106. X     INSTPGMFLAGS =
  107. X
  108. X     INSTBINFLAGS = -m 0755
  109. X     INSTUIDFLAGS = -m 4755
  110. X     INSTLIBFLAGS = -m 0664
  111. X     INSTINCFLAGS = -m 0444
  112. X     INSTMANFLAGS = -m 0444
  113. X     INSTDATFLAGS = -m 0444
  114. X    INSTKMEMFLAGS = -m 4755
  115. X
  116. X          DESTDIR =
  117. X
  118. X     TOP_INCLUDES = -I$(INCROOT)
  119. X
  120. X      CDEBUGFLAGS = -O
  121. X        CCOPTIONS =
  122. X      COMPATFLAGS =
  123. X
  124. X      ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
  125. X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
  126. X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
  127. X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
  128. X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  129. X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
  130. X   LDCOMBINEFLAGS = -X -r
  131. X
  132. X        MACROFILE = sun.cf
  133. X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
  134. X
  135. X    IMAKE_DEFINES =
  136. X
  137. X         IRULESRC = $(CONFIGDIR)
  138. X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
  139. X
  140. X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
  141. X            $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
  142. X            $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
  143. X
  144. X###########################################################################
  145. X# X Window System Build Parameters
  146. X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
  147. X
  148. X###########################################################################
  149. X# X Window System make variables; this need to be coordinated with rules
  150. X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
  151. X
  152. X          PATHSEP = /
  153. X        USRLIBDIR = $(DESTDIR)/usr/lib
  154. X           BINDIR = $(DESTDIR)/usr/bin/X11
  155. X          INCROOT = $(DESTDIR)/usr/include
  156. X     BUILDINCROOT = $(TOP)
  157. X      BUILDINCDIR = $(BUILDINCROOT)/X11
  158. X      BUILDINCTOP = ..
  159. X           INCDIR = $(INCROOT)/X11
  160. X           ADMDIR = $(DESTDIR)/usr/adm
  161. X           LIBDIR = $(USRLIBDIR)/X11
  162. X        CONFIGDIR = $(LIBDIR)/config
  163. X       LINTLIBDIR = $(USRLIBDIR)/lint
  164. X
  165. X          FONTDIR = $(LIBDIR)/fonts
  166. X         XINITDIR = $(LIBDIR)/xinit
  167. X           XDMDIR = $(LIBDIR)/xdm
  168. X           AWMDIR = $(LIBDIR)/awm
  169. X           TWMDIR = $(LIBDIR)/twm
  170. X           GWMDIR = $(LIBDIR)/gwm
  171. X          MANPATH = $(DESTDIR)/usr/man
  172. X    MANSOURCEPATH = $(MANPATH)/man
  173. X           MANDIR = $(MANSOURCEPATH)n
  174. X        LIBMANDIR = $(MANSOURCEPATH)3
  175. X      XAPPLOADDIR = $(LIBDIR)/app-defaults
  176. X
  177. X        SOXLIBREV = 4.2
  178. X          SOXTREV = 4.0
  179. X         SOXAWREV = 4.0
  180. X        SOOLDXREV = 4.0
  181. X         SOXMUREV = 4.0
  182. X        SOXEXTREV = 4.0
  183. X
  184. X       FONTCFLAGS = -t
  185. X
  186. X     INSTAPPFLAGS = $(INSTDATFLAGS)
  187. X
  188. X            IMAKE = imake
  189. X           DEPEND = makedepend
  190. X              RGB = rgb
  191. X            FONTC = bdftosnf
  192. X        MKFONTDIR = mkfontdir
  193. X        MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier.sh
  194. X
  195. X        CONFIGSRC = $(TOP)/config
  196. X        CLIENTSRC = $(TOP)/clients
  197. X          DEMOSRC = $(TOP)/demos
  198. X           LIBSRC = $(TOP)/lib
  199. X          FONTSRC = $(TOP)/fonts
  200. X       INCLUDESRC = $(TOP)/X11
  201. X        SERVERSRC = $(TOP)/server
  202. X          UTILSRC = $(TOP)/util
  203. X        SCRIPTSRC = $(UTILSRC)/scripts
  204. X       EXAMPLESRC = $(TOP)/examples
  205. X       CONTRIBSRC = $(TOP)/../contrib
  206. X           DOCSRC = $(TOP)/doc
  207. X           RGBSRC = $(TOP)/rgb
  208. X        DEPENDSRC = $(UTILSRC)/makedepend
  209. X         IMAKESRC = $(CONFIGSRC)
  210. X         XAUTHSRC = $(LIBSRC)/Xau
  211. X          XLIBSRC = $(LIBSRC)/X
  212. X           XMUSRC = $(LIBSRC)/Xmu
  213. X       TOOLKITSRC = $(LIBSRC)/Xt
  214. X       AWIDGETSRC = $(LIBSRC)/Xaw
  215. X       OLDXLIBSRC = $(LIBSRC)/oldX
  216. X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
  217. X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
  218. X     MKFONTDIRSRC = $(FONTSRC)/mkfontdir
  219. X     EXTENSIONSRC = $(TOP)/extensions
  220. X
  221. X  DEPEXTENSIONLIB = $(USRLIBDIR)/libXext.a
  222. X     EXTENSIONLIB =  -lXext
  223. X
  224. X          DEPXLIB = $(DEPEXTENSIONLIB)
  225. X             XLIB = $(EXTENSIONLIB) -lX11
  226. X
  227. X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
  228. X         XAUTHLIB =  -lXau
  229. X
  230. X        DEPXMULIB =
  231. X           XMULIB = -lXmu
  232. X
  233. X       DEPOLDXLIB =
  234. X          OLDXLIB = -loldX
  235. X
  236. X      DEPXTOOLLIB =
  237. X         XTOOLLIB = -lXt
  238. X
  239. X        DEPXAWLIB =
  240. X           XAWLIB = -lXaw
  241. X
  242. X LINTEXTENSIONLIB = $(USRLIBDIR)/llib-lXext.ln
  243. X         LINTXLIB = $(USRLIBDIR)/llib-lX11.ln
  244. X          LINTXMU = $(USRLIBDIR)/llib-lXmu.ln
  245. X        LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln
  246. X          LINTXAW = $(USRLIBDIR)/llib-lXaw.ln
  247. X
  248. X        XWLIBSRC = $(CONTRIBSRC)/toolkits/Xw
  249. X        DEPXWLIB = $(USRLIBDIR)/libXw.a
  250. X        XWLIB =  -lXw
  251. X
  252. X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
  253. X
  254. X         DEPLIBS1 = $(DEPLIBS)
  255. X         DEPLIBS2 = $(DEPLIBS)
  256. X         DEPLIBS3 = $(DEPLIBS)
  257. X
  258. X###########################################################################
  259. X# Imake rules for building libraries, programs, scripts, and data files
  260. X# rules:  $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
  261. X
  262. X###########################################################################
  263. X# start of Imakefile
  264. X
  265. X    SRCS = bitmap.c bonus.c collision.c demo.c draw.c erase.c events.c\
  266. X     gameover.c initx.c main.c maze.c message.c normal.c quitx.c scores.c\
  267. X     setinmaze.c setup.c special.c time.c update.c windowx.c
  268. X    OBJS = bitmap.o bonus.o collision.o demo.o draw.o erase.o events.o\
  269. X     gameover.o initx.o main.o maze.o message.o normal.o quitx.o scores.o\
  270. X     setinmaze.o setup.o special.o time.o update.o windowx.o
  271. X
  272. X    PROGRAMS = jetpack
  273. X
  274. X    DESTDIR = /usrd/s/m/meb2
  275. X
  276. X# These defines override the template defaults. Trash em if you want to
  277. X# use the template locations
  278. X    USRLIBDIR = $(DESTDIR)/lib/jetpack
  279. X    BINDIR = $(DESTDIR)/bin
  280. X    MANPATH = $(DESTDIR)/man
  281. X    MANDIR = $(MANSOURCEPATH)1
  282. X    TOP_INCLUDES =
  283. X    DEPXLIB =
  284. X    EXTRA_LIBRARIES = $(XLIB)
  285. X
  286. X# I like my programs optimized, stripped, and setuid. Do what you like.
  287. X    INSTPGMFLAGS = $(INSTUIDFLAGS) -s
  288. X    CDEBUGFLAGS = -O4
  289. X
  290. X# Since my programs are setuid, I make the data files readable only by me.
  291. X    INSTDATFLAGS = -m 0600
  292. X
  293. X# These defines are needed by jetpack. Delete the -DBLIT if you don't want
  294. X# the game to do all the drawing to an offscreen pixmap. (This is good for
  295. X# machines that don't have hardware blitting -- if you have an xterm or a
  296. X# graphics workhorse, leave it in, there will be no flicker)
  297. X    DEFINES = -DBLIT -DSCOREPATH=\"$(SCOREFILE)\" -DLEVELPATH=\"$(LEVELFILE)\"
  298. X
  299. X# The score file can be any name you like, just make sure the directory
  300. X# it's supposed to reside in exists, or jetpack will start creating score
  301. X# files in the directories it is run from. Same for the level files, only
  302. X# the filename you give here is only a prefix -- the complete filename has
  303. X# the level number appended to it.
  304. X    SCOREFILE = $(USRLIBDIR)/jetpack.scores
  305. X    LEVELFILE = $(USRLIBDIR)/jetpack.lev
  306. X
  307. X PROGRAM = jetpack
  308. X
  309. Xall:: jetpack
  310. X
  311. Xjetpack: $(OBJS) $(DEPLIBS)
  312. X    $(RM) $@
  313. X    $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
  314. X
  315. Xinstall:: jetpack
  316. X    $(INSTALL) -c $(INSTPGMFLAGS)   jetpack $(BINDIR)
  317. X
  318. Xinstall.man:: jetpack.man
  319. X    $(INSTALL) -c $(INSTMANFLAGS) jetpack.man $(MANDIR)/jetpack.n
  320. X
  321. Xdepend::
  322. X    $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  323. X
  324. Xlint:
  325. X    $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
  326. Xlint1:
  327. X    $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
  328. X
  329. Xclean::
  330. X    $(RM) $(PROGRAM)
  331. X
  332. Xdepend::
  333. X    $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  334. X
  335. Xinstall:: levels/000
  336. X    $(INSTALL) -c $(INSTDATFLAGS) levels/000 $(LEVELFILE)000
  337. X
  338. X# oops, I can't figure how to override the template default to install the
  339. X# man page as jetpack.1, so I install both and remove the bad one.
  340. Xinstall.man:: jetpack.man
  341. X    $(INSTALL) -c $(INSTMANFLAGS) jetpack.man $(MANDIR)/jetpack.1
  342. X    @rm -f $(MANDIR)/jetpack.n
  343. X
  344. X###########################################################################
  345. X# common rules for all Makefiles - do not edit
  346. X
  347. Xemptyrule::
  348. X
  349. Xclean::
  350. X    $(RM_CMD) \#*
  351. X
  352. XMakefile::
  353. X    -@if [ -f Makefile ]; then \
  354. X    echo "    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
  355. X    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
  356. X    else exit 0; fi
  357. X    $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
  358. X
  359. Xtags::
  360. X    $(TAGS) -w *.[ch]
  361. X    $(TAGS) -xw *.[ch] > TAGS
  362. X
  363. X###########################################################################
  364. X# empty rules for directories that do not have SUBDIRS - do not edit
  365. X
  366. Xinstall::
  367. X    @echo "install in $(CURRENT_DIR) done"
  368. X
  369. Xinstall.man::
  370. X    @echo "install.man in $(CURRENT_DIR) done"
  371. X
  372. XMakefiles::
  373. X
  374. Xincludes::
  375. X
  376. X###########################################################################
  377. X# dependencies generated by makedepend
  378. X
  379. END_OF_FILE
  380. if test 10733 -ne `wc -c <'Makefile.sample'`; then
  381.     echo shar: \"'Makefile.sample'\" unpacked with wrong size!
  382. fi
  383. # end of 'Makefile.sample'
  384. fi
  385. if test -f 'bitmap.c' -a "${1}" != "-c" ; then 
  386.   echo shar: Will not clobber existing file \"'bitmap.c'\"
  387. else
  388. echo shar: Extracting \"'bitmap.c'\" \(10333 characters\)
  389. sed "s/^X//" >'bitmap.c' <<'END_OF_FILE'
  390. X/*    bitmap.c : function to create bitmaps used in jetpack
  391. X*/
  392. X
  393. X#include "copyright.h"
  394. X#include "defs.h"
  395. X#include "bitmap.h"
  396. X
  397. X/*    all the pixmaps of various objects.
  398. X*/
  399. XPixmap    playerpix[PLAYERPHASES], burnpix[BURNDIRECTIONS];
  400. XPixmap    firepix[FIREPHASES], sweeperpix[SWEEPERPHASES],
  401. X        guardpix[GUARDDIRECTIONS][GUARDPHASES];
  402. XPixmap    explodepix[EXPLODEFRAMES];
  403. XPixmap    doorpix[DOORFRAMES];
  404. XPixmap    fuelpix, keypix;
  405. XPixmap    extramanpix;
  406. X
  407. X/*    These arrays hold the color names for each part of each bitmap.
  408. X    They make the pixmap creation code more modifiable.
  409. X*/
  410. Xint    playercolor[PLAYERPARTS] = { CBLUE, CGREY };
  411. Xint    burncolor[BURNPARTS] = { CRED, CYELLOW };
  412. Xint    firecolor[FIREPARTS] = { CRED, CYELLOW };
  413. Xint    sweepcolor[SWEEPERPARTS] = { CGREEN, CGREY, CWHITE };
  414. Xint    guardcolor[GUARDPARTS] = { CGREY, CYELLOW };
  415. Xint    guardflamecolor[GUARDFLAMEPARTS] = { CRED, CYELLOW };
  416. Xint    guardlightcolor = CRED;
  417. Xint    explodecolor = CRED;
  418. Xint    skelcolor = CWHITE;
  419. Xint    fuelcolor[FUELPARTS] = { CORANGE, CRED, CGREY, CWHITE };
  420. Xint    keycolor[KEYPARTS] = { CYELLOW };
  421. Xint    doorcolor[DOORFRAMES][DOORPARTS] = {{ CWHITE }, { CGREY }};
  422. Xint extramancolor = CBLUE;
  423. X
  424. Xset_up_bitmaps()
  425. X{
  426. X    /*    first-stage pixmaps -- each different colored part must be created
  427. X        from a mono bitmap, and then laid atop each other to make the
  428. X        final multi-color pixmap.
  429. X    */
  430. X    Pixmap playerbit[PLAYERPHASES][PLAYERPARTS];
  431. X    Pixmap burnbit[BURNDIRECTIONS][BURNPARTS];
  432. X    Pixmap firebit[FIREPHASES][FIREPARTS];
  433. X    Pixmap sweeperbit[SWEEPERPHASES][SWEEPERPARTS];
  434. X    Pixmap guardbit[GUARDPARTS];
  435. X    Pixmap guardlightbit[GUARDLIGHTS];
  436. X    Pixmap guardflamebit[GUARDDIRECTIONS][GUARDFLAMEPARTS];
  437. X    Pixmap explodebit[EXPLODEFRAMES];
  438. X    Pixmap skelbit[EXPLODEFRAMES];
  439. X    Pixmap doorbit[DOORFRAMES][DOORPARTS];
  440. X    Pixmap fuelbit[FUELPARTS];
  441. X    Pixmap keybit[KEYPARTS];
  442. X    Pixmap extramanbit;
  443. X
  444. X    int    i, j, k, g[GUARDLIGHTS];
  445. X
  446. X    /*    Each of the following sections essentially does this:
  447. X            create and erase the main pixmap
  448. X            create all the secondary pixmaps from bitmap data
  449. X            copy the secondary pixmaps onto the main pixmap with the
  450. X                proper color
  451. X    */
  452. X
  453. X    /*    Player pixmaps
  454. X    */
  455. X    for(i=0; i<PLAYERPHASES; i++) {
  456. X        playerpix[i] = XCreatePixmap(display, gamewindow, PLAYERWIDTH,
  457. X                                        PLAYERHEIGHT, depth);
  458. X        XFillRectangle(display, playerpix[i], ctable[CBLACK].smallgc,
  459. X                        0, 0, PLAYERWIDTH, PLAYERHEIGHT);
  460. X        for(j=0; j<PLAYERPARTS; j++) {
  461. X            playerbit[i][j] = XCreateBitmapFromData(display, gamewindow,
  462. X                                                    player_bits[i][j],
  463. X                                                    PLAYERWIDTH,
  464. X                                                    PLAYERHEIGHT);
  465. X            XCopyPlane(display, playerbit[i][j], playerpix[i],
  466. X                        ctable[playercolor[j]].smallgc, 0, 0,
  467. X                        PLAYERWIDTH, PLAYERHEIGHT, 0, 0, 1);
  468. X        }
  469. X    }
  470. X
  471. X    /*    Pixmaps for the jetpack flame
  472. X    */
  473. X    for(i=0; i<BURNDIRECTIONS; i++) {
  474. X        burnpix[i] = XCreatePixmap(display, gamewindow, BURNWIDTH,
  475. X                                    BURNHEIGHT, depth);
  476. X        XFillRectangle(display, burnpix[i], ctable[CBLACK].smallgc,
  477. X                        0, 0, BURNWIDTH, BURNHEIGHT);
  478. X        for(j=0; j<BURNPARTS; j++) {
  479. X            burnbit[i][j] = XCreateBitmapFromData(display, gamewindow,
  480. X                                                    burn_bits[i][j],
  481. X                                                    BURNWIDTH,
  482. X                                                    BURNHEIGHT);
  483. X            XCopyPlane(display, burnbit[i][j], burnpix[i],
  484. X                        ctable[burncolor[j]].smallgc, 0, 0,
  485. X                        BURNWIDTH, BURNHEIGHT, 0, 0, 1);
  486. X        }
  487. X    }
  488. X
  489. X    /* Wall sweeper pixmaps (very pretty)
  490. X    */
  491. X    for(i=0; i<SWEEPERPHASES; i++) {
  492. X        sweeperpix[i] = XCreatePixmap(display, gamewindow, SWEEPERWIDTH,
  493. X                                        SWEEPERHEIGHT, depth);
  494. X        XFillRectangle(display, sweeperpix[i], ctable[CBLACK].smallgc,
  495. X                        0, 0, SWEEPERWIDTH, SWEEPERHEIGHT);
  496. X        for(j=0; j<SWEEPERPARTS; j++) {
  497. X            sweeperbit[i][j] = XCreateBitmapFromData(display, gamewindow,
  498. X                                                        sweeper_bits[i][j],
  499. X                                                        SWEEPERWIDTH, 
  500. X                                                        SWEEPERHEIGHT);
  501. X            XCopyPlane(display, sweeperbit[i][j], sweeperpix[i],
  502. X                        ctable[sweepcolor[j]].smallgc, 0, 0,
  503. X                        SWEEPERWIDTH, SWEEPERHEIGHT, 0, 0, 1);
  504. X        }
  505. X    }
  506. X
  507. X    /*    Fireball pixmaps
  508. X    */
  509. X    for(i=0; i<FIREPHASES; i++) {
  510. X        firepix[i] = XCreatePixmap(display, gamewindow, FIREWIDTH,
  511. X                                    FIREHEIGHT, depth);
  512. X        XFillRectangle(display, firepix[i], ctable[CBLACK].smallgc,
  513. X                        0, 0, FIREWIDTH, FIREHEIGHT);
  514. X        for(j=0; j<FIREPARTS; j++) {
  515. X            firebit[i][j] = XCreateBitmapFromData(display, gamewindow,
  516. X                                                    fire_bits[i][j],
  517. X                                                    FIREWIDTH,
  518. X                                                    FIREHEIGHT);
  519. X            XCopyPlane(display, firebit[i][j], firepix[i],
  520. X                        ctable[firecolor[j]].smallgc, 0, 0,
  521. X                        FIREWIDTH, FIREHEIGHT, 0, 0, 1);
  522. X        }
  523. X    }
  524. X
  525. X    /*    Guard pixmaps. These are a little odd because of the random
  526. X        blinking light sequences. There are three sets of lights on the
  527. X        guard, and each can be on or off. This makes 8 different frames,
  528. X        but to cut down on bitmap data, I only made the three light
  529. X        bitmaps rather than 8.
  530. X    */
  531. X    for(i=0; i<GUARDPARTS; i++) {
  532. X        guardbit[i] = XCreateBitmapFromData(display, gamewindow,
  533. X                                            guard_bits[i], GUARDWIDTH,
  534. X                                            GUARDHEIGHT);
  535. X        for(j=0; j<GUARDDIRECTIONS; j++) {
  536. X            guardflamebit[j][i] = XCreateBitmapFromData(display, gamewindow,
  537. X                                                    guard_flame_bits[j][i],
  538. X                                                    GUARDWIDTH,
  539. X                                                    GUARDHEIGHT);
  540. X        }
  541. X    }
  542. X    for(i=0; i<GUARDLIGHTS; i++) {
  543. X        guardlightbit[i] = XCreateBitmapFromData(display, gamewindow,
  544. X                                            guard_light_bits[i],
  545. X                                            GUARDWIDTH, GUARDHEIGHT);
  546. X    }
  547. X    for(i=0; i<GUARDDIRECTIONS; i++) {
  548. X        for(j=0; j<GUARDPHASES; j++) {
  549. X            guardpix[i][j] = XCreatePixmap(display, gamewindow, GUARDWIDTH,
  550. X                                            GUARDHEIGHT, depth);
  551. X            XFillRectangle(display, guardpix[i][j],
  552. X                            ctable[CBLACK].smallgc, 0, 0,
  553. X                            GUARDWIDTH, GUARDHEIGHT);
  554. X            for(k=0; k<GUARDPARTS; k++) {
  555. X                XCopyPlane(display, guardbit[k], guardpix[i][j],
  556. X                            ctable[guardcolor[k]].smallgc,
  557. X                            0, 0, GUARDWIDTH, GUARDHEIGHT, 0, 0, 1);
  558. X            }
  559. X            for(k=0; k<GUARDFLAMEPARTS; k++) {
  560. X                XCopyPlane(display, guardflamebit[i][k], guardpix[i][j],
  561. X                            ctable[guardflamecolor[k]].smallgc,
  562. X                            0, 0, GUARDWIDTH, GUARDHEIGHT, 0, 0, 1);
  563. X            }
  564. X            /*    This initialization will need to be expanded if I add more
  565. X                lights.
  566. X            */
  567. X            g[2] = j / 4;
  568. X            g[1] = (j % 4) / 2;
  569. X            g[0] = (j % 4) % 2;
  570. X            for(k=0; k<GUARDLIGHTS; k++) {
  571. X                if(g[k]) XCopyPlane(display, guardlightbit[k], guardpix[i][j],
  572. X                                    ctable[guardlightcolor].smallgc,
  573. X                                    0, 0, GUARDWIDTH, GUARDHEIGHT, 0, 0, 1);
  574. X            }
  575. X        }
  576. X    }
  577. X
  578. X    /*    Player explosion pixmaps
  579. X    */
  580. X    for(i=0; i<EXPLODEFRAMES; i++) {
  581. X        explodepix[i] = XCreatePixmap(display, gamewindow, EXPLODEWIDTH,
  582. X                                        EXPLODEHEIGHT, depth);
  583. X        XFillRectangle(display, explodepix[i], ctable[CBLACK].smallgc,
  584. X                        0, 0, EXPLODEWIDTH, EXPLODEHEIGHT);
  585. X        explodebit[i] = XCreateBitmapFromData(display, gamewindow,
  586. X                                                explode_bits[i],
  587. X                                                EXPLODEWIDTH,
  588. X                                                EXPLODEHEIGHT);
  589. X        skelbit[i] = XCreateBitmapFromData(display, gamewindow,
  590. X                                                skel_bits[i], SKELWIDTH,
  591. X                                                SKELHEIGHT);
  592. X        XCopyPlane(display, explodebit[i], explodepix[i],
  593. X                    ctable[explodecolor].smallgc, 0, 0, EXPLODEWIDTH,
  594. X                    EXPLODEHEIGHT, 0, 0, 1);
  595. X        XCopyPlane(display, skelbit[i], explodepix[i],
  596. X                    ctable[skelcolor].smallgc, 0, 0, SKELWIDTH,
  597. X                    SKELHEIGHT, (EXPLODEWIDTH - SKELWIDTH) / 2,
  598. X                    (EXPLODEWIDTH - SKELWIDTH) / 2, 1);
  599. X    }
  600. X
  601. X    /*    Fuel pod pixmap
  602. X    */
  603. X    fuelpix = XCreatePixmap(display, gamewindow, FUELWIDTH, FUELHEIGHT,
  604. X                            depth);
  605. X    XFillRectangle(display, fuelpix, ctable[CBLACK].smallgc, 0, 0,
  606. X                    FUELWIDTH, FUELHEIGHT);
  607. X    for(i=0; i<FUELPARTS; i++) {
  608. X            fuelbit[i] = XCreateBitmapFromData(display, gamewindow,
  609. X                                                fuel_bits[i],
  610. X                                                FUELWIDTH, FUELHEIGHT);
  611. X            XCopyPlane(display, fuelbit[i], fuelpix,
  612. X                        ctable[fuelcolor[i]].smallgc, 0, 0,
  613. X                        FUELWIDTH, FUELHEIGHT, 0, 0, 1);
  614. X    }
  615. X
  616. X    /*    Key pixmap
  617. X    */
  618. X    keypix = XCreatePixmap(display, gamewindow, KEYWIDTH, KEYHEIGHT,
  619. X                            depth);
  620. X    XFillRectangle(display, keypix, ctable[CBLACK].smallgc, 0, 0,
  621. X                    KEYWIDTH, KEYHEIGHT);
  622. X    for(i=0; i<KEYPARTS; i++) {
  623. X            keybit[i] = XCreateBitmapFromData(display, gamewindow,
  624. X                                                key_bits[i], KEYWIDTH,
  625. X                                                KEYHEIGHT);
  626. X            XCopyPlane(display, keybit[i], keypix,
  627. X                        ctable[keycolor[i]].smallgc, 0, 0,
  628. X                        KEYWIDTH, KEYHEIGHT, 0, 0, 1);
  629. X    }
  630. X
  631. X    /*    Door pixmaps. The only difference in frames is the color, but I
  632. X        wanted it this way in case I want to animate the door in the
  633. X        future.
  634. X    */
  635. X    for(i=0; i<DOORFRAMES; i++) {
  636. X        doorpix[i] = XCreatePixmap(display, gamewindow, DOORWIDTH,
  637. X                                    DOORHEIGHT, depth);
  638. X        XFillRectangle(display, doorpix[i], ctable[CBLACK].smallgc,
  639. X                        0, 0, DOORWIDTH, DOORHEIGHT);
  640. X        for(j=0; j<DOORPARTS; j++) {
  641. X            doorbit[i][j] = XCreateBitmapFromData(display, gamewindow,
  642. X                                                    door_bits[i][j], 
  643. X                                                    DOORWIDTH, DOORHEIGHT);
  644. X            XCopyPlane(display, doorbit[i][j], doorpix[i],
  645. X                        ctable[doorcolor[i][j]].smallgc, 0, 0, 
  646. X                        DOORWIDTH, DOORHEIGHT, 0, 0, 1);
  647. X        }
  648. X    }
  649. X
  650. X    /*    Extra player pixmap
  651. X    */
  652. X    extramanpix = XCreatePixmap(display, gamewindow, EXTRAMANWIDTH,
  653. X                                EXTRAMANHEIGHT, depth);
  654. X    XFillRectangle(display, extramanpix, ctable[CBLACK].smallgc,
  655. X                    0, 0, EXTRAMANWIDTH, EXTRAMANHEIGHT);
  656. X    extramanbit = XCreateBitmapFromData(display, gamewindow, extraman_bits,
  657. X                                        EXTRAMANWIDTH, EXTRAMANHEIGHT);
  658. X    XCopyPlane(display, extramanbit, extramanpix,
  659. X                ctable[extramancolor].smallgc,
  660. X                0, 0, EXTRAMANWIDTH, EXTRAMANHEIGHT, 0, 0, 1);
  661. X
  662. X    /*    free all the temporary pixmaps
  663. X    */
  664. X    for(i=0; i<PLAYERPHASES; i++) {
  665. X        for(j=0; j<PLAYERPARTS; j++) {
  666. X            XFreePixmap(display, playerbit[i][j]);
  667. X        }
  668. X    }
  669. X    for(i=0; i<BURNDIRECTIONS; i++) {
  670. X        for(j=0; j<BURNPARTS; j++) {
  671. X            XFreePixmap(display, burnbit[i][j]);
  672. X        }
  673. X    }
  674. X    for(i=0; i<FIREPHASES; i++) {
  675. X        for(j=0; j<FIREPARTS; j++) {
  676. X            XFreePixmap(display, firebit[i][j]);
  677. X        }
  678. X    }
  679. X    for(i=0; i<SWEEPERPHASES; i++) {
  680. X        for(j=0; j<SWEEPERPARTS; j++) {
  681. X            XFreePixmap(display, sweeperbit[i][j]);
  682. X        }
  683. X    }
  684. X    for(i=0; i<GUARDPARTS; i++) {
  685. X        XFreePixmap(display, guardbit[i]);
  686. X    }
  687. X    for(i=0; i<GUARDLIGHTS; i++) {
  688. X        XFreePixmap(display, guardlightbit[i]);
  689. X    }
  690. X    for(i=0; i<GUARDDIRECTIONS; i++) {
  691. X        for(j=0; j<GUARDFLAMEPARTS; j++) {
  692. X            XFreePixmap(display, guardflamebit[i][j]);
  693. X        }
  694. X    }
  695. X    for(i=0; i<EXPLODEFRAMES; i++) {
  696. X        XFreePixmap(display, explodebit[i]);
  697. X        XFreePixmap(display, skelbit[i]);
  698. X    }
  699. X    for(i=0; i<DOORFRAMES; i++) {
  700. X        for(j=0; j<DOORPARTS; j++) {
  701. X            XFreePixmap(display, doorbit[i][j]);
  702. X        }
  703. X    }
  704. X    for(i=0; i<FUELPARTS; i++) {
  705. X        XFreePixmap(display, fuelbit[i]);
  706. X    }
  707. X    for(i=0; i<KEYPARTS; i++) {
  708. X        XFreePixmap(display, keybit[i]);
  709. X    }
  710. X    XFreePixmap(display, extramanbit);
  711. X}
  712. END_OF_FILE
  713. if test 10333 -ne `wc -c <'bitmap.c'`; then
  714.     echo shar: \"'bitmap.c'\" unpacked with wrong size!
  715. fi
  716. # end of 'bitmap.c'
  717. fi
  718. if test -f 'copyright.h' -a "${1}" != "-c" ; then 
  719.   echo shar: Will not clobber existing file \"'copyright.h'\"
  720. else
  721. echo shar: Extracting \"'copyright.h'\" \(548 characters\)
  722. sed "s/^X//" >'copyright.h' <<'END_OF_FILE'
  723. X/*
  724. X
  725. X    Copyright (c) 1992 Mark Bradley
  726. X
  727. XThis software may be freely distributed, copied, and used provided that:
  728. X    1)    no modified versions of the software are distributed without
  729. X        express written consent of the author,
  730. X    2)    no fee is charged for distributing, copying, or using the
  731. X        software,
  732. X    3)    this copyright and notice appears in all copies of the software.
  733. X
  734. XNo guarantees are made about the software, and the author disclaims all
  735. Xliability against use of the software.  This software is provided "as is"
  736. Xwithout express or implied warranty.
  737. X
  738. X*/
  739. END_OF_FILE
  740. if test 548 -ne `wc -c <'copyright.h'`; then
  741.     echo shar: \"'copyright.h'\" unpacked with wrong size!
  742. fi
  743. # end of 'copyright.h'
  744. fi
  745. if test -f 'draw.c' -a "${1}" != "-c" ; then 
  746.   echo shar: Will not clobber existing file \"'draw.c'\"
  747. else
  748. echo shar: Extracting \"'draw.c'\" \(16987 characters\)
  749. sed "s/^X//" >'draw.c' <<'END_OF_FILE'
  750. X/*    draw.c : routines that draw objects in the window
  751. X*/
  752. X
  753. X#include "copyright.h"
  754. X#include "defs.h"
  755. X
  756. XPixmap    drawpixmap;
  757. X
  758. Xchar    fuelstring[20] = "Fuel: ";
  759. Xchar    scorestring[30] = "Score: ";
  760. Xchar    levelstring[40] = "Mazes Completed: ";
  761. Xchar    bonusstring[30] = "Bonus: ";
  762. X
  763. Xint    oldscore = -1, oldlevel = -1;
  764. X
  765. Xint    titley = 130;
  766. X
  767. X/*    draw draws all the objects in the window.
  768. X*/
  769. Xdraw()
  770. X{
  771. X#ifdef    BLIT
  772. X    XCopyArea(display, drawpixmap, gamewindow, ctable[CBLACK].smallgc,
  773. X                0, 0, WINDOWWIDTH, WINDOWHEIGHT, 0, 0);
  774. X    XFillRectangle(display, drawpixmap, ctable[CBLACK].smallgc, 0, 0,
  775. X                    WINDOWWIDTH, WINDOWHEIGHT);
  776. X#else
  777. X    erase_draw_zones();
  778. X    init_zones();
  779. X#endif
  780. X
  781. X    draw_info();
  782. X
  783. X    draw_player();
  784. X    draw_maze();
  785. X    draw_door();
  786. X    draw_sweepers();
  787. X    draw_treasures();
  788. X    draw_fireballs();
  789. X    draw_guards();
  790. X    draw_messages();
  791. X}
  792. X
  793. X/*    draw_maze draws the lines of the maze that appear in the window
  794. X*/
  795. Xdraw_maze()
  796. X{
  797. X    register int    i, x1, y1, x2, y2;
  798. X
  799. X    for(i=0; i<mazelcount; i++) {
  800. X        x1 = mazelines[i].x1 - plx + WINDOWWIDTH / 2;
  801. X        y1 = mazelines[i].y1 - ply + WINDOWHEIGHT / 2;
  802. X        x2 = mazelines[i].x2 - plx + WINDOWWIDTH / 2;
  803. X        y2 = mazelines[i].y2 - ply + WINDOWHEIGHT / 2;
  804. X        if(((x1 >= -EDGE) && (y1 >= -EDGE) && (x1 <= WINDOWWIDTH + EDGE) &&
  805. X            (y1 <= WINDOWHEIGHT + EDGE)) || ((x2 >= -EDGE) && (y2 >= -EDGE)
  806. X            && (x2 <= WINDOWWIDTH + EDGE) && (y2 <= WINDOWHEIGHT + EDGE))) {
  807. X
  808. X#ifdef    BLIT
  809. X                XDrawLine(display, drawpixmap, ctable[CWHITE].smallgc,
  810. X                            x1, y1, x2, y2);
  811. X#else
  812. X                set_zone(x1, y1, x2, y2, ZLINE, i);
  813. X#endif
  814. X        }
  815. X    }
  816. X}
  817. X
  818. X/*    draw_player draws the player in the center of the window
  819. X*/
  820. Xdraw_player()
  821. X{
  822. X    if(dead) return;
  823. X    if(exploded > -1) {
  824. X
  825. X#ifdef    BLIT
  826. X        XCopyArea(display, explodepix[exploded], drawpixmap,
  827. X                    ctable[CWHITE].smallgc, 0, 0, EXPLODEWIDTH,
  828. X                    EXPLODEHEIGHT, WINDOWWIDTH / 2 - EXPLODEWIDTH / 2,
  829. X                    WINDOWHEIGHT / 2 - EXPLODEHEIGHT / 2);
  830. X#else
  831. X        set_zone(WINDOWWIDTH / 2 - EXPLODEWIDTH / 2, WINDOWHEIGHT / 2 -
  832. X                    EXPLODEHEIGHT / 2, EXPLODEWIDTH, EXPLODEHEIGHT,
  833. X                    ZEXPLODE, 0);
  834. X#endif
  835. X
  836. X    } else {
  837. X
  838. X#ifdef    BLIT
  839. X        XCopyArea(display, playerpix[playerphase], drawpixmap,
  840. X                    ctable[CWHITE].smallgc, 0, 0, PLAYERWIDTH,
  841. X                    PLAYERHEIGHT, WINDOWWIDTH / 2 - PLAYERWIDTH / 2,
  842. X                    WINDOWHEIGHT / 2 - PLAYERHEIGHT / 2);
  843. X#else
  844. X        set_zone(WINDOWWIDTH / 2 - PLAYERWIDTH / 2, WINDOWHEIGHT / 2 -
  845. X                    PLAYERHEIGHT / 2, PLAYERWIDTH, PLAYERHEIGHT,
  846. X                    ZPLAYER, 0);
  847. X#endif
  848. X
  849. X        if(burn)
  850. X
  851. X#ifdef    BLIT
  852. X            XCopyArea(display, burnpix[playerphase / FACEFRONT],
  853. X                            drawpixmap, ctable[CWHITE].smallgc, 0, 0,
  854. X                            PLAYERWIDTH, PLAYERHEIGHT, WINDOWWIDTH / 2 -
  855. X                            PLAYERWIDTH / 2, WINDOWHEIGHT / 2 -
  856. X                            PLAYERHEIGHT / 2);
  857. X#else
  858. X        set_zone(WINDOWWIDTH / 2 - PLAYERWIDTH / 2, WINDOWHEIGHT / 2 -
  859. X                    PLAYERHEIGHT / 2, PLAYERWIDTH, PLAYERHEIGHT,
  860. X                    ZBURN, 0);
  861. X#endif
  862. X
  863. X    }
  864. X}
  865. X
  866. X/*    draw_fireballs draws all the fireballs in the window
  867. X*/
  868. Xdraw_fireballs()
  869. X{
  870. X    register int    i, fx, fy;
  871. X
  872. X    for(i=0; i<numfire; i++) {
  873. X        fx = transx(firex[i], FIREWIDTH);
  874. X        fy = transy(firey[i], FIREHEIGHT);
  875. X        if((fx >= -FIREWIDTH - EDGE) && (fy >= -FIREHEIGHT - EDGE) &&
  876. X            (fx <= WINDOWWIDTH + EDGE) && (fy <= WINDOWHEIGHT + EDGE)) {
  877. X
  878. X#ifdef    BLIT
  879. X            XCopyArea(display, firepix[firephase[i]], drawpixmap,
  880. X                        ctable[CWHITE].smallgc, 0, 0, FIREWIDTH,
  881. X                        FIREHEIGHT, fx, fy);
  882. X#else
  883. X            set_zone(fx, fy, FIREWIDTH, FIREHEIGHT, ZFIRE, i);
  884. X#endif
  885. X
  886. X        }
  887. X    }
  888. X}
  889. X
  890. X/*    draw_guards draws all the guards in the window
  891. X*/
  892. Xdraw_guards()
  893. X{
  894. X    register int    i, gx, gy;
  895. X
  896. X    for(i=0; i<numguard; i++) {
  897. X        gx = transx(guardx[i], GUARDWIDTH);
  898. X        gy = transy(guardy[i], GUARDHEIGHT);
  899. X        if((gx >= -GUARDWIDTH - EDGE) && (gy >= -GUARDHEIGHT - EDGE) &&
  900. X            (gx <= WINDOWWIDTH + EDGE) && (gy <= WINDOWHEIGHT + EDGE)) {
  901. X
  902. X#ifdef    BLIT
  903. X            XCopyArea(display, guardpix[guarddir[i]][guardphase[i]],
  904. X                        drawpixmap, ctable[CWHITE].smallgc, 0, 0,
  905. X                        GUARDWIDTH, GUARDHEIGHT, gx, gy);
  906. X#else
  907. X            set_zone(gx, gy, GUARDWIDTH, GUARDHEIGHT, ZGUARD, i);
  908. X#endif
  909. X
  910. X        }
  911. X    }
  912. X}
  913. X
  914. X/*    draw_sweepers draws all the sweepers in the window
  915. X*/
  916. Xdraw_sweepers()
  917. X{
  918. X    register int    i, sx, sy;
  919. X
  920. X    for(i=0; i<numsweep; i++) {
  921. X        sx = transx(sweepx[i], SWEEPERWIDTH);
  922. X        sy = transy(sweepy[i], SWEEPERHEIGHT);
  923. X        if((sx >= -SWEEPERWIDTH - EDGE) && (sy >= -SWEEPERHEIGHT - EDGE) &&
  924. X            (sx <= WINDOWWIDTH + EDGE) && (sy <= WINDOWHEIGHT + EDGE)) {
  925. X
  926. X#ifdef    BLIT
  927. X            XCopyArea(display, sweeperpix[sweepphase[i]], drawpixmap,
  928. X                        ctable[CWHITE].smallgc, 0, 0, SWEEPERWIDTH,
  929. X                        SWEEPERHEIGHT, sx, sy);
  930. X#else
  931. X            set_zone(sx, sy, SWEEPERWIDTH, SWEEPERHEIGHT, ZSWEEP, i);
  932. X#endif
  933. X
  934. X        }
  935. X    }
  936. X}
  937. X
  938. X/*    draw_treasures draws the key and fuel pods in the window
  939. X*/
  940. Xdraw_treasures()
  941. X{
  942. X    register int    i, tx, ty, width;
  943. X
  944. X    for(i=0; i<numfuel; i++) {
  945. X        if(fuelalive[i]) {
  946. X            tx = transx(fuelx[i], FUELWIDTH);
  947. X            ty = transy(fuely[i], FUELHEIGHT);
  948. X            if((tx >= -FUELWIDTH - EDGE) && (ty >= -FUELHEIGHT - EDGE) &&
  949. X                (tx <= WINDOWWIDTH + EDGE) && (ty <= WINDOWHEIGHT + EDGE)) {
  950. X
  951. X#ifdef    BLIT
  952. X                XCopyArea(display, fuelpix, drawpixmap,
  953. X                            ctable[CWHITE].smallgc, 0, 0, FUELWIDTH,
  954. X                            FUELHEIGHT, tx, ty);
  955. X#else
  956. X                set_zone(tx, ty, FUELWIDTH, FUELHEIGHT, ZFUEL, i);
  957. X#endif
  958. X
  959. X            }
  960. X        } else if(fueltimer[i]) {
  961. X            tx = transx(fuelx[i], FUELWIDTH);
  962. X            ty = transy(fuely[i], FUELHEIGHT);
  963. X            width = XTextWidth(fontinfo,"100",3) / 2;
  964. X
  965. X#ifdef    BLIT
  966. X            XDrawString(display, drawpixmap,
  967. X                        ctable[CGREEN].smallgc, tx + FUELWIDTH / 2
  968. X                        - width, ty + FUELHEIGHT / 2,
  969. X                        "100", 3);
  970. X#else
  971. X            set_zone(tx + FUELWIDTH / 2 - width, ty + FUELHEIGHT / 2 -
  972. X                        fontinfo->ascent, width * 2, fontinfo->ascent +
  973. X                        fontinfo->descent, ZFUEL, i);
  974. X#endif
  975. X
  976. X            fueltimer[i]--;
  977. X        }
  978. X    }
  979. X    if(keyalive) {
  980. X        tx = transx(keyx, KEYWIDTH);
  981. X        ty = transy(keyy, KEYHEIGHT);
  982. X        if((tx >= -KEYWIDTH - EDGE) && (ty >= -KEYHEIGHT - EDGE) &&
  983. X            (tx <= WINDOWWIDTH + EDGE) && (ty <= WINDOWHEIGHT + EDGE)) {
  984. X
  985. X#ifdef    BLIT
  986. X            XCopyArea(display, keypix, drawpixmap,
  987. X                        ctable[CWHITE].smallgc, 0, 0, KEYWIDTH,
  988. X                        KEYHEIGHT, tx, ty);
  989. X#else
  990. X            set_zone(tx, ty, KEYWIDTH, KEYHEIGHT, ZKEY, 0);
  991. X#endif
  992. X
  993. X        }
  994. X    } else if(keytimer) {
  995. X        tx = transx(keyx, KEYWIDTH);
  996. X        ty = transy(keyy, KEYHEIGHT);
  997. X        width = XTextWidth(fontinfo,"500",3) / 2;
  998. X
  999. X#ifdef    BLIT
  1000. X        XDrawString(display, drawpixmap, ctable[CGREEN].smallgc,
  1001. X                    tx + KEYWIDTH / 2 - width, ty + KEYHEIGHT / 2,
  1002. X                    "500", 3);
  1003. X#else
  1004. X        set_zone(tx + KEYWIDTH / 2 - width, ty + KEYHEIGHT / 2 -
  1005. X                    fontinfo->ascent, width * 2, fontinfo->ascent +
  1006. X                    fontinfo->descent, ZKEY, 0);
  1007. X#endif
  1008. X
  1009. X        keytimer--;
  1010. X    }
  1011. X}
  1012. X
  1013. X/*    draw_door draws the door in the window
  1014. X*/
  1015. Xdraw_door()
  1016. X{
  1017. X    register int    dx, dy, phase;
  1018. X
  1019. X    dx = transx(doorx, DOORWIDTH);
  1020. X    dy = transy(doory, DOORHEIGHT);
  1021. X    if((dx >= -DOORWIDTH - EDGE) && (dy >= -DOORHEIGHT - EDGE) &&
  1022. X        (dx <= WINDOWWIDTH + EDGE) && (dy <= WINDOWHEIGHT + EDGE)) {
  1023. X        phase = indoor;
  1024. X        if(indoor && (exploded > -1)) phase = 0;
  1025. X
  1026. X#ifdef    BLIT
  1027. X        XCopyArea(display, doorpix[phase], drawpixmap,
  1028. X                    ctable[CWHITE].smallgc, 0, 0, DOORWIDTH,
  1029. X                    DOORHEIGHT, dx, dy - (DOORHEIGHT - PLAYERHEIGHT) / 2);
  1030. X#else
  1031. X        set_zone(dx, dy - (DOORHEIGHT - PLAYERHEIGHT) / 2, DOORWIDTH,
  1032. X                    DOORHEIGHT, ZDOOR, 0);
  1033. X#endif
  1034. X
  1035. X    }
  1036. X}
  1037. X
  1038. X/*    transx translates an x coordinate against the player's x coordinate to
  1039. X    fit it properly in the window.
  1040. X*/
  1041. Xint    transx(x, off)
  1042. Xint    x, off;
  1043. X{
  1044. X    return(x - plx + WINDOWWIDTH / 2 - off / 2);
  1045. X}
  1046. X
  1047. X/*    transy translates an y coordinate against the player's y coordinate to
  1048. X    fit it properly in the window.
  1049. X*/
  1050. Xint    transy(y, off)
  1051. Xint    y, off;
  1052. X{
  1053. X    return(y - ply + WINDOWHEIGHT / 2 - off / 2);
  1054. X}
  1055. X
  1056. X/*    refresh_info redraws the info window
  1057. X*/
  1058. Xrefresh_info()
  1059. X{
  1060. X    register int    i;
  1061. X
  1062. X    XClearWindow(display, infowindow);
  1063. X    if(!keyalive) XCopyArea(display, keypix, infowindow,
  1064. X                            ctable[CWHITE].smallgc, 0, 0, KEYWIDTH,
  1065. X                            KEYHEIGHT, WINDOWWIDTH / 2 - 10 - KEYWIDTH, 5);
  1066. X    for(i=0; i<men; i++) {
  1067. X        XCopyArea(display, extramanpix, infowindow, ctable[CWHITE].smallgc,
  1068. X                    0, 0, EXTRAMANWIDTH, EXTRAMANHEIGHT, WINDOWWIDTH - (i +
  1069. X                    1) * (EXTRAMANWIDTH + 3), 5);
  1070. X    }
  1071. X    if(gameover) XDrawString(display,infowindow, ctable[CRED].biggc,
  1072. X                                100,30,"DEMO",strlen("DEMO"));
  1073. X    oldlevel = -1;
  1074. X    oldscore = -1;
  1075. X    draw_info();
  1076. X}
  1077. X
  1078. X/*    draw_messages draws any active messages in the window
  1079. X*/
  1080. Xdraw_messages()
  1081. X{
  1082. X    register int    tmpcolor;
  1083. X
  1084. X    if(messagetime != 0) {
  1085. X
  1086. X#ifdef    BLIT
  1087. X        if(messagecolor == CBLACK)
  1088. X            tmpcolor = random() % (NCOLORS-1) + 1;
  1089. X        else tmpcolor = messagecolor;
  1090. X        XDrawString(display, drawpixmap,
  1091. X                    ctable[tmpcolor].smallgc, messagex, messagey,
  1092. X                    messagestring, messagelength);
  1093. X#else
  1094. X        set_zone(messagex, messagey - fontinfo->ascent, messagewidth,
  1095. X                    fontinfo->ascent + fontinfo->descent, ZSMESS, 0);
  1096. X#endif
  1097. X
  1098. X        messagetime--;
  1099. X    }
  1100. X    if(bigmessagetime != 0) {
  1101. X
  1102. X#ifdef    BLIT
  1103. X        if(bigmessagecolor == CBLACK)
  1104. X            tmpcolor = random() % (NCOLORS-1) + 1;
  1105. X        else tmpcolor = bigmessagecolor;
  1106. X        XDrawString(display, drawpixmap,
  1107. X                    ctable[tmpcolor].biggc,
  1108. X                    bigmessagex, bigmessagey,
  1109. X                    bigmessagestring, bigmessagelength);
  1110. X#else
  1111. X        set_zone(bigmessagex, bigmessagey - bigfontinfo->ascent,
  1112. X                    bigmessagewidth, bigfontinfo->ascent +
  1113. X                    bigfontinfo->descent, ZBMESS, 0);
  1114. X#endif
  1115. X
  1116. X        bigmessagetime--;
  1117. X    }
  1118. X}
  1119. X
  1120. X/*    draw_info draws the stuff in the info window that needs to be updated
  1121. X    frequently
  1122. X*/
  1123. Xdraw_info()
  1124. X{
  1125. X    int    tmp;
  1126. X
  1127. X    sprintf(fuelstring, "Fuel: %04d", playerfuel);
  1128. X    if(playerfuel < 100) tmp = CRED;
  1129. X    else if(playerfuel < 500) tmp = CYELLOW;
  1130. X    else tmp = CGREEN;
  1131. X    XDrawImageString(display, infowindow, ctable[tmp].smallgc,
  1132. X                        10, 10, fuelstring, strlen(fuelstring));
  1133. X    if(level != oldlevel) {
  1134. X        sprintf(levelstring, "Level: %03d", level);
  1135. X        XDrawImageString(display, infowindow, ctable[CWHITE].smallgc,
  1136. X                            10, 20 + fontinfo->ascent + fontinfo->descent,
  1137. X                            levelstring, strlen(levelstring));
  1138. X        oldlevel = level;
  1139. X    }
  1140. X    sprintf(bonusstring, "Bonus: %06d", bonus);
  1141. X    XDrawImageString(display, infowindow, ctable[CWHITE].smallgc,
  1142. X                        WINDOWWIDTH / 2, 10, bonusstring,
  1143. X                        strlen(bonusstring));
  1144. X    if(score != oldscore) {
  1145. X        sprintf(scorestring, "Score: %09d", score);
  1146. X        XDrawImageString(display, infowindow, ctable[CWHITE].smallgc,
  1147. X                            WINDOWWIDTH / 2, 20 + fontinfo->ascent +
  1148. X                            fontinfo->descent, scorestring,
  1149. X                            strlen(scorestring));
  1150. X        oldscore = score;
  1151. X    }
  1152. X}
  1153. X
  1154. X/*  place_string draws a centered string on the title screen
  1155. X*/
  1156. Xplace_string(s, y, color, info)
  1157. Xchar        *s;
  1158. Xint         y, color;
  1159. XXFontStruct *info;
  1160. X{
  1161. X    register int    length, width;
  1162. X
  1163. X    length = strlen(s);
  1164. X    width = XTextWidth(info, s, length);
  1165. X
  1166. X#ifdef  BLIT
  1167. X    if(info == bigfontinfo) {
  1168. X        XDrawString(display, drawpixmap, ctable[color].biggc,
  1169. X                    WINDOWWIDTH / 2 - width / 2, y, s, length);
  1170. X    } else {
  1171. X        XDrawString(display, drawpixmap, ctable[color].smallgc,
  1172. X                    WINDOWWIDTH / 2 - width / 2, y, s, length);
  1173. X    }
  1174. X#else
  1175. X    if(info == bigfontinfo) {
  1176. X        XDrawString(display, gamewindow, ctable[color].biggc,
  1177. X                    WINDOWWIDTH / 2 - width / 2, y, s, length);
  1178. X    } else {
  1179. X        XDrawString(display, gamewindow, ctable[color].smallgc,
  1180. X                    WINDOWWIDTH / 2 - width / 2, y, s, length);
  1181. X    }
  1182. X#endif
  1183. X
  1184. X}
  1185. X
  1186. X/*  title_draw updates and draws the title screen
  1187. X*/
  1188. Xtitle_draw()
  1189. X{
  1190. X    register int    i, j;
  1191. X
  1192. X    update_fireballs();
  1193. X    update_sweepers();
  1194. X    update_guards();
  1195. X
  1196. X#ifdef  BLIT
  1197. X    XFillRectangle(display, drawpixmap, ctable[CBLACK].smallgc, 0,
  1198. X                    titley, WINDOWWIDTH, WINDOWHEIGHT - titley);
  1199. X    XCopyArea(display, scorepixmap, drawpixmap, ctable[CWHITE].smallgc,
  1200. X                0, 0, SCOREWIDTH, SCOREHEIGHT, SCOREX, SCOREY);
  1201. X#else
  1202. X    XCopyArea(display, scorepixmap, gamewindow, ctable[CBLACK].smallgc,
  1203. X                0, 0, SCOREWIDTH, SCOREHEIGHT, SCOREX, SCOREY);
  1204. X    erase_draw_zones();
  1205. X    init_zones();
  1206. X#endif
  1207. X
  1208. X    draw_maze();
  1209. X    draw_guards();
  1210. X    draw_sweepers();
  1211. X    draw_fireballs();
  1212. X    /*  make the player image do random things
  1213. X    */
  1214. X    if(random() % 30 == 0) burn = 1 - burn;
  1215. X    if(random() % 30 == 0) playerdir = random() % 3 - 1;
  1216. X    if(!burn && (playerdir != STOP)) {
  1217. X        playerphase += playerdir;
  1218. X        if(playerphase > FACERIGHT - 1) playerphase = FACEFRONT + 1;
  1219. X        if(playerphase < FACELEFT + 1) playerphase = FACEFRONT - 1;
  1220. X        if((playerdir == GOLEFT) && (playerphase < FACEFRONT))
  1221. X            playerphase = FACEFRONT;
  1222. X        if((playerdir == GORIGHT) && (playerphase > FACEFRONT))
  1223. X            playerphase = FACEFRONT;
  1224. X    } else playerphase = (playerdir+1) * FACEFRONT;
  1225. X
  1226. X#ifdef  BLIT
  1227. X    XCopyArea(display, playerpix[playerphase], drawpixmap,
  1228. X                ctable[CWHITE].smallgc, 0, 0, PLAYERWIDTH,
  1229. X                PLAYERHEIGHT, WINDOWWIDTH / 2 - PLAYERWIDTH / 2, titley);
  1230. X    if(burn) XCopyArea(display, burnpix[playerphase / FACEFRONT],
  1231. X                        drawpixmap, ctable[CWHITE].smallgc, 0, 0,
  1232. X                        PLAYERWIDTH, PLAYERHEIGHT, WINDOWWIDTH / 2 -
  1233. X                        PLAYERWIDTH / 2, titley);
  1234. X#else
  1235. X    XFillRectangle(display, gamewindow, ctable[CBLACK].smallgc,
  1236. X                    WINDOWWIDTH / 2 - PLAYERWIDTH / 2, titley, PLAYERWIDTH,
  1237. X                    PLAYERHEIGHT);
  1238. X    XCopyArea(display, playerpix[playerphase], gamewindow,
  1239. X                ctable[CWHITE].smallgc, 0, 0, PLAYERWIDTH,
  1240. X                PLAYERHEIGHT, WINDOWWIDTH / 2 - PLAYERWIDTH / 2, titley);
  1241. X    if(burn) XCopyArea(display, burnpix[playerphase / FACEFRONT],
  1242. X                        gamewindow, ctable[CWHITE].smallgc, 0, 0,
  1243. X                        PLAYERWIDTH, PLAYERHEIGHT, WINDOWWIDTH / 2 -
  1244. X                        PLAYERWIDTH / 2, titley);
  1245. X#endif
  1246. X}
  1247. X
  1248. X/*  title_refresh draws the title screen stuff that doesn't have to be
  1249. X    continuously updated
  1250. X*/
  1251. Xtitle_refresh()
  1252. X{
  1253. X    char            scstring[30];
  1254. X    register int    y, width;
  1255. X
  1256. X    y = 5 + bigfontinfo->ascent;
  1257. X    place_string("Jetpack", y, CYELLOW, bigfontinfo);
  1258. X    y += bigfontinfo->descent + 5 + fontinfo->ascent;
  1259. X    place_string("By Mark Bradley", y, CBLUE, fontinfo);
  1260. X    y += fontinfo->descent + 5 + fontinfo->ascent;
  1261. X    place_string("Controls:", y, CWHITE, fontinfo);
  1262. X    y += fontinfo->descent + fontinfo->ascent;
  1263. X    place_string(
  1264. X        "  keypad 4, a, left button : move left                       ",
  1265. X        y, CGREEN, fontinfo);
  1266. X    place_string(
  1267. X        "                                           K : commit suicide",
  1268. X        y, CRED, fontinfo);
  1269. X    y += fontinfo->descent + fontinfo->ascent;
  1270. X    place_string(
  1271. X        " keypad 6, d, right button : move right                      ",
  1272. X        y, CGREEN, fontinfo);
  1273. X    place_string(
  1274. X        "                                           p : pause game    ",
  1275. X        y, CBLUE, fontinfo);
  1276. X    y += fontinfo->descent + fontinfo->ascent;
  1277. X    place_string(
  1278. X        "               keypad 5, s : stop                            ",
  1279. X        y, CRED, fontinfo);
  1280. X    place_string(
  1281. X        "                                           Q : quit game     ",
  1282. X        y, CGREY, fontinfo);
  1283. X    y += fontinfo->descent + fontinfo->ascent;
  1284. X    place_string(
  1285. X        "             center button : fire jetpack                    ",
  1286. X        y, CYELLOW, fontinfo);
  1287. X    y += fontinfo->descent + 10 + fontinfo->ascent;
  1288. X    place_string("Extra Player awarded every 10000 points", y, CGREY,
  1289. X                    fontinfo);
  1290. X
  1291. X#ifdef  BLIT
  1292. X    XCopyArea(display, fuelpix, drawpixmap, ctable[CWHITE].smallgc,
  1293. X                0, 0, FUELWIDTH, FUELHEIGHT, WINDOWWIDTH / 4 - FUELWIDTH /
  1294. X               2, 20 - FUELHEIGHT / 2);
  1295. X    XCopyArea(display, keypix, drawpixmap, ctable[CWHITE].smallgc,
  1296. X                0, 0, KEYWIDTH, KEYHEIGHT, 3 * (WINDOWWIDTH / 4) -
  1297. X                KEYWIDTH / 2, 20 - KEYHEIGHT / 2);
  1298. X    width = XTextWidth(fontinfo, "100", 3);
  1299. X    XDrawString(display, drawpixmap, ctable[CGREEN].smallgc,
  1300. X                WINDOWWIDTH / 4 - width / 2, 20 + FUELHEIGHT / 2 + 5 +
  1301. X                fontinfo->ascent, "100", 3);
  1302. X    width = XTextWidth(fontinfo, "500", 3);
  1303. X    XDrawString(display, drawpixmap, ctable[CGREEN].smallgc,
  1304. X                3 * (WINDOWWIDTH / 4) - width / 2, 20 + KEYHEIGHT / 2 +
  1305. X                10 + fontinfo->ascent, "500", 3);
  1306. X#else
  1307. X    XCopyArea(display, fuelpix, gamewindow, ctable[CWHITE].smallgc,
  1308. X                0, 0, FUELWIDTH, FUELHEIGHT, WINDOWWIDTH / 4 - FUELWIDTH /
  1309. X               2, 20 - FUELHEIGHT / 2);
  1310. X    XCopyArea(display, keypix, gamewindow, ctable[CWHITE].smallgc,
  1311. X                0, 0, KEYWIDTH, KEYHEIGHT, 3 * (WINDOWWIDTH / 4) -
  1312. X                KEYWIDTH / 2, 20 - KEYHEIGHT / 2);
  1313. X    width = XTextWidth(fontinfo, "100", 3);
  1314. X    XDrawString(display, gamewindow, ctable[CGREEN].smallgc,
  1315. X                WINDOWWIDTH / 4 - width / 2, 20 + FUELHEIGHT / 2 + 5 +
  1316. X                fontinfo->ascent, "100", 3);
  1317. X    width = XTextWidth(fontinfo, "500", 3);
  1318. X    XDrawString(display, gamewindow, ctable[CGREEN].smallgc,
  1319. X                3 * (WINDOWWIDTH / 4) - width / 2, 20 + KEYHEIGHT / 2 +
  1320. X                10 + fontinfo->ascent, "500", 3);
  1321. X#endif
  1322. X
  1323. X    sprintf(scstring, "Last Score: %09d", lastscore);
  1324. X    XDrawString(display, infowindow, ctable[CGREY].biggc,
  1325. X                WINDOWWIDTH / 2 -
  1326. X                XTextWidth(bigfontinfo, scstring, strlen(scstring)) / 2,
  1327. X                INFOHEIGHT / 2, scstring, strlen(scstring));
  1328. X}
  1329. END_OF_FILE
  1330. if test 16987 -ne `wc -c <'draw.c'`; then
  1331.     echo shar: \"'draw.c'\" unpacked with wrong size!
  1332. fi
  1333. # end of 'draw.c'
  1334. fi
  1335. if test -f 'message.c' -a "${1}" != "-c" ; then 
  1336.   echo shar: Will not clobber existing file \"'message.c'\"
  1337. else
  1338. echo shar: Extracting \"'message.c'\" \(2687 characters\)
  1339. sed "s/^X//" >'message.c' <<'END_OF_FILE'
  1340. X/*    message.c : routines that implement a message display system
  1341. X*/
  1342. X
  1343. X#include "copyright.h"
  1344. X#include "defs.h"
  1345. X#include "message.h"
  1346. X
  1347. Xstruct levelmessage    lmessage[MAXLEVELMESSAGES];
  1348. Xint                    numlmessage;
  1349. X
  1350. Xchar    messagestring[MAXMESSAGELENGTH],
  1351. X        bigmessagestring[MAXBIGMESSAGELENGTH];
  1352. Xint        messagex, messagey, bigmessagex, bigmessagey,
  1353. X        messagetime = 0, bigmessagetime = 0,
  1354. X        messagecolor, bigmessagecolor,
  1355. X        messagelength = 0, bigmessagelength = 0,
  1356. X        messagewidth, bigmessagewidth;
  1357. X
  1358. X/*    message puts a message s on the screen in color for time
  1359. X*/
  1360. Xmessage(s, color, time)
  1361. Xchar    *s;
  1362. Xint        color, time;
  1363. X{
  1364. X    messagecolor = color;
  1365. X    messagetime = time;
  1366. X    strncpy(messagestring, s, MAXMESSAGELENGTH);
  1367. X    messagelength = strlen(messagestring);
  1368. X    messagewidth = XTextWidth(fontinfo, messagestring, messagelength);
  1369. X    messagey = WINDOWHEIGHT / 5 + 50;
  1370. X    messagex = WINDOWWIDTH / 2 - messagewidth / 2;
  1371. X}
  1372. X
  1373. X/*    message puts a big message s on the screen in color for time
  1374. X*/
  1375. Xbigmessage(s, color, time)
  1376. Xchar    *s;
  1377. Xint        color, time;
  1378. X{
  1379. X    bigmessagecolor = color;
  1380. X    bigmessagetime = time;
  1381. X    strncpy(bigmessagestring, s, MAXBIGMESSAGELENGTH);
  1382. X    bigmessagelength = strlen(bigmessagestring);
  1383. X    bigmessagewidth = XTextWidth(bigfontinfo, bigmessagestring,
  1384. X                                    bigmessagelength);
  1385. X    bigmessagey = WINDOWHEIGHT / 5;
  1386. X    bigmessagex = WINDOWWIDTH / 2 - bigmessagewidth / 2;
  1387. X}
  1388. X
  1389. X/*    dumb_message puts up a message to the player when something happens.
  1390. X    Called dumb because the procedure is ugly and the messages are mostly
  1391. X    snide remarks.
  1392. X*/
  1393. Xdumb_message(kind)
  1394. Xint    kind;
  1395. X{
  1396. X    register int    opinion, num;
  1397. X
  1398. X    if(gameover) return;
  1399. X    if((messagetime != 0) && (kind != MKILL) && (kind != MSUICIDE) &&
  1400. X        (kind != MEXIT)) return;
  1401. X    if(exploded > -1) return;
  1402. X    if((dumbmessagechance[kind] > 1) &&
  1403. X        (random() % (dumbmessagechance[kind]) == 0)) return;
  1404. X    opinion = -1;
  1405. X    switch(kind) {
  1406. X        case MKILL:
  1407. X        case MCLOSE:
  1408. X        case MSUICIDE:
  1409. X        case MQUIT:
  1410. X            opinion = 0;
  1411. X            break;
  1412. X        case MFUEL:
  1413. X            if(playerfuel > FUELCAPACITY - FUELINCREMENT) opinion = 0;
  1414. X            if(playerfuel < 300) opinion = 1;
  1415. X            break;
  1416. X        case MKEY:
  1417. X            if(playerfuel < 400) {
  1418. X                opinion = 2;
  1419. X                break;
  1420. X            }
  1421. X            if(bonus < initbonus / 3) {
  1422. X                opinion = 0;
  1423. X                break;
  1424. X            }
  1425. X            if(bonus > (initbonus * 3) / 4) {
  1426. X                opinion = 1;
  1427. X                break;
  1428. X            }
  1429. X            opinion = 3;
  1430. X            break;
  1431. X        case MEXIT:
  1432. X            if(bonus == 0) {
  1433. X                opinion = 0;
  1434. X                break;
  1435. X            }
  1436. X            if(bonus >  (2 * initbonus) / 3) {
  1437. X                opinion = 1;
  1438. X                break;
  1439. X            }
  1440. X            if(bonus < initbonus / 3) {
  1441. X                opinion = 2;
  1442. X                break;
  1443. X            }
  1444. X            opinion = 3;
  1445. X            break;
  1446. X        default:
  1447. X            break;
  1448. X    }
  1449. X    if(opinion == -1) return;
  1450. X    num = random() % numdumbmessages[kind][opinion];
  1451. X    message(dumbmessage[kind][opinion][num], random() % (NCOLORS - 1) + 1,
  1452. X    dumbmessagetime[kind]);
  1453. X}
  1454. END_OF_FILE
  1455. if test 2687 -ne `wc -c <'message.c'`; then
  1456.     echo shar: \"'message.c'\" unpacked with wrong size!
  1457. fi
  1458. # end of 'message.c'
  1459. fi
  1460. if test -f 'scores.c' -a "${1}" != "-c" ; then 
  1461.   echo shar: Will not clobber existing file \"'scores.c'\"
  1462. else
  1463. echo shar: Extracting \"'scores.c'\" \(9523 characters\)
  1464. sed "s/^X//" >'scores.c' <<'END_OF_FILE'
  1465. X/*    scores.c : routines that implement and maintain the high scores.
  1466. X*/
  1467. X
  1468. X#include "copyright.h"
  1469. X#include "defs.h"
  1470. X
  1471. X/*    If the scorefile is not externally defined at compile time, the
  1472. X    default scorefile is jetpack.scores . However, this means scorefiles
  1473. X    will be created in the user's cwd whenever he/she runs the game.
  1474. X*/
  1475. X#ifndef SCOREPATH
  1476. X#define SCOREPATH "jetpack.scores"
  1477. X#endif
  1478. X
  1479. XPixmap    scorepixmap;
  1480. X
  1481. X#define    MAXHIGHLENGTH    46
  1482. X#define MAXNAMELENGTH    21
  1483. X
  1484. Xint        numhighs;
  1485. Xint        highscore[MAXHIGHSCORES];
  1486. Xint        highlevel[MAXHIGHSCORES];
  1487. Xchar    highstring[MAXHIGHSCORES][MAXHIGHLENGTH];
  1488. Xchar    dtext[MAXNAMELENGTH], dialogtime[10];
  1489. Xint        scorefd;
  1490. XFILE    *scorefile;
  1491. XWindow    dialogwindow,dialogstringwindow,dialogbuttonwindow;
  1492. Xint        dialogwidth, dialogheight;
  1493. X
  1494. X/*    open_scores tries to open the score file, and if it can't it tries to
  1495. X    create one.
  1496. X*/
  1497. Xopen_scores()
  1498. X{
  1499. X    numhighs = 0;
  1500. X    scorefd = open(SCOREPATH, O_RDWR);
  1501. X    if(scorefd == -1) {
  1502. X        scorefd = open(SCOREPATH, O_RDWR | O_CREAT, 0444);
  1503. X        if(scorefd == -1) {
  1504. X            scorefd = open("jetpack.scores", O_RDWR);
  1505. X            if(scorefd == -1) {
  1506. X                scorefd = open("jetpack.scores", O_RDWR | O_CREAT, 0444);
  1507. X                if(scorefd == -1) {
  1508. X                    fprintf(stderr,"Jetpack : Couldn't open scorefile.\n");
  1509. X                    exit(1);
  1510. X                } else {
  1511. X                    flock(scorefd,LOCK_EX);
  1512. X                    scorefile = fdopen(scorefd,"r+");
  1513. X                    write_scores();
  1514. X                    flock(scorefd,LOCK_UN);
  1515. X                    return;
  1516. X                }
  1517. X            } else {
  1518. X                flock(scorefd,LOCK_EX);
  1519. X                scorefile = fdopen(scorefd,"r+");
  1520. X                read_scores();
  1521. X                flock(scorefd,LOCK_UN);
  1522. X                return;
  1523. X            }
  1524. X        } else {
  1525. X            flock(scorefd,LOCK_EX);
  1526. X            scorefile = fdopen(scorefd,"r+");
  1527. X            write_scores();
  1528. X            flock(scorefd,LOCK_UN);
  1529. X            return;
  1530. X        }
  1531. X    } else {
  1532. X        flock(scorefd,LOCK_EX);
  1533. X        scorefile = fdopen(scorefd,"r+");
  1534. X        read_scores();
  1535. X        flock(scorefd,LOCK_UN);
  1536. X        return;
  1537. X    }
  1538. X}
  1539. X
  1540. X/*    close_scores closes the score file.
  1541. X*/
  1542. Xclose_scores()
  1543. X{
  1544. X    fclose(scorefile);
  1545. X    close(scorefd);
  1546. X}
  1547. X
  1548. X/*    read_scores reads the high score data from the score file. 
  1549. X*/
  1550. Xread_scores()
  1551. X{
  1552. X    register int    i;
  1553. X
  1554. X    rewind(scorefile);
  1555. X    fflush(scorefile);
  1556. X    fread(&numhighs, sizeof(int), 1, scorefile);
  1557. X    for(i=0; i<numhighs; i++) {
  1558. X        fread(highstring[i], sizeof(char), MAXHIGHLENGTH - 2, scorefile);
  1559. X        fread(highlevel+i, sizeof(int), 1, scorefile);
  1560. X        fread(highscore+i, sizeof(int), 1, scorefile);
  1561. X        highstring[i][MAXHIGHLENGTH-1] = '\0';
  1562. X    }
  1563. X    fflush(scorefile);
  1564. X}
  1565. X
  1566. X/*    write_scores writes the high score data into the score file.
  1567. X*/
  1568. Xwrite_scores()
  1569. X{
  1570. X    register int    i;
  1571. X
  1572. X    rewind(scorefile);
  1573. X    fflush(scorefile);
  1574. X    fwrite(&numhighs, sizeof(int), 1, scorefile);
  1575. X    for(i=0; i<numhighs; i++) {
  1576. X        fwrite(highstring[i], sizeof(char), MAXHIGHLENGTH - 2, scorefile);
  1577. X        fwrite(highlevel+i, sizeof(int), 1, scorefile);
  1578. X        fwrite(highscore+i, sizeof(int), 1, scorefile);
  1579. X    }
  1580. X    fflush(scorefile);
  1581. X}
  1582. X
  1583. X/*    read_new_scores re-reads in the score file info just in case it has
  1584. X    been changed.
  1585. X*/
  1586. Xread_new_scores()
  1587. X{
  1588. X    flock(scorefd,LOCK_EX);
  1589. X    read_scores();
  1590. X    flock(scorefd,LOCK_UN);
  1591. X    XFillRectangle(display, scorepixmap, ctable[CBLACK].smallgc,
  1592. X                    0, 0, SCOREWIDTH, SCOREHEIGHT);
  1593. X    draw_scores(-1);
  1594. X}
  1595. X
  1596. X/*    check_score checks the score global variable against the high score
  1597. X    table, and if it makes it, gets the player's name and saves the new
  1598. X    high scores in the file.
  1599. X*/
  1600. Xcheck_score()
  1601. X{
  1602. X    register int    i, spot;
  1603. X    char            buf[MAXNAMELENGTH];
  1604. X
  1605. X    spot = 0;
  1606. X    flock(scorefd,LOCK_EX);
  1607. X    read_scores();
  1608. X    flock(scorefd,LOCK_UN);
  1609. X    for(i=0; i<numhighs; i++) {
  1610. X        if(score > highscore[i]) {
  1611. X            get_high_name(buf);
  1612. X            spot = 1;
  1613. X            break;
  1614. X        }
  1615. X    }
  1616. X    if(spot == 0) {
  1617. X        if(numhighs < MAXHIGHSCORES) get_high_name(buf);
  1618. X        else return;
  1619. X    }
  1620. X    flock(scorefd,LOCK_EX);
  1621. X    read_scores();
  1622. X    for(i=0; i<numhighs; i++) {
  1623. X        if(score > highscore[i]) {
  1624. X            shift_highs(i);
  1625. X            highscore[i] = score;
  1626. X            highlevel[i] = level;
  1627. X            sprintf(highstring[i], "%-20s     %-3d       %-9d", buf,
  1628. X                    level, score);
  1629. X            write_scores();
  1630. X            flock(scorefd,LOCK_UN);
  1631. X            return;
  1632. X        }
  1633. X    }
  1634. X    /*    Didn't beat anyone else, but if the scoreboard isn't full, let it
  1635. X        in.
  1636. X    */
  1637. X    if(numhighs < MAXHIGHSCORES) {
  1638. X        highscore[numhighs] = score;
  1639. X        highlevel[numhighs] = level;
  1640. X        sprintf(highstring[numhighs], "%-20s     %-3d       %-9d", buf,
  1641. X                level, score);
  1642. X        numhighs++;
  1643. X        write_scores();
  1644. X        flock(scorefd,LOCK_UN);
  1645. X        return;
  1646. X    }
  1647. X    /* Sorry, you got bumped off while you entered your name */
  1648. X}
  1649. X
  1650. X#define    HIGHTITLE    "Mad Mark's Top Fliers:"
  1651. X#define    HIGHTOP        "Name:                    Level:    Score:   "
  1652. X
  1653. X/*    draw_scores draws the high score table on the scorepixmap. which
  1654. X    allows only 5 of the names to be drawn at a time, which keeps things
  1655. X    from lagging.
  1656. X*/
  1657. Xdraw_scores(which)
  1658. Xint    which;
  1659. X{
  1660. X    register int    i, j, length, width, y, first, last;
  1661. X
  1662. X    length = strlen(HIGHTITLE);
  1663. X    width = XTextWidth(bigfontinfo,HIGHTITLE,length);
  1664. X    XDrawImageString(display, scorepixmap,
  1665. X                        ctable[random()%(NCOLORS-1)+1].biggc,
  1666. X                        SCOREWIDTH / 2 - width / 2, 3 + bigfontinfo->ascent,
  1667. X                        HIGHTITLE, length);
  1668. X    y = bigfontinfo->ascent + bigfontinfo->descent + 3;
  1669. X    length = strlen(HIGHTOP);
  1670. X    width = XTextWidth(fontinfo,HIGHTOP,length);
  1671. X    XDrawString(display, scorepixmap, ctable[CWHITE].smallgc,
  1672. X                SCOREWIDTH / 2 - width / 2, y + 3 + fontinfo->ascent,
  1673. X                HIGHTOP, length);
  1674. X    y += fontinfo->ascent * 2 + fontinfo->descent + 4;
  1675. X    if(which == -1) {
  1676. X        first = 0;
  1677. X        last = MAXHIGHSCORES;
  1678. X    } else {
  1679. X        first = which * 5;
  1680. X        last = which * 5 + 5;
  1681. X    }
  1682. X    i = y + first * (fontinfo->ascent + fontinfo->descent);
  1683. X    for(j=first; ((j<numhighs) && (j<last)); j++) {
  1684. X        length = strlen(highstring[j]);
  1685. X        width = XTextWidth(fontinfo,highstring[j],length);
  1686. X        XDrawImageString(display, scorepixmap,
  1687. X                            ctable[random()%(NCOLORS-1)+1].smallgc,
  1688. X                            SCOREWIDTH / 2 - width / 2, i, highstring[j],
  1689. X                            length);
  1690. X        i += fontinfo->ascent + fontinfo->descent;
  1691. X    }
  1692. X}
  1693. X
  1694. X/*    shift_highs pushes all the scores from place i down one spot.
  1695. X*/
  1696. Xshift_highs(i)
  1697. Xint    i;
  1698. X{
  1699. X    int    j;
  1700. X
  1701. X    for(j=MAXHIGHSCORES-1; j>i; j--) {
  1702. X        highscore[j] = highscore[j-1];
  1703. X        highlevel[j] = highlevel[j-1];
  1704. X        strncpy(highstring[j],highstring[j-1],44);
  1705. X    }
  1706. X    if(numhighs < MAXHIGHSCORES) numhighs++;
  1707. X}
  1708. X
  1709. X/*    get_high_name brings up a dialog that prompts the player to enter
  1710. X    his/her name. The name is stored in buf.
  1711. X*/
  1712. Xget_high_name(buf)
  1713. Xchar    *buf;
  1714. X{
  1715. X    XEvent                    event;
  1716. X    register int            j, finished, timer;
  1717. X    /*
  1718. X    register unsigned long    utimer, usecond;
  1719. X    */
  1720. X
  1721. X    XMapRaised(display, dialogwindow);
  1722. X    XMapRaised(display, dialogstringwindow);
  1723. X    XMapRaised(display, dialogbuttonwindow);
  1724. X    XFlush(display);
  1725. X
  1726. X    dtext[0] = '\0';
  1727. X    finished = 0;
  1728. X    while(!finished) {
  1729. X            XNextEvent(display, &event);
  1730. X            switch(event.type) {
  1731. X                case ConfigureNotify:
  1732. X                case Expose:
  1733. X                case MapNotify:
  1734. X                    display_dialog(event.xany.window);
  1735. X                    break;
  1736. X                case ButtonPress:
  1737. X                    if(event.xbutton.window == dialogbuttonwindow) {
  1738. X                        XFillRectangle(display, dialogbuttonwindow,
  1739. X                                        ctable[CBLUE].smallgc, 0, 0,
  1740. X                                        50, 30);
  1741. X                        display_dialog(dialogbuttonwindow);
  1742. X                        finished = 1;
  1743. X                    }
  1744. X                    break;
  1745. X                case KeyPress:
  1746. X                    finished = dialog_key(&event);
  1747. X                    break;
  1748. X            }
  1749. X    }
  1750. X
  1751. X    /*    check to see if there are non-blank characters in the name. If
  1752. X        there aren't any, the user is shy, so return "Anonymous"
  1753. X    */
  1754. X    for(j=0, finished=0; dtext[j] != '\0'; j++) {
  1755. X        if(dtext[j] != ' ') finished = 1;
  1756. X    }
  1757. X    if(!finished) strncpy(dtext,"Anonymous",20);
  1758. X
  1759. X    strncpy(buf, dtext, 20);
  1760. X
  1761. X    /*    unmap the dialog
  1762. X    */
  1763. X    XUnmapWindow(display, dialogstringwindow);
  1764. X    XUnmapWindow(display, dialogbuttonwindow);
  1765. X    XUnmapWindow(display, dialogwindow);
  1766. X    XFlush(display);
  1767. X}
  1768. X
  1769. X/*    dialog_key processes keypresses from the dialog
  1770. X*/
  1771. Xint    dialog_key(event)
  1772. XXKeyEvent    *event;
  1773. X{
  1774. X    int                length, l;
  1775. X    char            buf[MAXNAMELENGTH];
  1776. X    KeySym            keysym;
  1777. X    XComposeStatus    composestatus;
  1778. X
  1779. X    length = XLookupString(event, buf, MAXNAMELENGTH, &keysym,
  1780. X                            &composestatus);
  1781. X    buf[1] = '\0';
  1782. X    l = strlen(dtext);
  1783. X    /*    check for printable character
  1784. X    */
  1785. X    if((keysym >= ' ') && (keysym <= '~') && (length > 0)) {
  1786. X        if((l + strlen(buf)) < MAXNAMELENGTH) {
  1787. X            strcat(dtext, buf);
  1788. X            display_dialog(dialogstringwindow);
  1789. X        }
  1790. X    } else {
  1791. X        switch(keysym) {
  1792. X            /*    delete key
  1793. X            */
  1794. X            case XK_BackSpace:
  1795. X            case XK_Delete:
  1796. X                if(l >= 1) {
  1797. X                    XClearWindow(display, dialogstringwindow);
  1798. X                    l--;
  1799. X                    dtext[l] = '\0';
  1800. X                    display_dialog(dialogstringwindow);
  1801. X                    XFlush(display);
  1802. X                }
  1803. X                break;
  1804. X
  1805. X            /* return is as good as hitting ok
  1806. X            */
  1807. X            case '\n':
  1808. X            case XK_Return:
  1809. X            case XK_KP_Enter:
  1810. X                XFillRectangle(display, dialogbuttonwindow,
  1811. X                                ctable[CBLUE].smallgc, 0, 0, 50, 30);
  1812. X                display_dialog(dialogbuttonwindow);
  1813. X                return(1);
  1814. X            default:
  1815. X                break;
  1816. X        }
  1817. X    }
  1818. X    return(0);
  1819. X}
  1820. X
  1821. X/*    display_dialog draws the part of the dialog specified by w. Also
  1822. X    refreshes anything that needs to be.
  1823. X*/
  1824. Xdisplay_dialog(w)
  1825. XWindow    w;
  1826. X{
  1827. X    if(w == dialogwindow) {
  1828. X        XDrawString(display, dialogwindow, ctable[CGREEN].biggc,
  1829. X                    10, 5 + bigfontinfo->ascent, "You made a high score!",
  1830. X                    strlen("You made a high score!"));
  1831. X        XDrawString(display, dialogwindow, ctable[CBLUE].biggc,
  1832. X                    10, 10 + bigfontinfo->descent + 2 *
  1833. X                    bigfontinfo->ascent, "Enter your name:",
  1834. X                    strlen("Enter your name:"));
  1835. X    }
  1836. X    if(w == dialogstringwindow)
  1837. X        XDrawString(display, dialogstringwindow,
  1838. X                    ctable[CRED].biggc, 10,
  1839. X                    5 + bigfontinfo->ascent, dtext, strlen(dtext));
  1840. X    if(w == dialogbuttonwindow)
  1841. X        XDrawString(display, dialogbuttonwindow,
  1842. X                    ctable[CWHITE].biggc, 10,
  1843. X                    5 + bigfontinfo->ascent, "OK", strlen("OK"));
  1844. X    if(w == gamewindow) 
  1845. X
  1846. X#ifdef    BLIT
  1847. X        XCopyArea(display, drawpixmap, gamewindow, ctable[CBLACK].smallgc,
  1848. X                    0, 0, WINDOWWIDTH, WINDOWHEIGHT, 0, 0);
  1849. X#else
  1850. X        refresh();
  1851. X#endif
  1852. X
  1853. X    if(w == infowindow) refresh_info();
  1854. X    XFlush(display);
  1855. X}
  1856. END_OF_FILE
  1857. if test 9523 -ne `wc -c <'scores.c'`; then
  1858.     echo shar: \"'scores.c'\" unpacked with wrong size!
  1859. fi
  1860. # end of 'scores.c'
  1861. fi
  1862. echo shar: End of archive 2 \(of 4\).
  1863. cp /dev/null ark2isdone
  1864. MISSING=""
  1865. for I in 1 2 3 4 ; do
  1866.     if test ! -f ark${I}isdone ; then
  1867.     MISSING="${MISSING} ${I}"
  1868.     fi
  1869. done
  1870. if test "${MISSING}" = "" ; then
  1871.     echo You have unpacked all 4 archives.
  1872.     rm -f ark[1-9]isdone
  1873. else
  1874.     echo You still need to unpack the following archives:
  1875.     echo "        " ${MISSING}
  1876. fi
  1877. ##  End of shell archive.
  1878. exit 0
  1879.