home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume18 / xboing / part12 < prev    next >
Encoding:
Internet Message Format  |  1993-09-13  |  58.9 KB

  1. Path: uunet!news.tek.com!news.cna.tek.com!not-for-mail
  2. From: billr@saab.cna.tek.com (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v18i071:  xboing - blockout variant with color and sound for X, Part12/30
  5. Date: 30 Aug 1993 10:27:59 -0700
  6. Organization: Tektronix, Inc., Redmond, OR
  7. Lines: 2239
  8. Approved: billr@saab.CNA.TEK.COM
  9. Message-ID: <25tdav$hvg@saab.cna.tek.com>
  10. NNTP-Posting-Host: saab.cna.tek.com
  11. Xref: uunet comp.sources.games:1871
  12.  
  13. Submitted-by: jck@kimba.catt.citri.edu.au (Justin Kibell)
  14. Posting-number: Volume 18, Issue 71
  15. Archive-name: xboing/part12
  16. Environment: X11, Xlib, XPM
  17.  
  18.  
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of archive 12 (of 30)."
  27. # Contents:  bitmaps/titleI.xpm.uu init.c main.c
  28. # Wrapped by billr@saab on Mon Aug 30 09:14:25 1993
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'bitmaps/titleI.xpm.uu' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'bitmaps/titleI.xpm.uu'\"
  32. else
  33. echo shar: Extracting \"'bitmaps/titleI.xpm.uu'\" \(4959 characters\)
  34. sed "s/^X//" >'bitmaps/titleI.xpm.uu' <<'END_OF_FILE'
  35. Xbegin 644 titleI.xpm
  36. XM+RH@6%!-("HO"G-T871I8R!C:&%R("H@=&ET;&5)7WAP;5M=(#T@>PHO*B!W
  37. XM:61T:"!H96EG:'0@;F-O;&]R<R!C:&%R<U]P97)?<&EX96P@*B\*(C0Q(#<T
  38. XM(#@@,2(L"B\J(&-O;&]R<R`J+PHB(`ES($YO;F4)8R!.;VYE(BP*(BX)8R`C
  39. XM.#`R1C`P(BP*(E@)8R`C03`V,#`P(BP*(F\)8R`C.3`S1C$P(BP*(D\)8R`C
  40. XM1C!$,#0P(BP*(BL)8R`C1#`Y13(P(BP*(D`)8R`C1C!#,#,P(BP*(B,)8R`C
  41. XM0S`W1C$P(BP*+RH@<&EX96QS("HO"B(@("`@("`@("`@("`@("`@("`@("`@
  42. XM("`@("`@("`@("`@("`@("`@("(L"B(@("`@("`@("`@("`@("`@("`@("`@
  43. XM("`@("`@("`@("`@("`@("`@("(L"B(N6&]O;V]O;V]O;V]O;V]O;V]O;V]O
  44. XM;V]O;V]O;V]O;V]O;V]O;V]O("(L"B)83T\K*RLK*RLK*RLK*RLK*RLK*RLK
  45. XM*RLK*RLK*RLK*RLK*RLK*RLK6"(L"B)83T]`*RLK*RLK*RLK*RLK*RLK*RLK
  46. XM*RLK*RLK*RLK*RLK*RLK*RLC("(L"B)83T]/0"LK*RLK*RLK*RLK*RLK*RLK
  47. XM*RLK*RLK*RLK*RLK*RLK*R-8+B(L"B)83T]/3RLK*RLK*RLK*RLK*RLK*RLK
  48. XM*RLK*RLK*RLK*RLK*RLK(UA8("(L"B)83T]/3T]`*RLK*RLK*RLK*RLK*RLK
  49. XM*RLK*RLK*RLK*RLK*RLC6%A8+B(L"B)83T]/3T\K6%A86%A86%A86%@K*T!`
  50. XM*R-86%A86%A86%A8(R-86%A8("(L"B)83T]/3T\C+BXN+BXN+BXN+BXC3T]/
  51. XM*UAO+F\N+BXN+BXN;UA86%A86"(L"B)83T]/*R-O;RXN+BYO(R,C(R,K3T]/
  52. XM(V]8;V\N;RXN+BXN+BY86%A8("(L"B)83T]/(RXN+BXN+BXC3T]/3T]/0$]/
  53. XM(V]O6%A8+F\N+BXN;RXN6%A8+B(L"B)83RLC;V\N+F\C(R,K3T]/3T]`0$]/
  54. XM(V]O6"Y8+BXN+BYO+BYO+EA8+B(L"B)83R,N;RXN+B-/3T]/3T]`0$!`0$]/
  55. XM(V]O;V]O6%A86%@N+BXN+BY8("(L"B(@(R`@("`@+B`C*T]/3T!`0$!`0$]/
  56. XM(V]O;V]O;UA86&\@("X@+B`N("(L"B(@("`@("`@("`@;T]`0$!`0$!`0$]/
  57. XM(V]O;V]O;V]O6"X@("`@("`@("(L"B(@("`@("`@("`@6$]`0$!/0$!`0$]/
  58. XM(V]O;V]O;V]O6"X@("`@("`@("(L"B(@("`@("`@("`@6$!`0$!`0$!/*T]/
  59. XM(V]O;V]86&]O;R`@("`@("`@("(L"B(@("`@("`@("`@6$!/3T!`0$!/0$]/
  60. XM(V]O;V]8;V]O6"X@("`@("`@("(L"B(@("`@("`@("`@6$!`3T]`0"M/3T]/
  61. XM(V]O;V]86&]86"X@("`@("`@("(L"B(@("`@("`@("`@6$]`3T!/*T]`0$]/
  62. XM*V]O;V]8;UAO6"X@("`@("`@("(L"B(@("`@("`@("`@6$]/0$!`0$!`0$!/
  63. XM*UAO;V]O6%A86"X@("`@("`@("(L"B(@("`@("`@("`@6$]`3T]/0$!/0$]/
  64. XM*UA8;V]O;UA86"X@("`@("`@("(L"B(@("`@("`@("`@6$!`3T]/3T]/3T]/
  65. XM*UA86%AO6%A86"X@("`@("`@("(L"B(@("`@("`@("`@6$]/3T]/3T]/3T]/
  66. XM*UA86%AO6%A86"X@("`@("`@("(L"B(@("`@("`@("`@6$]/3T]/3T]/3T]/
  67. XM*UA86%A86%A86"X@("`@("`@("(L"B(@("`@("`@("`@6$]/3T]/3T]/3T]/
  68. XM*UA86%A86%A86"X@("`@("`@("(L"B(@("`@("`@("`@6$]/3T]/3T]/3T]/
  69. XM*UA86%A86%A86"X@("`@("`@("(L"B(@("`@("`@("`@6$]`*T!/3T]`*T!/
  70. XM*UA8(UA86"-86"X@("`@("`@("(L"B(@("`@("`@("`@6$\K(RM/3T\K(RM/
  71. XM*UA8(UA8(R-86"X@("`@("`@("(L"B(@("`@("`@("`@6$]`*T]/0"LK*T]/
  72. XM*U@C(R-86%@C6"X@("`@("`@("(L"B(@("`@("`@("`@6$]/3T]/*R,K3T]/
  73. XM*UA8(UA86%A8(RX@("`@("`@("(L"B(@("`@("`@("`@;RLK*RLK*RM/3T]/
  74. XM*U@C6"-8(U@C(RX@("`@("`@("(L"B(@("`@("`@("`@;R,C(R,C*T]/3T]/
  75. XM*R,C6%@C(R,C(RX@("`@("`@("(L"B(@("`@("`@("`@;R,C(R,C*RM/3T]/
  76. XM*R,C6"-8(U@C(RX@("`@("`@("(L"B(@("`@("`@("`@+B,C(R,C(R,K3T]/
  77. XM*R,C(UA86%A8(RX@("`@("`@("(L"B(@("`@("`@("`@;RLK(R,C(R,K*T!/
  78. XM*R,C(R-8(U@C(RX@("`@("`@("(L"B(@("`@("`@("`@6$\K(R,C(R,C(RM/
  79. XM*R,C(R,C(R,C(RX@("`@("`@("(L"B(@("`@("`@("`@;T`K(R,C(R,C(RM/
  80. XM*R,C(R,C*RLK(RX@("`@("`@("(L"B(@("`@("`@("`@+B,C(R,C(R,C(RM/
  81. XM0",C(R,C*T\K(RX@("`@("`@("(L"B(@("`@("`@("`@+B,C6",C6%@C(RM/
  82. XM*R,C(R,C*RLK*U@@("`@("`@("(L"B(@("`@("`@("`@+B-86%@C(UA8(RM/
  83. XM*R,C(R,C(R,K3U@@("`@("`@("(L"B(@("`@("`@("`@+BLC6",C6%A8(RM/
  84. XM3RLK(R,K*R,K3U@@("`@("`@("(L"B(@("`@("`@("`@+B,C(R,C6%A86"M/
  85. XM3T\K(RM/*R,K3U@@("`@("`@("(L"B(@("`@("`@("`@+B,C6%@C6%A8(RM/
  86. XM3T]`*T]/0"M/3U@@("`@("`@("(L"B(@("`@("`@("`@+B-86%A86%@C(RM/
  87. XM3T]/3T]/3T]/3U@@("`@("`@("(L"B(@("`@("`@("`@+B-86%A86%A8(RM/
  88. XM3T]/3T`K0$]/3U@@("`@("`@("(L"B(@("`@("`@("`@+EA86%A86%A86"M/
  89. XM3T]/3RLC*T]/3U@@("`@("`@("(L"B(@("`@("`@("`@+EA86%A86%A86"M/
  90. XM3T]/3T`K3T]/3U@@("`@("`@("(L"B(@("`@("`@("`@+EA86%A86%A86"M/
  91. XM3T]/3T]/3T]/3U@@("`@("`@("(L"B(@("`@("`@("`@(&]8+EA86%A86"M/
  92. XM3T]/3T]/3T!`3U@@("`@("`@("(L"B(@("`@("`@("`@+F]O;RY86%A86"M/
  93. XM3T]/3T]/0$!`0%@@("`@("`@("(L"B(@("`@("`@("`@+F]8+EA86%A8;RM/
  94. XM3T]/0$]/3T!`3U@@("`@("`@("(L"B(@("`@("`@("`@+EA86%A86%AO;R-/
  95. XM3T]/0$]/0$!`3U@@("`@("`@("(L"B(@("`@("`@("`@+F]8+EAO6%AO6"-/
  96. XM3T]`0$!/0$]`3U@@("`@("`@("(L"B(@("`@("`@("`@(&]O;V]O;V]O6"M/
  97. XM3T]/0$!`3T]`0%@@("`@("`@("(L"B(@("`@("`@("`@+F]O;V]O;V]O6"-/
  98. XM3T!/0$!`0$]`0%@@("`@("`@("(L"B(@("`@("`@("`@(&]O;V]O;V]O;R-/
  99. XM3T!`3T]`0$!`0%@@("`@("`@("(L"B(@("`@("`@("`@+F]O;V]O;V]O;R-/
  100. XM3T!`3T!`0$!`3U@@("`@("`@("(L"B(@("`@("`@("`@+F]O;V]O;V]O;R-/
  101. XM0$!`0$!`0$!`3U@@("`@("`@("(L"B(N6&]O;V]O;V]O6",C(UAO;V]O;R-/
  102. XM3T!`0$!`0$]`3RMO;V]O;V]O("(L"B)83T\K*RLK*RLK3T]/3R-O;V]O;R-/
  103. XM3T!`0$!`3T]/3RLK*RLK*RLK6"(L"B)83T]`*RLK*RLK*T`K3RLC(R-8;R-/
  104. XM0$!`3T!/0$`K0"LK*RLK*RLC("(L"B)83T]/0"LK*RLK*RLK*RM/3T\C;R-/
  105. XM3T!/3T]`0"LK*RLK*RLK*R-8+B(L"B)83T]/3RLK*RLK*RLK*RM/*T\K(T!/
  106. XM0"M`0"M`*RLK*RLK*RLC(R-8("(L"B)83T]/3T]`*RLK*RLK*RLK*RM`3T]/
  107. XM0"LK*RLK*RLK*RLK*RLC6%A8+B(L"B)83T]/3T\K6%A86%A86%A86%@C(R,C
  108. XM6%A86"-86%A86%A86",C6%A8("(L"B)83T]/3T\C+BXN+BXN+BXN+BXN+BXN
  109. XM+BYO+BXN+BXN+BXN;UA86%A8+B(L"B)83T]/*R-O;RXN+BXN+BXN+BXN+BXN
  110. XM+BXN+BXN+BXN+BXN;V\N6%A8+B(L"B)83T]/(RXN+BXN+BXN+BXN+BXN+BXN
  111. XM+BXN+BXN+BXN+BXN+BYO6%A8("(L"B)83RLC;V\N+BXN+BXN+BXN+BXN+BXN
  112. XM+BXN+BXN+BXN+BXN+BYO;V]8+B(L"B)83R,N;RXN+BXN+BXN+BXN+BXN+BXN
  113. XM+BXN+BXN+BXN+BXN+BXN+F]8+B(L"B(@(R`@("`@("X@("X@+B`N("X@+B`N
  114. XM("X@+B`N("X@+B`N("X@+B`N("(L"B(@("`@("`@("`@("`@("`@("`@("`@
  115. X7("`@("`@("`@("`@("`@("`@(")].PH@
  116. X`
  117. Xend
  118. END_OF_FILE
  119. if test 4959 -ne `wc -c <'bitmaps/titleI.xpm.uu'`; then
  120.     echo shar: \"'bitmaps/titleI.xpm.uu'\" unpacked with wrong size!
  121. fi
  122. # end of 'bitmaps/titleI.xpm.uu'
  123. fi
  124. if test -f 'init.c' -a "${1}" != "-c" ; then 
  125.   echo shar: Will not clobber existing file \"'init.c'\"
  126. else
  127. echo shar: Extracting \"'init.c'\" \(25223 characters\)
  128. sed "s/^X//" >'init.c' <<'END_OF_FILE'
  129. X#include "include/copyright.h"
  130. X
  131. X/*
  132. X *  Include file dependencies:
  133. X */
  134. X
  135. X#include <stdio.h>
  136. X#include <stdlib.h>
  137. X#include <stddef.h>
  138. X#include <sys/time.h>
  139. X#include <X11/Xlib.h>
  140. X#include <X11/Xutil.h>
  141. X#include <X11/Xos.h>
  142. X
  143. X#include "include/score.h"
  144. X#include "include/presents.h"
  145. X#include "include/special.h"
  146. X#include "include/main.h"
  147. X#include "include/version.h"
  148. X#include "include/error.h"
  149. X#include "include/mess.h"
  150. X#include "include/ball.h"
  151. X#include "include/gun.h"
  152. X#include "include/sfx.h"
  153. X#include "include/blocks.h"
  154. X#include "include/level.h"
  155. X#include "include/bonus.h"
  156. X#include "include/stage.h"
  157. X#include "include/paddle.h"
  158. X#include "include/intro.h"
  159. X#include "include/inst.h"
  160. X#include "include/highscore.h"
  161. X#include "include/keys.h"
  162. X#include "include/audio.h"
  163. X#include "include/misc.h"
  164. X
  165. X#include "include/init.h"
  166. X
  167. X/*
  168. X *  Internal macro definitions:
  169. X */
  170. X
  171. X#define TITLE_FONT     "-adobe-helvetica-bold-r-*-*-24-*-*-*-*-*-*-*"
  172. X#define COPY_FONT   "-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*"
  173. X#define TEXT_FONT      "-adobe-helvetica-medium-r-*-*-18-*-*-*-*-*-*-*"
  174. X
  175. X/*
  176. X *  Internal type declarations:
  177. X */
  178. X
  179. X#if NeedFunctionPrototypes
  180. Xstatic void ParseCommandLine(char **argv, int argc);
  181. Xstatic void InitialiseSettings(void);
  182. Xstatic int compareArgument(char *arg1, char *arg2, int minMatch);
  183. Xstatic void HandleDisplayErrors(char *displayName);
  184. Xstatic void PrintVersion(void);
  185. Xstatic void PrintUsage(void);
  186. Xstatic void PrintHelp(void);
  187. Xstatic void InitialiseGraphics(Display *display, Window window);
  188. Xstatic void InitialiseColourNames(Display *display, Colormap colormap);
  189. Xstatic void InitialiseFonts(Display *display);
  190. Xstatic void ReleaseGraphics(Display *display);
  191. Xstatic void ReleaseFonts(Display *display);
  192. Xstatic void ExitProgramNow(int value);
  193. Xstatic void TurnOnSynchronise(Display *display);
  194. X#else
  195. Xstatic void ExitProgramNow();
  196. Xstatic void ParseCommandLine();
  197. Xstatic void InitialiseSettings();
  198. Xstatic int compareArgument();
  199. Xstatic void HandleDisplayErrors();
  200. Xstatic void PrintVersion();
  201. Xstatic void PrintUsage();
  202. Xstatic void PrintHelp();
  203. Xstatic void InitialiseGraphics();
  204. Xstatic void InitialiseColourNames();
  205. Xstatic void InitialiseFonts();
  206. Xstatic void ReleaseGraphics();
  207. Xstatic void ReleaseFonts();
  208. Xstatic void TurnOnSynchronise();
  209. X#endif
  210. X
  211. X/*
  212. X *  Internal variable declarations:
  213. X */
  214. X
  215. Xint red, tann, yellow, green, white, black, blue, purple, reds[14], greens[14];
  216. XGC gc, gcxor, gcand, gcor, gcsfx;
  217. XXFontStruct *titleFont, *copyFont, *textFont;
  218. XColormap     colormap;
  219. Xstatic XVisualInfo    visual_info;
  220. Xstatic unsigned long event_mask;
  221. Xstatic char *displayName = (char *) NULL;
  222. Xstatic int    syncOn;
  223. Xstatic int    grabPointer;
  224. Xstatic int    useDefaultColourmap;
  225. Xint    noSound, debug;
  226. X
  227. X#if NeedFunctionPrototypes
  228. Xstatic void InitialiseGraphics(Display *display, Window window)
  229. X#else
  230. Xstatic void InitialiseGraphics(display, window)
  231. X    Display *display;
  232. X    Window window;
  233. X#endif
  234. X{
  235. X    XGCValues    gcv;
  236. X
  237. X    /* Create a graphics context using copy mode */
  238. X    gcv.function               = GXcopy;
  239. X    gcv.fill_style            = FillTiled;
  240. X    gcv.graphics_exposures    = False;
  241. X    if (!(gc = XCreateGC(display, window, 
  242. X        GCFunction | GCFillStyle | GCGraphicsExposures, &gcv)))
  243. X        ShutDown(display, 1, "Cannot create GXcopy graphics context.");
  244. X
  245. X    /* Create a graphics context using xor mode */
  246. X    gcv.function               = GXxor;
  247. X    gcv.graphics_exposures    = False;
  248. X    if (!(gcxor = XCreateGC(display, window, 
  249. X        GCFunction | GCGraphicsExposures, &gcv)))
  250. X        ShutDown(display, 1, "Cannot create GXxor graphics context.");
  251. X
  252. X    /* Create a graphics context using and mode */
  253. X    gcv.function               = GXand;
  254. X    gcv.graphics_exposures    = False;
  255. X    if (!(gcand = XCreateGC(display, window, 
  256. X        GCFunction | GCGraphicsExposures, &gcv)))
  257. X        ShutDown(display, 1, "Cannot create GXand graphics context.");
  258. X    XSetForeground(display, gcand, 0);
  259. X    XSetBackground(display, gcand, ~0);
  260. X
  261. X    /* Create a graphics context using or mode */
  262. X    gcv.function               = GXor;
  263. X    gcv.graphics_exposures    = False;
  264. X    if (!(gcor = XCreateGC(display, window, 
  265. X        GCFunction | GCGraphicsExposures, &gcv)))
  266. X        ShutDown(display, 1, "Cannot create GXor graphics context.");
  267. X
  268. X    /* Create a graphics context for use by sfx */
  269. X    gcv.function               = GXcopy;
  270. X    gcv.graphics_exposures    = False;
  271. X    if (!(gcsfx = XCreateGC(display, window, 
  272. X        GCFunction | GCGraphicsExposures, &gcv)))
  273. X        ShutDown(display, 1, "Cannot create GXsfx graphics context.");
  274. X}
  275. X
  276. X#if NeedFunctionPrototypes
  277. Xstatic void InitialiseColourNames(Display *display, Colormap colormap)
  278. X#else
  279. Xstatic void InitialiseColourNames(display, colormap)
  280. X    Display *display;
  281. X    Colormap colormap;
  282. X#endif
  283. X{
  284. X    /* Obtain the colour index of several colours from colourmap */
  285. X    red     = ColourNameToPixel(display, colormap, "red");
  286. X    tann    = ColourNameToPixel(display, colormap, "tan");
  287. X    yellow  = ColourNameToPixel(display, colormap, "yellow");
  288. X    green   = ColourNameToPixel(display, colormap, "green");
  289. X    white   = ColourNameToPixel(display, colormap, "white");
  290. X    black   = ColourNameToPixel(display, colormap, "black");
  291. X    purple  = ColourNameToPixel(display, colormap, "purple");
  292. X    blue    = ColourNameToPixel(display, colormap, "blue");
  293. X}
  294. X
  295. X#if NeedFunctionPrototypes
  296. Xstatic void InitialiseCycleColourNames(Display *display, Colormap colormap)
  297. X#else
  298. Xstatic void InitialiseCycleColourNames(display, colormap)
  299. X    Display *display;
  300. X    Colormap colormap;
  301. X#endif
  302. X{
  303. X    reds[0] = ColourNameToPixel(display, colormap, "#f00");
  304. X    reds[1] = ColourNameToPixel(display, colormap, "#e00");
  305. X    reds[2] = ColourNameToPixel(display, colormap, "#d00");
  306. X    reds[3] = ColourNameToPixel(display, colormap, "#c00");
  307. X    reds[4] = ColourNameToPixel(display, colormap, "#b00");
  308. X    reds[5] = ColourNameToPixel(display, colormap, "#a00");
  309. X    reds[6] = ColourNameToPixel(display, colormap, "#900");
  310. X    reds[7] = ColourNameToPixel(display, colormap, "#800");
  311. X    reds[8] = ColourNameToPixel(display, colormap, "#700");
  312. X    reds[9] = ColourNameToPixel(display, colormap, "#600");
  313. X    reds[10] = ColourNameToPixel(display, colormap, "#500");
  314. X    reds[11] = ColourNameToPixel(display, colormap, "#400");
  315. X    reds[12] = ColourNameToPixel(display, colormap, "#300");
  316. X    reds[13] = ColourNameToPixel(display, colormap, "#200");
  317. X
  318. X    greens[0] = ColourNameToPixel(display, colormap, "#0f0");
  319. X    greens[1] = ColourNameToPixel(display, colormap, "#0e0");
  320. X    greens[2] = ColourNameToPixel(display, colormap, "#0d0");
  321. X    greens[3] = ColourNameToPixel(display, colormap, "#0c0");
  322. X    greens[4] = ColourNameToPixel(display, colormap, "#0b0");
  323. X    greens[5] = ColourNameToPixel(display, colormap, "#0a0");
  324. X    greens[6] = ColourNameToPixel(display, colormap, "#090");
  325. X    greens[7] = ColourNameToPixel(display, colormap, "#080");
  326. X    greens[8] = ColourNameToPixel(display, colormap, "#070");
  327. X    greens[9] = ColourNameToPixel(display, colormap, "#060");
  328. X    greens[10] = ColourNameToPixel(display, colormap, "#050");
  329. X    greens[11] = ColourNameToPixel(display, colormap, "#040");
  330. X    greens[12] = ColourNameToPixel(display, colormap, "#030");
  331. X    greens[13] = ColourNameToPixel(display, colormap, "#020");
  332. X}
  333. X
  334. X#if NeedFunctionPrototypes
  335. Xstatic void InitialiseFonts(Display *display)
  336. X#else
  337. Xstatic void InitialiseFonts(display)
  338. X    Display *display;
  339. X#endif
  340. X{
  341. X    /* Create all required font structures */
  342. X
  343. X    /* Font used for titles */
  344. X    if (!(titleFont = XLoadQueryFont(display, TITLE_FONT)))
  345. X    {
  346. X        WarningMessage("Cannot open the title font. Using fixed.");
  347. X        titleFont = XLoadQueryFont(display, "fixed");
  348. X    }
  349. X
  350. X    /* Very small font used for copyright message etc. */
  351. X    if (!(copyFont = XLoadQueryFont(display, COPY_FONT)))
  352. X    {
  353. X        WarningMessage("Cannot open the copyright font. Using fixed.");
  354. X        copyFont = XLoadQueryFont(display, "fixed");
  355. X    }
  356. X
  357. X    /* Font used for general text everywhere */
  358. X    if (!(textFont = XLoadQueryFont(display, TEXT_FONT)))
  359. X    {
  360. X        WarningMessage("Cannot open the text font. Using fixed.");
  361. X        textFont = XLoadQueryFont(display, "fixed");
  362. X    }
  363. X}
  364. X
  365. X#if NeedFunctionPrototypes
  366. Xstatic void ReleaseFonts(Display *display)
  367. X#else
  368. Xstatic void ReleaseFonts(display)
  369. X    Display *display;
  370. X#endif
  371. X{
  372. X    /* Free all the fonts used */
  373. X    if (titleFont)    XFreeFont(display, titleFont);
  374. X    if (copyFont)    XFreeFont(display, copyFont);
  375. X    if (textFont)    XFreeFont(display, textFont);
  376. X}
  377. X
  378. X#if NeedFunctionPrototypes
  379. Xstatic void ExitProgramNow(int value)
  380. X#else
  381. Xstatic void ExitProgramNow(value)
  382. X    int value;
  383. X#endif
  384. X{
  385. X    /* Return to the shell with error code */
  386. X    exit(value);
  387. X}
  388. X
  389. X#if NeedFunctionPrototypes
  390. Xstatic void ReleaseGraphics(Display *display)
  391. X#else
  392. Xstatic void ReleaseGraphics(display)
  393. X    Display *display;
  394. X#endif
  395. X{
  396. X    /* Free the graphics contexts */
  397. X    if (gc)     XFreeGC(display, gc);
  398. X    if (gcxor)     XFreeGC(display, gcxor);
  399. X    if (gcand)     XFreeGC(display, gcand);
  400. X    if (gcor)     XFreeGC(display, gcor);
  401. X    if (gcsfx)     XFreeGC(display, gcsfx);
  402. X}
  403. X
  404. X#if NeedFunctionPrototypes
  405. Xvoid ShutDown(Display *display, int exit_code, char *message)
  406. X#else
  407. Xvoid ShutDown(display, exit_code, message)
  408. X    Display *display;
  409. X    int exit_code;
  410. X    char *message;
  411. X#endif
  412. X{
  413. X    /* This is the last function called when exiting */
  414. X
  415. X    /* Remove the colour map */
  416. X    if (colormap) XUninstallColormap(display, colormap);
  417. X
  418. X    /* Close the audio device if available and wanted */
  419. X    if (noSound == False)
  420. X        FreeAudioSystem();
  421. X
  422. X    FreeMisc(display);                /* Free backing store pixmap*/
  423. X    FreeKeyControl(display);        /* Free key control         */
  424. X    FreeHighScore(display);            /* Free high score memory     */
  425. X    FreeInstructions(display);        /* Free instructions        */
  426. X    FreeBonus(display);                /* Free bonus memory         */
  427. X    FreeIntroduction(display);        /* Free introduction memory */
  428. X    FreeMessageSystem(display);        /* Free message system         */
  429. X    FreePaddle(display);            /* Free paddle pixmaps         */
  430. X    FreeLevelInfo(display);            /* Free level pixmaps         */
  431. X    FreeScoreDigits(display);        /* Free digit pixmaps         */
  432. X    FreeBlockPixmaps(display);        /* Free all block pixmaps     */
  433. X    FreeBall(display);                /* Free the ball animation     */
  434. X    FreeBullet(display);            /* Free the bullet          */
  435. X    ReleaseGraphics(display);        /* Free graphics contexts     */
  436. X    ReleaseFonts(display);            /* Unload fonts used        */
  437. X
  438. X    /* Output an error message if required */
  439. X    if (message[0] != '\0')
  440. X    {
  441. X        /* If we had an error then use error message */
  442. X        if (exit_code == 1)
  443. X            ErrorMessage(message);
  444. X        else
  445. X            NormalMessage(message);
  446. X    }
  447. X
  448. X    /* Exit with the error code */
  449. X    ExitProgramNow(exit_code);
  450. X}
  451. X
  452. X#if NeedFunctionPrototypes
  453. Xstatic int ErrorHandler(Display *display, XErrorEvent *err)
  454. X#else
  455. Xstatic int ErrorHandler(display, err)
  456. X    Display *display;
  457. X    XErrorEvent *err;
  458. X#endif
  459. X{
  460. X     char msg[80];
  461. X     char string[256];
  462. X
  463. X    /* Obtain the error message from the server */
  464. X    XGetErrorText(display, err->error_code, msg, 80);
  465. X    sprintf(string, "Xlib Error: %s", msg);
  466. X
  467. X    /* Close down the system */
  468. X    ShutDown(display, 1, string);
  469. X
  470. X    /* Not reached but makes the compiler happy */
  471. X    return True;
  472. X}
  473. X
  474. X#if NeedFunctionPrototypes
  475. Xstatic void HandleDisplayErrors(char *displayName)
  476. X#else
  477. Xstatic void HandleDisplayErrors(displayName)
  478. X    char *displayName;
  479. X#endif
  480. X{
  481. X     char string[256];
  482. X
  483. X    /* Check if the DISPLAY variable is set and write correct message */
  484. X    if (getenv("DISPLAY") == NULL)
  485. X        WarningMessage("Your X-Window system display variable is not set.");
  486. X    else
  487. X    {
  488. X        sprintf(string, "Cannot connect to display called <%s>.", displayName);
  489. X        WarningMessage(string);
  490. X    }
  491. X}
  492. X
  493. X#if NeedFunctionPrototypes
  494. Xstatic void PrintVersion(void)
  495. X#else
  496. Xstatic void PrintVersion()
  497. X#endif
  498. X{
  499. X    /* Print version for program to user for command line help */
  500. X    fprintf(stdout, 
  501. X        "XBoing by Justin Kibell (jck@citri.edu.au)\n"); 
  502. X    fprintf(stdout, 
  503. X      "Version %d.%d %s\n", VERSION, REVNUM + buildNum, dateString);
  504. X    fprintf(stdout, "(c) Copyright 1993, All Rights Reserved\n");
  505. X
  506. X    /* Exit now */
  507. X    ExitProgramNow(0);
  508. X}
  509. X
  510. X#if NeedFunctionPrototypes
  511. Xstatic void PrintUsage(void)
  512. X#else
  513. Xstatic void PrintUsage()
  514. X#endif
  515. X{
  516. X    /* Print usage to user for command line help */
  517. X
  518. X    fprintf(stdout, "%s%s",
  519. X        "Usage: XBoing [-version] [-usage] [-help] [-sync] ",
  520. X        "[-display <displayName>]\n"); 
  521. X    fprintf(stdout, "%s%s\n%s%s\n",
  522. X        "              [-speed <1-9>] [-scores] [-keys] [-sound] [-setup]",
  523. X        " [-nosfx]",
  524. X        "              [-nograb] [-maxvol <1-100>] [-startlevel <1-MAX>]",
  525. X        " [-usedefcmap]");
  526. X
  527. X    /* Exit now */
  528. X    ExitProgramNow(0);
  529. X}
  530. X
  531. X#if NeedFunctionPrototypes
  532. Xstatic void PrintSetup(void)
  533. X#else
  534. Xstatic void PrintSetup()
  535. X#endif
  536. X{
  537. X    /* Print setup information about xboing */
  538. X    char *str;
  539. X
  540. X    fprintf(stdout, "xboing: Setup Information\n");
  541. X    fprintf(stdout, "           Audio: %s\n", 
  542. X        AUDIO_AVAILABLE ? "Available" : "Not available");
  543. X    fprintf(stdout, "         Version: %d.%d\n", VERSION, REVNUM + buildNum);
  544. X    fprintf(stdout, "        Compiled: %s\n", dateString);
  545. X
  546. X    /* If the environment variable exists - use it */
  547. X    if ((str = getenv("XBOING_SCORE_FILE")) != NULL)
  548. X        fprintf(stdout, "      Score File: %s\n", str);
  549. X    else
  550. X        fprintf(stdout, "      Score File: %s\n", HIGH_SCORE_FILE);
  551. X
  552. X    /* If the environment variable exists - use it */
  553. X    if ((str = getenv("XBOING_LEVELS_DIR")) != NULL)
  554. X        fprintf(stdout, " Level directory: %s\n", str);
  555. X    else
  556. X        fprintf(stdout, " Level directory: %s\n", LEVEL_INSTALL_DIR);
  557. X
  558. X    fprintf(stdout, "Number of levels: %d\n", MAX_NUM_LEVELS);
  559. X
  560. X    /* If the environment variable exists - use it */
  561. X    if ((str = getenv("XBOING_SOUND_DIR")) != NULL)
  562. X        fprintf(stdout, "Sounds directory: %s\n", str);
  563. X    else
  564. X        fprintf(stdout, "Sounds directory: %s\n", SOUNDS_DIR);
  565. X
  566. X    /* Exit now */
  567. X    ExitProgramNow(0);
  568. X}
  569. X
  570. X
  571. X#if NeedFunctionPrototypes
  572. Xstatic void PrintHelp(void)
  573. X#else
  574. Xstatic void PrintHelp()
  575. X#endif
  576. X{
  577. X    /* Print help for program to user for command line help */
  578. X    fprintf(stdout, 
  579. X        "XBoing by Justin Kibell (jck@citri.edu.au)\n"); 
  580. X    fprintf(stdout, "Version %d.%d %s\n", VERSION, REVNUM + buildNum,
  581. X        "(c) Copyright 1993, All Rights Reserved\n");
  582. X
  583. X    fprintf(stdout, "Help: \n");
  584. X    fprintf(stdout, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
  585. X        "    -speed <n>              - The game speed, 1 - 9. 9 = fast\n",
  586. X        "    -maxvol <n>             - The maximum volume as percentage.\n",
  587. X        "    -startlevel <n>         - The starting level for game.\n",
  588. X        "    -help                   - Produce this help message.\n",
  589. X        "    -sync                   - Turn on X synchronisation.\n",
  590. X        "    -usage                  - Print a brief help message.\n",
  591. X        "    -version                - Print out the current version.\n",
  592. X        "    -scores                 - Print out the current highscores.\n",
  593. X        "    -keys                   - Use keys instead of mouse control.\n",
  594. X        "    -sound                  - Turn audio ON for game.\n",
  595. X        "    -setup                  - Print setup information.\n",
  596. X        "    -nosfx                  - Do not use special effects.\n",
  597. X        "    -nograb                 - Turn off pointer grab.\n",
  598. X        "    -usedefcmap             - Use the default colourmap.\n",
  599. X        "    -display <display>      - Set the display for the game.\n");
  600. X
  601. X    /* Exit now */
  602. X    ExitProgramNow(0);
  603. X}
  604. X
  605. X#if NeedFunctionPrototypes
  606. Xstatic int compareArgument(char *arg1, char *arg2, int minMatch)
  607. X#else
  608. Xstatic int compareArgument(arg1, arg2, minMatch)
  609. X    char *arg1;
  610. X    char *arg2;
  611. X    int minMatch;
  612. X#endif
  613. X{
  614. X    if ((strlen(arg1) < minMatch) || (strlen(arg2) < minMatch)) 
  615. X        return 1;
  616. X    if (strlen(arg1) > strlen(arg2)) 
  617. X        return 1;
  618. X
  619. X    /* Return true or false basically */
  620. X    return (strncmp(arg1, arg2, strlen(arg1)));
  621. X}
  622. X
  623. X#if NeedFunctionPrototypes
  624. Xstatic void TurnOnSynchronise(Display *display)
  625. X#else
  626. Xstatic void TurnOnSynchronise(display)
  627. X    Display *display;
  628. X#endif
  629. X{
  630. X    /* Turn the X synchronisation on to flush all calls each frame */
  631. X    XSynchronize(display, True);
  632. X}
  633. X
  634. X#if NeedFunctionPrototypes
  635. Xstatic void InitialiseSettings(void)
  636. X#else
  637. Xstatic void InitialiseSettings()
  638. X#endif
  639. X{
  640. X    /* Initialise some variables */
  641. X    syncOn = False;
  642. X    debug = False;
  643. X    grabPointer = True;
  644. X    useDefaultColourmap = False;
  645. X
  646. X    /* The audio is off by default */
  647. X    noSound = True;
  648. X
  649. X    /* So the audio code will use system default */
  650. X    SetMaximumVolume(0);    
  651. X
  652. X    /* Always start on level one */
  653. X    SetStartingLevel(1);
  654. X    SetLevelNumber(1);
  655. X
  656. X    /* Not so fast */
  657. X    SetUserSpeed(7);
  658. X
  659. X    useSpecialEffects(True);
  660. X    score = 0L;
  661. X}
  662. X
  663. X#if NeedFunctionPrototypes
  664. Xstatic void ParseCommandLine(char **argv, int argc)
  665. X#else
  666. Xstatic void ParseCommandLine(argv, argc)
  667. X    char **argv;
  668. X    int argc;
  669. X#endif
  670. X{
  671. X    /* Parse the command line options */
  672. X    int i, l;
  673. X    char str[80];
  674. X
  675. X    /* Initialise variables */
  676. X    InitialiseSettings();
  677. X
  678. X    for (i = 1; i < argc; i++)
  679. X    {
  680. X        if (argv[i][0] != '-')
  681. X        {
  682. X            PrintUsage();
  683. X            break;
  684. X        }
  685. X
  686. X        if (!compareArgument(argv[i], "-display", 7))
  687. X        {
  688. X            /* Set the display name for later connection */
  689. X            i++;
  690. X            if (i < argc)
  691. X                displayName = argv[i];
  692. X            else PrintUsage();
  693. X
  694. X        } else if (!compareArgument(argv[i], "-help", 4))
  695. X        {
  696. X            /* Print out the help information and quit */
  697. X            PrintHelp();
  698. X
  699. X        } else if (!compareArgument(argv[i], "-debug", 5))
  700. X        {
  701. X            /* Turn on debugging */
  702. X            NormalMessage("Debugging mode activated.");
  703. X            debug = True;
  704. X
  705. X        } else if (!compareArgument(argv[i], "-setup", 5))
  706. X        {
  707. X            /* Print out information on setup */
  708. X            PrintSetup();
  709. X
  710. X        } else if (!compareArgument(argv[i], "-sync", 4))
  711. X        {
  712. X            /* Turn on X protocol synchronisation */
  713. X            syncOn = True;
  714. X
  715. X        } else if (!compareArgument(argv[i], "-version", 7))
  716. X        {
  717. X            /* Print out the version information and quit */
  718. X            PrintVersion();
  719. X
  720. X        } else if (!compareArgument(argv[i], "-sound", 5))
  721. X        {
  722. X            /* Enable the sound in the game */
  723. X            noSound = False;
  724. X
  725. X        } else if (!compareArgument(argv[i], "-keys", 4))
  726. X        {
  727. X            /* Set the paddle control mode to use keys */
  728. X            SetPaddleControlMode(CONTROL_KEYS);
  729. X
  730. X        } else if (!compareArgument(argv[i], "-scores", 6))
  731. X        {
  732. X            /* List all the highscores */
  733. X            CommandlineHighscorePrint();
  734. X            ExitProgramNow(0);
  735. X
  736. X        } else if (!compareArgument(argv[i], "-usage", 5))
  737. X        {
  738. X            /* Print out the usage and quit */
  739. X            PrintUsage();
  740. X
  741. X        } else if (!compareArgument(argv[i], "-nosfx", 5))
  742. X        {
  743. X            /* Turn off special effects then */
  744. X            useSpecialEffects(False);
  745. X            
  746. X        } else if (!compareArgument(argv[i], "-nograb", 6))
  747. X        {
  748. X            /* Turn off pointer grabbing */
  749. X            grabPointer = False;
  750. X
  751. X        } else if (!compareArgument(argv[i], "-usedefcmap", 10))
  752. X        {
  753. X            /* Try to use the default colourmap */
  754. X            useDefaultColourmap = True;
  755. X
  756. X        } else if (!compareArgument(argv[i], "-speed", 5))
  757. X        {
  758. X            /* Set the speed for the game */
  759. X            i++;
  760. X            if (i < argc)
  761. X            {
  762. X                /* Obtain the speed setting */
  763. X                l = atoi(argv[i]);
  764. X                if ((l > 0) && (l <= 9))
  765. X                    SetUserSpeed(10 - l);
  766. X                else 
  767. X                {
  768. X                    WarningMessage("The speed setting range is [1-9]");
  769. X                    PrintUsage();
  770. X                }
  771. X            } else PrintUsage();
  772. X
  773. X        } else if (!compareArgument(argv[i], "-startlevel", 10))
  774. X        {
  775. X            /* Set the starting level */
  776. X            i++;
  777. X            if (i < argc)
  778. X            {
  779. X                /* Obtain the start level setting */
  780. X                l = atoi(argv[i]);
  781. X                if ((l > 0) && (l <= MAX_NUM_LEVELS))
  782. X                    SetStartingLevel(l);
  783. X                else 
  784. X                {
  785. X                    sprintf(str, "The starting level range is [1-%d]", 
  786. X                        MAX_NUM_LEVELS);
  787. X                    WarningMessage(str);
  788. X                    PrintUsage();
  789. X                }
  790. X            } else PrintUsage();
  791. X
  792. X        } else if (!compareArgument(argv[i], "-maxvol", 6))
  793. X        {
  794. X            /* Set the maximum volume to use for the game */
  795. X            i++;
  796. X            if (i < argc)
  797. X            {
  798. X                /* Obtain the maximum volume setting */
  799. X                l = atoi(argv[i]);
  800. X                if ((l >= 1) && (l <= 100))
  801. X                    SetMaximumVolume(l);
  802. X                else 
  803. X                {
  804. X                    WarningMessage("Maximum volume range is [1-100]");
  805. X                    PrintUsage();
  806. X                }
  807. X            } else PrintUsage();
  808. X
  809. X        } else PrintUsage();
  810. X    }
  811. X}
  812. X
  813. X#if NeedFunctionPrototypes
  814. Xvoid UnGrabPointer(Display *display)
  815. X#else
  816. Xvoid UnGrabPointer(display)
  817. X    Display *display;
  818. X#endif
  819. X{
  820. X    /* Ungrab the pointer */
  821. X    if (grabPointer == True)
  822. X        XUngrabPointer(display, CurrentTime);
  823. X}
  824. X
  825. X#if NeedFunctionPrototypes
  826. Xvoid GrabPointer(Display *display, Window window)
  827. X#else
  828. Xvoid GrabPointer(display, window)
  829. X    Display *display;
  830. X    Window window;
  831. X#endif
  832. X{
  833. X    Cursor cursor;
  834. X    XColor colour;
  835. X    Pixmap cursorPixmap;
  836. X
  837. X    /* Create a cursor with nothing inside it */
  838. X    colour.pixel = WhitePixel(display, DefaultScreen(display));
  839. X    XQueryColor(display, 
  840. X        DefaultColormap(display, DefaultScreen(display)), &colour);
  841. X    cursorPixmap = XCreatePixmap(display, window, 1, 1, 1);
  842. X
  843. X    cursor = XCreatePixmapCursor(display, 
  844. X        cursorPixmap, cursorPixmap, &colour, &colour, 0, 0);
  845. X    if (cursorPixmap) XFreePixmap(display, cursorPixmap);
  846. X
  847. X    if (grabPointer == True)
  848. X    {
  849. X        /* Grab the pointer so you cannot move the  mouse out of the main
  850. X          * window. Also set the cursor to a new cursor with no shape.
  851. X          */
  852. X        if (XGrabPointer(display, window, True,
  853. X            ButtonReleaseMask | ButtonPressMask,
  854. X            GrabModeAsync, GrabModeAsync, window,
  855. X            cursor, CurrentTime) != GrabSuccess)
  856. X        {
  857. X            /* Error while grab - not too bad but let user know. */    
  858. X            WarningMessage("Pointer grab unsuccessful.");
  859. X        }
  860. X    }
  861. X    else
  862. X        XDefineCursor(display, window, cursor);
  863. X}
  864. X
  865. X#if NeedFunctionPrototypes
  866. XDisplay *InitialiseGame(char **argv, int argc)
  867. X#else
  868. XDisplay *InitialiseGame(argv, argc)
  869. X    char **argv;
  870. X    int argc;
  871. X#endif
  872. X{
  873. X    int screen_num;
  874. X    static Display *display;
  875. X
  876. X    /* Setup the default speed for game */
  877. X    SetUserSpeed(5);
  878. X
  879. X    /* Set the paddle control mode to mouse */
  880. X    SetPaddleControlMode(CONTROL_MOUSE);
  881. X
  882. X    /* Parse all command line arguments - may exit here */
  883. X    ParseCommandLine(argv, argc);
  884. X
  885. X    DEBUG("Command line parsed.")
  886. X
  887. X    /* Open a display connection */
  888. X    if (!(display = XOpenDisplay(displayName)))
  889. X    {
  890. X        /* Handle display connection errors */
  891. X        HandleDisplayErrors(displayName);
  892. X        ExitProgramNow(1);
  893. X    }
  894. X
  895. X    /* User wants synchronisation turned on so do it */
  896. X    if (syncOn == True) TurnOnSynchronise(display);
  897. X
  898. X    /* Set the error handlers to point to mine */
  899. X    XSetErrorHandler(ErrorHandler);
  900. X
  901. X    /* Seed the random number generator */
  902. X    srand(time(NULL));
  903. X
  904. X    /* Obtain the screen number for this display */
  905. X    screen_num = XDefaultScreen(display);
  906. X
  907. X    /* Make sure that we are using a colour visual */
  908. X    if (!XMatchVisualInfo(display, screen_num, 
  909. X        DefaultDepth(display, screen_num), PseudoColor, &visual_info))
  910. X    {
  911. X        if (!XMatchVisualInfo(display, screen_num, 
  912. X            DefaultDepth(display, screen_num), DirectColor, &visual_info))
  913. X        {
  914. X            if (!XMatchVisualInfo(display, screen_num, 
  915. X                DefaultDepth(display, screen_num), TrueColor, &visual_info))
  916. X            {
  917. X                ErrorMessage("Sorry, you must have a colour display. :-(");
  918. X                ExitProgramNow(1);
  919. X            }
  920. X        }
  921. X    }
  922. X
  923. X    DEBUG("Display system checked.")
  924. X
  925. X    /* Create our own colour map or use the default one */
  926. X    if (useDefaultColourmap == True)
  927. X        colormap = XDefaultColormap(display, screen_num);
  928. X    else
  929. X        colormap = XCreateColormap(display, RootWindow(display, screen_num), 
  930. X            visual_info.visual, AllocNone);
  931. X
  932. X    DEBUG("Colourmap created.")
  933. X
  934. X    /* Be polite */
  935. X    NormalMessage("Please wait, initialising xboing ...");
  936. X
  937. X    /* Initialise the audio system if possible */
  938. X    if (noSound == False)
  939. X    {
  940. X        /* Try to turn audio on */
  941. X        if (SetUpAudioSystem(display) == False)
  942. X        {
  943. X            /* Audio failed - let user know */
  944. X            noSound = True;
  945. X            WarningMessage("Audio unavailable or not supported.");
  946. X        }
  947. X    }
  948. X
  949. X    DEBUG("Sound system checked.")
  950. X
  951. X    /* Find out some colours */
  952. X    InitialiseColourNames(display, colormap);
  953. X
  954. X    DEBUG("Initialised colour names.")
  955. X
  956. X    /* Create all windows */
  957. X    CreateAllWindows(display, colormap, argv, argc);
  958. X
  959. X    DEBUG("Created all windows.")
  960. X
  961. X    InitialiseGraphics(display, playWindow);
  962. X    InitialiseFonts(display);
  963. X
  964. X    DEBUG("Created GC and fonts.")
  965. X
  966. X    SetBackgrounds(display, colormap);
  967. X
  968. X    DEBUG("Created background pixmaps.")
  969. X
  970. X    /* Initialise all pixmaps and objects and setup special screens etc. */
  971. X    InitialiseMessageSystem(display,     messWindow,     colormap);
  972. X    DEBUG("InitialiseMessageSystem done.")
  973. X    InitialiseBlocks(display,             playWindow,     colormap);
  974. X    DEBUG("InitialiseBlocks done.")
  975. X    InitialiseBall(display,             playWindow,     colormap);
  976. X    DEBUG("InitialiseBall done.")
  977. X    InitialiseBullet(display,             playWindow,     colormap);
  978. X    DEBUG("InitialiseBullet done.")
  979. X    InitialiseScoreDigits(display,         scoreWindow,     colormap);
  980. X    DEBUG("InitialiseScoreDigits done.")
  981. X    InitialiseLevelInfo(display,         levelWindow,     colormap);
  982. X    DEBUG("InitialiseLevelInfo done.")
  983. X    InitialisePaddle(display,             playWindow,     colormap);
  984. X    DEBUG("InitialisePaddle done.")
  985. X
  986. X    SetUpPresents(display,                 mainWindow,     colormap);
  987. X    DEBUG("SetUpPresents done.")
  988. X    SetUpKeys(display,                     playWindow,     colormap);
  989. X    DEBUG("SetUpKeys done.")
  990. X    SetUpInstructions(display,             playWindow,     colormap);
  991. X    DEBUG("SetUpInstructions done.")
  992. X    SetUpIntroduction(display,             playWindow,     colormap);
  993. X    DEBUG("SetUpIntroduction done.")
  994. X    SetUpBonus(display,                 mainWindow,     colormap);
  995. X    DEBUG("SetUpBonus done.")
  996. X    SetUpHighScore(display,             playWindow,     colormap);
  997. X    DEBUG("SetUpHighScore done.")
  998. X
  999. X    /* Do this after pixmaps all the colourmap */
  1000. X    InitialiseCycleColourNames(display, colormap);
  1001. X
  1002. X    DEBUG("Colour cycle indexes created.")
  1003. X
  1004. X    DisplayLevelInfo(display, levelWindow, level);
  1005. X    SetLevelTimeBonus(display, timeWindow, 180);
  1006. X    DrawSpecials(display);
  1007. X
  1008. X    event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
  1009. X       ButtonReleaseMask | ExposureMask | StructureNotifyMask;
  1010. X    XSelectInput(display, mainWindow, event_mask);
  1011. X
  1012. X    event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
  1013. X       ButtonReleaseMask;
  1014. X    XSelectInput(display, playWindow, event_mask);
  1015. X
  1016. X    /* Actually map the main window */
  1017. X    XMapWindow(display, mainWindow);
  1018. X
  1019. X    /* Install our new colormap into the server list */
  1020. X    XInstallColormap(display, colormap);
  1021. X
  1022. X    DEBUG("Entering main loop.")
  1023. X
  1024. X    /* Return the new display */
  1025. X    return display;
  1026. X}
  1027. END_OF_FILE
  1028. if test 25223 -ne `wc -c <'init.c'`; then
  1029.     echo shar: \"'init.c'\" unpacked with wrong size!
  1030. fi
  1031. # end of 'init.c'
  1032. fi
  1033. if test -f 'main.c' -a "${1}" != "-c" ; then 
  1034.   echo shar: Will not clobber existing file \"'main.c'\"
  1035. else
  1036. echo shar: Extracting \"'main.c'\" \(25219 characters\)
  1037. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  1038. X#include "include/copyright.h"
  1039. X
  1040. X/*
  1041. X *  Include file dependencies:
  1042. X */
  1043. X
  1044. X#include <stdio.h>
  1045. X#include <stdlib.h>
  1046. X#include <stddef.h>
  1047. X#include <X11/Xlib.h>
  1048. X#include <X11/Xutil.h>
  1049. X#include <X11/Xos.h>
  1050. X#include <X11/keysym.h>
  1051. X
  1052. X#include "include/score.h"
  1053. X#include "include/presents.h"
  1054. X#include "include/special.h"
  1055. X#include "include/audio.h"
  1056. X#include "include/mess.h"
  1057. X#include "include/ball.h"
  1058. X#include "include/gun.h"
  1059. X#include "include/sfx.h"
  1060. X#include "include/init.h"
  1061. X#include "include/blocks.h"
  1062. X#include "include/misc.h"
  1063. X#include "include/level.h"
  1064. X#include "include/bonus.h"
  1065. X#include "include/stage.h"
  1066. X#include "include/paddle.h"
  1067. X#include "include/intro.h"
  1068. X#include "include/inst.h"
  1069. X#include "include/highscore.h"
  1070. X#include "include/keys.h"
  1071. X
  1072. X#include "include/main.h"
  1073. X
  1074. X/*
  1075. X *  Internal macro definitions:
  1076. X */
  1077. X
  1078. X#define PADDLE_ANIMATE_DELAY    5
  1079. X#define BONUS_SEED                2000    
  1080. X
  1081. X/*
  1082. X *  Internal type declarations:
  1083. X */
  1084. X
  1085. X#if NeedFunctionPrototypes
  1086. Xstatic KeySym     GetKeySym(XEvent event);
  1087. Xstatic void     handleGameMode(Display *display);
  1088. Xstatic void     handleEventLoop(Display *display);
  1089. Xstatic void     ToggleGamePaused(Display *display, Window window);
  1090. Xstatic void     SetGamePaused(Display *display);
  1091. Xstatic void     handleGameStates(Display *display);
  1092. Xstatic void     sleepSync(Display *display, unsigned long ms);
  1093. Xstatic void     handleMiscKeys(Display *display, KeySym keysym);
  1094. X#else
  1095. Xstatic void     handleMiscKeys();
  1096. Xstatic void     sleepSync();
  1097. Xstatic void     handleGameStates();
  1098. Xstatic KeySym     GetKeySym();
  1099. Xstatic void     handleGameMode();
  1100. Xstatic void     handleEventLoop();
  1101. Xstatic void     ToggleGamePaused();
  1102. Xstatic void     SetGamePaused();
  1103. X#endif
  1104. X
  1105. X/*
  1106. X *  Internal variable declarations:
  1107. X */
  1108. X
  1109. Xstatic char copyright[] = "(c) Copyright 1993, Justin Kibell, All Rights Reserved. email: jck@citri.edu.au";
  1110. X
  1111. Xint paddleMotion = 0;
  1112. Xint paddleDx = 0;
  1113. Xint speedLevel = 5;
  1114. Xint frame, gameActive;
  1115. Xint mode, oldmode;
  1116. Xstatic int iconified = False;
  1117. Xlong speed;
  1118. Xstatic int userDelay = 1;
  1119. Xstatic int paddleControl;
  1120. Xstatic time_t pauseStartTime;
  1121. Xtime_t pausedTime;
  1122. X
  1123. X#if NeedFunctionPrototypes
  1124. Xvoid SetUserSpeed(int delay)
  1125. X#else
  1126. Xvoid SetUserSpeed(delay)
  1127. X    int delay;
  1128. X#endif
  1129. X{
  1130. X    int temp;
  1131. X
  1132. X    /* Set an entire game speedup or slowdown speed */
  1133. X    temp = (long) (speed / userDelay);
  1134. X    userDelay = delay;
  1135. X    speed = (long) (temp * userDelay);
  1136. X    speedLevel = 10 - delay;
  1137. X}
  1138. X
  1139. X#if NeedFunctionPrototypes
  1140. Xint GetPaddleControlMode(void)
  1141. X#else
  1142. Xint GetPaddleControlMode()
  1143. X#endif
  1144. X{
  1145. X    /* Get the paddle control mode */
  1146. X    return paddleControl;
  1147. X}
  1148. X
  1149. X#if NeedFunctionPrototypes
  1150. Xvoid SetPaddleControlMode(int type)
  1151. X#else
  1152. Xvoid SetPaddleControlMode(type)
  1153. X    int type;
  1154. X#endif
  1155. X{
  1156. X    /* Set the paddle control mode to the new mode */
  1157. X    paddleControl = type;
  1158. X}
  1159. X
  1160. X#if NeedFunctionPrototypes
  1161. Xvoid SetGameSpeed(int delay)
  1162. X#else
  1163. Xvoid SetGameSpeed(delay)
  1164. X    int delay;
  1165. X#endif
  1166. X{
  1167. X    /* This is the speed used in the sleeping routine */
  1168. X    if (delay >= 0)
  1169. X        speed = (long) (delay * userDelay);
  1170. X}
  1171. X
  1172. X#if NeedFunctionPrototypes
  1173. Xstatic void sleepSync(Display *display, unsigned long ms)
  1174. X#else
  1175. Xstatic void sleepSync(display, ms)
  1176. X    Display *display;
  1177. X    unsigned long ms;
  1178. X#endif
  1179. X{
  1180. X    struct timeval st, et;
  1181. X    long SyncTime;
  1182. X
  1183. X    gettimeofday(&st, NULL);
  1184. X    XSync(display, False);
  1185. X    gettimeofday(&et, NULL);
  1186. X
  1187. X    SyncTime = (((et.tv_sec - st.tv_sec) * 1000) +
  1188. X               ((et.tv_usec - st.tv_usec) / 1000) );
  1189. X
  1190. X    if ((ms) > ((1000 / 60) + SyncTime))
  1191. X        ms_sleep(ms - SyncTime);
  1192. X}
  1193. X
  1194. X#if NeedFunctionPrototypes
  1195. Xstatic KeySym GetKeySym(XEvent event)
  1196. X#else
  1197. Xstatic KeySym GetKeySym(event)
  1198. X    XEvent event;
  1199. X#endif
  1200. X{
  1201. X    int count;
  1202. X    char key;
  1203. X    KeySym keysym;
  1204. X    XComposeStatus compose;
  1205. X
  1206. X    /* Lookup a keysym using the event key */
  1207. X    count = XLookupString(&event.xkey, &key, 1, &keysym, &compose);
  1208. X
  1209. X    return keysym;
  1210. X}
  1211. X
  1212. X#if NeedFunctionPrototypes
  1213. Xint paddleIsMoving(void)
  1214. X#else
  1215. Xint paddleIsMoving()
  1216. X#endif
  1217. X{
  1218. X    /* Returns direction of paddle 1 right -1 left 0 stopped */
  1219. X    return paddleMotion;
  1220. X}
  1221. X
  1222. X#if NeedFunctionPrototypes
  1223. Xvoid handlePaddleMoving(Display *display)
  1224. X#else
  1225. Xvoid handlePaddleMoving(display)
  1226. X    Display *display;
  1227. X#endif
  1228. X{
  1229. X    static oldx = 0;
  1230. X    int rx, ry, x, y;
  1231. X    unsigned int mask;
  1232. X    Window root, child;
  1233. X
  1234. X    if (paddleControl == CONTROL_KEYS)
  1235. X    {
  1236. X        switch (paddleMotion)
  1237. X        {
  1238. X            case 1:        /* Move the paddle to the right 1 increment */
  1239. X                MovePaddle(display, playWindow, 
  1240. X                    PADDLE_RIGHT, currentPaddleSize, 0);
  1241. X                break;
  1242. X
  1243. X            case -1:        /* Move the paddle to the left 1 increment */
  1244. X                MovePaddle(display, playWindow, 
  1245. X                    PADDLE_LEFT, currentPaddleSize, 0);
  1246. X                break;
  1247. X
  1248. X            default:
  1249. X                break;
  1250. X        }
  1251. X    } else if (paddleControl == CONTROL_MOUSE)
  1252. X    {
  1253. X        /* Obtain the position of the pointer in the play window */
  1254. X        if (XQueryPointer(display, playWindow, &root, &child, 
  1255. X            &rx, &ry, &x, &y, &mask) == True)
  1256. X        {
  1257. X            /* Has the pointer moved since our last poll */
  1258. X            if (x != oldx)
  1259. X            {
  1260. X                paddleDx = x - oldx;
  1261. X
  1262. X                /* Move the paddle to the position of the mouse pointer */
  1263. X                MovePaddle(display, playWindow, 
  1264. X                    PADDLE_NONE, currentPaddleSize, x);
  1265. X                oldx = x;
  1266. X
  1267. X                /* Adjust the paddle motion variable so the ball moves when in
  1268. X                 * the BALL_READY state and BALL_CREATE state.
  1269. X                 */
  1270. X                if (x > oldx)
  1271. X                    paddleMotion = 1;
  1272. X                else
  1273. X                    paddleMotion = -1;
  1274. X            }
  1275. X            else
  1276. X            {
  1277. X                /* Reset to no motion */
  1278. X                paddleMotion = 0;
  1279. X                paddleDx = 0;
  1280. X            }
  1281. X        }
  1282. X    }
  1283. X}
  1284. X
  1285. X
  1286. X#if NeedFunctionPrototypes
  1287. Xstatic void ToggleGamePaused(Display *display, Window window)
  1288. X#else
  1289. Xstatic void ToggleGamePaused(display, window)
  1290. X    Display *display;
  1291. X    Window window;
  1292. X#endif
  1293. X{
  1294. X    if (mode == MODE_PAUSE)
  1295. X    {
  1296. X        /* Finished pause resume game */
  1297. X        mode = MODE_GAME;
  1298. X        SetCurrentMessage(display, messWindow, "- Play ball -", False);
  1299. X        
  1300. X        /* How many seconds were we paused for? */
  1301. X        pausedTime += (time(NULL) - pauseStartTime);
  1302. X
  1303. X         XSelectInput(display, mainWindow, 
  1304. X            KeyPressMask | KeyReleaseMask | ButtonPressMask |
  1305. X               ButtonReleaseMask | ExposureMask | StructureNotifyMask);
  1306. X
  1307. X         GrabPointer(display, window);
  1308. X    }
  1309. X    else 
  1310. X        SetGamePaused(display);
  1311. X}
  1312. X
  1313. X#if NeedFunctionPrototypes
  1314. Xstatic void SetGamePaused(Display *display)
  1315. X#else
  1316. Xstatic void SetGamePaused(display)
  1317. X    Display *display;
  1318. X#endif
  1319. X{
  1320. X    if (mode == MODE_GAME)
  1321. X    {
  1322. X        /* Set game to paused mode */
  1323. X        mode = MODE_PAUSE;
  1324. X        SetCurrentMessage(display, messWindow, 
  1325. X            "- Game paused -", False);
  1326. X        
  1327. X        /* we need to keep track of how long we were paused so that later
  1328. X         * in the highscore thing I can take that off the time.
  1329. X         */
  1330. X        pauseStartTime = time(NULL);
  1331. X
  1332. X        XSelectInput(display, mainWindow, 
  1333. X            KeyPressMask | ExposureMask | StructureNotifyMask);
  1334. X
  1335. X        UnGrabPointer(display);
  1336. X    }
  1337. X}
  1338. X
  1339. X#if NeedFunctionPrototypes
  1340. Xvoid handleIconify(Display *display, XUnmapEvent *event)
  1341. X#else
  1342. Xvoid handleIconify(display, event)
  1343. X    Display *display;
  1344. X    XUnmapEvent *event;
  1345. X#endif
  1346. X{
  1347. X    ToggleGamePaused(display, mainWindow);
  1348. X}
  1349. X
  1350. X#if NeedFunctionPrototypes
  1351. Xvoid SelectiveRedraw(Display *display)
  1352. X#else
  1353. Xvoid SelectiveRedraw(display)
  1354. X    Display *display;
  1355. X#endif
  1356. X{
  1357. X    switch (mode)
  1358. X    {
  1359. X        case MODE_GAME:
  1360. X        case MODE_PAUSE:
  1361. X            RedrawPlayWindow(display, playWindow);
  1362. X            break;
  1363. X
  1364. X        case MODE_INTRO:
  1365. X            RedrawIntroduction(display, playWindow);
  1366. X            break;
  1367. X
  1368. X        case MODE_INSTRUCT:
  1369. X            RedrawInstructions(display, playWindow);
  1370. X            break;
  1371. X
  1372. X        case MODE_KEYS:
  1373. X            RedrawKeys(display, playWindow);
  1374. X            break;
  1375. X
  1376. X        case MODE_BONUS:
  1377. X            RedrawBonus(display, mainWindow);
  1378. X            break;
  1379. X
  1380. X        case MODE_HIGHSCORE:
  1381. X            RedrawHighScore(display, playWindow);
  1382. X            break;
  1383. X
  1384. X        default:
  1385. X            break;
  1386. X    }
  1387. X
  1388. X    /* Redisplay the message and the level/score info */
  1389. X    RedrawLevelInfo(display, levelWindow);
  1390. X    DisplayCurrentMessage(display, messWindow);
  1391. X
  1392. X    /* To be sure - to be sure */
  1393. X    XFlush(display);
  1394. X}
  1395. X
  1396. X#if NeedFunctionPrototypes
  1397. Xvoid handleExposure(Display *display, XEvent event)
  1398. X#else
  1399. Xvoid handleExposure(display, event)
  1400. X    Display *display;
  1401. X    XEvent event;
  1402. X#endif
  1403. X{
  1404. X    /* Only redraw window once so wait until all expose events have sent
  1405. X     * and then redraw all that we need to redraw based on current game
  1406. X     * mode.
  1407. X     */
  1408. X    if (event.xexpose.count == 0)
  1409. X        SelectiveRedraw(display);
  1410. X}
  1411. X
  1412. X#if NeedFunctionPrototypes
  1413. Xvoid handleMouseButtons(Display *display, XEvent event, int Down)
  1414. X#else
  1415. Xvoid handleMouseButtons(display, event, Down)
  1416. X    Display *display;
  1417. X    XEvent event;
  1418. X    int Down;
  1419. X#endif
  1420. X{
  1421. X    if (Down == True)
  1422. X    {
  1423. X        /* Button pressed down */
  1424. X        switch(event.xbutton.button)
  1425. X        {
  1426. X            /* Shoot a bullet */
  1427. X            case Button1:
  1428. X            case Button2: 
  1429. X            case Button3:
  1430. X                /* If we are playing the game and a ball needs to be started
  1431. X                 * then start it otherwise shoot a bullet.
  1432. X                 */
  1433. X                if (mode == MODE_GAME)
  1434. X                    if (ActivateWaitingBall() == False)
  1435. X                        shootBullet(display, playWindow);
  1436. X                break;
  1437. X        }
  1438. X    }
  1439. X}
  1440. X
  1441. X#if NeedFunctionPrototypes
  1442. Xstatic void handleControlKeys(Display *display)
  1443. X#else
  1444. Xstatic void handleControlKeys(display)
  1445. X    Display *display;
  1446. X#endif
  1447. X{
  1448. X    /* Toggle game mode */
  1449. X    if (GetPaddleControlMode() == CONTROL_KEYS)
  1450. X    {
  1451. X        SetCurrentMessage(display, messWindow, 
  1452. X            "Control: Mouse", True);
  1453. X        SetPaddleControlMode(CONTROL_MOUSE);
  1454. X    }
  1455. X    else
  1456. X    {
  1457. X        SetCurrentMessage(display, messWindow, 
  1458. X            "Control: Keys", True);
  1459. X        SetPaddleControlMode(CONTROL_KEYS);
  1460. X    }
  1461. X
  1462. X    /* Play a bit of sound */
  1463. X    if (noSound == False)
  1464. X        playSoundFile("toggle", 50);
  1465. X}
  1466. X
  1467. X#if NeedFunctionPrototypes
  1468. Xstatic void handleSoundKey(Display *display)
  1469. X#else
  1470. Xstatic void handleSoundKey(display)
  1471. X    Display *display;
  1472. X#endif
  1473. X{
  1474. X    if (noSound == False)
  1475. X    {
  1476. X        /* Try and turn audio off */
  1477. X        FreeAudioSystem();
  1478. X
  1479. X        noSound = True;
  1480. X        SetCurrentMessage(display, messWindow, 
  1481. X            "- Audio OFF -", True);
  1482. X    }
  1483. X    else
  1484. X    {
  1485. X        /* Try and turn audio on */
  1486. X        if (SetUpAudioSystem(display) == False)
  1487. X        {
  1488. X            /* Unable to turn audio on */
  1489. X            noSound = True;
  1490. X            SetCurrentMessage(display, messWindow, 
  1491. X                "- Audio unavailable -", True);
  1492. X        }
  1493. X        else
  1494. X        {
  1495. X            /* Audio is now active */
  1496. X            noSound = False;
  1497. X            SetCurrentMessage(display, messWindow, 
  1498. X                "- Audio ON -", True);
  1499. X        }
  1500. X    }
  1501. X}
  1502. X
  1503. X#if NeedFunctionPrototypes
  1504. Xstatic void handleGameKeys(Display *display, KeySym keysym)
  1505. X#else
  1506. Xstatic void handleGameKeys(display, keysym)
  1507. X    Display *display;
  1508. X    KeySym keysym;
  1509. X#endif
  1510. X{
  1511. X    int temp;
  1512. X
  1513. X    /* Switch on the keysym */
  1514. X    switch (keysym)
  1515. X    {
  1516. X        case XK_d:    
  1517. X        case XK_D:    
  1518. X            /* Obtain an active ball - ie: not on paddle */
  1519. X            if ((temp = GetAnActiveBall()) >= 0)
  1520. X            {
  1521. X                /* Erase and reset ball to new one */
  1522. X                ClearBallNow(display, playWindow, temp);
  1523. X            }
  1524. X            break;
  1525. X
  1526. X        case XK_Left:
  1527. X        case XK_j:
  1528. X        case XK_J:
  1529. X            /* Set paddle to move left */
  1530. X            paddleMotion = -1;
  1531. X            break;
  1532. X
  1533. X        case XK_k:
  1534. X        case XK_K:
  1535. X            /* Shoot a bullet if available */
  1536. X            if (ActivateWaitingBall() == False)
  1537. X                shootBullet(display, playWindow);
  1538. X            break;
  1539. X
  1540. X        case XK_Right:
  1541. X        case XK_l:
  1542. X        case XK_L:
  1543. X            /* Set paddle to move right */
  1544. X            paddleMotion = 1;
  1545. X            break;
  1546. X
  1547. X        case XK_Escape:
  1548. X            /* Abort game and return to intros */
  1549. X            SetGameSpeed(FAST_SPEED);
  1550. X            ResetIntroduction();
  1551. X            mode = MODE_INTRO;
  1552. X
  1553. X            SetCurrentMessage(display, messWindow, 
  1554. X                "Game aborted.", True);
  1555. X            break;
  1556. X
  1557. X          case XK_minus:
  1558. X            if (debug == True)
  1559. X            {
  1560. X                SkipToNextLevel(display, playWindow);
  1561. X                SetCurrentMessage(display, messWindow,
  1562. X                    "Skipping to next level ...", True);
  1563. X            }
  1564. X            break;
  1565. X
  1566. X        case XK_p:
  1567. X        case XK_P:
  1568. X            ToggleGamePaused(display, mainWindow);
  1569. X            break;
  1570. X
  1571. X        default:     /* All other keys */
  1572. X            handleMiscKeys(display, keysym);
  1573. X    }
  1574. X}
  1575. X
  1576. X#if NeedFunctionPrototypes
  1577. Xstatic void handleIntroKeys(Display *display, KeySym keysym)
  1578. X#else
  1579. Xstatic void handleIntroKeys(display, keysym)
  1580. X    Display *display;
  1581. X    KeySym keysym;
  1582. X#endif
  1583. X{
  1584. X    /* Switch on the keysym */
  1585. X    switch (keysym)
  1586. X    {
  1587. X
  1588. X        case XK_space:
  1589. X            if (mode == MODE_INTRO || mode == MODE_HIGHSCORE 
  1590. X              || mode == MODE_INSTRUCT || mode == MODE_KEYS)
  1591. X            {
  1592. X                ResetBorderGlow(display, playWindow);
  1593. X                SetGameSpeed(FAST_SPEED);
  1594. X                gameActive = False;
  1595. X                mode = MODE_GAME;
  1596. X            }
  1597. X
  1598. X            if (mode == MODE_BONUS)
  1599. X                SetBonusWait(BONUS_FINISH, frame);
  1600. X            break;
  1601. X
  1602. X        case XK_c:
  1603. X        case XK_C:
  1604. X            /* Cycle through the introduction screens if note in a game */
  1605. X            if (mode == MODE_INTRO)
  1606. X            {
  1607. X                /* Ok - Goto the instructions mode */
  1608. X                SetGameSpeed(FAST_SPEED);
  1609. X                ResetInstructions();
  1610. X                mode = MODE_INSTRUCT;
  1611. X            } else if (mode == MODE_INSTRUCT)
  1612. X            {
  1613. X                /* Ok - Goto the keys mode */
  1614. X                SetGameSpeed(FAST_SPEED);
  1615. X                ResetKeys();
  1616. X                mode = MODE_KEYS;
  1617. X            } else if (mode == MODE_KEYS)
  1618. X            {
  1619. X                /* Ok - Goto the highscore mode */
  1620. X                SetGameSpeed(FAST_SPEED);
  1621. X                ResetHighScore(GLOBAL);
  1622. X                mode = MODE_HIGHSCORE;
  1623. X            } else if (mode == MODE_HIGHSCORE)
  1624. X            {
  1625. X                /* Ok - Goto back to the intro mode */
  1626. X                SetGameSpeed(FAST_SPEED);
  1627. X                ResetIntroduction();
  1628. X                mode = MODE_INTRO;
  1629. X            } 
  1630. X            break;
  1631. X
  1632. X        case XK_H:    /* Personal highscores */
  1633. X            if (mode == MODE_INTRO || mode == MODE_INSTRUCT 
  1634. X                || mode == MODE_KEYS || mode == MODE_HIGHSCORE)
  1635. X            {
  1636. X                /* Display the high scores thanks */
  1637. X                SetGameSpeed(FAST_SPEED);
  1638. X                ResetHighScore(PERSONAL);
  1639. X                mode = MODE_HIGHSCORE;
  1640. X
  1641. X                /* Play a bit of sound */
  1642. X                if (noSound == False)
  1643. X                    playSoundFile("toggle", 50);
  1644. X                
  1645. X            }
  1646. X            break;
  1647. X
  1648. X        case XK_h:    /* Global highscores */
  1649. X            if (mode == MODE_INTRO || mode == MODE_INSTRUCT 
  1650. X                || mode == MODE_KEYS || mode == MODE_HIGHSCORE)
  1651. X            {
  1652. X                SetGameSpeed(FAST_SPEED);
  1653. X                ResetHighScore(GLOBAL);
  1654. X                mode = MODE_HIGHSCORE;
  1655. X
  1656. X                /* Play a bit of sound */
  1657. X                if (noSound == False)
  1658. X                    playSoundFile("toggle", 50);
  1659. X            }
  1660. X            break;
  1661. X
  1662. X        case XK_s:
  1663. X        case XK_S:
  1664. X            if (mode == MODE_INTRO || mode == MODE_INSTRUCT 
  1665. X                || mode == MODE_KEYS || mode == MODE_HIGHSCORE)
  1666. X            {
  1667. X                /* toggle the special effects system */
  1668. X                if (getSpecialEffects(display) == True)
  1669. X                {
  1670. X                    /* Turn off special effects */
  1671. X                    useSpecialEffects(False);
  1672. X
  1673. X                    SetCurrentMessage(display, messWindow, 
  1674. X                        "- SFX OFF -", True);
  1675. X                }
  1676. X                else
  1677. X                {
  1678. X                    /* Cannot use sfx on this display */
  1679. X                    if (getSpecialEffects(display) == -1)
  1680. X                    {
  1681. X                        SetCurrentMessage(display, messWindow, 
  1682. X                            "- SFX Unavailable -", True);
  1683. X                    }
  1684. X                    else
  1685. X                    {
  1686. X                        /* Try and turn on special effects */
  1687. X                        useSpecialEffects(True);
  1688. X
  1689. X                        SetCurrentMessage(display, messWindow, 
  1690. X                            "- SFX ON -", True);
  1691. X                    }
  1692. X                }
  1693. X            }
  1694. X            break;
  1695. X
  1696. X        default:     /* All other keys */
  1697. X            handleMiscKeys(display, keysym);
  1698. X    }
  1699. X}
  1700. X#if NeedFunctionPrototypes
  1701. Xstatic void handleQuitKeys(Display *display, KeySym keysym)
  1702. X#else
  1703. Xstatic void handleQuitKeys(display, keysym)
  1704. X    Display *display;
  1705. X    KeySym keysym;
  1706. X#endif
  1707. X{
  1708. X    /* Switch on the keysym */
  1709. X    switch (keysym)
  1710. X    {
  1711. X        case XK_y:
  1712. X        case XK_Y:
  1713. X            /* Save out the scores if you were playing */
  1714. X            if (oldmode == MODE_GAME || oldmode == MODE_BONUS)
  1715. X            {
  1716. X                /* Save out scores when quitting */
  1717. X                UpdateHighScores();
  1718. X            }
  1719. X
  1720. X            /* Shut down and exit game */
  1721. X            ShutDown(display, 0, "Thank you for playing XBoing.");
  1722. X            break;
  1723. X
  1724. X        case XK_n:
  1725. X        case XK_N:
  1726. X            /* Change back to the previous mode */
  1727. X            SetCurrentMessage(display, messWindow, "Quit aborted!", True);
  1728. X            mode = oldmode;
  1729. X            break;
  1730. X
  1731. X        default:
  1732. X            /* Yes or No keys thanks */
  1733. X            XBell(display, 0);
  1734. X            break;
  1735. X    }
  1736. X}
  1737. X
  1738. X#if NeedFunctionPrototypes
  1739. Xstatic void handlePresentsKeys(Display *display, KeySym keysym)
  1740. X#else
  1741. Xstatic void handlePresentsKeys(display, keysym)
  1742. X    Display *display;
  1743. X    KeySym keysym;
  1744. X#endif
  1745. X{
  1746. X    /* Switch on the keysym */
  1747. X    switch (keysym)
  1748. X    {
  1749. X        case XK_space:
  1750. X            QuickFinish(display, mainWindow);
  1751. X            break;
  1752. X
  1753. X        case XK_Q:
  1754. X        case XK_q:
  1755. X            /* Shut down and exit game */
  1756. X            ShutDown(display, 0, "Thank you for playing XBoing.");
  1757. X            break;
  1758. X
  1759. X        default:
  1760. X            break;
  1761. X    }
  1762. X}
  1763. X
  1764. X
  1765. X#if NeedFunctionPrototypes
  1766. Xstatic void handleMiscKeys(Display *display, KeySym keysym)
  1767. X#else
  1768. Xstatic void handleMiscKeys(display, keysym)
  1769. X    Display *display;
  1770. X    KeySym keysym;
  1771. X#endif
  1772. X{
  1773. X    /* Switch on the keysym */
  1774. X    switch (keysym)
  1775. X    {
  1776. X        case XK_a:
  1777. X        case XK_A:
  1778. X            handleSoundKey(display);
  1779. X            break;
  1780. X
  1781. X        case XK_i:
  1782. X        case XK_I:
  1783. X            /* Iconify the window quickly - main loop handles events */
  1784. X            XIconifyWindow(display, mainWindow, 0);
  1785. X            break;
  1786. X
  1787. X        case XK_g:
  1788. X        case XK_G:
  1789. X            handleControlKeys(display);
  1790. X            break;
  1791. X
  1792. X        case XK_Q:
  1793. X        case XK_q:
  1794. X            /* Issue message and change to quit mode */
  1795. X            SetCurrentMessage(display, messWindow, 
  1796. X                "Really Quit? [Y/N]", False);
  1797. X            oldmode = mode;
  1798. X            mode = MODE_QUIT;
  1799. X            break;
  1800. X
  1801. X        case XK_1:    /* Set speed to speed 1 */
  1802. X            SetUserSpeed(9);
  1803. X            SetCurrentMessage(display, messWindow, "Warp 1", True);
  1804. X            if (noSound == False) playSoundFile("tone", 50);
  1805. X            break;
  1806. X
  1807. X        case XK_2:    /* Set speed to speed 2 */
  1808. X            SetUserSpeed(8);
  1809. X            SetCurrentMessage(display, messWindow, "Warp 2", True);
  1810. X            if (noSound == False) playSoundFile("tone", 50);
  1811. X            break;
  1812. X
  1813. X        case XK_3:    /* Set speed to speed 3 */
  1814. X            SetUserSpeed(7);
  1815. X            SetCurrentMessage(display, messWindow, "Warp 3", True);
  1816. X            if (noSound == False) playSoundFile("tone", 50);
  1817. X            break;
  1818. X
  1819. X        case XK_4:    /* Set speed to speed 4 */
  1820. X            SetUserSpeed(6);
  1821. X            SetCurrentMessage(display, messWindow, "Warp 4", True);
  1822. X            if (noSound == False) playSoundFile("tone", 50);
  1823. X            break;
  1824. X
  1825. X        case XK_5:    /* Set speed to speed 5 */
  1826. X            SetUserSpeed(5);
  1827. X            SetCurrentMessage(display, messWindow, "Warp 5", True);
  1828. X            if (noSound == False) playSoundFile("tone", 50);
  1829. X            break;
  1830. X
  1831. X        case XK_6:    /* Set speed to speed 6 */
  1832. X            SetUserSpeed(4);
  1833. X            SetCurrentMessage(display, messWindow, "Warp 6", True);
  1834. X            if (noSound == False) playSoundFile("tone", 50);
  1835. X            break;
  1836. X
  1837. X        case XK_7:    /* Set speed to speed 7 */
  1838. X            SetUserSpeed(3);
  1839. X            SetCurrentMessage(display, messWindow, "Warp 7", True);
  1840. X            if (noSound == False) playSoundFile("tone", 50);
  1841. X            break;
  1842. X
  1843. X        case XK_8:    /* Set speed to speed 8 */
  1844. X            SetUserSpeed(2);
  1845. X            SetCurrentMessage(display, messWindow, "Warp 8", True);
  1846. X            if (noSound == False) playSoundFile("tone", 50);
  1847. X            break;
  1848. X
  1849. X        case XK_9:    /* Set speed to speed 9 */
  1850. X            SetUserSpeed(1);
  1851. X            SetCurrentMessage(display, messWindow, "Warp 9", True);
  1852. X            if (noSound == False) playSoundFile("tone", 50);
  1853. X            break;
  1854. X
  1855. X        default:     /* All other keys */
  1856. X            break;
  1857. X    }
  1858. X}
  1859. X
  1860. X#if NeedFunctionPrototypes
  1861. Xvoid handleKeyPress(Display *display, KeySym keysym, int Pressed)
  1862. X#else
  1863. Xvoid handleKeyPress(display, keysym, Pressed)
  1864. X    Display *display;
  1865. X    KeySym keysym;
  1866. X    int Pressed;
  1867. X#endif
  1868. X{
  1869. X
  1870. X    if (Pressed == False)
  1871. X    {
  1872. X        /* key was released */
  1873. X        paddleMotion = 0;
  1874. X    }
  1875. X    else
  1876. X    {
  1877. X        /* Switch on the game mode */
  1878. X        switch (mode)
  1879. X        {
  1880. X            case MODE_QUIT:
  1881. X                handleQuitKeys(display, keysym);
  1882. X                break;
  1883. X
  1884. X            case MODE_WAIT:
  1885. X            case MODE_BALL_WAIT:
  1886. X            case MODE_PAUSE:
  1887. X            case MODE_GAME:
  1888. X                handleGameKeys(display, keysym);
  1889. X                break;
  1890. X
  1891. X            case MODE_HIGHSCORE:
  1892. X            case MODE_BONUS:
  1893. X            case MODE_INTRO:
  1894. X            case MODE_INSTRUCT:
  1895. X            case MODE_KEYS:
  1896. X                handleIntroKeys(display, keysym);
  1897. X                break;
  1898. X
  1899. X            case MODE_PRESENTS:
  1900. X                handlePresentsKeys(display, keysym);
  1901. X                break;
  1902. X
  1903. X            case MODE_NONE:
  1904. X                break;
  1905. X        }
  1906. X    }
  1907. X}
  1908. X
  1909. X
  1910. X
  1911. X#if NeedFunctionPrototypes
  1912. Xstatic void handleGameMode(Display *display)
  1913. X#else
  1914. Xstatic void handleGameMode(display)
  1915. X    Display *display;
  1916. X#endif
  1917. X{
  1918. X    static int bonusRow = 0;
  1919. X    static int bonusCol = 0;
  1920. X    static int nextBonusFrame = 0;
  1921. X
  1922. X    /* If we are going to play then setup first level */
  1923. X    if (gameActive == False)
  1924. X    {
  1925. X        /* Choose a random velocity for the ball */
  1926. X
  1927. X        /* Always start at level 1 or level specified */
  1928. X        SetLevelNumber(GetStartingLevel());
  1929. X
  1930. X        /* Set some important variables */
  1931. X        livesLeft             = 3;
  1932. X        score                 = 0;
  1933. X        nextBonusFrame         = 0;
  1934. X        currentPaddleSize     = PADDLE_HUGE;
  1935. X        pausedTime            = 0;
  1936. X        bonusBlock             = False;
  1937. X
  1938. X        /* Setup the stage and load 1st level */
  1939. X        SetupStage(display, playWindow);
  1940. X
  1941. X        /* Start game play */
  1942. X        gameActive = True;
  1943. X
  1944. X        /* Keep track of the game duration - shown in highscores */
  1945. X        gameTime = time(NULL);
  1946. X    }
  1947. X
  1948. X    /* If we need to move the paddle then do so */
  1949. X    if ((frame % PADDLE_ANIMATE_DELAY) == 0)
  1950. X        handlePaddleMoving(display);
  1951. X
  1952. X    if (mode == MODE_GAME)
  1953. X    {
  1954. X        HandleBallMode(display, playWindow);
  1955. X
  1956. X        /* Add bonus coin block at random intervals */
  1957. X        if (nextBonusFrame == 0 && bonusBlock == False)
  1958. X            nextBonusFrame = frame + (rand() % BONUS_SEED);
  1959. X
  1960. X        /* Do we need to add a bonus coin? */
  1961. X        if (nextBonusFrame <= frame && bonusBlock == False)
  1962. X        {
  1963. X            /* Add the bonus block now - different types */
  1964. X            switch (rand() % 10)
  1965. X            {
  1966. X                case 0: case 1: 
  1967. X                case 2: case 3: 
  1968. X                case 4: case 5: 
  1969. X                case 6: case 7:
  1970. X                    /* Add a normal bonus block */
  1971. X                    AddBonusBlock(display, playWindow, &bonusRow, &bonusCol, 
  1972. X                        BONUS_BLK);
  1973. X                    break;
  1974. X
  1975. X                case 8:
  1976. X                    /* Add the x2 bonus block */
  1977. X                    AddBonusBlock(display, playWindow, &bonusRow, &bonusCol, 
  1978. X                        BONUSX2_BLK);
  1979. X                    break;
  1980. X
  1981. X                case 9:
  1982. X                    /* Add the x4 bonus block */
  1983. X                    AddBonusBlock(display, playWindow, &bonusRow, &bonusCol, 
  1984. X                        BONUSX4_BLK);
  1985. X                    break;
  1986. X
  1987. X            }
  1988. X
  1989. X            nextBonusFrame = 0;
  1990. X        }
  1991. X    }
  1992. X
  1993. X    HandleBulletMode(display, playWindow);
  1994. X
  1995. X    /* If any blocks need exploding then do so */
  1996. X    ExplodeBlocksPending(display, playWindow);
  1997. X
  1998. X    /* So blocks need animation all the time so do it */
  1999. X    HandlePendingAnimations(display, playWindow);
  2000. X
  2001. X    /* See if the level is finished and update level info if needed */
  2002. X    if (mode == MODE_GAME)
  2003. X        CheckGameRules(display, playWindow);
  2004. X}
  2005. X
  2006. X#if NeedFunctionPrototypes
  2007. Xstatic void handleGameStates(Display *display)
  2008. X#else
  2009. Xstatic void handleGameStates(display)
  2010. X    Display *display;
  2011. X#endif
  2012. X{
  2013. X    /* Update the message window if any new messages come along */
  2014. X    DisplayCurrentMessage(display, messWindow);
  2015. X
  2016. X    /* In game effects */
  2017. X    switch (currentSfxMode())
  2018. X    {
  2019. X        case SFX_SHAKE:
  2020. X            /* Something exploded or bumped the screen */
  2021. X            WindowShakeEffect(display, playWindow);
  2022. X            break;
  2023. X
  2024. X        case SFX_FADE:
  2025. X            /* fade when play arena is taken off screen */
  2026. X            WindowFadeEffect(display, playWindow);
  2027. X            break;
  2028. X            
  2029. X        case SFX_BLIND:
  2030. X            /* bring the backing buffer pixmap into view via a blind effect */
  2031. X            WindowBlindEffect(display, playWindow);
  2032. X            break;
  2033. X            
  2034. X        case SFX_SHATTER:
  2035. X            /* bring the backing buffer pixmap into view via a blind effect */
  2036. X            WindowShatterEffect(display, playWindow);
  2037. X            break;
  2038. X            
  2039. X        case SFX_NONE:
  2040. X        default:
  2041. X            break;
  2042. X    }
  2043. X
  2044. X    /* Switch on the current game mode */
  2045. X    switch (mode)
  2046. X    {
  2047. X        case MODE_GAME:
  2048. X            handleGameMode(display);
  2049. X            break;
  2050. X
  2051. X        case MODE_PRESENTS:
  2052. X            Presents(display, mainWindow);
  2053. X            break;
  2054. X
  2055. X        case MODE_BONUS:
  2056. X            DoBonus(display, mainWindow);
  2057. X            break;
  2058. X
  2059. X        case MODE_INTRO:
  2060. X            Introduction(display, playWindow);
  2061. X            break;
  2062. X
  2063. X        case MODE_INSTRUCT:
  2064. X            Instructions(display, playWindow);
  2065. X            break;
  2066. X
  2067. X        case MODE_KEYS:
  2068. X            Keys(display, playWindow);
  2069. X            break;
  2070. X
  2071. X        case MODE_HIGHSCORE:
  2072. X            HighScore(display, playWindow);
  2073. X            break;
  2074. X
  2075. X        case MODE_PAUSE:
  2076. X        case MODE_QUIT:
  2077. X            break;
  2078. X    }
  2079. X
  2080. X    /* Flush the display */
  2081. X    XFlush(display);
  2082. X}
  2083. X
  2084. X#if NeedFunctionPrototypes
  2085. Xstatic void handleEventLoop(Display *display)
  2086. X#else
  2087. Xstatic void handleEventLoop(display)
  2088. X    Display *display;
  2089. X#endif
  2090. X{
  2091. X    XEvent event;
  2092. X    int pending;
  2093. X    KeySym keysym;
  2094. X
  2095. X    pending = frame = 0;
  2096. X
  2097. X    /* Initial mode for game is Introduction */
  2098. X    mode = MODE_PRESENTS;
  2099. X
  2100. X    /* No special effects yet */
  2101. X    changeSfxMode(SFX_NONE);
  2102. X
  2103. X    /* Flush all events until app is fully mapped */
  2104. X    do
  2105. X    {
  2106. X        /* handle audio device events if they exist */
  2107. X        audioDeviceEvents();
  2108. X
  2109. X        /* Get the next event */
  2110. X        XNextEvent(display, &event);
  2111. X    }
  2112. X    while (event.type != MapNotify);
  2113. X
  2114. X    /* Grab the pointer to the main window */
  2115. X    GrabPointer(display, mainWindow);
  2116. X
  2117. X    /* Loop forever and ever */
  2118. X    while (True)
  2119. X    {
  2120. X        /* handle and audio device events if supported */
  2121. X        audioDeviceEvents();
  2122. X
  2123. X        /* Sleep a bit if not iconified */
  2124. X        if (iconified == False)
  2125. X            sleepSync(display, speed);
  2126. X
  2127. X        /* See if any events are waiting for me to handle */
  2128. X        if (iconified == False && mode != MODE_PAUSE)
  2129. X        {
  2130. X            /* Get an event but don't wait if none arrives */
  2131. X            pending = XPending(display);
  2132. X            frame++;
  2133. X        }
  2134. X        else
  2135. X        {
  2136. X            /* Wait here for an event and then get the number waiting */
  2137. X            XPeekEvent(display, &event);
  2138. X            pending = XPending(display);
  2139. X        }
  2140. X        
  2141. X        /* Handle any events pending */
  2142. X        while (pending > 0)
  2143. X        {
  2144. X            /* Get the next X event thanks */
  2145. X            XNextEvent(display, &event);
  2146. X
  2147. X            switch(event.type)
  2148. X            {
  2149. X                case UnmapNotify:
  2150. X                    /* Turn off just all events except the mapping ones */
  2151. X                    XSelectInput(display, mainWindow, StructureNotifyMask);
  2152. X                    handleIconify(display, (XUnmapEvent *) &event);
  2153. X                    iconified = True;
  2154. X                    break;
  2155. X
  2156. X                case MapNotify:
  2157. X                    /* Turn back on all the events that are needed */
  2158. X                    XSelectInput(display, mainWindow, 
  2159. X                        KeyPressMask | KeyReleaseMask | ButtonPressMask |
  2160. X                           ButtonReleaseMask | ExposureMask | StructureNotifyMask);
  2161. X
  2162. X                    SelectiveRedraw(display);
  2163. X                     GrabPointer(display, mainWindow);
  2164. X                    iconified = False;
  2165. X
  2166. X                    break;
  2167. X
  2168. X                case ButtonRelease:
  2169. X                    handleMouseButtons(display, event, False);
  2170. X                    break;
  2171. X
  2172. X                case ButtonPress:
  2173. X                    handleMouseButtons(display, event, True);
  2174. X                    break;
  2175. X
  2176. X                case KeyRelease:
  2177. X                    keysym = GetKeySym(event);
  2178. X                    handleKeyPress(display, keysym, False);
  2179. X                    break;
  2180. X
  2181. X                case KeyPress:
  2182. X                    keysym = GetKeySym(event);
  2183. X                    handleKeyPress(display, keysym, True);
  2184. X                    break;
  2185. X
  2186. X                case Expose:
  2187. X                    handleExposure(display, event);
  2188. X                    break;
  2189. X
  2190. X                default:
  2191. X                    break;
  2192. X            }
  2193. X
  2194. X            /* Decrement the number of pending events */
  2195. X            pending--;
  2196. X        }
  2197. X
  2198. X        /* handle all game states and animations */
  2199. X        if (iconified == False) 
  2200. X            handleGameStates(display);
  2201. X    }
  2202. X
  2203. X    /* NOT REACHED */
  2204. X}
  2205. X
  2206. X#if NeedFunctionPrototypes
  2207. Xvoid main(int argc, char **argv)
  2208. X#else
  2209. Xvoid main(argc, argv)
  2210. X    int argc;
  2211. X    char **argv;
  2212. X#endif
  2213. X{
  2214. X    static Display *display;
  2215. X
  2216. X    /* Initialise everything and return display */
  2217. X    display = InitialiseGame(argv, argc);
  2218. X
  2219. X    SetGameSpeed(FAST_SPEED);
  2220. X    gameActive = False;
  2221. X    iconified = False;
  2222. X
  2223. X    /* main event loop */
  2224. X    handleEventLoop(display);
  2225. X
  2226. X    /* NOTREACHED */
  2227. X}
  2228. END_OF_FILE
  2229. if test 25219 -ne `wc -c <'main.c'`; then
  2230.     echo shar: \"'main.c'\" unpacked with wrong size!
  2231. fi
  2232. # end of 'main.c'
  2233. fi
  2234. echo shar: End of archive 12 \(of 30\).
  2235. cp /dev/null ark12isdone
  2236. MISSING=""
  2237. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ; do
  2238.     if test ! -f ark${I}isdone ; then
  2239.     MISSING="${MISSING} ${I}"
  2240.     fi
  2241. done
  2242. if test "${MISSING}" = "" ; then
  2243.     echo You have unpacked all 30 archives.
  2244.     echo "Now execute sdecode.sh to build files."
  2245.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2246. else
  2247.     echo You still need to unpack the following archives:
  2248.     echo "        " ${MISSING}
  2249. fi
  2250. ##  End of shell archive.
  2251. exit 0
  2252.