home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / init.bak < prev    next >
Text File  |  1995-07-20  |  11KB  |  516 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <exec/interrupts.h>
  4. #include <devices/input.h>
  5. #include <devices/inputevent.h>
  6. #include <devices/timer.h>
  7. #include <libraries/dos.h>
  8. #include <intuition/intuition.h>
  9. #include <graphics/gfx.h>
  10. #include <graphics/gfxbase.h>
  11. #include <graphics/gfxmacros.h>
  12. #include <graphics/gfxbase.h>
  13. #include <graphics/rastport.h>
  14. #include <graphics/view.h>
  15. #include <hardware/custom.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <h/rot.h>
  19.  
  20. #define ESC 0x45
  21. #define DEPTH  1
  22. #define WIDTH  640
  23. #define HEIGHT 400
  24.  
  25. extern LONG inputkey;
  26. extern LONG Lturn,Rturn;
  27. extern LONG Thrust; 
  28. extern LONG Fire,Pause;
  29. extern LONG Photon,Aim;
  30.  
  31. extern LONG Lturn2,Rturn2;
  32. extern LONG Thrust2; 
  33. extern LONG Fire2;
  34. extern LONG Photon2,Aim2;
  35.  
  36. extern struct control control;
  37. extern struct ship ship[7];
  38. extern struct asteroid a[32];
  39.  
  40. struct NewScreen newscreen =
  41. {
  42. 0,0,
  43. 640,400,
  44. 1,
  45. 0,0,
  46. HIRES | LACE,
  47. CUSTOMBITMAP,
  48. NULL,NULL,NULL,NULL
  49. };
  50.  
  51.  
  52. struct TextAttr basic = {"basic.font",32,0,0};
  53. struct TextFont *basicfont;
  54.  
  55. struct TextAttr hires = {"hires-5a.font",8,0,0};
  56. struct TextFont *hiresfont;
  57.  
  58. struct TextAttr fixplain7 = {"fixplain7.font",12,0,0};
  59. struct TextFont *fixplain7font;
  60.  
  61. struct BitMap *bm1[2],*bm2[2];       /*struct BitMap bm[2];*/
  62. struct View *view[2],*oldview;
  63.  
  64. struct RasInfo *ri1[2],*ri2[2];
  65. struct RastPort *rp1[2],*rp2[2];
  66. struct ViewPort *vp[2];
  67.  
  68. struct GfxBase *GfxBase;
  69. struct IntuitionBase *IntuitionBase;
  70. struct Library *DiskfontBase;
  71. struct DosLibrary    *DOSBase;
  72. struct Library        *IFFParseBase;
  73.  
  74. struct Screen *screen;
  75.  
  76.  
  77. Initialization()
  78. {
  79. LONG x,i;
  80.  
  81. IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",NULL);
  82. if (IntuitionBase == NULL) printf("INTUITIONBASE error!!\n");
  83.  
  84. GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",NULL);
  85. if (GfxBase == NULL) printf("GFXBASE error!!\n");
  86.  
  87. DiskfontBase = (struct Library *) OpenLibrary("diskfont.library",NULL);
  88. if (DiskfontBase == NULL) printf("DISKFONTBASE error!!\n");
  89.  
  90. DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37);
  91. if (DOSBase == NULL) printf("DOSBASE error!!\n");
  92.  
  93. IFFParseBase = (struct Library *)OpenLibrary("iffparse.library",37);
  94. if (IFFParseBase == NULL) printf("IFFPARSEBASE error!!\n");
  95.  
  96. basicfont = (struct TextFont *)OpenDiskFont(&basic);
  97. if (basicfont == NULL) printf("basic font error ***\n");
  98.  
  99. hiresfont = (struct TextFont *)OpenDiskFont(&hires);
  100. if (hiresfont == NULL) printf("hires font error ***\n");
  101.  
  102. fixplain7font = (struct TextFont *)OpenDiskFont(&fixplain7);
  103. if (fixplain7font == NULL) printf("fixplain7 font error ***\n");
  104.  
  105.  
  106. for (i=0;i<2;i++)
  107.     {
  108.     bm1[i] = (struct BitMap *)AllocMem(sizeof(struct BitMap),MEMF_PUBLIC|MEMF_CLEAR);
  109.     bm2[i] = (struct BitMap *)AllocMem(sizeof(struct BitMap),MEMF_PUBLIC|MEMF_CLEAR);
  110.  
  111.     InitBitMap(bm1[i],DEPTH,WIDTH,HEIGHT);
  112.     InitBitMap(bm2[i],DEPTH,WIDTH,HEIGHT);
  113.  
  114.     for (x=0;x<DEPTH;x++)
  115.         {
  116.         bm1[i]->Planes[x] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
  117.         if (bm1[i]->Planes[x] == NULL) printf("BITMAP error\n");
  118.         else BltClear(bm1[i]->Planes[x],RASSIZE(WIDTH,HEIGHT),NULL);
  119.  
  120.         bm2[i]->Planes[x] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
  121.         if (bm2[i]->Planes[x] == NULL) printf("BITMAP error\n");
  122.         else BltClear(bm2[i]->Planes[x],RASSIZE(WIDTH,HEIGHT),NULL);
  123.         }
  124.     }
  125.  
  126. newscreen.CustomBitMap = bm1[0];
  127. screen = (struct Screen *)OpenScreen(&newscreen);
  128. if (screen == NULL) printf("error opening screen\n");
  129.  
  130.  
  131. for (i=0;i<2;i++)
  132. {
  133. rp1[i] = (struct RastPort *)AllocMem(sizeof(struct RastPort),MEMF_PUBLIC|MEMF_CLEAR);
  134. rp2[i] = (struct RastPort *)AllocMem(sizeof(struct RastPort),MEMF_PUBLIC|MEMF_CLEAR);
  135. InitRastPort(rp1[i]);
  136. InitRastPort(rp2[i]);
  137. rp1[i]->BitMap = bm1[i];
  138. rp2[i]->BitMap = bm2[i];
  139.  
  140. ri1[i] = (struct RasInfo *)AllocMem(sizeof(struct RasInfo),MEMF_PUBLIC|MEMF_CLEAR);
  141. ri2[i] = (struct RasInfo *)AllocMem(sizeof(struct RasInfo),MEMF_PUBLIC|MEMF_CLEAR);
  142. ri1[i]->BitMap = bm1[i];
  143. ri1[i]->RxOffset = 0;
  144. ri1[i]->RyOffset = 0;
  145. ri1[i]->Next = ri2[i];
  146. ri2[i]->BitMap = bm2[i];
  147. ri2[i]->RxOffset = 0;
  148. ri2[i]->RyOffset = 0;
  149. ri2[i]->Next = NULL;
  150.  
  151. vp[i] = (struct ViewPort *)AllocMem(sizeof(struct ViewPort),MEMF_PUBLIC|MEMF_CLEAR);
  152. InitVPort(vp[i]);
  153. vp[i]->DWidth = WIDTH;
  154. vp[i]->DHeight = HEIGHT;
  155. vp[i]->RasInfo = ri1[i];
  156. vp[i]->Modes = DUALPF | LACE | HIRES;
  157.  
  158. view[i] = (struct View *)AllocMem(sizeof(struct View),MEMF_PUBLIC|MEMF_CLEAR);
  159. InitView(view[i]);
  160. view[i]->ViewPort = vp[i];
  161. view[i]->Modes = LACE;
  162. MakeVPort(view[i],vp[i]);
  163. MrgCop(view[i]);
  164.  
  165. SetRGB4(vp[i],0,0,0,0);
  166. SetRGB4(vp[i],1,15,15,15);
  167. SetRGB4(vp[i],8,0,0,0);
  168. SetRGB4(vp[i],9,7,7,7);
  169. SetRGB4(vp[i],10,0,0,0);
  170.  
  171. SetDrMd(rp1[i],JAM1);
  172. SetDrMd(rp2[i],JAM1);
  173.  
  174. SetFont(rp2[i],basicfont);
  175. }
  176.  
  177. LoadAllImages();
  178. LoadAllSounds();
  179. LoadHighScores();
  180.  
  181. SetRGB4(vp[0],0,10,10,10);
  182.  
  183. SetDelay(60,0);
  184. initaudio();
  185. addtimer();
  186. addhandler();
  187.  
  188. SetRGB4(vp[0],0,0,0,0);
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195. Cleanup()
  196. {
  197. LONG i,x;
  198.  
  199. closeaudio();
  200. removetimer();
  201. removehandler();
  202. freeimages();
  203.  
  204. if (basicfont) CloseFont(basicfont);
  205. if (hiresfont) CloseFont(hiresfont);
  206. if (fixplain7font) CloseFont(fixplain7font);
  207.  
  208. CloseScreen(screen);
  209.  
  210.  
  211. for (i=0;i<2;i++)
  212.     {
  213.     if (ri1[i]) FreeMem(ri1[i],sizeof(struct RasInfo));
  214.     if (rp1[i]) FreeMem(rp1[i],sizeof(struct RastPort));
  215.     if (ri2[i]) FreeMem(ri2[i],sizeof(struct RasInfo));
  216.     if (rp2[i]) FreeMem(rp2[i],sizeof(struct RastPort));
  217.     if (vp[i]) FreeMem(vp[i],sizeof(struct ViewPort));
  218.     if (view[i]) FreeMem(view[i],sizeof(struct View));
  219.  
  220.     if (bm1[i]) FreeMem(bm1[i],sizeof(struct BitMap));
  221.     if (bm2[i]) FreeMem(bm2[i],sizeof(struct BitMap));
  222.  
  223.     for (x=0;x<DEPTH;x++)
  224.         {
  225.  
  226.         if (bm1[i]->Planes[x]) FreeRaster(bm1[i]->Planes[x],WIDTH,HEIGHT);
  227.         if (bm2[i]->Planes[x]) FreeRaster(bm2[i]->Planes[x],WIDTH,HEIGHT);
  228.         }
  229.     /*
  230.     if (view[i]->ViewPort) FreeVPortCopLists(view[i]->ViewPort);
  231.     if (view[i]->LOFCprList) FreeCprList(view[i]->LOFCprList);
  232.     if (view[i]->SHFCprList) FreeCprList(view[i]->SHFCprList);
  233.     */
  234.     }
  235.  
  236. if (IFFParseBase)  CloseLibrary(IFFParseBase);
  237. if (DiskfontBase)  CloseLibrary((struct Library *)DiskfontBase);
  238. if (DOSBase)       CloseLibrary((struct Library *)DOSBase);
  239. if (GfxBase)        CloseLibrary(GfxBase);
  240. if (IntuitionBase) CloseLibrary(IntuitionBase);
  241.  
  242. SetDelay(0,300000);
  243.  
  244. exit(0);
  245. }
  246.  
  247.  
  248. HandleOptions()
  249. {
  250. LONG x;
  251. BYTE string[10];
  252.  
  253. SetFont(rp1[0],fixplain7font);
  254. Move(rp1[0],280,100);
  255. Text(rp1[0],"OPTIONS",7);
  256.  
  257. Move(rp1[0],180,235);
  258. Text(rp1[0],"<F2>",4);
  259. Move(rp1[0],180,250);
  260. Text(rp1[0],"<F3>",4);
  261. Move(rp1[0],180,265);
  262. Text(rp1[0],"<F4>",4);
  263. Move(rp1[0],180,280);
  264. Text(rp1[0],"<F5>",4);
  265. Move(rp1[0],180,310);
  266. Text(rp1[0],"<F1>",4);
  267.  
  268. SetFont(rp1[0],hiresfont);
  269. Move(rp1[0],225,234);
  270. Text(rp1[0],"PLAYER ONE --",13);
  271. Move(rp1[0],310,234);
  272. if (control.player[0] == TRUE)
  273.     {
  274.     if (control.input[0] == 0) Text(rp1[0],"HUMAN (KEYBOARD)",16);
  275.     else                      Text(rp1[0],"HUMAN (JOYSTICK)",16);
  276.     }
  277. else                         Text(rp1[0],"NONE",4);
  278.  
  279. Move(rp1[0],225,249);
  280. Text(rp1[0],"PLAYER TWO --",13);
  281. Move(rp1[0],310,249);
  282. if (control.player[1] == TRUE)
  283.     {
  284.     if (control.input[1] == 0) Text(rp1[0],"HUMAN (KEYBOARD)",16);
  285.     else                      Text(rp1[0],"HUMAN (JOYSTICK)",16);
  286.     }
  287. else                         Text(rp1[0],"NONE",4);
  288.  
  289. Move(rp1[0],225,264);
  290. Text(rp1[0],"ENEMY SHIPS--",13);
  291. Move(rp1[0],310,264);
  292. sprintf(string,"%d",control.enemyonscreen);
  293. Text(rp1[0],string,strlen(string));
  294.  
  295. Move(rp1[0],225,279);
  296. Text(rp1[0],"FIRE TYPE--",11);
  297. Move(rp1[0],310,279);
  298. if (control.fire[0] == 0) Text(rp1[0],"NORMAL FIRE",11);
  299. else
  300. if (control.fire[0] == 1) Text(rp1[0],"HEAVY FIRE",10);
  301. else
  302. if (control.fire[0] == 2) Text(rp1[0],"DOUBLE FIRE",11);
  303. else                     Text(rp1[0],"SUPER FIRE",10);
  304.  
  305. Move(rp1[0],225,309);
  306. Text(rp1[0],"TO RETURN",9);
  307.  
  308. inputkey = NULL;
  309. while (inputkey != F1)
  310.     {
  311.     if (inputkey == F2)
  312.         {
  313.          SetAPen(rp1[0],0);
  314.          RectFill(rp1[0],309,226,409,235);
  315.         SetAPen(rp1[0],1);
  316.         Move(rp1[0],310,234);
  317.         
  318.          if (++control.player[0] > 2) control.player[0] = 1;
  319.          if (control.player[0] == 1) Text(rp1[0],"HUMAN (KEYBOARD)",16);
  320.         else
  321.         if (control.player[0] == 2) Text(rp1[0],"HUMAN (JOYSTICK)",16);
  322.         else                       Text(rp1[0],"NONE",4);
  323.         Delay(10);
  324.         }
  325.     else
  326.     if (inputkey == F3)
  327.         {
  328.         SetAPen(rp1[0],0);
  329.          RectFill(rp1[0],309,241,409,250);
  330.         SetAPen(rp1[0],1);
  331.         Move(rp1[0],310,249);
  332.  
  333.          if (++control.player[1] > 2) control.player[1] = 0;
  334.          if (control.player[1] == 1) Text(rp1[0],"HUMAN (KEYBOARD)",16);
  335.         else
  336.          if (control.player[1] == 2) Text(rp1[0],"HUMAN (JOYSTICK)",16);
  337.         else                       Text(rp1[0],"NONE",4);
  338.         Delay(10);
  339.         }
  340.     if (inputkey == F4)
  341.         {
  342.         SetAPen(rp1[0],0);
  343.          RectFill(rp1[0],309,256,409,265);
  344.         SetAPen(rp1[0],1);
  345.         Move(rp1[0],310,264);
  346.         
  347.          if (++control.enemyonscreen > 3) control.enemyonscreen = 0;
  348.         sprintf(string,"%d",control.enemyonscreen);
  349.         Text(rp1[0],string,strlen(string));
  350.         Delay(10);
  351.         }
  352.     if (inputkey == F5)
  353.         {
  354.         SetAPen(rp1[0],0);
  355.          RectFill(rp1[0],309,271,409,280);
  356.         SetAPen(rp1[0],1);
  357.         Move(rp1[0],310,279);
  358.         
  359.          if (++control.fire[0] > 3) control.fire[0] = 0;
  360.          if (control.fire[0] == 0) Text(rp1[0],"NORMAL FIRE",11);
  361.         else
  362.          if (control.fire[0] == 1) Text(rp1[0],"HEAVY FIRE",10);
  363.         else
  364.          if (control.fire[0] == 2) Text(rp1[0],"DOUBLE FIRE",11);
  365.         else                     Text(rp1[0],"SUPER FIRE",10);
  366.         Delay(10);
  367.         }
  368.     }
  369. inputkey = NULL;
  370.  
  371. for(x=0;x<2;x++)
  372.     if (control.player[x] > 1)
  373.         {
  374.         control.player[x] = 1;
  375.         control.input[x] = 1;
  376.         }
  377.     else    control.input[x] = 0;
  378.  
  379. control.playernum = control.player[0]+control.player[1];
  380. }
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387. DrawTitleScreen()
  388. {
  389.  
  390. SetAPen(rp1[0],1);
  391.  
  392. SetFont(rp1[0],basicfont);            /* title screen */
  393. Move(rp1[0],180,100);
  394. Text(rp1[0],"ASTERIODS II",12);
  395.  
  396. SetFont(rp1[0],hiresfont);            /* title screen */
  397.  
  398. Move(rp1[0],255,130);
  399. Text(rp1[0],"by mike seifert",15);
  400.  
  401. Move(rp1[0],240,200);
  402. Text(rp1[0],"PRESS  <F1>  TO START",21); 
  403.  
  404. Move(rp1[0],240,210);
  405. Text(rp1[0],"PRESS  <F2>  TO CHANGE OPTIONS",30);
  406.  
  407. Move(rp1[0],240,220);
  408. Text(rp1[0],"PRESS  <F3>  TO VIEW HIGH SCORES",32);
  409.  
  410. Move(rp1[0],240,250);
  411. Text(rp1[0],"PRESS  <ESC>  TO EXIT",21);
  412. }
  413.  
  414.  
  415. startwait()
  416. {
  417. inputkey = FALSE;
  418. while (inputkey != F1)
  419.     {
  420.     if (inputkey == F2) 
  421.         {
  422.         ClearScreen();
  423.         HandleOptions();
  424.         ClearScreen();
  425.         DrawTitleScreen();
  426.         }
  427.     else
  428.     if (inputkey == F3) 
  429.         {
  430.         ClearScreen();
  431.         DisplayHighScores();
  432.  
  433.         inputkey = FALSE;
  434.         while (inputkey != F1)
  435.             {
  436.             Delay(2);
  437.             }
  438.         inputkey = FALSE;
  439.  
  440.         ClearScreen();
  441.         DrawTitleScreen();
  442.         }
  443.     else
  444.     if (inputkey == ESC) Cleanup();
  445.     }
  446. inputkey = FALSE;
  447. }
  448.  
  449.  
  450. DrawGameScreen()
  451. {
  452. LONG x;
  453.  
  454. for(x=0;x<2;x++)
  455.     {
  456.     SetFont(rp2[x],hiresfont);
  457.  
  458.     Move(rp2[x],20,10);
  459.     Text(rp2[x],"PLAYER 1 SHIELDS",16);
  460.     Move(rp2[x],20,20);
  461.     Text(rp2[x],"TECHNOLOGY LEVEL",16);
  462.     Move(rp2[x],20,389);
  463.     Text(rp2[x],"PLAYER 1 SCORE",14);
  464.     Move(rp2[x],20,399);
  465.     Text(rp2[x],"SHIPS REMAINING",15);
  466.  
  467.     Move(rp2[x],320,10);
  468.     Text(rp2[x],"PLAYER 2 SHIELDS",16);
  469.     Move(rp2[x],320,20);
  470.     Text(rp2[x],"TECHNOLOGY LEVEL",16);
  471.     Move(rp2[x],320,389);
  472.     Text(rp2[x],"PLAYER 2 SCORE",14);
  473.     Move(rp2[x],320,399);
  474.     Text(rp2[x],"SHIPS REMAINING",15);
  475.  
  476.     IncreaseScore(0,0);
  477.     IncreaseScore(1,0);
  478.  
  479.     IncreaseLives(0,0);
  480.     IncreaseLives(1,0);
  481.  
  482.      IncreaseShields(0,0);
  483.     IncreaseShields(1,0);
  484.  
  485.      IncreaseTech(0,0);
  486.     IncreaseTech(1,0);
  487.     }
  488. }
  489.  
  490. ClearScreen()
  491. {
  492. LONG x;
  493.  
  494. for(x=0;x<2;x++)
  495.     {
  496.     SetAPen(rp1[x],0);
  497.     SetAPen(rp2[x],8);
  498.     SetRast(rp1[x],0);
  499.     SetRast(rp2[x],8);
  500.     }
  501.  
  502. for(x=0;x<2;x++)
  503.     {
  504.     SetAPen(rp1[x],1);
  505.     SetAPen(rp2[x],9);
  506.     }
  507. }
  508.  
  509. changeview(bit)
  510. LONG bit;
  511. {
  512.  
  513.  
  514.  
  515. RethinkDisplay();
  516.