home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / disk.c < prev    next >
C/C++ Source or Header  |  2009-01-20  |  6KB  |  317 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 <string.h>
  17. #include <h/rot.h>
  18. #include <h/extern.h>
  19.  
  20.  
  21. SaveKeyDefines()
  22. {
  23. LONG file;
  24.  
  25. file = Open ("keydefinitions",MODE_OLDFILE);
  26. if (file == NULL)
  27.     {
  28.     file = Open ("keydefinitions",MODE_NEWFILE);
  29.     if (file == NULL)
  30.         {
  31.         printf("Options file creation error\n");
  32.         return;
  33.         }
  34.     }
  35.  
  36. Write(file,&k,sizeof(k));
  37. Close(file);
  38. }
  39.  
  40.  
  41. LoadKeyDefines()
  42. {
  43. LONG file;
  44. struct keys temp;
  45.  
  46. file = Open ("keydefinitions",MODE_OLDFILE);
  47. if (file != NULL)
  48.     {
  49.     Read(file,&temp,sizeof(temp));
  50.  
  51.     k.left       = temp.left;
  52.     k.right      = temp.right;
  53.     k.fire       = temp.fire;
  54.     k.thrust     = temp.thrust;
  55.     k.hyperspace = temp.hyperspace;
  56.     k.pause      = temp.pause;
  57.  
  58.     Close(file);
  59.     }
  60. }
  61.  
  62.  
  63.  
  64. LoadOptions()
  65. {
  66. LONG file,x;
  67.  
  68. file = Open ("options",MODE_OLDFILE);
  69. if (file != NULL)
  70.     {
  71.     Read(file,&so,sizeof(so));
  72.  
  73.     control.playernum =      so.playernum;
  74.     control.input[0] =       so.input[0];
  75.     control.input[1] =       so.input[1];
  76.     control.enemyonscreen =  so.enemyonscreen;
  77.     control.ftrnum =         so.ftrnum;
  78.     control.delay =          so.delay;
  79.     control.playmode =       so.playmode;
  80.     control.game =           so.game;
  81.     control.startlevel =     so.startlevel;
  82.     control.difficulty =     so.difficulty;
  83.     control.autofire =         so.autofire;
  84.     control.firewrap =       so.firewrap;
  85.     control.standarddebris = so.standarddebris;
  86.     control.screentype =     so.screentype;
  87.     control.fontsize =       so.fontsize;
  88.  
  89.     for(x=0;x<control.playernum;x++)
  90.         control.player[x] = TRUE;
  91.  
  92.     for(x=control.playernum;x<control.maxplayernum;x++)
  93.         control.player[x] = FALSE;
  94.  
  95.     if (control.game == 1)
  96.         {
  97.         control.ftrnum = 0;
  98.         control.enemyonscreen=0;
  99.         }
  100.  
  101.     Close(file);
  102.     }
  103. }
  104.  
  105.  
  106. SaveOptions()
  107. {
  108. LONG file;
  109.  
  110. file = Open ("options",MODE_OLDFILE);
  111. if (file == NULL)
  112.     {
  113.     file = Open ("options",MODE_NEWFILE);
  114.     if (file == NULL)
  115.         {
  116.         printf("Options file creation error\n");
  117.         return;
  118.         }
  119.     }
  120.  
  121. so.playernum = control.playernum;
  122. so.input[0] = control.input[0];
  123. so.input[1] = control.input[1];
  124. so.enemyonscreen = control.enemyonscreen;
  125. so.ftrnum = control.ftrnum;
  126. so.delay = control.delay;
  127. so.playmode = control.playmode;
  128. so.game = control.game;
  129. so.startlevel = control.startlevel;
  130. so.difficulty = control.difficulty;
  131. so.autofire = control.autofire;
  132. so.firewrap = control.firewrap;
  133. so.standarddebris = control.standarddebris;
  134. so.screentype = control.screentype;
  135. so.fontsize = control.fontsize;
  136.  
  137. Write(file,&so,sizeof(so));
  138. Close(file);
  139. }
  140.  
  141.  
  142. LoadHighScores()
  143. {
  144. LONG file;
  145.  
  146. file = Open ("highscores",MODE_OLDFILE);
  147. if (file == NULL)
  148.     {
  149.     file = Open ("highscores",MODE_NEWFILE);
  150.     if (file == NULL)
  151.         {
  152.         printf("High score file creation error\n");
  153.         exit(FALSE);
  154.         }
  155.     else
  156.         {
  157.         Write(file,hsl,sizeof(hsl));
  158.         Close(file);
  159.         }
  160.     }
  161. else
  162.     {
  163.     Read(file,hsl,sizeof(hsl));
  164.     Close(file);
  165.     }
  166. }
  167.  
  168.  
  169. DisplayHighScores(wrp)
  170. struct RastPort *wrp;
  171. {
  172. LONG x;
  173. UBYTE string[20];
  174. LONG yy[24],y0,y1;
  175. LONG x0,x1,x2;
  176.  
  177. y0= gi.he/2-100;
  178. y1= gi.he/2-120;
  179. for(x=0;x<22;x++)
  180.     yy[x] = y0 + x*(gi.smallfontheight+2);
  181.  
  182. x0 = gi.wi/2-22*(gi.smallfontheight-2);
  183. x1 = x0+25*(gi.smallfontheight-2);
  184. x2 = x1+13*(gi.smallfontheight-2);
  185.  
  186.  
  187. SetAPen(wrp,1);
  188. SetFont(wrp,basicfont);
  189. Move(wrp,gi.wi/2-120,70);
  190. Text(wrp,"HIGH SCORES",11);
  191.  
  192. SetFont(wrp,fixplain7font);
  193. Move(wrp,x0,y1);
  194. Text(wrp,"NAME",4);
  195. Move(wrp,x1,y1);
  196. Text(wrp,"SCORE",5);
  197. Move(wrp,x2,y1);
  198. Text(wrp,"LEVEL",5);
  199.  
  200.  
  201. SetFont(wrp,hiresfont);
  202. for (x=0;x<20;x++)
  203.     {
  204.     Move(wrp,x0,yy[x]);
  205.     Text(wrp,hsl[x].name,strlen(hsl[x].name));
  206.  
  207.     Move(wrp,x1,yy[x]);
  208.     sprintf(string,"%8d  ",hsl[x].score);
  209.     Text(wrp,string,strlen(string));
  210.  
  211.     Move(wrp,x2,yy[x]);
  212.     sprintf(string,"%3d",hsl[x].level);
  213.     Text(wrp,string,strlen(string));
  214.     }
  215.  
  216. Move(wrp,gi.wi/2-10*(gi.smallfontheight-2),gi.he-60);
  217. Text(wrp,"PRESS <F1> TO CONTINUE",22);
  218. }
  219.  
  220.  
  221. dohighscorelist(n)
  222. LONG n;
  223. {
  224. UBYTE string[20];
  225. UBYTE temp[40];
  226. UBYTE not[3] = " ";
  227. LONG x,place,file;
  228. LONG len=0;
  229. static UBYTE ascii[] = " 1234567890-+\   QWERTYUIOP[]    ASDFGHJKL;'      ZXCVBNM,./      ";
  230. struct IntuiMessage *msg;
  231. LONG code=NULL,class;
  232. LONG x0,x1,y0,yy[24];
  233.  
  234. while (msg = (struct IntuiMessage *)GetMsg(masterwindow->UserPort)) ReplyMsg((struct Message *)msg);
  235.  
  236.  
  237. x0 = gi.wi/2-22*(gi.smallfontheight-2);
  238. x1 = x0+25*(gi.smallfontheight-2);
  239. y0= gi.he/2-100;
  240. for(x=0;x<22;x++)
  241.     yy[x] = y0 + x*(gi.smallfontheight+2);
  242.  
  243.  
  244. for(x=0;x<20;x++)
  245.     if (control.score[n] > hsl[x].score)
  246.         {
  247.         place = x;
  248.         break;
  249.         }
  250.  
  251. for(x=19;x>place-1;x--)
  252.     {
  253.     strcpy(hsl[x].name,hsl[x-1].name);
  254.     hsl[x].score = hsl[x-1].score;
  255.     hsl[x].level = hsl[x-1].level;
  256.     }
  257.  
  258. strcpy(hsl[place].name,not);            /* just to blank the name for screen */
  259. hsl[place].score = control.score[n];
  260. hsl[place].level = control.level;
  261.  
  262. DisplayHighScores(mwrp);
  263.  
  264. Move(mwrp,x0-11*(gi.smallfontheight-2),yy[place]);
  265. sprintf(string,"PLAYER %d--",n+1);
  266. Text(mwrp,string,strlen(string));
  267.  
  268. Move(mwrp,x0,yy[place]);
  269.  
  270. while ((code != F1) && (code != RET) && (code != ESC))
  271. {
  272. WaitPort(masterwindow->UserPort);
  273. while (msg = (struct IntuiMessage *)GetMsg(masterwindow->UserPort))
  274.     {
  275.     class = msg->Class;
  276.     code = msg->Code;
  277.     ReplyMsg((struct Message *)msg);
  278.  
  279.     if (class == RAWKEY)
  280.         {
  281.         if ((code > 0) && (code < 0x41) && (len < 30))
  282.             {
  283.             Text(mwrp,&ascii[code],1);
  284.             hsl[place].name[len] = ascii[code];
  285.             len++;
  286.             }
  287.         else
  288.         if ((code == 0x46) || (code == 0x41))
  289.             {
  290.             len--;
  291.             SetAPen(mwrp,0);
  292.             RectFill(mwrp,x0-1,yy[place]-gi.smallfontheight,x1-1,yy[place]+1);
  293.             SetAPen(mwrp,1);
  294.             stccpy(temp,hsl[place].name,len+1);
  295.             stccpy(hsl[place].name,temp,len+1);
  296.             Move(mwrp,x0,yy[place]);
  297.             Text(mwrp,hsl[place].name,strlen(hsl[place].name));
  298.             }
  299.         Delay(1);
  300.         }
  301.     }
  302. }
  303.  
  304. stccpy(temp,hsl[place].name,len+1);
  305. stccpy(hsl[place].name,temp,len+1);
  306.  
  307. file = Open ("highscores",MODE_OLDFILE);
  308. if (file == NULL)
  309.     {
  310.     printf ("*** undetermined file error");
  311.     }
  312. else
  313.     {
  314.     Write(file,hsl,sizeof(hsl));
  315.     Close(file);
  316.     }
  317. }