home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 282.dms / 282.adf / SourceCode / parcode.c < prev    next >
C/C++ Source or Header  |  2004-11-28  |  23KB  |  876 lines

  1. /***************************************************************************
  2.  *     Paranoid --- The newest game from 7087                              *
  3.  *     Feel free to copy the source code                                   *
  4.  ***************************************************************************/
  5. #include <intuition/intuition.h>
  6. #include <graphics/gfxbase.h>
  7. #include <graphics/sprite.h>
  8. #include <graphics/gfxmacros.h>
  9. #include <libraries/dosextens.h>
  10. #include <exec/memory.h>
  11.  
  12. /**************************************************************************
  13.  *    Feststehende Daten,die sich nicht mehr veraendern (Sprites...)      *
  14.  **************************************************************************/
  15.  
  16. /* ColorTable fuer die Steine */
  17. long sc1[]={ 0l,27l,19l,19l,20l,19l,19l,30l,23l};
  18. long sc2[]={ 0l,23l,17l,27l,21l,30l,31l,26l,28l};
  19. long sc3[]={ 0l,28l,18l,23l,29l,26l,16l,24l,28l};
  20.  
  21. UWORD platte1_img [] = {
  22. 0x0000,0x0000,0x3fff,0x3000,0x6000,0x7fff,0x8000,0xffff,0x9fff,0xf000,
  23. 0xffff,0xf000,0x7fff,0x7000,0x3fff,0x3000,0x0000,0x0000 };
  24.  
  25. UWORD platte2_img [] = {
  26. 0x0000,0x0000,0xfffc,0x000c,0x0006,0xfffe,0x0001,0xffff,0xfff9,0x000f,
  27. 0xffff,0x000f,0xfffe,0x000e,0xfffc,0x000c,0x0000,0x0000 };
  28.  
  29. UWORD ball_img [] = {
  30. 0x0000,0x0000,
  31. 0x7000,0x1000,
  32. 0x7800,0xb800,
  33. 0x7800,0x9000,
  34. 0x3800,0xc000,
  35. 0x1000,0x6000,
  36. 0x0000,0x0000 };
  37.  
  38. UWORD mouse_pointer [] = {
  39. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  40. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  41.  
  42. UWORD sound2[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  43. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  44.  
  45. struct SimpleSprite platte1_spr= { platte1_img,7l };
  46. struct SimpleSprite platte2_spr= { platte2_img,7l };
  47. struct SimpleSprite ball_spr= { ball_img,5l };
  48.  
  49. /**************************************************************************
  50.  * einige Variablen fuer Spiel + System                                   *
  51.  **************************************************************************/
  52. short platte1_nr,platte2_nr,ball_nr,GetSprite();
  53. long spr_offset,horpos,verpos,mousemove;
  54. char oldmouse;
  55. float ballwinkel,speed,rad(),sin(),cos(),ran();
  56. float sinwert,coswert;
  57. long ballx,bally,newx,newy;
  58. long xcheck,ycheck;
  59. UBYTE oldscore[5];
  60. UBYTE newscore[5];
  61. short stage,lives,stone,score;
  62. long stonecount;
  63.  
  64. struct Level
  65. {
  66.  short p_num;
  67.  UBYTE stones [320];
  68. };
  69. struct Level level;
  70.  
  71. struct HighScore
  72. {
  73.  short punkte;
  74.  char name[30];
  75. };
  76. struct HighScore highscore[10];
  77.  
  78. /**************************************************************************
  79.  *               Variablen fuer das System                                *
  80.  **************************************************************************/
  81. struct Screen *scr,*MasterScreen();
  82. struct ViewPort *vp;
  83. struct RastPort *rp;
  84. struct BitMap *bm; long bm5base;
  85. struct FileHeader *fh,*Open();
  86. struct ColorMap *GetColorMap(),*cmap;
  87. UBYTE *button=(UBYTE *) 0xbfe001; 
  88. UBYTE *key=(UBYTE *) 0xbfec01;
  89. struct Window *win,*MasterWindow();
  90. struct IntuitionBase *IntuitionBase;
  91. long AllocMem(),soundbuffer,s1,s2;
  92. short soundflag=0;
  93. UWORD pattern[1024];
  94. struct BitMap hitmap;
  95. UBYTE hitbit[1280];
  96. long hitnr=0l,hitdel=0l;
  97. short hitflag=0;
  98.  
  99. /**************************************************************************
  100.  *   Vorspann und HauptMenu                                               *
  101.  **************************************************************************/
  102.  
  103. main()
  104. {
  105.  openstuff();
  106.  Disable();
  107.  GetData();
  108.  InitBitMap (&hitmap,5l,16l,16l);
  109.  if (!(s1=AllocMem(68000l,MEMF_CHIP|MEMF_PUBLIC)))
  110.  { printf ("No Memory for sounds\n"); CloseMaster(scr,win); }
  111.  if (!(fh=Open ("Paranoid:music/synt.snd",1004l)))
  112.  { printf ("Sounddata not found\n"); CloseMaster(scr,win); }
  113.  Read (fh,s1,66802l);
  114.  Close (fh);
  115.  if (!(s2=AllocMem(68000l,MEMF_CHIP|MEMF_PUBLIC)))
  116.  { printf ("No Memory for sounds\n"); CloseMaster(scr,win); }
  117.  if (!(fh=Open ("Paranoid:music/loopsynt.snd",1004l)))
  118.  { printf ("loopsynt not found\n"); CloseMaster(scr,win); }
  119.  Read (fh,s2,67325l);
  120.  Close (fh);
  121.  GetPicture ("Paranoid:gfx/titlescreen.dat",320l,200l,5l);
  122.  PlaySound (s1,66802l,358,3,64l+(64l<<8l));
  123.  Delay (50l);
  124.  PlaySound (s2,67325l,358,3,64l+(64l<<8l));
  125.  Delay (300l);
  126.  FreeMem (s1,68000l);
  127.  Enable();
  128.  while (*button&(UBYTE)64);  /* Solange,bis Button unten*/ 
  129.  while (TRUE)
  130.  {
  131.   GetPicture("Paranoid:gfx/mscreen.dat",320l,178l,4l);
  132.   if (s2) { FreeMem (s2,68000l); s2=0l; silence(15); }
  133.   while (TRUE)
  134.   {
  135.    while (!(*button&(UBYTE)64)); /* Solange,bis Button oben */
  136.    while (*button&(UBYTE)64);  /* Solange,bis Button unten */
  137.    if (CheckRange (51,64,60,73))   { playit(); break; }
  138.    if (CheckRange (51,94,60,103))  { editor(); break; }
  139.    if (CheckRange (51,130,60,139))
  140.    { 
  141.     GetPicture ("Paranoid:gfx/highscreen.dat",320l,256l,2l);
  142.     PrintHighScore();
  143.     while (!(*button&(UBYTE)64));
  144.     while (*button&(UBYTE)64);  /* Solange,bis Button unten */
  145.     while (!(*button&(UBYTE)64));
  146.     break;
  147.    }
  148.   }
  149.   Delay (30l);
  150.   if (*key==117) CloseMaster (scr,win);
  151.  }
  152. }
  153.  
  154. playit()
  155. {
  156.  long loop;
  157.  float t=sin(1.0);/* Lade Mathtrans.library*/
  158.  spr_offset=8l;
  159.  xcheck=4l;
  160.  ycheck=0l;
  161.  score=stage=0;lives=5;
  162.  for (loop=0l;loop<5l;loop++) oldscore[loop]=0;
  163.  GetPicture("Paranoid:gfx/playscreen.dat",320l,256l,4l);
  164.  SetPointer (win,mouse_pointer,16l,16l,0l,0l);
  165.  RemakeDisplay();
  166.  GetSound();
  167.  SetRGB4 (vp,16l,12l,0l,12l);
  168.  SetRGB4 (vp,17l,10l,10l,10l);
  169.  SetRGB4 (vp,18l,7l,7l,7l);
  170.  SetRGB4 (vp,19l,13l,13l,13l);
  171.  SetRGB4 (vp,20l,6l,6l,15l);
  172.  SetRGB4 (vp,21l,4l,4l,15l);
  173.  SetRGB4 (vp,22l,15l,15l,15l);
  174.  SetRGB4 (vp,23l,14l,2l,2l);
  175.  SetRGB4 (vp,24l,1l,6l,1l);
  176.  SetRGB4 (vp,25l,15l,15l,15l);
  177.  SetRGB4 (vp,26l,3l,9l,3l);
  178.  SetRGB4 (vp,27l,15l,5l,0l);
  179.  SetRGB4 (vp,28l,10l,0l,0l);
  180.  SetRGB4 (vp,29l,0l,0l,11l);
  181.  SetRGB4 (vp,30l,3l,12l,3l);
  182.  SetRGB4 (vp,31l,15l,0l,15l);
  183.  if (!(platte1_nr=GetSprite (&platte1_spr,2l)))
  184.  { printf ("No Sprite 2 allocation\n"); CloseMaster (scr,win); }
  185.  if (!(platte2_nr=GetSprite (&platte2_spr,3l)))
  186.  { printf ("No Sprite 3 allocation\n"); CloseMaster (scr,win); }
  187.  if (!(ball_nr=GetSprite (&ball_spr,1l)))
  188.  { printf ("No Sprite 4 allocation\n"); CloseMaster (scr,win); }
  189.  LoadStage(21l,25l);
  190.  realstart:
  191.  horpos=160l;verpos=237l;ballwinkel=45.0;bally=verpos-5l;speed=4.0;
  192.  newwinkel(45.0);
  193.  PrintStuff();
  194.  GetMouseMove();
  195.  do
  196.  {
  197.   MoveSprite (vp,&platte1_spr,horpos,verpos);
  198.   MoveSprite (vp,&platte2_spr,horpos+spr_offset,verpos);
  199.   MoveSprite (vp,&ball_spr,horpos+10l,bally);
  200.   GetMouseMove();
  201.   WaitTOF ();
  202.  } while (*button&(UBYTE)64);
  203.  ballx=horpos+10l;
  204.  do
  205.  { 
  206.   for (t=1.0;t<=speed;t++)
  207.   {
  208.    newx=ballx+(long)(t*coswert);
  209.    newy=bally-(long)(t*sinwert);
  210.    if (newx<20l)
  211.    {
  212.     silence(1);
  213.     soundflag=1;
  214.     newx++; score++;
  215.     newwinkel(90.0);
  216.     PlaySound (soundbuffer+39028l,5986l,358,1,64l);
  217.     break;
  218.    }
  219.    if (newx>296l)
  220.    {
  221.     silence(2);
  222.     newwinkel(90.0);
  223.     PlaySound (soundbuffer+39028l,5986l,358,2,64l<<8);
  224.     soundflag=2;
  225.     newx--;score++;
  226.     break;
  227.    }
  228.    if (newy<56l)
  229.    {
  230.     silence(3);
  231.     newwinkel(0.0);
  232.     PlaySound (soundbuffer+39028l,5986l,358,3,
  233.                (304l-newx)/5l+((newx/5l)<<8));
  234.     soundflag=3;
  235.     newy++;score++;
  236.     break;
  237.    }    
  238.    if (newy>verpos-5l)
  239.    {
  240.     if ((newx+3l>horpos)&&(newx<horpos+14l+spr_offset))
  241.     {
  242.      silence(12);
  243.      soundflag=12;
  244.      newwinkel(0.0);
  245.      newy--;
  246.      PlaySound (soundbuffer,6130l,250,12,(64l<<16)+(64l<<24));
  247.      break;
  248.     }
  249.    else 
  250.     {
  251.      silence(3);
  252.      MoveSprite (vp,&ball_spr,newx,newy);
  253.      if (ran()>.5)
  254.      PlaySound (soundbuffer+6135l,12412l,406,3,64l<<8);
  255.      else
  256.      PlaySound (soundbuffer+18548l,20480l,298,3,64l);
  257.      Delay (50l*1l);
  258.      shutup(3);
  259.      Delay(60l*1l);
  260.      lives--; if (!(lives)) break;
  261.      goto realstart;
  262.     }
  263.    }
  264.    loop=0l;
  265.    if (loop=pixtest(newx,newy))
  266.    {
  267.     silence(3);
  268.     soundflag=3;
  269.     if ((long)loop==1l) newwinkel (0.0);
  270.     if ((long)loop==2l) newwinkel (90.0);
  271.     KillStone (newx,newy,25l);
  272.     newx=ballx; newy=bally;
  273.     PlaySound (soundbuffer+61398l,1480l,358,3,
  274.                (304l-newx)/5l+((newx/5l)<<8));
  275.     score+=2;
  276.     stonecount--;
  277.     break;
  278.    }
  279.   }
  280.   ballx=newx;bally=newy;
  281.   MoveSprite (vp,&ball_spr,ballx,bally);
  282.   GetMouseMove();
  283.   MoveSprite (vp,&platte1_spr,horpos,verpos);
  284.   MoveSprite (vp,&platte2_spr,horpos+spr_offset,verpos);
  285.   PrintScore();
  286.   if ((++hitdel>1000l)&&((hitdel>>1l)<<1l==hitdel))
  287.   {
  288.    if (hitdel>1200l) hitdel=0l;
  289.    BltBitMapRastPort (&hitmap,0l,0l,rp,281l,223l,16l,16l,0xccl);
  290.    if (++hitnr>=8l) hitnr=0l;
  291.    for (loop=0l;loop<5l;loop++)
  292.    hitmap.Planes[loop]=(UBYTE *)((long)(hitbit)+160l*hitnr+32l*loop);
  293.   }
  294.   if ((hitdel>1000l)&&(horpos+spr_offset+16l>=281l))
  295.   {
  296.    speed=4.0;
  297.    hitflag=0;
  298.    spr_offset=8l;
  299.    hitdel=0l;
  300.    t=ran();
  301.    if (t<.1) spr_offset=16l;
  302.    if ((t>=.1)&&(t<.2)) score+=40; 
  303.    if ((t>=.2)&&(t<.3)) { lives++; PrintStuff(); }
  304.    if ((t>=.3)&&(t<.4)) { stage++; LoadStage(21l,25l); goto realstart;}
  305.    if ((t>=.4)&&(t<.5)) hitflag=1;
  306.    if ((t>=.5)&&(t<.6)) score+=75;
  307.    if ((t>=.6)&&(t<.7)) goto realstart;
  308.    if ((t>=.7)&&(t<.8)) speed=2.0;
  309.    if ((t>=.8)&&(t<.9)) speed=3.0; 
  310.    if (t>=.9) speed=5.0;
  311.   }
  312.   if (hitflag) { ballwinkel+=((ran()-.5)*10.0); newwinkel (ballwinkel);}
  313.   WaitTOF();
  314.   if (soundflag) { shutup(soundflag); soundflag=0; }
  315.   if (lives<1) break;
  316.   if (!(stonecount)) { stage++;LoadStage(21l,25l); goto realstart; }
  317.  } while (*key!=117);
  318.  FreeMem (soundbuffer,64000l);
  319.  FreeSprite (2l);
  320.  FreeSprite (3l);
  321.  FreeSprite (1l);
  322.  ClearPointer (win);
  323.  RethinkDisplay();
  324.  silence(15);
  325.  if (score>highscore[9].punkte) PutHighScore();
  326. }
  327. editor()
  328. {
  329.  short xmouse,ymouse;
  330.  GetPicture ("Paranoid:gfx/escreen.dat",320l,256l,5l);
  331.  DisplayBeep (scr);
  332.  stage=0l;level.p_num=0;stone=1;
  333.  PrintMuster(); PrintRunde ();
  334.  CleanFields();
  335.  while (TRUE)
  336.  {
  337.   while (!(*button&(UBYTE)64));
  338.   while (*button&(UBYTE)64);
  339.   if (CheckRange (2,105,20,113)) break;
  340.   if ((CheckRange (2,90,20,103))&&(stage>0l))
  341.   { stage--; PrintRunde(); continue; }
  342.   if ((CheckRange (2,75,20,88))&&(stage<99l))
  343.   { stage++; PrintRunde(); continue; }
  344.   if ((CheckRange (157,34,168,44))&&(level.p_num>0))
  345.   { level.p_num--; PrintMuster(); continue; }
  346.   if ((CheckRange (144,34,155,44))&&(level.p_num<15))
  347.   { level.p_num++; PrintMuster(); continue; }  
  348.   if (CheckRange (144,9,168,19)) { CleanFields(); continue; }
  349.   if (CheckRange (80,12,95,17)) { stone=1; continue; }
  350.   if (CheckRange (102,12,117,17)) { stone=2; continue; }
  351.   if (CheckRange (124,12,139,17)) { stone=3; continue; }
  352.   if (CheckRange (80,24,95,29)) { stone=4; continue; }
  353.   if (CheckRange (102,24,117,29)) { stone=5; continue; }
  354.   if (CheckRange (124,24,139,29)) {stone=6; continue; }
  355.   if (CheckRange (80,36,95,41)) {stone=7; continue; }
  356.   if (CheckRange (124,36,139,41)) { stone=8; continue; }
  357.   if (CheckRange (102,36,117,41)) { stone=0; continue; }
  358.   if (CheckRange (35,80,306,219)) { paint(); continue; }
  359.   if (CheckRange (2,27,20,44)) { SaveStage(); continue;}
  360.   if (CheckRange (2,9,20,25))
  361.   { LoadStage(32l,35l); PrintRunde(); PrintMuster(); continue;}
  362.  }
  363. }
  364. /*********************************************************************
  365.  *   Hier stehen die Hilfsroutinen                                   *
  366.  *********************************************************************/
  367. GetMouseMove()
  368. {
  369.  register char *move=(char *) 0xdff00b;
  370.  register char new,summ;
  371.  new=*move;
  372.  summ=oldmouse-new;
  373.  oldmouse=new;
  374.  mousemove=(long)(-1.2*(float)(summ));
  375.  horpos+=mousemove;
  376.  if (horpos+mousemove<20l) horpos=20l;
  377.  if (horpos+mousemove>284l-spr_offset) horpos=284l-spr_offset;
  378. }
  379. float rad (deg)
  380. float deg;
  381. {
  382.  return (3.141593*deg/180.0);
  383. }
  384. newwinkel(grad)
  385. float grad;
  386. {
  387.  while (grad>=180.0) grad-=180.0;
  388.  while (grad<=-180.0) grad+=180.0;
  389.  ballwinkel=2.0*grad-ballwinkel;
  390.  if (ballwinkel>180.2)  ballwinkel-=360.0;
  391.  if (ballwinkel<-180.2) ballwinkel+=360.0;
  392.  if ((ballwinkel>.0)&&(ballwinkel<=180.0))
  393.  ycheck=0l;
  394.  else  ycheck=4l;
  395.  if ((ballwinkel>-90.0)&&(ballwinkel<=90.0))
  396.  xcheck=4l;
  397.  else  xcheck=0l;
  398.  sinwert=sin(rad(ballwinkel));
  399.  coswert=cos(rad(ballwinkel));
  400. }
  401. PlaySound (start,laenge,rate,channels,volume)
  402. ULONG *start,volume,laenge;
  403. USHORT rate,channels;
  404. {
  405.  USHORT loop,avol;
  406.  USHORT *ctlw,*c0tl,*c0per,*c0vol;
  407.  ULONG  *c0thi;
  408.  c0thi = (ULONG  *) 0xdff0a0;
  409.  c0tl  = (USHORT *) 0xdff0a4;
  410.  c0per = (USHORT *) 0xdff0a6;
  411.  c0vol = (USHORT *) 0xdff0a8;
  412.  ctlw  = (USHORT *) 0xdff096;
  413.  for (loop=1;loop<=8;loop*=2)
  414.  {
  415.   avol=0;
  416.   avol=(UBYTE)(volume>>(8*(loop/2-loop/8)));
  417.   if (loop&channels)
  418.   {
  419.    *c0thi = (ULONG) start;
  420.    *c0tl  = (UWORD) (laenge>>1l);
  421.    *c0vol = avol;
  422.    *c0per = rate;
  423.   }
  424.   c0thi=(ULONG *)((ULONG)(c0thi)+0x10l);
  425.   c0tl=(USHORT *)((ULONG)(c0tl)+0x10l);
  426.   c0per=(UWORD *)((ULONG)(c0per)+0x10l);
  427.   c0vol=(UWORD *)((ULONG)(c0vol)+0x10l);
  428.  }
  429.  *ctlw  = 0x8200+channels;
  430. }
  431. shutup(channels)
  432. UWORD channels;
  433. {
  434.  USHORT loop;
  435.  USHORT *c0tl=(USHORT *) 0xdff0a4;
  436.  ULONG  *c0thi=(ULONG *) 0xdff0a0; 
  437.  for (loop=1;loop<=8;loop*=2)
  438.  {
  439.   if (loop&channels)
  440.   {
  441.    *c0thi = (ULONG) sound2;
  442.    *c0tl  = 20;
  443.   }
  444.   c0thi=(ULONG *)((ULONG)(c0thi)+0x10l);
  445.   c0tl=(USHORT *)((ULONG)(c0tl)+0x10l);
  446.  }
  447. }
  448. silence(channels)
  449. USHORT channels;
  450. {
  451.  USHORT *ctlw=(USHORT *) 0xdff096;
  452.  *ctlw=channels;
  453. }
  454. /* Hier steht pixtest(); */
  455. #asm
  456.     public    _pixtest
  457. _pixtest:
  458.     movem.l    d1-d7/a0-a6,-(sp)
  459. ;60(a7) ist x,64(a7) ist y
  460.     addq.l    #1,60(a7)
  461.     move.l    _ycheck,d0
  462.     add.l    d0,64(a7)
  463.     jsr    offset
  464. ; schleife 1 mit d3
  465.     move.l    #2,d3
  466.     move.l    #1,d4
  467. loop1:
  468.     clr.l    d0
  469.     bset    d6,d0
  470.     and.b    (a0),d0
  471.     tst.b    d0
  472.     bne    raus1
  473.     subq.l    #1,d6
  474.     cmp.l    #-1,d6
  475.     bne    loop1on
  476.     move.l    #7,d6
  477.     addq.l    #1,a0
  478. loop1on:
  479.     addq.l    #1,d4
  480.     dbra    d3,loop1
  481.     subq.l    #1,60(a7)
  482.     move.l    _xcheck,d0
  483.     add.l    d0,60(a7)
  484.     move.l    _ycheck,d0
  485.     sub.l    d0,64(a7)
  486.     addq.l    #1,64(a7)    
  487.     jsr    offset
  488. ; schleife 1 mit d3
  489.     move.l    #2,d3
  490.     move.l    #1,d4
  491. loop2:
  492.     clr.l    d0
  493.     bset    d6,d0
  494.     and.b    (a0),d0
  495.     tst.b    d0
  496.     bne    raus2
  497.     adda.l    #40,a0    ;eventuell anpassen
  498.     addq.l    #1,d4
  499.     dbra    d3,loop2
  500. .pixend
  501.     movem.l    (sp)+,d1-d7/a0-a6
  502.     rts
  503. ;offset und bytepos berechnen,x und y sind um vier verschoben
  504. offset:
  505.     move.l    68(a7),d0
  506.     mulu    #40,d0    ; eventuell anpassen
  507.     move.l    64(a7),d1
  508.     divu    #8,d1
  509.     add.w    d1,d0
  510.     add.l    _bm5base,d0
  511.     movea.l    d0,a0
  512.     mulu    #8,d1
  513.     addq.l    #7,d1
  514.     sub.l    64(a7),d1
  515.     move.l    d1,d6
  516.     rts
  517. raus1:
  518.     move.l    _newx,_ballx
  519.     move.l    _newy,_bally
  520.     add.l    d4,_newx
  521.     move.l    _ycheck,d1
  522.     add.l    _newy,d1
  523.     move.l    d1,_newy
  524.     move.l    #1,d0
  525.     jmp    .pixend
  526. raus2:
  527.     move.l    _newx,_ballx
  528.     move.l    _newy,_bally
  529.     add.l    d4,_newy
  530.     move.l    _xcheck,d1
  531.     add.l    _newx,d1
  532.     move.l    d1,_newx
  533.     move.l    #2,d0
  534.     jmp    .pixend
  535. #endasm
  536. /************************************************************************
  537.  * Diese Routinen werden auch vom Editor benutzt.                       *
  538.  ************************************************************************/
  539.  
  540.  
  541. openstuff()
  542. {
  543.  if (!(OpenMaster())) { printf ("Keine Libraries\n"); exit(); }
  544.  SetRast (IntuitionBase->ActiveWindow->RPort,0l);
  545.  if (!(scr=MasterScreen(320,256,31,0l)))
  546.  { printf ("Kein Screen\n"); CloseMaster (0l,0l); }
  547.  if (!(win=MasterWindow (scr,0,0,320,256,0l,BORDERLESS,0l)))
  548.  { printf ("Kein Window\n"); CloseMaster (scr,0l); }
  549.  if (!(cmap=GetColorMap(32l))){printf ("Color Map\n"); CloseMaster (scr,win);}
  550.  vp=&(scr->ViewPort); rp=&(scr->RastPort);
  551.  bm=&(scr->BitMap); bm5base=(long)bm->Planes[4];
  552. }
  553. GetSound()
  554. {
  555. if (!(soundbuffer=AllocMem(64000l,MEMF_CHIP|MEMF_PUBLIC)))
  556.  { printf ("No Memory for sounds\n"); CloseMaster(scr,win); }
  557.  if (!(fh=Open ("Paranoid:music/parsound.dat",1004l)))
  558.  { printf ("Sounddata not found\n"); CloseMaster(scr,win); }
  559.  Disable();
  560.  Read (fh,soundbuffer,62878l);
  561.  Close (fh);
  562.  Enable();
  563. }
  564. GetPicture(name,x,y,planes)
  565. char *name;
  566. long x,y,planes;
  567. {
  568.  long loop;
  569.  if (!(fh=Open(name,1005l)))
  570.  { printf ("No Picture\n"); CloseMaster (scr,win);}
  571.  SetRast (rp,0l);
  572.  ScreenToBack (scr);
  573.  Disable();
  574.  for (loop=0l;loop<planes;loop++)
  575.  Read (fh,bm->Planes[loop],(x*y)/8l);
  576.  Read (fh,cmap->ColorTable,2l*(1l<<planes));
  577.  Close (fh);
  578.  LoadRGB4 (vp,cmap->ColorTable,(1l<<planes));
  579.  RemakeDisplay();
  580.  Enable();
  581.  ScreenToFront (scr);
  582. }
  583. GetData ()
  584. {
  585.  long loop;
  586.  if (!(fh=Open("Paranoid:gfx/muster.dat",1004l)))
  587.  { printf ("No pattern\n"); CloseMaster (scr,win);}
  588.  Read (fh,pattern,2048l);
  589.  Close (fh);
  590.  if (!(fh=Open("Paranoid:gfx/hit.dat",1004l)))
  591.  { printf ("No hit\n"); CloseMaster (scr,win);}
  592.  Read (fh,hitbit,1280l);
  593.  Close (fh);
  594.  for (loop=0l;loop<5l;loop++)
  595.  hitmap.Planes[loop]=(UBYTE *)((long)(hitbit)+32l*loop);
  596.  if (!(fh=Open("Paranoid:highscore",1004l)))
  597.  { printf ("No scorelist\n"); return;}
  598.  Read (fh,highscore,320l);
  599.  Close (fh);
  600. }
  601. SetStone(x,y,num,base)
  602. ULONG x,y,num,base;
  603. {
  604.  long c1,c2,c3;
  605.  c1=sc1[num]; c2=sc2[num]; c3=sc3[num];
  606.  SetAfPt (rp,0l,0);
  607.  SetAPen (rp,c2);
  608.  RectFill (rp,base+17l*x,80l+7l*y,base+17l*x+15l,80l+7l*y+5l);
  609.  SetAPen (rp,c1);
  610.  Move (rp,base+17l*x,80l+7l*y+5l);
  611.  Draw (rp,base+17l*x,80l+7l*y);
  612.  Draw (rp,base+17l*x+15l,80l+7l*y);
  613.  SetAPen (rp,c3);
  614.  Move (rp,base+1l+17l*x,80l+7l*y+5l);
  615.  Draw (rp,base+17l*x+15l,80l+7l*y+5l);
  616.  Draw (rp,base+17l*x+15l,81l+7l*y);
  617. }
  618. KillStone (x,y,base)
  619. long x,y,base;
  620. {
  621.  UWORD *pzeiger=(UWORD *)((long)(pattern)+128l*(long)(level.p_num));
  622.  long xloc,yloc;
  623.  SetAPen (rp,15l);
  624.  SetAfPt (rp,pzeiger,-4);
  625.  xloc=(x-base)/17l;
  626.  yloc=(y-80l)/7l;
  627.  RectFill (rp,base+xloc*17l,80l+yloc*7l,base+xloc*17l+15l,80l+7l*yloc+5l);
  628.  SetAfPt (rp,0l,0);
  629. }
  630. CheckRange (x1,y1,x2,y2)
  631. short x1,y1,x2,y2;
  632. {
  633.  short xm,ym;
  634.  if (*button&(UBYTE)64) return (0);
  635.  xm=scr->MouseX; ym=scr->MouseY;
  636.  if ((xm<x1)||(xm>x2)||(ym<y1)||(ym>y2))
  637.  return (0);
  638.  while (!(*button&(UBYTE)64)); 
  639.  xm=scr->MouseX; ym=scr->MouseY;
  640.  if ((xm<x1)||(xm>x2)||(ym<y1)||(ym>y2))
  641.  return (0);
  642.  else return(1);
  643. }
  644. PrintRunde()
  645. {
  646.  char runde[2];short st=(short)stage;
  647.  runde[0]=48+(char)(st/10);
  648.  st=st-10*(st/10);
  649.  runde[1]=48+(char)st;
  650.  SetAPen (rp,1l);
  651.  Move (rp,4l,55l);
  652.  Text (rp,runde,1l);
  653.  Move (rp,11l,64l);
  654.  Text (rp,&(runde[1]),1l);
  655. }
  656. PrintMuster ()
  657. {
  658.  char ziffer[2];short pn=level.p_num;
  659.  UWORD *pzeiger;
  660.  pzeiger=(UWORD *)((long)(pattern)+128l*(long)(level.p_num));
  661.  SetAPen (rp,15l); SetAfPt (rp,pzeiger,-4);
  662.  RectFill (rp,201l,14l,299l,39l);
  663.  RectFill (rp,176l,16l,191l,31l);
  664.  SetAfPt (rp,0l,0); SetAPen (rp,1l);
  665.  ziffer[0]=48+(char)(pn/10);
  666.  pn=pn-10*(pn/10);
  667.  ziffer[1]=48+(char)pn;
  668.  Move (rp,148l,30l);
  669.  Text (rp,ziffer,1l);
  670.  Move (rp,157l,30l);
  671.  Text (rp,&(ziffer[1]),1l);
  672. }
  673. CleanFields()
  674. {
  675.  long loop;
  676.  UWORD *pzeiger;
  677.  for (loop=0l;loop<320l;loop++) level.stones[loop]=0;
  678.  pzeiger=(UWORD *)((long)(pattern)+128l*(long)(level.p_num));
  679.  SetAPen (rp,15l); SetAfPt (rp,pzeiger,-4);
  680.  RectFill (rp,32l,57l,311l,243l);
  681.  SetAfPt (rp,0l,0);
  682. }
  683. paint()
  684. {
  685.  long xloc,yloc;
  686.  xloc=(long)((scr->MouseX-35l)/17);
  687.  yloc=(long)((scr->MouseY-80l)/7l);
  688.  if (!(stone))
  689.  {
  690.   KillStone ((long)(scr->MouseX),(long)(scr->MouseY),35l); 
  691.   level.stones[xloc+yloc*16]=0;
  692.   return (0l);
  693.  }
  694.  do
  695.  {
  696.   SetStone (xloc,yloc,(long)stone,35l);
  697.   level.stones[xloc+yloc*16]=(UBYTE)stone;
  698.   xloc=(long)((scr->MouseX-35l)/17);
  699.   yloc=(long)((scr->MouseY-80l)/7l);
  700.   if ((scr->MouseX>306)||(scr->MouseX<35)) return;
  701.   if ((scr->MouseY>219)||(scr->MouseY<80)) return;
  702.   while (*button&(UBYTE)64)
  703.   {
  704.    if ((scr->MouseX>306)||(scr->MouseX<35)) return;
  705.    if ((scr->MouseY>219)||(scr->MouseY<80)) return;
  706.   }
  707.  } while (1);
  708. }
  709. SaveStage()
  710. {
  711.  char name[50];
  712.  char ziffer[2];short st=(short)stage;
  713.  ziffer[0]=48+(char)(st/10);
  714.  st=st-10*(st/10);
  715.  ziffer[1]=48+(char)st;
  716.  sprintf (name,"Paranoid:levels/runde%c%c",ziffer[0],ziffer[1]);
  717.  if (!(fh=Open(name,1006l)))
  718.  { printf ("No Save-File\n"); CloseMaster (scr,win);}
  719.  Write (fh,&level,322l);
  720.  Close (fh);
  721. }
  722. LoadStage(b1,b2)
  723. long b1,b2;
  724. {
  725.  long x,y;
  726.  char name[50],ziffer[2];
  727.  short st;
  728.  UWORD *pzeiger;
  729.  begin_load:
  730.  st=(short)stage;
  731.  ziffer[0]=48+(char)(st/10);
  732.  st=st-10*(st/10);
  733.  ziffer[1]=48+(char)st;
  734.  sprintf (name,"Paranoid:levels/runde%c%c",ziffer[0],ziffer[1]);
  735.  if (!(fh=Open(name,1004l)))
  736.  { DisplayBeep (scr); stage=0; goto begin_load; }
  737.  Read (fh,&level,322l);
  738.  Close (fh);
  739.  pzeiger=(UWORD *)((long)(pattern)+128l*(long)(level.p_num));
  740.  SetAPen (rp,15l); SetAfPt (rp,pzeiger,-4);
  741.  RectFill (rp,b1,57l,b1+279l,243l);
  742.  SetAfPt (rp,0l,0);
  743.  stonecount=0l;
  744.  for (y=0l;y<20l;y++)
  745.  {
  746.   for (x=0l;x<16l;x++)
  747.   {
  748.    if (level.stones[y*16l+x])
  749.    { SetStone (x,y,(long)(level.stones[y*16l+x]),b2); stonecount++; }
  750.   }
  751.  }
  752.  if (!(stonecount)) { stage++; goto begin_load; }
  753. }
  754. PrintScore()
  755. {
  756.  long loop,wert=10000l,posn=40l;
  757.  long punkte=(long)score;
  758.  SetAPen (rp,1l);
  759.  for (loop=0l;loop<5l;loop++)
  760.  {
  761.   newscore[loop]=(UBYTE)(48l+punkte/wert);
  762.   punkte=punkte-wert*(punkte/wert);
  763.   wert/=10l;
  764.   if (oldscore[loop]!=newscore[loop])
  765.   {
  766.    Move (rp,posn,23l);
  767.    Text (rp,&(newscore[loop]),1l);
  768.   }
  769.   posn+=9l;
  770.   oldscore[loop]=newscore[loop]; 
  771.  }
  772. }
  773. PrintStuff()
  774. {
  775.  char ziffer[2];short st=stage;
  776.  char qwertz[2];short li=lives;
  777.  ziffer[0]=48+(char)(st/10);
  778.  st=st-10*(st/10);
  779.  ziffer[1]=48+(char)st;
  780.  qwertz[0]=48+(char)(li/10);
  781.  li=li-10*(li/10);
  782.  qwertz[1]=48+(char)li;
  783.  SetAPen (rp,1l);
  784.  Move (rp,110l,23l); Text (rp,ziffer,1l);
  785.  Move (rp,119l,23l); Text (rp,&(ziffer[1]),1l);
  786.  Move (rp,150l,23l); Text (rp,qwertz,1l);
  787.  Move (rp,159l,23l); Text (rp,&(qwertz[1]),1l);
  788. }
  789. /***************************************************************************
  790.  *     Hier stehen die HighScore Routinen                                  *
  791.  ***************************************************************************/
  792. PrintHighScore()
  793. {
  794.  long loop;
  795.  char sbuff[10];
  796.  SetAPen (rp,1l);
  797.  for (loop=0l;loop<10l;loop++)
  798.  {
  799.   sprintf (sbuff,"%d",highscore[loop].punkte);
  800.   Move (rp,10l,40l+loop*15l);
  801.   Text (rp,sbuff,(long) strlen(sbuff));
  802.   Move (rp,61l,40l+loop*15l);
  803.   Text (rp,highscore[loop].name,(long) strlen (highscore[loop].name));
  804.  }
  805. }
  806.  
  807. PutHighScore()
  808. {
  809.  long loop,t;
  810.  GetPicture ("Paranoid:gfx/highscreen.dat",320l,256l,2l);
  811.  for (loop=9l;loop>=0l;loop--)
  812.  {
  813.   if (score<highscore[loop].punkte) break;
  814.  }
  815.  loop++;
  816.  for (t=9l;t>loop;t--)
  817.  {
  818.   highscore[t].punkte=highscore[t-1l].punkte;
  819.   strcpy(highscore[t].name,highscore[t-1l].name);
  820.  }
  821.  highscore[loop].punkte=score;
  822.  PrintHighScore();
  823.  GetName (loop);
  824.  if (!(fh=Open ("Paranoid:highscore",1006l)))
  825.  { printf ("highdata not found\n"); return; }
  826.  Write (fh,highscore,320l);
  827.  Close (fh);
  828. }
  829. GetName (nummer)
  830. long nummer;
  831. {
  832.  long count=0l;
  833.  UBYTE nbuff[40];
  834.  nbuff[0]=0;
  835.  while (1)
  836.  {
  837.   SetAPen (rp,0l);
  838.   RectFill (rp,60l,30l+nummer*15l,300l,43l+nummer*15l);
  839.   SetAPen (rp,1l);
  840.   Move (rp,61l,40l+nummer*15l);
  841.   Text (rp,nbuff,(long)strlen(nbuff));
  842.   if (count>28l) break;
  843.   while (!(*button&(UBYTE)64)); /* Solange,bis Button oben */
  844.   while (*button&(UBYTE)64);  /* Solange,bis Button unten */
  845.   if (CheckRange(220,203,258,244)) break;
  846.   if ((count>0l)&&(CheckRange(61,203,99,244))) { nbuff[--count]=0; continue;}
  847.   if (CheckRange(109,210,212,216))
  848.   {
  849.    nbuff[count]=(UBYTE)(65+(scr->MouseX-109)/8);
  850.    nbuff[++count]=0;
  851.    continue;
  852.   }
  853.   if (CheckRange (109,220,212,226))
  854.   {
  855.    nbuff[count]=(UBYTE)(78+(scr->MouseX-109)/8);
  856.    nbuff[++count]=0;
  857.    continue;
  858.   }
  859.   if (CheckRange (109,230,188,236))
  860.   {
  861.    nbuff[count]=(UBYTE)(48+(scr->MouseX-109)/8);
  862.    nbuff[++count]=0;
  863.    continue;
  864.   }
  865.   if (CheckRange (189,230,196,236))
  866.   { nbuff[count]='-'; nbuff[++count]=0; continue; }
  867.   if (CheckRange (197,230,204,236))
  868.   { nbuff[count]='/'; nbuff[++count]=0; continue; }
  869.   if (CheckRange (205,230,212,236))
  870.   { nbuff[count]='.'; nbuff[++count]=0; continue; }
  871.   if (CheckRange (213,230,220,236))
  872.   { nbuff[count]=' '; nbuff[++count]=0; continue;}
  873.  }
  874.  strcpy (highscore[nummer].name,nbuff);
  875. }
  876.