home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / temp < prev   
Text File  |  2009-09-29  |  10KB  |  509 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 *ri[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.  
  107. for (i=0;i<2;i++)
  108.     {
  109.     InitBitMap(bm1[i],DEPTH,WIDTH,HEIGHT);
  110.     InitBitMap(bm2[i],DEPTH,WIDTH,HEIGHT);
  111.  
  112.     for (x=0;x<DEPTH;x++)
  113.         {
  114.         bm1[i]->Planes[x] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
  115.         if (bm1[i]->Planes[x] == NULL) printf("BITMAP error\n");
  116.         else BltClear(bm1[i]->Planes[x],RASSIZE(WIDTH,HEIGHT),NULL);
  117.  
  118.         bm2[i]->Planes[x] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
  119.         if (bm2[i]->Planes[x] == NULL) printf("BITMAP error\n");
  120.         else BltClear(bm2[i]->Planes[x],RASSIZE(WIDTH,HEIGHT),NULL);
  121.         }
  122.     }
  123.  
  124. newscreen.CustomBitMap = bm1[0];
  125. screen = (struct Screen *)OpenScreen(&newscreen);
  126. if (screen == NULL) printf("error opening screen\n");
  127. else
  128.     {
  129.     vp[0] = &(screen->ViewPort);
  130.     rp1[0] = &(screen->RastPort);        /*    screen pointers   */
  131.     ri1[0] = vp[0]->RasInfo;
  132.     }
  133.  
  134. ri2[0]->BitMap = bm2[0];
  135. rp2[0]->BitMap = bm2[0];            /*    set dualplayfield structures   */
  136. InitRastPort(rp2[0]);
  137.  
  138. Forbid();
  139. ri1[0]->Next = ri2[0];
  140. vp[0]->Modes |= DUALPF;                /*    attach dualplayfield to screen   */
  141. MakeScreen(screen);
  142. RethinkDisplay();
  143. Permit();
  144.  
  145.  
  146.  
  147. InitRastPort(rp1[1]);
  148. InitRastPort(rp2[1]);
  149.  
  150. rp1[1]->BitMap = bm1[1];
  151. rp2[1]->BitMap = bm2[1];
  152.  
  153. ri1[1]->BitMap = bm1[1];
  154. ri1[i]->Next = ri2[1];
  155. ri2[1]->BitMap = bm2[1];
  156. ri2[i]->Next = NULL;
  157.  
  158. InitVPort(vp[1]);
  159.  
  160. vp[1]->DWidth = WIDTH;
  161. vp[1]->DHeight = HEIGHT;
  162. vp[1]->RasInfo = ri1[i];
  163. vp[1]->Modes = DUALPF | LACE | HIRES;
  164.  
  165.  
  166. for (i=0;i<2;i++)
  167.     {
  168.     InitView(view[i]);
  169.     view[i]->ViewPort = vp[i];
  170.     view[i]->Modes = LACE;
  171.  
  172.     MakeVPort(&view[i],vp[i]);
  173.     }
  174.  
  175. SetRGB4(vp[i],0,0,0,0);
  176. SetRGB4(vp[i],1,15,15,15);
  177. SetRGB4(vp[i],8,0,0,0);
  178. SetRGB4(vp[i],9,7,7,7);
  179. SetRGB4(vp[i],10,0,0,0);
  180.  
  181. SetDrMd(rp1[i],JAM1);
  182. SetDrMd(rp2[i],JAM1);
  183.  
  184. SetFont(rp2[i],basicfont);
  185. }
  186.  
  187. LoadAllImages();
  188. LoadAllSounds();
  189. LoadHighScores();
  190.  
  191.  
  192. SetDelay(60,0);
  193. initaudio();
  194. addtimer();
  195. addhandler();
  196. }
  197.  
  198.  
  199.  
  200.  
  201.  
  202. Cleanup()
  203. {
  204. LONG i,x;
  205.  
  206. closeaudio();
  207. removetimer();
  208. removehandler();
  209. freeimages();
  210.  
  211. if (basicfont) CloseFont(basicfont);
  212. if (hiresfont) CloseFont(hiresfont);
  213. if (fixplain7font) CloseFont(fixplain7font);
  214.  
  215. CloseScreen(screen);
  216.  
  217. /*
  218. if (oldview) 
  219.     {
  220.     LoadView(oldview);
  221.     WaitTOF();
  222.     }
  223. */
  224.  
  225. for (i=0;i<2;i++)
  226.     {
  227.     for (x=0;x<DEPTH;x++)
  228.         {
  229.         if (bm1[i].Planes[x]) FreeRaster(bm1[i].Planes[x],WIDTH,HEIGHT);
  230.         if (bm2[i].Planes[x]) FreeRaster(bm2[i].Planes[x],WIDTH,HEIGHT);
  231.         }
  232. /*    if (view[i].ViewPort) FreeVPortCopLists(view[i].ViewPort);
  233.     if (view[i].LOFCprList) FreeCprList(view[i].LOFCprList);
  234.     if (view[i].SHFCprList) FreeCprList(view[i].SHFCprList);*/
  235.     }
  236.  
  237. if (IFFParseBase)  CloseLibrary(IFFParseBase);
  238. if (DiskfontBase)  CloseLibrary((struct Library *)DiskfontBase);
  239. if (DOSBase)       CloseLibrary((struct Library *)DOSBase);
  240. if (GfxBase)        CloseLibrary(GfxBase);
  241. if (IntuitionBase) CloseLibrary(IntuitionBase);
  242.  
  243. SetDelay(0,300000);
  244.  
  245. exit(0);
  246. }
  247.  
  248.  
  249.  
  250.  
  251. HandleOptions()
  252. {
  253. LONG x;
  254. BYTE string[10];
  255.  
  256. SetFont(rp1[0],fixplain7font);
  257. Move(rp1[0],280,100);
  258. Text(rp1[0],"OPTIONS",7);
  259.  
  260. Move(rp1[0],180,235);
  261. Text(rp1[0],"<F2>",4);
  262. Move(rp1[0],180,250);
  263. Text(rp1[0],"<F3>",4);
  264. Move(rp1[0],180,265);
  265. Text(rp1[0],"<F4>",4);
  266. Move(rp1[0],180,280);
  267. Text(rp1[0],"<F5>",4);
  268. Move(rp1[0],180,310);
  269. Text(rp1[0],"<F1>",4);
  270.  
  271. SetFont(rp1[0],hiresfont);
  272. Move(rp1[0],225,234);
  273. Text(rp1[0],"PLAYER ONE --",13);
  274. Move(rp1[0],310,234);
  275. if (control.player[0] == TRUE)
  276.     {
  277.     if (control.input[0] == 0) Text(rp1[0],"HUMAN (KEYBOARD)",16);
  278.     else                      Text(rp1[0],"HUMAN (JOYSTICK)",16);
  279.     }
  280. else                         Text(rp1[0],"NONE",4);
  281.  
  282. Move(rp1[0],225,249);
  283. Text(rp1[0],"PLAYER TWO --",13);
  284. Move(rp1[0],310,249);
  285. if (control.player[1] == TRUE)
  286.     {
  287.     if (control.input[1] == 0) Text(rp1[0],"HUMAN (KEYBOARD)",16);
  288.     else                      Text(rp1[0],"HUMAN (JOYSTICK)",16);
  289.     }
  290. else                         Text(rp1[0],"NONE",4);
  291.  
  292. Move(rp1[0],225,264);
  293. Text(rp1[0],"ENEMY SHIPS--",13);
  294. Move(rp1[0],310,264);
  295. sprintf(string,"%d",control.enemyonscreen);
  296. Text(rp1[0],string,strlen(string));
  297.  
  298. Move(rp1[0],225,279);
  299. Text(rp1[0],"FIRE TYPE--",11);
  300. Move(rp1[0],310,279);
  301. if (control.fire[0] == 0) Text(rp1[0],"NORMAL FIRE",11);
  302. else
  303. if (control.fire[0] == 1) Text(rp1[0],"HEAVY FIRE",10);
  304. else
  305. if (control.fire[0] == 2) Text(rp1[0],"DOUBLE FIRE",11);
  306. else                     Text(rp1[0],"SUPER FIRE",10);
  307.  
  308. Move(rp1[0],225,309);
  309. Text(rp1[0],"TO RETURN",9);
  310.  
  311. inputkey = NULL;
  312. while (inputkey != F1)
  313.     {
  314.     if (inputkey == F2)
  315.         {
  316.          SetAPen(rp1[0],0);
  317.          RectFill(rp1[0],309,226,409,235);
  318.         SetAPen(rp1[0],1);
  319.         Move(rp1[0],310,234);
  320.         
  321.          if (++control.player[0] > 2) control.player[0] = 1;
  322.          if (control.player[0] == 1) Text(rp1[0],"HUMAN (KEYBOARD)",16);
  323.         else
  324.         if (control.player[0] == 2) Text(rp1[0],"HUMAN (JOYSTICK)",16);
  325.         else                       Text(rp1[0],"NONE",4);
  326.         Delay(10);
  327.         }
  328.     else
  329.     if (inputkey == F3)
  330.         {
  331.         SetAPen(rp1[0],0);
  332.          RectFill(rp1[0],309,241,409,250);
  333.         SetAPen(rp1[0],1);
  334.         Move(rp1[0],310,249);
  335.  
  336.          if (++control.player[1] > 2) control.player[1] = 0;
  337.          if (control.player[1] == 1) Text(rp1[0],"HUMAN (KEYBOARD)",16);
  338.         else
  339.          if (control.player[1] == 2) Text(rp1[0],"HUMAN (JOYSTICK)",16);
  340.         else                       Text(rp1[0],"NONE",4);
  341.         Delay(10);
  342.         }
  343.     if (inputkey == F4)
  344.         {
  345.         SetAPen(rp1[0],0);
  346.          RectFill(rp1[0],309,256,409,265);
  347.         SetAPen(rp1[0],1);
  348.         Move(rp1[0],310,264);
  349.         
  350.          if (++control.enemyonscreen > 3) control.enemyonscreen = 0;
  351.         sprintf(string,"%d",control.enemyonscreen);
  352.         Text(rp1[0],string,strlen(string));
  353.         Delay(10);
  354.         }
  355.     if (inputkey == F5)
  356.         {
  357.         SetAPen(rp1[0],0);
  358.          RectFill(rp1[0],309,271,409,280);
  359.         SetAPen(rp1[0],1);
  360.         Move(rp1[0],310,279);
  361.         
  362.          if (++control.fire[0] > 3) control.fire[0] = 0;
  363.          if (control.fire[0] == 0) Text(rp1[0],"NORMAL FIRE",11);
  364.         else
  365.          if (control.fire[0] == 1) Text(rp1[0],"HEAVY FIRE",10);
  366.         else
  367.          if (control.fire[0] == 2) Text(rp1[0],"DOUBLE FIRE",11);
  368.         else                     Text(rp1[0],"SUPER FIRE",10);
  369.         Delay(10);
  370.         }
  371.     }
  372. inputkey = NULL;
  373.  
  374. for(x=0;x<2;x++)
  375.     if (control.player[x] > 1)
  376.         {
  377.         control.player[x] = 1;
  378.         control.input[x] = 1;
  379.         }
  380.     else    control.input[x] = 0;
  381.  
  382. control.playernum = control.player[0]+control.player[1];
  383. }
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390. DrawTitleScreen()
  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.