home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / xjewel / intro.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  6.4 KB  |  268 lines

  1. /*
  2. **
  3. **    X11 Jewel By David Cooper and Jose Guterman 05/92
  4. **
  5. */
  6.  
  7. #ifdef VMS
  8. #include <decw$include/Xlib.h>
  9. #include <decw$include/Xutil.h>
  10. #include <decw$include/Xos.h>
  11. #else
  12. #include <X11/Xlib.h>
  13. #include <X11/Xutil.h>
  14. #include <X11/Xos.h>
  15. #endif
  16. #include <stdlib.h>
  17.  
  18. #include "general.h"
  19. #include "logic.h"
  20. #include "jewel.h"
  21. #include "xhscore.h"
  22. #include "xw.h"
  23.  
  24. static enum IStates { PRESENT, LOGO, BY, SHINE, FINI} IntroState;
  25.  
  26.  
  27. #define PRES_FONT "-*-*-bold-o-*-*-24-*-*-*-p-*-iso8859-1"
  28. #define PRESENT_LOC_X 100
  29. #define PRESENT_LOC_Y 100
  30. static char *PresentString="Presenting...";
  31. #define THANK_LOC_Y 500
  32. static char *ThankString="Originally by Yoshihiro Satoh of hp";
  33. #define PHASE_LOC_X ((SCREEN_X-biglogo_width)/2)
  34. #define PHASE_LOC_Y 300
  35.  
  36.  
  37. #define NUM_SHINE 4
  38. #define STEP 2
  39. #define YELSTEP 20
  40. #define SHINESTEP 10
  41. #include "bitmaps/biglogo.xbm"
  42. static GC GreenGC, YelGC, PresGC;
  43. static XFontStruct *PresFont;
  44. static Pixmap BigLogoPM;
  45. static int count=0;
  46. static int ShineX=0;
  47. static BOOL dir_forward=0;
  48. #define LM (biglogo_width/2)
  49. #define XM (PHASE_LOC_X + LM)
  50. #define GWIDTH ((biglogo_width/STEP)+1)
  51. #define GHEIGHT ((biglogo_height/STEP)+1)
  52.  
  53. void Start_Intro()
  54.     {
  55.     if (JewelState != NULL_STATE)
  56.         { XClearWindow(xw_display, xw_window); }
  57.  
  58.     IntroState=PRESENT;
  59.     JewelState=INTRO;
  60.  
  61.     count=0;
  62.     xw_set_timer(200L);
  63.     }
  64.  
  65. void Intro_Timeout()
  66.     {
  67.     switch(IntroState)
  68.         {
  69.         case PRESENT:
  70.             /* start logo */
  71.             count++;
  72.             if (count <= strlen(PresentString))
  73.                 {
  74.                 XDrawString(xw_display, xw_window, PresGC, PRESENT_LOC_X,
  75.                     PRESENT_LOC_Y+((PresFont->ascent)*3/2),
  76.                     PresentString, count);
  77.                 XFlush(xw_display);
  78.                 }
  79.             else
  80.                 {
  81.                 IntroState=LOGO;
  82.                 /* set up */
  83.                 count=0;
  84.                 }
  85.             xw_set_timer(200L);
  86.             break;
  87.         case LOGO:
  88.             /* put more logo up */
  89.             XCopyPlane(xw_display, BigLogoPM, xw_window, GreenGC,
  90.                 (LM-count*STEP), 0, STEP, biglogo_height,
  91.                 (XM-count*STEP), PHASE_LOC_Y, 1L);
  92.             
  93.             XCopyPlane(xw_display, BigLogoPM, xw_window, GreenGC,
  94.                 (LM+count*STEP), 0, STEP, biglogo_height,
  95.                 (XM+count*STEP), PHASE_LOC_Y, 1L);
  96.             
  97.             XCopyPlane(xw_display, BigLogoPM, xw_window, YelGC,
  98.                 (LM-count*STEP)-YELSTEP, 0, YELSTEP, biglogo_height,
  99.                 (XM-count*STEP)-YELSTEP, PHASE_LOC_Y, 1L);
  100.  
  101.             XCopyPlane(xw_display, BigLogoPM, xw_window, YelGC,
  102.                 (LM+count*STEP)+STEP, 0, YELSTEP, biglogo_height,
  103.                 (XM+count*STEP)+STEP, PHASE_LOC_Y, 1L);
  104.             XFlush(xw_display);
  105.  
  106.             count++;
  107.  
  108.             XFlush(xw_display);
  109.             if (count < (GWIDTH/2))
  110.                 { xw_set_timer(2L); }
  111.             else
  112.                 {
  113.                 IntroState=BY;
  114.                 xw_set_timer(200L);
  115.                 }
  116.             break;
  117.         case BY:
  118.             {
  119.             XCharStruct Sizes;
  120.             int dir, asc, dsc;
  121.  
  122.             XTextExtents(VerFont,ThankString, strlen(ThankString),
  123.                 &dir,&asc,&dsc,&Sizes);
  124.             XDrawImageString(xw_display, xw_window, VerGC,
  125.                 (SCREEN_X - Sizes.width)/2,
  126.                 THANK_LOC_Y+((VerFont->ascent)*3/2),
  127.                 ThankString, strlen(ThankString));
  128.  
  129.             XTextExtents(VerFont,StartString, strlen(StartString),
  130.                 &dir,&asc,&dsc,&Sizes);
  131.             XDrawImageString(xw_display, xw_window, VerGC,
  132.                 (SCREEN_X - Sizes.width)/2,
  133.                 START_LOC_Y+((VerFont->ascent)*3/2),
  134.                 StartString, strlen(StartString));
  135.  
  136.             XDrawImageString(xw_display, xw_window, VerGC, VER_LOC_X,
  137.                 VER_LOC_Y+((VerFont->ascent)*3/2),
  138.                 VerString, strlen(VerString));
  139.             XFlush(xw_display);
  140.             count=0;
  141.             ShineX=0;
  142.             dir_forward=TRUE;
  143.             IntroState=SHINE;
  144.             xw_set_timer(200L);
  145.             }
  146.             break;
  147.         case SHINE:
  148.             XCopyPlane(xw_display, BigLogoPM, xw_window, GreenGC,
  149.                 (ShineX+ ((dir_forward)?0:SHINESTEP)), 0,
  150.                 STEP, biglogo_height,
  151.                 (ShineX+PHASE_LOC_X + ((dir_forward)?0:SHINESTEP)),
  152.                 PHASE_LOC_Y, 1L);
  153.             
  154.             XCopyPlane(xw_display, BigLogoPM, xw_window, YelGC,
  155.                 (ShineX+((dir_forward)?STEP:0)), 0,
  156.                 SHINESTEP, biglogo_height,
  157.                 (ShineX+PHASE_LOC_X+((dir_forward)?STEP:0)),
  158.                 PHASE_LOC_Y, 1L);
  159.  
  160.             XFlush(xw_display);
  161.  
  162.             ShineX+=((dir_forward)?(STEP):(-STEP));
  163.             xw_set_timer(2L);
  164.             if (ShineX>biglogo_width)
  165.                 {
  166.                 ShineX=biglogo_width;
  167.                 dir_forward=FALSE;
  168.                 }
  169.             if (ShineX<0)
  170.                 {
  171.                 ShineX=0;
  172.                 dir_forward=TRUE;
  173.                 count++;
  174.                 if (count>NUM_SHINE)
  175.                     {
  176.                     IntroState=FINI;
  177.                     xw_set_timer(1000L);
  178.                     }
  179.                 }
  180.             break;
  181.         case FINI:
  182.             Set_State_High_Score();
  183.             JewelState=HIGHSCORE;
  184.             break;
  185.         }
  186.     }
  187.  
  188. void Init_Intro()
  189.     {
  190.     XGCValues gcv;
  191.     unsigned long gcvm;
  192.     
  193.     gcvm=(GCGraphicsExposures | GCForeground | GCBackground | GCPlaneMask);
  194.  
  195.     gcv.graphics_exposures=False;
  196.     gcv.plane_mask=(green | yellow | black);
  197.     gcv.foreground=yellow;
  198.     gcv.background=black;
  199.     YelGC=XCreateGC(xw_display, xw_window, gcvm, &gcv);
  200.     gcv.foreground=green;
  201.     GreenGC=XCreateGC(xw_display, xw_window, gcvm, &gcv);
  202.  
  203.     BigLogoPM=XCreateBitmapFromData(xw_display, xw_window,
  204.                 biglogo_bits, biglogo_width, biglogo_height);
  205.  
  206.     if ( (PresFont=XLoadQueryFont(xw_display,PRES_FONT)) == NULL)
  207.         { xw_fatal("Cannot load PRESENT font.\n",__LINE__,__FILE__); }
  208.     gcvm|=GCFont;
  209.     gcv.font=PresFont->fid;
  210.     gcv.foreground=yellow;
  211.     PresGC=XCreateGC(xw_display, xw_window, gcvm, &gcv);
  212.     }
  213.  
  214. void Expose_Intro()
  215.     {
  216.     switch(IntroState)
  217.         {
  218.         case PRESENT:
  219.             XDrawString(xw_display, xw_window, PresGC, PRESENT_LOC_X,
  220.                 PRESENT_LOC_Y+((PresFont->ascent)*3/2),
  221.                 PresentString, count);
  222.             break;
  223.         case LOGO:
  224.             XDrawString(xw_display, xw_window, PresGC, PRESENT_LOC_X,
  225.                 PRESENT_LOC_Y+((PresFont->ascent)*3/2),
  226.                 PresentString, strlen(PresentString));
  227.             XCopyPlane(xw_display, BigLogoPM, xw_window, GreenGC,
  228.                 0, 0, biglogo_width, biglogo_height,
  229.                 PHASE_LOC_X, PHASE_LOC_Y, 1L);
  230.             break;
  231.         case BY:
  232.         case SHINE:
  233.             {
  234.             XCharStruct Sizes;
  235.             int dir, asc, dsc;
  236.  
  237.             XDrawString(xw_display, xw_window, PresGC, PRESENT_LOC_X,
  238.                 PRESENT_LOC_Y+((PresFont->ascent)*3/2),
  239.                 PresentString, strlen(PresentString));
  240.  
  241.             XCopyPlane(xw_display, BigLogoPM, xw_window, GreenGC,
  242.                 0, 0, biglogo_width, biglogo_height,
  243.                 PHASE_LOC_X, PHASE_LOC_Y, 1L);
  244.  
  245.             XTextExtents(VerFont,ThankString, strlen(ThankString),
  246.                 &dir,&asc,&dsc,&Sizes);
  247.             XDrawImageString(xw_display, xw_window, VerGC,
  248.                 (SCREEN_X - Sizes.width)/2,
  249.                 THANK_LOC_Y+((VerFont->ascent)*3/2),
  250.                 ThankString, strlen(ThankString));
  251.  
  252.             XTextExtents(VerFont,StartString, strlen(StartString),
  253.                 &dir,&asc,&dsc,&Sizes);
  254.             XDrawImageString(xw_display, xw_window, VerGC,
  255.                 (SCREEN_X - Sizes.width)/2,
  256.                 START_LOC_Y+((VerFont->ascent)*3/2),
  257.                 StartString, strlen(StartString));
  258.  
  259.             XDrawImageString(xw_display, xw_window, VerGC, VER_LOC_X,
  260.                 VER_LOC_Y+((VerFont->ascent)*3/2),
  261.                 VerString, strlen(VerString));
  262.             }
  263.             break;
  264.         }
  265.     XFlush(xw_display);
  266.     }
  267.  
  268.