home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume18 / xboing / part05 / keys.c
C/C++ Source or Header  |  1993-09-13  |  9KB  |  375 lines

  1. #include "include/copyright.h"
  2.  
  3. /*
  4.  *  Include file dependencies:
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <stddef.h>
  10. #include <X11/Xlib.h>
  11. #include <X11/Xutil.h>
  12. #include <X11/Xos.h>
  13. #include <xpm.h>
  14.  
  15. #include "bitmaps/mouse.xpm"
  16. #include "bitmaps/leftarrow.xpm"
  17. #include "bitmaps/rightarrow.xpm"
  18.  
  19. #include "include/error.h"
  20. #include "include/highscore.h"
  21. #include "include/special.h"
  22. #include "include/misc.h"
  23. #include "include/sfx.h"
  24. #include "include/main.h"
  25. #include "include/init.h"
  26. #include "include/stage.h"
  27. #include "include/blocks.h"
  28. #include "include/ball.h"
  29. #include "include/score.h"
  30. #include "include/paddle.h"
  31. #include "include/level.h"
  32. #include "include/mess.h"
  33. #include "include/version.h"
  34. #include "include/audio.h"
  35. #include "include/intro.h"
  36.  
  37. #include "include/keys.h"
  38.  
  39. /*
  40.  *  Internal macro definitions:
  41.  */
  42.  
  43. #define GAP 12
  44.  
  45. /*
  46.  *  Internal type declarations:
  47.  */
  48.  
  49. #if NeedFunctionPrototypes
  50. static void DoKeysWait(void);
  51. #else
  52. static void DoKeysWait();
  53. #endif
  54.  
  55.  
  56. /*
  57.  *  Internal variable declarations:
  58.  */
  59.  
  60. static int endFrame = 0;
  61. static int startFrame = 0;
  62. enum KeysStates KeysState;
  63. static int waitingFrame, waitMode;
  64. static Pixmap mouse, leftarrow, rightarrow;
  65. static Pixmap mouseM, leftarrowM, rightarrowM;
  66.  
  67. #if NeedFunctionPrototypes
  68. void SetUpKeys(Display *display, Window window, Colormap colormap)
  69. #else
  70. void SetUpKeys(display, window, colormap)
  71.     Display *display;
  72.     Window window;
  73.     Colormap colormap;
  74. #endif
  75. {
  76.     XpmAttributes   attributes;
  77.     int             XpmErrorStatus;
  78.  
  79.     attributes.valuemask = XpmColormap;
  80.     attributes.colormap = colormap;
  81.  
  82.     XpmErrorStatus = XpmCreatePixmapFromData(display, window, mouse_xpm,
  83.         &mouse, &mouseM, &attributes);
  84.     HandleXPMError(display, XpmErrorStatus, "InitialiseKeys(mouse)");
  85.  
  86.     XpmErrorStatus = XpmCreatePixmapFromData(display, window, leftarrow_xpm,
  87.         &leftarrow, &leftarrowM, &attributes);
  88.     HandleXPMError(display, XpmErrorStatus, "InitialiseKeys(leftarrow)");
  89.  
  90.     XpmErrorStatus = XpmCreatePixmapFromData(display, window, rightarrow_xpm,
  91.         &rightarrow, &rightarrowM, &attributes);
  92.     HandleXPMError(display, XpmErrorStatus, "InitialiseKeys(rightarrow)");
  93.  
  94.     /* Free the xpm pixmap attributes */
  95.     XpmFreeAttributes(&attributes);
  96.  
  97.     ResetKeys();
  98. }
  99.  
  100. #if NeedFunctionPrototypes
  101. static void DoText(Display *display, Window window)
  102. #else
  103. static void DoText(display, window)
  104.     Display *display;
  105.     Window window;
  106. #endif
  107. {
  108.     char string[80];
  109.     int y;
  110.     int x;
  111.  
  112.     DrawShadowCentredText(display, window, titleFont, 
  113.         "- Game Controls -", 140, red, PLAY_WIDTH);
  114.  
  115.     SetCurrentMessage(display, messWindow, "Don`t use drugs!", False);
  116.  
  117.     y = 190;
  118.  
  119.     DrawLine(display, window, 32, y+2, PLAY_WIDTH - 28, y+2, black, 3);
  120.     DrawLine(display, window, 30, y, PLAY_WIDTH - 30, y, white, 3);
  121.     y += textFont->ascent + GAP/2;
  122.  
  123.     x = (PLAY_WIDTH / 2) - 17 - 10 - 35;
  124.     RenderShape(display, window, leftarrow, leftarrowM,
  125.         x, y + 28, 35, 19, True);
  126.  
  127.     DrawShadowText(display, window, textFont, "Paddle left", 
  128.         x - 40 - 60, y + 28, green);
  129.  
  130.     x = (PLAY_WIDTH / 2) - 17;
  131.     RenderShape(display, window, mouse, mouseM,
  132.         x, y, 35, 57, True);
  133.  
  134.     x = (PLAY_WIDTH / 2) + 17 + 10;
  135.     RenderShape(display, window, rightarrow, rightarrowM,
  136.         x, y + 28, 35, 19, True);
  137.  
  138.     DrawShadowText(display, window, textFont, "Paddle right", 
  139.         x + 40, y + 28, green);
  140.  
  141.     y = 290;
  142.     x = 30;
  143.  
  144.     strcpy(string, "<s> = Sfx On/Off");
  145.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  146.     y += textFont->ascent + GAP;
  147.  
  148.     strcpy(string, "<P> = Pause/Resume");
  149.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  150.     y += textFont->ascent + GAP;
  151.  
  152.     strcpy(string, "<I> = Iconify Quickly");
  153.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  154.     y += textFont->ascent + GAP;
  155.  
  156.     strcpy(string, "<h> = Roll of Honour");
  157.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  158.     y += textFont->ascent + GAP;
  159.  
  160.     strcpy(string, "<H> = Personal scores");
  161.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  162.     y += textFont->ascent + GAP;
  163.  
  164.     strcpy(string, "<d> = Kill Ball");
  165.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  166.     y += textFont->ascent + GAP;
  167.  
  168.     strcpy(string, "<q> = Quit XBoing");
  169.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  170.     y += textFont->ascent + GAP;
  171.  
  172.     y = 290;
  173.     x = 280;
  174.  
  175.     strcpy(string, "<j> = Paddle left");
  176.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  177.     y += textFont->ascent + GAP;
  178.  
  179.     strcpy(string, "<k> = Shoot");
  180.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  181.     y += textFont->ascent + GAP;
  182.  
  183.     strcpy(string, "<l> = Paddle right");
  184.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  185.     y += textFont->ascent + GAP;
  186.  
  187.     strcpy(string, "<a> = Audio On/Off");
  188.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  189.     y += textFont->ascent + GAP;
  190.  
  191.     strcpy(string, "<c> = Cycle intros");
  192.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  193.     y += textFont->ascent + GAP;
  194.  
  195.     strcpy(string, "<g> = Toggle control");
  196.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  197.     y += textFont->ascent + GAP;
  198.  
  199.     strcpy(string, "<1-9> = Game speed");
  200.     DrawShadowText(display, window, textFont, string, x, y, yellow);
  201.     y += textFont->ascent + GAP * 2;
  202.  
  203.     DrawLine(display, window, 32, y+2, PLAY_WIDTH - 28, y+2, black, 3);
  204.     DrawLine(display, window, 30, y, PLAY_WIDTH - 30, y, white, 3);
  205.  
  206.     strcpy(string, "Press <Space> to start game");
  207.     DrawShadowCentredText(display, window, textFont, string, 
  208.         PLAY_HEIGHT - 40, tann, PLAY_WIDTH);
  209. }
  210.  
  211. #if NeedFunctionPrototypes
  212. static void DoSparkle(Display *display, Window window)
  213. #else
  214. static void DoSparkle(display, window)
  215.     Display *display;
  216.     Window window;
  217. #endif
  218. {
  219.     static Pixmap store;
  220.     static int x = 100;
  221.     static int y = 20;
  222.     static int in = 0;
  223.  
  224.     if (frame >= endFrame)
  225.         KeysState = KEYS_FINISH;
  226.  
  227.     if (!store)
  228.     {
  229.         store = XCreatePixmap(display, window, 20, 20,
  230.             DefaultDepth(display, XDefaultScreen(display)));
  231.     }
  232.  
  233.     if (in == 0) 
  234.         XCopyArea(display, window, store, gc, x, y, 20, 20, 0, 0);
  235.  
  236.     if (frame == startFrame)
  237.     {
  238.         RenderShape(display, window, stars[in], starsM[in],
  239.             x, y, 20, 20, False);
  240.  
  241.          in++;
  242.         startFrame = frame + 15;
  243.  
  244.         if (in == 11) 
  245.         {
  246.             XCopyArea(display, store, window, gc, 0, 0, 20, 20, x, y);
  247.             in = 0;
  248.             startFrame = frame + 500;
  249.             x = (rand() % 474) + 5;
  250.             y = (rand() % 74) + 5;
  251.         }    
  252.     }
  253. }
  254.  
  255. #if NeedFunctionPrototypes
  256. static void DoFinish(Display *display, Window window)
  257. #else
  258. static void DoFinish(display, window)
  259.     Display *display;
  260.     Window window;
  261. #endif
  262. {
  263.     static int toggle = GLOBAL;
  264.  
  265.     ResetHighScore(toggle);
  266.     mode = MODE_HIGHSCORE;
  267.  
  268.     /* Switch between the global highscores and personal version */
  269.     if (toggle == GLOBAL)
  270.         toggle = PERSONAL;
  271.     else
  272.         toggle = GLOBAL;
  273.  
  274.     if (noSound == False)
  275.         playSoundFile("weeek", 100);
  276. }
  277.  
  278.  
  279. #if NeedFunctionPrototypes
  280. void Keys(Display *display, Window window)
  281. #else
  282. void Keys(display, window)
  283.     Display *display;
  284.     Window window;
  285. #endif
  286. {
  287.     switch (KeysState)
  288.     {
  289.         case KEYS_TITLE:
  290.             if (getSpecialEffects(display) == True)
  291.                 DoIntroTitle(display, bufferWindow);
  292.             else
  293.                 DoIntroTitle(display, window);
  294.             KeysState = KEYS_TEXT;
  295.             break;
  296.  
  297.         case KEYS_TEXT:
  298.             if (getSpecialEffects(display) == True)
  299.             {
  300.                 DoText(display, bufferWindow);
  301.                 while (WindowShatterEffect(display, window));
  302.             }
  303.             else
  304.                 DoText(display, window);
  305.             KeysState = KEYS_SPARKLE;
  306.             break;
  307.  
  308.         case KEYS_SPARKLE:
  309.             DoSparkle(display, window);
  310.             BorderGlow(display, window);
  311.             if ((frame % FLASH) == 0)
  312.                 RandomDrawSpecials(display);
  313.             break;
  314.  
  315.         case KEYS_FINISH:
  316.             DoFinish(display, window);
  317.             break;
  318.  
  319.         case KEYS_WAIT:
  320.             DoKeysWait();
  321.             break;
  322.  
  323.         default:
  324.             break;
  325.     }
  326. }
  327.  
  328. #if NeedFunctionPrototypes
  329. void RedrawKeys(Display *display, Window window)
  330. #else
  331. void RedrawKeys(display, window)
  332.     Display *display;
  333.     Window window;
  334. #endif
  335. {
  336.     DoIntroTitle(display, window);
  337.     DoText(display, window);
  338. }
  339.  
  340. #if NeedFunctionPrototypes
  341. void FreeKeyControl(Display *display)
  342. #else
  343. void FreeKeyControl(display)
  344.     Display *display;
  345. #endif
  346. {
  347.     if (mouse)             XFreePixmap(display, mouse);
  348.     if (mouseM)         XFreePixmap(display, mouseM);
  349.     if (leftarrow)        XFreePixmap(display, leftarrow);
  350.     if (leftarrowM)        XFreePixmap(display, leftarrowM);
  351.     if (rightarrow)        XFreePixmap(display, rightarrow);
  352.     if (rightarrowM)       XFreePixmap(display, rightarrowM);
  353. }
  354.  
  355. #if NeedFunctionPrototypes
  356. void ResetKeys(void)
  357. #else
  358. void ResetKeys()
  359. #endif
  360. {
  361.     KeysState = KEYS_TITLE;
  362.     startFrame     = frame + 100;
  363.     endFrame     = frame + 4000;
  364. }
  365.  
  366. #if NeedFunctionPrototypes
  367. static void DoKeysWait(void)
  368. #else
  369. static void DoKeysWait()
  370. #endif
  371. {
  372.     if (frame == waitingFrame)
  373.         KeysState = waitMode;
  374. }
  375.