Advertisement
ZoriaRPG

Arkanoid.zs

Aug 12th, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 71.41 KB | None | 0 0
  1. import "std.zh"
  2.  
  3. //TODO:
  4. // Add corner check for WALLS for various angles.
  5. // Implement new angles after collision with walls and bricks.
  6. // Implement enemies.
  7.  
  8. //Arkanoid script
  9. //v0.19
  10. //22nd August, 2018
  11.  
  12. //////////////////////
  13. /// Script issues: ///
  14. //////////////////////
  15.  
  16. // We need to either re-arrange the living/dead/death logic, or add another animation phase.
  17. // May as well set up the Vaus explosion and add it with a SPARKLE LWeapon.
  18.  
  19.  
  20.  
  21. //# QUEST ISSUE: Bricks Break playing the wrong sound, despite being set. Might be a 2.54 bug? -Z
  22.  
  23. /* ZC issues:
  24.     Continue script does not run when Init script runs. It NEEDS to do that! Otherwise, settings that affect things such as Link's tile
  25.     don't happen before the opening wipe.
  26.    
  27. */
  28.  
  29. /// Changes, Revision History
  30. ///
  31. ///
  32. /// Alpha 0.16: Reverted Alpha 0.15 changes back to before adding any angular physics.
  33. ///     Then, re-implemented ONLY the Vaus midpoint physics.
  34. ///     Fixed the hack for UID in brick.take_hit(). This means that ZC 2.54 Alpha **32** is now the minimum ZC version.
  35.  
  36. //Alpha 18: Added 'fast mouse' mode, enabled using V to increase the fast mouse speed, and C tpo decrease it.
  37. //  The mouse mode must be enabled for this to function!
  38. //  Fast Mouse moves the Vaus N pixels per frame, based on the distance that the mouse travels * fast_mouse.
  39.  
  40. //Radians for special directions.
  41. const float DIR_UUL = 4.3197;
  42. const float DIR_LUU = 4.3197;
  43. const float DIR_LLU = 3.5343;
  44. const float DIR_ULL = 3.5343;
  45. const float DIR_LLD = 2.7489;
  46. const float DIR_DLL = 2.7489;
  47. const float DIR_DDL = 1.9635;
  48. const float DIR_LDD = 1.9635;
  49. const float DIR_DDR = 1.1781;
  50. const float DIR_RDD = 1.1781;
  51. const float DIR_RRD = 0.3927;
  52. const float DIR_DRR = 0.3927;
  53. const float DIR_RRU = 5.1051;
  54. const float DIR_URR = 5.1051;
  55. const float DIR_RUU = 5.1141;
  56. const float DIR_UUR = 5.1141;
  57.  
  58. int last_mouse_x;
  59. int fast_mouse;
  60. const int FAST_MOUSE_MAX = 6;
  61.  
  62. const int MIN_ZC_ALPHA_BUILD = 33; //Alphas are negatives, so we neex to check maximum, not minimum.
  63.  
  64.  
  65. const float ARKANOID_VERSION = 0.16;
  66.  
  67. int GAME[256];
  68. const int GAME_MISC_FLAGS = 0;
  69. const int GMFS_PLAYED_GAME_OVER_MUSIC = 0x01;
  70.  
  71. const int FFC_VAUS = 1;
  72. const int CMB_VAUS_EXTENDED = 1528;
  73. const int CMB_VAUS = 1524;
  74. const int CMB_VAUS_DEAD = 1520;
  75.  
  76. const int MID_STAGE_START = 4;
  77. const int NPCM_AWARDED_POINTS = 3; //brick->Misc[], flag to mark if points were awarded to the player.
  78. const int NPC_ATTRIB_POINTS = 0; //brick->Attributes[], value for score.
  79.  
  80. //Counters
  81. const int CR_SCORE = 7; //script 1
  82. const int CR_LIVES = 8;
  83.  
  84. int quit;
  85.  
  86. const int QUIT_TITLE = -1;
  87. const int QUIT_GAME_RUNNING = 0; //i.e., !quit
  88. const int QUIT_GAMEOVER = 1;
  89.  
  90. const int MAX_BALL_SPEED = 300;
  91.  
  92. int caught;
  93. int frame;
  94. bool newstage = true;
  95. bool revive_vaus = false;
  96.  
  97. int ball_x;
  98. int ball_y;
  99. int ball_dir;
  100. int ball_angle;
  101. int ball_speed;
  102. int ball_vx;
  103. int ball_vy;
  104. int paddle_x;
  105. int paddle_y;
  106. int paddle_width = 16;
  107. int paddle_speed = 2;
  108. int extended;
  109.  
  110. int ball_uid;
  111.  
  112. //animation
  113. int death_frame;
  114.  
  115. const int DEATH_ANIM_MAX = 8;
  116.  
  117. int death_anim[DEATH_ANIM_MAX];
  118. const int DEATH_ANIM_TIMER = 0;
  119. const int DEATH_ANIM_1 = 1; //1-7 Unused
  120. const int DEATH_ANIM_2 = 2;
  121. const int DEATH_ANIM_3 = 3;
  122. const int DEATH_ANIM_4 = 4;
  123. const int DEATH_ANIM_5 = 5;
  124. const int DEATH_ANIM_6 = 6;
  125. const int DEATH_ANIM_COUNTDOWN_TO_QUIT = 7;
  126.  
  127.  
  128.  
  129. const int COUNTDOWN_TO_QUIT_FRAMES = 289; //36*8+1;
  130.  
  131. int templayer[4];
  132.  
  133. int input_accel; //pressing left and right for multiple frames increases this
  134. int frames_pressed[18];
  135.  
  136. //ffc paddle;
  137.  
  138. int hit_zones[5]; //angle offsets for where the ball strikes the paddle
  139.  
  140. const int WALL_LEFT = 24;
  141. const int WALL_TOP = 8; //Mix Ball Y
  142. const int WALL_RIGHT = 232;
  143.  
  144. const int BALL_MIN_Y = 9; //ceiling +1
  145. const int BALL_MAX_Y = 145; //one pixel under paddle top
  146. const int BALL_MIN_X = 25; //left wall +1
  147. const int BALL_MAX_X = 229; //right wall -1
  148.  
  149.  
  150.  
  151. const int START_PADDLE_X = 62;
  152. const int START_PADDLE_Y = 160;
  153. const int START_PADDLE_WIDTH = 32;
  154. const int START_PADDLE_HEIGHT = 8;
  155. const int BALL_WIDTH = 4;
  156. const int BALL_HEIGHT = 4;
  157. const int START_BALL_X = 98; //(START_PADDLE_X + 36);
  158. const int START_BALL_Y = 156; //START_PADDLE_Y - 4;
  159. const int START_BALL_DIR = 5; //DIR_UPRIGHT;
  160. const int START_BALL_RADS = 220; //angle in radians
  161. const int START_BALL_SPEED = 45;
  162. const int START_BALL_VX = 0;
  163. const int START_BALL_VY = 0;
  164.  
  165. const int PADDLE_MIN_X = 25;
  166. const int PADDLE_MAX_X = 200; //WALL_RIGHT -32; //This one varies as the paddle width may change.
  167. const int PADDLE_MAX_X_EXTENDED = 184; //WALL_RIGHT - 48; //This one varies as the paddle width may change.
  168. const int PADDLE_MIN_X_EXTENDED = 25;
  169.  
  170. const int _MOUSE_X = 0;
  171. const int _MOUSE_Y = 1;
  172. const int _MOUSE_LCLICK = 2;
  173.  
  174. //const float ACCEL_FACTOR = 0.25;
  175.  
  176. const int FRAMES_PER_MOVEMENT = 10;
  177. int USE_ACCEL = 0; //Do we accelerate KB/JP input?
  178. int USE_MOUSE = 0; //Are we using the mouse?
  179.  
  180.  
  181. /*
  182. const int CB_UP     = 0;
  183. const int CB_DOWN   = 1;
  184. const int CB_LEFT   = 2;
  185. const int CB_RIGHT  = 3;
  186. const int CB_A      = 4;
  187. const int CB_B      = 5;
  188. const int CB_L      = 7;
  189. const int CB_R      = 8;
  190. const int CB_START  = 6;
  191. const int CB_MAP    = 9;
  192. const int CB_EX1    = 10;
  193. const int CB_EX2    = 11;
  194. const int CB_EX3    = 12;
  195. const int CB_EX4    = 13;
  196. const int CB_AXIS_UP    = 14;
  197. const int CB_AXIS_DOWN  = 15;
  198. const int CB_AXIS_LEFT  = 16;
  199. const int CB_AXIS_RIGHT = 17;
  200.  
  201. */
  202.  
  203. ffc script paddle
  204. {
  205.     void run(){}
  206.    
  207.     bool move(bool mouse, bool accel, ffc p)
  208.     {
  209.         int dir; int dist;
  210.         if ( mouse )
  211.         {
  212.             Game->ClickToFreezeEnabled = false;
  213.             if ( fast_mouse )
  214.             {
  215.                 int distx = Input->Mouse[_MOUSE_X] - last_mouse_x;
  216.                 //Trace(distx);
  217.                 last_mouse_x = Input->Mouse[_MOUSE_X];
  218.                 if ( !extended )
  219.                 {
  220.                    
  221.                     if ( distx < 0 )
  222.                     {
  223.                         Trace(distx);
  224.                         for ( int q = Abs(distx) * fast_mouse; q > 0 ; --q )
  225.                         {
  226.                            
  227.                             if ( p->X > PADDLE_MIN_X )
  228.                             {
  229.                                 --p->X;
  230.                             }
  231.                            
  232.                         }
  233.                     }
  234.                     else if ( distx > 0 )
  235.                     {
  236.                         Trace(distx);
  237.                         for ( int q = Abs(distx) * fast_mouse; q > 0 ; --q )
  238.                         {
  239.                            
  240.                             if ( p->X < PADDLE_MAX_X )
  241.                             {
  242.                                 ++p->X;
  243.                             }
  244.                            
  245.                         }
  246.                     }
  247.                 }
  248.                 else //extended
  249.                 {
  250.                    
  251.                     if ( distx < 0 )
  252.                     {
  253.                         for ( int q = Abs(distx); q > 0 ; --q )
  254.                         {
  255.                             for ( int q = fast_mouse; q > 0; --q )
  256.                             {
  257.                                 if ( p->X > PADDLE_MIN_X_EXTENDED )
  258.                                 {
  259.                                     --p->X;
  260.                                 }
  261.                             }
  262.                         }
  263.                     }
  264.                     else
  265.                     {
  266.                         for ( int q = Abs(distx); q > 0 ; --q )
  267.                         {
  268.                             for ( int q = fast_mouse; q > 0; --q )
  269.                             {
  270.                                 if ( p->X > PADDLE_MAX_X_EXTENDED )
  271.                                 {
  272.                                     ++p->X;
  273.                                 }
  274.                             }
  275.                         }
  276.                     }
  277.                 }
  278.                
  279.             }
  280.             else
  281.             {
  282.                 //get the mouse movement this frame and apply a relative amount to the paddle
  283.                 //set the dir here
  284.                 //set the dist here
  285.                 //if moving left
  286.                 //if ( p->X > PADDLE_MIN_X )
  287.                 //{
  288.                 //  p->X = Input->Mouse[_MOUSE_X];
  289.                     //apply change -- ZC has no special mouse tracking.
  290.                 //}
  291.                 //if moving right
  292.                 if ( !extended )
  293.                 {
  294.                     if ( Input->Mouse[_MOUSE_X] <= PADDLE_MAX_X )
  295.                     {
  296.                         if ( Input->Mouse[_MOUSE_X] >= PADDLE_MIN_X )
  297.                         {
  298.                             //apply change
  299.                             p->X = Input->Mouse[_MOUSE_X];
  300.                         }
  301.                     }
  302.                 }
  303.                 else
  304.                 {
  305.                     if ( Input->Mouse[_MOUSE_X] <= PADDLE_MAX_X_EXTENDED )
  306.                     {
  307.                         if ( Input->Mouse[_MOUSE_X] >= PADDLE_MIN_X_EXTENDED )
  308.                         {
  309.                             //apply change
  310.                             p->X = Input->Mouse[_MOUSE_X];
  311.                         }
  312.                     }
  313.                 }
  314.             }
  315.         }
  316.         else //using a KB or joypad
  317.         {
  318.             Game->ClickToFreezeEnabled = true;
  319.             //check how long the dir button is held
  320.             if ( accel ) //if we allow acceleratiopn, move N pixeld * accel factor * frames held
  321.             {
  322.                
  323.                 if ( !extended )
  324.                 {
  325.                     if (  Input->Button[CB_LEFT] )
  326.                     {
  327.                         for ( int q = frames_pressed[CB_LEFT]; q > 0 ; --q )
  328.                         {
  329.                             if ( p->X > PADDLE_MIN_X )
  330.                             {
  331.                                 --p->X;
  332.                             }
  333.                         }
  334.                     }
  335.                     if (  Input->Button[CB_RIGHT] )
  336.                     {
  337.                         for ( int q = frames_pressed[CB_RIGHT]; q > 0; --q )
  338.                         {
  339.                             if ( p->X < PADDLE_MAX_X )
  340.                             {
  341.                                 ++p->X;
  342.                             }
  343.                         }
  344.                     }
  345.                 }
  346.                
  347.             }
  348.            
  349.             else //no accel offered, move a static number of pixels
  350.             {
  351.                
  352.                 if ( !extended )
  353.                 {
  354.                     if (  Input->Button[CB_LEFT] )
  355.                     {
  356.                         for ( int q = 0; q < paddle_speed; ++q )
  357.                         {
  358.                             if ( p->X > PADDLE_MIN_X )
  359.                             {
  360.                                 --p->X;
  361.                             }
  362.                         }
  363.                     }
  364.                     if (  Input->Button[CB_RIGHT] )
  365.                     {
  366.                         for ( int q = 0; q < paddle_speed; ++q )
  367.                         {
  368.                             if ( p->X < PADDLE_MAX_X )
  369.                             {
  370.                                 ++p->X;
  371.                             }
  372.                         }
  373.                     }
  374.                 }
  375.                 else
  376.                 {
  377.                     if (  Input->Button[CB_LEFT] )
  378.                     {
  379.                         if ( p->X > PADDLE_MIN_X_EXTENDED )
  380.                         {
  381.                             --p->X;
  382.                         }
  383.                     }
  384.                     if (  Input->Button[CB_RIGHT] ) {
  385.                         if ( p->X < PADDLE_MAX_X_EXTENDED )
  386.                         {
  387.                             ++p->X;
  388.                         }
  389.                     }
  390.                    
  391.                 }
  392.             }
  393.         }
  394.        
  395.     }
  396.  
  397.     void check_input()
  398.     {
  399.         if ( Input->Button[CB_LEFT] ) ++frames_pressed[CB_LEFT];
  400.         else frames_pressed[CB_LEFT] = 0;
  401.         if ( Input->Button[CB_RIGHT] ) ++frames_pressed[CB_RIGHT];
  402.         else frames_pressed[CB_RIGHT] = 0;
  403.        
  404.     }
  405.    
  406.     void extend(ffc p)
  407.     {
  408.         if ( extended )
  409.         {
  410.             if ( p->TileWidth < 3 )
  411.             {
  412.                 p->Data = CMB_VAUS_EXTENDED;
  413.                 p->TileWidth = 3;
  414.             }
  415.         }
  416.         else
  417.         {
  418.             if ( p->TileWidth > 2 )
  419.             {
  420.                 p->Data = CMB_VAUS;
  421.                 p->TileWidth = 2;
  422.             }
  423.         }
  424.     }
  425.     void setup(ffc p)
  426.     {
  427.         p->Y = START_PADDLE_Y;
  428.         p->X = START_PADDLE_X;
  429.         p->Data = CMB_VAUS;
  430.         p->TileWidth = 2;
  431.        
  432.     }
  433.     void dead(ffc p)
  434.     {
  435.         p->Data = CMB_VAUS_DEAD;
  436.         p->TileWidth = 2;
  437.         death_frame = frame;
  438.     }
  439.    
  440.  
  441. }
  442.  
  443. const int MISC_BALLID = 0; //Misc index of Vaud->Misc[]
  444. const int MISC_DEAD = 1; //Misc index of Vaud->Misc[]
  445. const int MISC_LAUNCHED = 0; //Misc index of ball->Misc[]
  446.  
  447. const int BALL_MINIMUM_Y = 24; //Invisible line at which point, ball is lost.
  448.  
  449. ffc script holdlink
  450. {
  451.     void run()
  452.     {
  453.         while(1)
  454.         {
  455.             Link->Y = START_PADDLE_Y - 4;
  456.             Waitframe();
  457.         }
  458.     }
  459. }
  460.        
  461. const int TEST_254_GETPIXEL = 1;
  462.  
  463. global script arkanoid
  464. {
  465.    
  466.     void run()
  467.     {
  468.         check_min_zc_build();
  469.        
  470.         TraceNL(); TraceS("Starting Arkanoid"); TraceNL(); TraceS("Game 'quit' state: "); Trace(quit);
  471.         TraceNL(); TraceS("Game version, Alpha "); Trace(ARKANOID_VERSION);
  472.        
  473.         //frame = -1;
  474.         ffc vaus = Screen->LoadFFC(FFC_VAUS);
  475.         lweapon movingball;
  476.         npc vaus_guard;
  477.         bool ext;
  478.         Link->CollDetection = false;
  479.         Link->DrawYOffset = -32768;
  480.        
  481.         if ( TEST_254_GETPIXEL )
  482.         {
  483.             bitmap bmp = Game->LoadBitmapID(RT_SCREEN);
  484.             int col[20];
  485.             for ( int q = 0; q < 20; ++ q )
  486.             {
  487.                 col[q] = bmp->GetPixel(10+q*8,10+q*8);
  488.             }
  489.             TraceNL();
  490.             for ( int q = 0; q < 20; ++q )
  491.             {
  492.                 TraceS("Bitmap col: "); Trace(col[q]);
  493.             }
  494.            
  495.             Screen->SetRenderTarget(2);
  496.             Screen->Rectangle(0, 0, 0, 256, 256, 0x55, 100, 0, 0, 0, true, 128);
  497.             Screen->SetRenderTarget(RT_SCREEN);
  498.             Waitframe();
  499.            
  500.             bitmap offscreen = Game->LoadBitmapID(2);
  501.             int col2[20];
  502.             for ( int q = 0; q < 20; ++ q )
  503.             {
  504.                 col2[q] = offscreen->GetPixel(10+q*8,10+q*8);
  505.             }
  506.             TraceNL();
  507.             for ( int q = 0; q < 20; ++q )
  508.             {
  509.                 TraceS("Offscreen Bitmap col: "); Trace(col2[q]);
  510.             }
  511.         }
  512.        
  513.         ball.setup_sprite(SPR_BALL);
  514.         while(true)
  515.         {
  516.             while(!quit)
  517.             {
  518.                 ++frame;
  519.                 if ( Input->Key[KEY_L] ) ++Game->Counter[CR_LIVES];
  520.                 hold_Link_y(); //Don't allow Link to leave the screen, bt
  521.                     //keep his X and Y matched to the Vaus!
  522.                 hold_Link_x(vaus); //Link is used to cause floating enemies to home in on the vaus.
  523.                 if ( newstage )
  524.                 {
  525.                     //vaus_guard = Screen->CreateNPC(NPC_VAUSGUARD);
  526.                     Game->PlayMIDI(MID_STAGE_START);
  527.                     brick.setup();
  528.                     Waitframes(6);
  529.                    
  530.                     brick.clear_combos();
  531.                    
  532.                     newstage = false;
  533.                     paddle.setup(vaus);
  534.                     ball.create(vaus);
  535.                     movingball = vaus->Misc[MISC_BALLID];
  536.                    
  537.                 }
  538.                 if ( revive_vaus ) //when this is called, the ball breaks through all bricks. Something isn't being set.
  539.                 {
  540.                     Game->PlayMIDI(MID_STAGE_START);
  541.                     vaus->Misc[MISC_DEAD] = 0;
  542.                     revive_vaus = false;
  543.                    
  544.                     paddle.setup(vaus);
  545.                     ball.create(vaus);
  546.                     movingball = vaus->Misc[MISC_BALLID];
  547.                 }
  548.                
  549.                 if ( !vaus->Misc[MISC_DEAD] )
  550.                 {
  551.                    
  552.                     if ( Input->Key[KEY_9] )
  553.                     {
  554.                         bitmap bmp = Game->LoadBitmapID(RT_SCREEN);
  555.                         int col[20];
  556.                         for ( int q = 0; q < 20; ++ q )
  557.                         {
  558.                             col[q] = bmp->GetPixel(10+q*8,10+q*8);
  559.                         }
  560.                         TraceNL();
  561.                         for ( int q = 0; q < 20; ++q )
  562.                         {
  563.                             TraceS("Bitmap col: "); Trace(col[q]);
  564.                         }
  565.                        
  566.                         Screen->SetRenderTarget(2);
  567.                         Screen->Rectangle(0, 0, 0, 256, 256, 0x55, 100, 0, 0, 0, true, 128);
  568.                         Screen->SetRenderTarget(RT_SCREEN);
  569.                         Waitframe();
  570.                        
  571.                         bitmap offscreen = Game->LoadBitmapID(2);
  572.                         int col2[20];
  573.                         for ( int q = 0; q < 20; ++ q )
  574.                         {
  575.                             col2[q] = offscreen->GetPixel(10+q*8,10+q*8);
  576.                         }
  577.                         TraceNL();
  578.                         for ( int q = 0; q < 20; ++q )
  579.                         {
  580.                             TraceS("Offscreen Bitmap col: "); Trace(col2[q]);
  581.                         }
  582.                     }  
  583.                     //if ( Input->Key[KEY_P] ) Trace(movingball->UID); //Frick, I'm an idiot. HIT_BY_LWEAPON is the SCREEN INDEX< not the UID!!
  584.                         //2.54 Absolutely needs HitBy_UID!
  585.                     if ( Input->Key[KEY_1] ) Trace(frame);
  586.                     //if ( frame%60 == 0 ) { Trace(movingball->Step); }
  587.                     //Trace(movingball->Step);
  588.                     change_setting(); //check for a setting change_setting
  589.                     paddle.extend(vaus);
  590.                     paddle.check_input();
  591.                     paddle.move(USE_MOUSE, USE_ACCEL, vaus);
  592.                    
  593.                     ball.launch(movingball);
  594.                     if ( !ball.launched(movingball) )
  595.                     {
  596.                         ball.move_with_vaus(movingball, vaus);
  597.                     }
  598.                    
  599.                    
  600.                     //clamp within bounds - MANDATORY because very fast Step speeds can cause the ball
  601.                     //to *phase* through pseudo-solid objects, such as walls and the Vaus.
  602.                     ball.clamp_rightwall(movingball);
  603.                     ball.clamp_ceiling(movingball);
  604.                     ball.clamp_leftwall(movingball);
  605.                     ball.clamp_bottom(movingball, vaus);
  606.                    
  607.                    
  608.                     //ball wall bounce checks
  609.                     ball.check_ceiling(movingball);
  610.                     ball.check_leftwall(movingball);
  611.                     ball.check_rightwall(movingball);
  612.                     ball.check_hitvaus(movingball, vaus);
  613.                     //ball.set_speed(movingball);
  614.                     /*
  615.                    
  616.                     I moved this to after Waitdraw, because I wanted the post-draw timing for ball bounce, and to ensure that
  617.                     the movingball lweapon stayed alive. -Z (Alpha 0.10)
  618.                     //Bounce ball on bricks.
  619.                     for ( int q = Screen->NumNPCs(); q > 0; --q )
  620.                     {
  621.                         npc b = Screen->LoadNPC(q);
  622.                         if ( b->Type != NPCT_OTHERFLOAT ) continue;
  623.                         TraceNL(); TraceS("movingball->X = "); Trace(movingball->X);
  624.                         TraceNL(); TraceS("movingball->Y = "); Trace(movingball->Y);
  625.                         brick.take_hit(b, movingball);
  626.                     }
  627.                     */
  628.                     movingball->DeadState = WDS_ALIVE; //Force it alive at all times if the vaus is alive.
  629.                         //We'll need another solition once we do the 3-way split ball. Bleah.
  630.                 }
  631.                
  632.                 //It's probably unwise to run this block twice! Where do I want it, before or after Waitdraw() ? -Z
  633.                 else
  634.                 {
  635.                     paddle.dead(vaus); //Set the death animation here.
  636.                    
  637.                     /*
  638.                     while ( (frame - 100) < death_frame )
  639.                     {
  640.                         //we should hide the vaus, and restart the stage here.
  641.                         ++frame;
  642.                         Waitdraw(); //Something is preventing the vaus from changing into the explosion style. S
  643.                         Waitframe();
  644.                     }
  645.                     lweapon deadball = movingball;
  646.                     deadball->DeadState = WDS_DEAD;
  647.                     movingball = vaus->Misc[10];
  648.                     if ( Game->Counter[CR_LIVES] )
  649.                     {
  650.                         --Game->Counter[CR_LIVES];
  651.                         revive_vaus = true;
  652.                     }
  653.                     */
  654.                    
  655.                 }
  656.                
  657.                
  658.                 Waitdraw();
  659.                
  660.                 if ( Input->Key[KEY_7] )
  661.                     {
  662.                         bitmap bmp = Game->LoadBitmapID(RT_SCREEN);
  663.                         int col[20];
  664.                         for ( int q = 0; q < 20; ++ q )
  665.                         {
  666.                             col[q] = bmp->GetPixel(10+q*8,10+q*8);
  667.                         }
  668.                         TraceNL();
  669.                         for ( int q = 0; q < 20; ++q )
  670.                         {
  671.                             TraceS("Bitmap col: "); Trace(col[q]);
  672.                         }
  673.                        
  674.                         Screen->SetRenderTarget(2);
  675.                         Screen->Rectangle(0, 0, 0, 256, 256, 0x55, 100, 0, 0, 0, true, 128);
  676.                         Screen->SetRenderTarget(RT_SCREEN);
  677.                         Waitframe();
  678.                        
  679.                         bitmap offscreen = Game->LoadBitmapID(2);
  680.                         int col2[20];
  681.                         for ( int q = 0; q < 20; ++ q )
  682.                         {
  683.                             col2[q] = offscreen->GetPixel(10+q*8,10+q*8);
  684.                         }
  685.                         TraceNL();
  686.                         for ( int q = 0; q < 20; ++q )
  687.                         {
  688.                             TraceS("Offscreen Bitmap col: "); Trace(col2[q]);
  689.                         }
  690.                     }
  691.                    
  692.                
  693.                 hold_Link_y();
  694.                
  695.                 if ( !vaus->Misc[MISC_DEAD] )
  696.                 {
  697.                     movingball->DeadState = WDS_ALIVE;
  698.                    
  699.                     //Bounce ball on bricks.
  700.                     for ( int q = Screen->NumNPCs(); q > 0; --q )
  701.                     {
  702.                         npc b = Screen->LoadNPC(q);
  703.                         if ( b->Type != NPCT_OTHERFLOAT ) continue;
  704.                         //TraceNL(); TraceS("movingball->X = "); Trace(movingball->X);
  705.                         //TraceNL(); TraceS("movingball->Y = "); Trace(movingball->Y);
  706.                         movingball->DeadState = WDS_ALIVE;
  707.                         //TraceNL(); TraceS("movingball ptr: "); Trace(movingball);
  708.                         brick.take_hit(b, movingball);
  709.                     }
  710.                    
  711.                 }
  712.                 else
  713.                 {
  714.                     paddle.dead(vaus);
  715.                     while ( (frame - 100) < death_frame )
  716.                     {
  717.                         //we should hide the vaus, and restart the stage here.
  718.                         ++frame;
  719.                         Waitdraw();
  720.                         Waitframe();
  721.                     }
  722.                     lweapon deadball = movingball;
  723.                     deadball->DeadState = WDS_DEAD;
  724.                     movingball = Debug->NULL(); //Because = NULL() requires alpha 32. :D
  725.                     if ( Game->Counter[CR_LIVES] )
  726.                     {
  727.                         --Game->Counter[CR_LIVES];
  728.                         revive_vaus = true;
  729.                     }
  730.                     else //Ugh, this is a mess. I might want to rewrite the gane over portion, as it feels as if it'll be a biugger kludge than just calling break.
  731.                     {
  732.                         if ( !death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT] )
  733.                         {
  734.                             death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT] = COUNTDOWN_TO_QUIT_FRAMES;
  735.                             continue;
  736.                         }
  737.                         else
  738.                         {
  739.                             --death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT];
  740.                             if ( death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT] == 1 )
  741.                             {
  742.                                 quit = QUIT_GAMEOVER; //Game over state.
  743.                                 TraceNL(); TraceS("Game 'quit' state is now: "); Trace(quit);
  744.                             }
  745.                         }
  746.                     }
  747.                        
  748.                 }
  749.                
  750.                 Waitframe();
  751.             }
  752.            
  753.             while (quit == QUIT_GAMEOVER) //Game Over
  754.             {
  755.                 if ( !(GAME[GAME_MISC_FLAGS]&GMFS_PLAYED_GAME_OVER_MUSIC) )
  756.                 {
  757.                     GAME[GAME_MISC_FLAGS]|=GMFS_PLAYED_GAME_OVER_MUSIC;
  758.                     //Play Game over MIDI
  759.                     Game->PlayMIDI(1);
  760.                 }
  761.                    
  762.                 Screen->DrawString(6, 96, 80, 1, 0x51, 0x00, 0, "GAME OVER", 128);
  763.                
  764.                 Waitdraw();
  765.                 Waitframe();
  766.             }
  767.             //We should never reach here.
  768.             Waitframe();
  769.         }
  770.     }
  771.     void change_setting()
  772.     {
  773.         if ( Input->Key[KEY_V] && (frame%10 == 0)) { if ( fast_mouse < FAST_MOUSE_MAX ) ++fast_mouse; TraceNL(); TraceS("fast_mouse is now: "); Trace(fast_mouse);  }
  774.         if ( Input->Key[KEY_C] && (frame%10 == 0) ) { if ( fast_mouse > 0 ) --fast_mouse; TraceNL(); TraceS("fast_mouse is now: "); Trace(fast_mouse);  }
  775.         if ( Input->Key[KEY_M] ) USE_MOUSE = 1;
  776.         if ( Input->Key[KEY_N] ) USE_MOUSE = 0;
  777.         if ( Input->Key[KEY_F] ) USE_ACCEL = 1;
  778.         if ( Input->Key[KEY_G] ) USE_ACCEL = 0;
  779.         if ( Input->Key[KEY_T] ) --paddle_speed; // paddle_speed = vbound(paddle_speed
  780.         if ( Input->Key[KEY_Y] ) ++paddle_speed; // paddle_speed = vbound(paddle_speed
  781.     }
  782.     void hold_Link_x(ffc v)
  783.     {
  784.         Link->X = v->X+(v->TileWidth*8);
  785.     }
  786.     void hold_Link_y()
  787.     {
  788.         Link->Y = START_PADDLE_Y - 4;
  789.     }
  790.     bool quit() { return ( quit ); }
  791.    
  792.     void check_min_zc_build()
  793.     {
  794.         if ( Game->Beta < MIN_ZC_ALPHA_BUILD )
  795.         {
  796.             Game->PlayMIDI(9);
  797.             int v_too_early = 600; int req_vers[3]; itoa(req_vers, MIN_ZC_ALPHA_BUILD);
  798.             TraceNL(); int vers[3]; itoa(vers,Game->Beta);
  799.             TraceS("This version of Arkanoid.qst requires Zelda Classic v2.54, Alpha (");
  800.             TraceS(req_vers);
  801.             TraceS("), or later.");
  802.             TraceNL();
  803.             TraceS("I'm detecting Zelda Classic v2.54, Alpha (");
  804.             TraceS(vers);
  805.             TraceS(") and therefore, I must refuse to run. :) ");
  806.             TraceNL();
  807.            
  808.             while(v_too_early--)
  809.             {
  810.                 //Screen->DrawString(7, 4, 40, 1, 0x04, 0x5F, 0,
  811.                 //"This version of Arkanoid.qst requires Zelda Classic 2.54, Alpha 32",
  812.                 //128);
  813.                 Screen->DrawString(7, 15, 40, 1, 0x04, 0x5F, 0,
  814.                 "You are not using a version of ZC adequate to run         ",
  815.                 128);
  816.                
  817.                 Screen->DrawString(7, 15, 55, 1, 0x04, 0x5F, 0,
  818.                 "this quest. Please see allegro.log for details.                   ",
  819.                 128);
  820.            
  821.                 Waitdraw();
  822.                 WaitNoAction();
  823.             }
  824.             Game->End();
  825.            
  826.         }
  827.     }
  828.    
  829. }
  830.  
  831. const int TILE_BALL = 50512;
  832. const int SPR_BALL = 100;
  833.  
  834.  
  835.  
  836. //preliminary ball
  837. ffc script ball
  838. {
  839.     void run(){}
  840.     void setup_sprite(int sprite_id)
  841.     {
  842.         spritedata sd = Game->LoadSpriteData(sprite_id);
  843.         sd->Tile = TILE_BALL;
  844.     }
  845.     void set_speed(lweapon b, int speed)
  846.     {
  847.         //Trace(bounces);
  848.         b->Step = speed; // bound(bounces,0,MAX_BOUNCES);
  849.         //Trace(b->Step);
  850.     }
  851.     void create(ffc vaus_id) //send the ball lweapon pointer back to the vaus
  852.     {
  853.         lweapon ball = Screen->CreateLWeapon(LW_SCRIPT1);
  854.         TraceNL(); TraceS("Creating ball with Script UID: "); Trace(ball->UID);
  855.         ball->HitWidth = 6; //Not 4, so that the ball bounces when its edges touch a brick.
  856.         ball->HitHeight = 6; //Not 4, so that the ball bounces when its edges touch a brick.
  857.         ball->UseSprite(SPR_BALL);
  858.         ball->X = vaus_id->X+18;
  859.         ball->Y = vaus_id->Y-2;
  860.         ball->Damage = 1;
  861.         ball_uid = ball->UID;
  862.         ball->HitXOffset = -1; //so that the ball bounces when its edges touch a brick.
  863.         ball->HitYOffset = -1; //so that the ball bounces when its edges touch a brick.
  864.         vaus_id->Misc[MISC_BALLID] = ball;
  865.     }
  866.     void launch(lweapon b)
  867.     {
  868.         if ( b->Misc[MISC_LAUNCHED] ) return;
  869.         bool launched;
  870.         for ( int q = CB_A; q < CB_R; ++q )
  871.         {
  872.             if ( Input->Press[q] ) { launched = true; break; }
  873.         }
  874.         if ( USE_MOUSE )
  875.         {
  876.             //if ( Input->Mouse[_MOUSE_LCLICK] )  //Not working?!
  877.             if ( Link->InputMouseB )
  878.                 launched = true;
  879.         }
  880.         if ( launched )
  881.         {
  882.             //b->Angular = true;
  883.             Game->PlaySound(6);
  884.             b->Dir = DIR_RIGHTUP;  
  885.             b->Step = 90;
  886.             b->Misc[MISC_LAUNCHED] = 1;
  887.         }
  888.     }
  889.     bool launched(lweapon b)
  890.     {
  891.         return (b->Misc[MISC_LAUNCHED]);
  892.     }
  893.     void move(lweapon b)
  894.     {
  895.        
  896.     }
  897.     float bound(int val, int min, int max)
  898.     {
  899.         if ( val < min ) return min;
  900.         if ( val > max ) return max;
  901.         return val;
  902.     }
  903.     //Not launched yet.
  904.     void move_with_vaus(lweapon b, ffc v)
  905.     {
  906.         b->X = v->X+18;
  907.     }
  908.     //ball.clamp*() are needed for when the step speed is so great that the ball skips past the equality checks.
  909.     void clamp_ceiling(lweapon b)
  910.     {
  911.         if ( b->Y < BALL_MIN_Y )           
  912.         {
  913.             b->Y = BALL_MIN_Y;
  914.         }
  915.     }
  916.     void clamp_leftwall(lweapon b)
  917.     {
  918.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  919.         if ( b->X < BALL_MIN_X ) b ->X = BALL_MIN_X;
  920.     }
  921.     void clamp_rightwall(lweapon b)
  922.     {
  923.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  924.         if ( b->X > BALL_MAX_X ) b->X = BALL_MAX_X;
  925.     }
  926.     /*
  927.     void clamp_bottom(lweapon b, ffc v)
  928.     {
  929.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  930.         if ( b->Y+4 > v->Y+8 ) dead(b,v);
  931.     }
  932.     */
  933.     //A function to check of the bounding will prevent the ball from falling out of field.
  934.     void clamp_bottom(lweapon b, ffc v)
  935.     {
  936.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  937.         if ( b->Y+4 > v->Y ) b->Y = v->Y-4;
  938.     }
  939.     void check_ceiling(lweapon b)
  940.     {
  941.         if ( b->Y == BALL_MIN_Y )          
  942.         {
  943.             Game->PlaySound(7);
  944.             if ( b->Angular )
  945.             {
  946.                 switch(b->Angle)
  947.                 {
  948.                     case DIR_LLU:
  949.                     {
  950.                         b->Angular = false;
  951.                         b->Dir = DIR_LEFTDOWN;
  952.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  953.                         break;
  954.                     }
  955.                     case DIR_LUU:
  956.                     {
  957.                         b->Angular = false;
  958.                         b->Dir = DIR_LEFTDOWN;
  959.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  960.                         break;
  961.                     }
  962.                     case DIR_RRU:
  963.                     {
  964.                         b->Angular = false;
  965.                         b->Dir = DIR_RIGHTDOWN;
  966.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  967.                         break;
  968.                     }
  969.                     case DIR_RUU:
  970.                     {
  971.                         b->Angular = false;
  972.                         b->Dir = DIR_RIGHTDOWN;
  973.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  974.                         break;
  975.                     }
  976.                    
  977.                 }
  978.             }
  979.             else
  980.             {
  981.                 switch(b->Dir)
  982.                 {
  983.                     case DIR_RIGHTUP: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  984.                     case DIR_LEFTUP: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  985.                     default: {
  986.                         TraceNL(); TraceS("Ball direction invalid for ball.check_ceiling().");
  987.                             TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  988.                         b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  989.                 }
  990.             }
  991.         }
  992.     }
  993.     void check_leftwall(lweapon b)
  994.     {
  995.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  996.         if ( b->X == BALL_MIN_X )
  997.         {
  998.             Game->PlaySound(7);
  999.             if ( b->Angular )
  1000.             {
  1001.                 switch(b->Angle)
  1002.                 {
  1003.                     case DIR_LLU:
  1004.                     {
  1005.                         b->Angular = false;
  1006.                         b->Dir = DIR_RIGHTUP;
  1007.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1008.                         break;
  1009.                     }
  1010.                     case DIR_LUU:
  1011.                     {
  1012.                         b->Angular = false;
  1013.                         b->Dir = DIR_RIGHTUP;
  1014.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1015.                         break;
  1016.                     }
  1017.                     case DIR_LLD:
  1018.                     {
  1019.                         b->Angular = false;
  1020.                         b->Dir = DIR_RIGHTDOWN;
  1021.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1022.                         break;
  1023.                     }
  1024.                     case DIR_LDD:
  1025.                     {
  1026.                         b->Angular = false;
  1027.                         b->Dir = DIR_RIGHTDOWN;
  1028.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1029.                         break;
  1030.                     }
  1031.                    
  1032.                 }
  1033.             }
  1034.             else
  1035.             {
  1036.                 switch(b->Dir)
  1037.                 {
  1038.                     case DIR_LEFTDOWN: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1039.                     case DIR_LEFTUP: { b->Dir = DIR_RIGHTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1040.                     default: {
  1041.                         TraceNL(); TraceS("Ball direction invalid for ball.check_leftwall().");
  1042.                             TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  1043.                         b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1044.                 }
  1045.             }
  1046.         }
  1047.     }
  1048.     void check_rightwall(lweapon b)
  1049.     {
  1050.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  1051.         if ( b->X == BALL_MAX_X )
  1052.         {
  1053.             Game->PlaySound(7);
  1054.             if ( b->Angular )
  1055.             {
  1056.                 switch(b->Angle)
  1057.                 {
  1058.                     case DIR_RRD:
  1059.                     {
  1060.                         b->Angular = false;
  1061.                         b->Dir = DIR_LEFTDOWN;
  1062.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1063.                         break;
  1064.                     }
  1065.                     case DIR_RDD:
  1066.                     {
  1067.                         b->Angular = false;
  1068.                         b->Dir = DIR_LEFTDOWN;
  1069.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1070.                         break;
  1071.                     }
  1072.                     case DIR_RRU:
  1073.                     {
  1074.                         b->Angular = false;
  1075.                         b->Dir = DIR_RIGHTUP;
  1076.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1077.                         break;
  1078.                     }
  1079.                     case DIR_RUU:
  1080.                     {
  1081.                         b->Angular = false;
  1082.                         b->Dir = DIR_RIGHTUP;
  1083.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1084.                         break;
  1085.                     }
  1086.                    
  1087.                 }
  1088.             }
  1089.             else
  1090.             {
  1091.                 switch(b->Dir)
  1092.                 {
  1093.                     case DIR_RIGHTDOWN: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1094.                     case DIR_RIGHTUP: { b->Dir = DIR_LEFTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1095.                     default: {
  1096.                         TraceNL(); TraceS("Ball direction invalid for ball.check_rightwall().");
  1097.                             TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  1098.                         b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1099.                 }
  1100.             }
  1101.         }
  1102.     }
  1103.     void check_hitvaus(lweapon b, ffc v)
  1104.     {
  1105.         if ( launched(b) )
  1106.         {
  1107.            
  1108.             if ( b->Angular )
  1109.             {
  1110.                 if ( b->Angle == DIR_UUR ){ return; }
  1111.                 if ( b->Angle == DIR_UUL ) { return; }
  1112.                 if ( b->Angle == DIR_ULL ) { return; }
  1113.                 if ( b->Angle == DIR_URR ) { return; }
  1114.             }
  1115.             else
  1116.             {
  1117.                 if ( b->Dir == DIR_RIGHTUP ) { return; }
  1118.                 if ( b->Dir == DIR_LEFTUP ) { return; }
  1119.             }
  1120.             //if ( Collision(b,v) ) //We'll refine this, later.
  1121.            
  1122.             //else
  1123.             //{
  1124.                 int hit_position; int vaus_midpoint =  v->X+(((v->TileWidth*16)/2)-1);
  1125.                 int midpoint_segment = v->X+(((v->TileWidth*16)/6));
  1126.                 int ball_midpoint = b->X+3;
  1127.                
  1128.                 if ( b->Y+4 == v->Y )
  1129.                     //Now we need to check here, if the paddle is under the ball:
  1130.                 {
  1131.                     if ( b->X >= v->X-3 ) //-3, because the ball is 4px wide, so we cover the last pixel of the ball against the furst pixel of the Vaus
  1132.                     {
  1133.                         if ( b->X <= v->X+((v->TileWidth*16)+4) ) //no +3 here, because it's the actual X, so the first pixel of the ball is covered by the last pixel of the vaus.
  1134.                         {
  1135.                             Game->PlaySound(6);
  1136.                             //b->Y = v->Y-1;
  1137.                            
  1138.                             if ( ball_midpoint <= vaus_midpoint ) //hit left side of vaus
  1139.                             {
  1140.                                 //more left than up, hit end of Vaus
  1141.                                 if ( b->X <= (v->X-1) )
  1142.                                 //if ( Abs(ball_midpoint-vaus_midpoint) <= 2 )
  1143.                                 {
  1144.                                     //angular up
  1145.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR Left-left-Up");
  1146.                                    
  1147.                                     b->Angular = true;
  1148.                                     b->Angle = DIR_LLU;
  1149.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_LUU);
  1150.                                     return;
  1151.                                 }
  1152.                                
  1153.                                 //more up than left, hit close to centre
  1154.                                 //else if ( (Abs(b->X+2)-vaus_midpoint) <= 3 )
  1155.                                 //if ( Abs(ball_midpoint-vaus_midpoint) <= 2 )
  1156.                                 if ( (Abs(vaus_midpoint - b->X+2)) <= 3 )
  1157.                                 {
  1158.                                     //angular up
  1159.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR Left-Up-Up");
  1160.                                    
  1161.                                     b->Angular = true;
  1162.                                     b->Angle = DIR_LUU;
  1163.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1164.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_LUU);
  1165.                                     return;
  1166.                                 }
  1167.                                 //hit between the zones, normal left-up
  1168.                                 else
  1169.                                 {
  1170.                                
  1171.                                     //hit the centre midpoint
  1172.                                     //set angular = false
  1173.                                     //set DIR_UL
  1174.                                     TraceNL(); TraceS("Setting ball dir to DIGITAL Left-Up");
  1175.                                     //b->Y = v->Y-1;
  1176.                                     b->Angular = false;
  1177.                                     b->Dir = DIR_UPLEFT;
  1178.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1179.                                     return;
  1180.                                 }
  1181.                                
  1182.                             }
  1183.                             else if ( ball_midpoint > vaus_midpoint ) //hit right side of vaus
  1184.                             {
  1185.                                 /*
  1186.                                 if ( Abs(ball_midpoint-vaus_midpoint) <= 2 )
  1187.                                 {
  1188.                                     //angular up
  1189.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR RIGHT-Up-Up");
  1190.                                     --b->Y;
  1191.                                     b->Angular = true;
  1192.                                     b->Angle = DIR_RUU;
  1193.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_RUU);
  1194.                        
  1195.                                 }
  1196.                                 if ( b->X >= (v->X+(v->TileWidth*16)-2) )
  1197.                                 {
  1198.                                     //angular, sideways
  1199.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR right-right-Up");
  1200.                                     --b->Y;
  1201.                                     b->Angular = true;
  1202.                                     b->Angle = DIR_RRU;
  1203.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_RRU);
  1204.                        
  1205.                                 }
  1206.                                 */
  1207.                                 //more up then right, hit vaus close to centre
  1208.                                 if ( (Abs(vaus_midpoint - b->X)) <= 3 )
  1209.                                 {
  1210.                                     //angular up
  1211.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR RIGHT-Up-Up");
  1212.                                    
  1213.                                     b->Angular = true;
  1214.                                     b->Angle = DIR_RUU;
  1215.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1216.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_RUU);
  1217.                                     return;
  1218.                                 }
  1219.                                 //more right than up, hit end of vaus
  1220.                                 else if ( b->X > ( vaus_midpoint + ((v->TileWidth*16)/2)-4) )
  1221.                                 //else if ( (Abs(vaus_midpoint - b->X)) >= v->X+((v->TileWidth*16)/2)-1 )
  1222.                                 {
  1223.                                     //angular up
  1224.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR RIGHT-right-Up");
  1225.                                    
  1226.                                     b->Angular = true;
  1227.                                     b->Angle = DIR_RRU;
  1228.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1229.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_RUU);
  1230.                                     return;
  1231.                                 }
  1232.                                 else
  1233.                                 {
  1234.                                     //hit the centre midpoint
  1235.                                     //set angular = false
  1236.                                     //set DIR_UR
  1237.                                     TraceNL(); TraceS("Setting ball dir to DIGITAL Right-Up");
  1238.                                     //b->Y = v->Y-6;
  1239.                                     b->Angular = false;
  1240.                                     b->Dir = DIR_UPRIGHT;
  1241.                                     //b->Dir = DIR_UPRIGHT;
  1242.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1243.                                     return;
  1244.                                 }
  1245.                                
  1246.                             }
  1247.                                
  1248.                             else //catchall
  1249.                             {
  1250.                                 switch(b->Dir)
  1251.                                 {
  1252.                                     case DIR_LEFTDOWN: { b->Dir = DIR_LEFTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1253.                                     case DIR_RIGHTDOWN: { b->Dir = DIR_RIGHTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1254.                                     default: { b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1255.                                 }
  1256.                             }
  1257.                         }
  1258.                         else
  1259.                         {
  1260.                             dead(b,v);
  1261.                         }
  1262.                     }
  1263.                     else
  1264.                     {
  1265.                         dead(b,v);
  1266.                     }
  1267.                 }
  1268.             //}
  1269.            
  1270.         }
  1271.     }
  1272.     void dead(lweapon b, ffc v)
  1273.     {
  1274.        
  1275.         Game->PlayMIDI(5);
  1276.         //remove the ball
  1277.         b->Y = -32768; b->Step = 0;
  1278.         v->Misc[MISC_DEAD] = 1;
  1279.         //if there are more balls in play, switch movingball to one of those
  1280.         //otherwise,
  1281.         //check next life
  1282.         //if more lives, reset playfield
  1283.         //otherwise game over
  1284.        
  1285.     }
  1286.    
  1287.    
  1288.    
  1289. }
  1290.  
  1291. ffc script ball_controller
  1292. {
  1293.     void run()
  1294.     {
  1295.         lweapon ball;
  1296.         lweapon active_ball; //will be used for when we have multiple balls.
  1297.         lweapon balls[3]; //for divide
  1298.         ball = Screen->CreateLWeapon(LW_SCRIPT1);
  1299.         ball->X = START_BALL_X;
  1300.         ball->Y = START_BALL_Y;
  1301.         this->Vx = START_BALL_VX;
  1302.         this->Vy = START_BALL_VY;
  1303.         bool alive = true;
  1304.         int num_balls = 1;
  1305.         while(alive)
  1306.         {
  1307.             if ( ball->Y <= BALL_MIN_Y )
  1308.             {
  1309.                 bounce();
  1310.             }
  1311.             if ( ball->X <= BALL_MIN_X )
  1312.             {
  1313.                 bounce();
  1314.             }
  1315.             if ( ball->X >= BALL_MAX_X )
  1316.             {
  1317.                 bounce();
  1318.             }
  1319.                
  1320.             if ( ball->Y >= BALL_MAX_Y )
  1321.             {
  1322.                 if ( num_balls < 2 )
  1323.                 {
  1324.                     alive = false;
  1325.                 }
  1326.                 else
  1327.                 {
  1328.                     kill_ball(ball); //removes this ball, and sets another ball to be the active one
  1329.                     --num_balls;
  1330.                 }
  1331.             }
  1332.             Waitframe();
  1333.         }
  1334.     }
  1335.     void bounce(){}
  1336.     void kill_ball(lweapon b){}
  1337.    
  1338. }
  1339.  
  1340. const int BRICK_MAX = 14;
  1341.  
  1342. //Layer 1
  1343. const int CMB_BRICK_RED     = 1488;
  1344. const int CMB_BRICK_WHITE   = 1490;
  1345. const int CMB_BRICK_BLUE    = 1492;
  1346. const int CMB_BRICK_ORANGE  = 1494;
  1347. const int CMB_BRICK_TEAL    = 1496;
  1348. const int CMB_BRICK_VIOLET  = 1498;
  1349. const int CMB_BRICK_GREEN   = 1500;
  1350. const int CMB_BRICK_YELLOW  = 1502;
  1351. const int CMB_BRICK_SILVER1 = 1504;
  1352. const int CMB_BRICK_SILVER2 = 1506;
  1353. const int CMB_BRICK_SILVER3 = 1508;
  1354. const int CMB_BRICK_SILVER4 = 1510;
  1355. const int CMB_BRICK_GOLD    = 1516;
  1356.  
  1357.  
  1358. //layer 2
  1359. const int CMB_BRICK_RED_LOW     = 1489;
  1360. const int CMB_BRICK_WHITE_LOW   = 1491;
  1361. const int CMB_BRICK_BLUE_LOW    = 1493;
  1362. const int CMB_BRICK_ORANGE_LOW  = 1495;
  1363. const int CMB_BRICK_TEAL_LOW    = 1497;
  1364. const int CMB_BRICK_VIOLET_LOW  = 1499;
  1365. const int CMB_BRICK_GREEN_LOW   = 1501;
  1366. const int CMB_BRICK_YELLOW_LOW  = 1503;
  1367. const int CMB_BRICK_SILVER1_LOW = 1505;
  1368. const int CMB_BRICK_SILVER2_LOW = 1507;
  1369. const int CMB_BRICK_SILVER3_LOW = 1509;
  1370. const int CMB_BRICK_SILVER4_LOW = 1511;
  1371. const int CMB_BRICK_GOLD_LOW    = 1517;
  1372.  
  1373. //enemies
  1374. const int NPC_BRICK_RED     = 181;
  1375. const int NPC_BRICK_WHITE   = 182;
  1376. const int NPC_BRICK_BLUE    = 183;
  1377. const int NPC_BRICK_ORANGE  = 184;
  1378. const int NPC_BRICK_TEAL    = 185;
  1379. const int NPC_BRICK_VIOLET  = 186;
  1380. const int NPC_BRICK_GREEN   = 187;
  1381. const int NPC_BRICK_YELLOW  = 188;
  1382. const int NPC_BRICK_SILVER1     = 189;
  1383. const int NPC_BRICK_SILVER2     = 190;
  1384. const int NPC_BRICK_SILVER3     = 255; //not set up yet;
  1385. const int NPC_BRICK_SILVER4     = 255; //not set up yet
  1386. const int NPC_BRICK_GOLD    = 191;
  1387.  
  1388.  
  1389. const int HIT_BY_LWEAPON = 2;
  1390. const int HIT_BY_LWEAPON_UID = 6;
  1391.  
  1392. ffc script brick
  1393. {
  1394.     void run()
  1395.     {
  1396.     }
  1397.     float bound(int val, int min, int max)
  1398.     {
  1399.         if ( val < min ) return min;
  1400.         if ( val > max ) return max;
  1401.         return val;
  1402.     }
  1403.     bool hit(npc a, lweapon v)
  1404.     {
  1405.         /*
  1406.         if ( a->HitBy[HIT_BY_LWEAPON] < 1 ) return false;
  1407.         a->Misc[12] = Screen->LoadLWeapon(a->HitBy[HIT_BY_LWEAPON]);
  1408.         lweapon hitwpn = a->Misc[12];
  1409.         return ( hitwpn->UID == v->UID );
  1410.         */
  1411.         return ( a->HitBy[HIT_BY_LWEAPON_UID] == v->UID );
  1412.         //int indx; //Until we have UIDs working for HitBy[], we need to do it this way.
  1413.         //for ( int q = Screen->NumLWeapons(); q > 0; --q )
  1414.         //{
  1415.         //  lweapon temp = Screen->LoadLWeapon(q);
  1416.         //  if ( temp->UID == v->UID )
  1417.         //  {
  1418.         //      indx = q; break;
  1419.         //  }
  1420.         //}
  1421.         //Link->Misc[0] = v; //We'll use this as scratch untyped space for the moment. -Z
  1422.         //TraceS("brick.hit() Link->Misc[] is: "); Trace(Link->Misc[0]);
  1423.         //TraceS("brick.hit() v is: "); Trace(v);
  1424.         //int temp_UID = v->UID * 10000; //this is a bug in HITBY[]. The HitBy value being stored is being multiplied by 10000, and it should not be.
  1425.             //as UID is not, and NEVER should be!!!
  1426.         //TraceNL(); TraceS("v->UID is: "); Trace(v->UID);
  1427.         /*
  1428.         To determine where a brick was hit, we first scan each brick and look to see which was
  1429.         hit at all, by our lweapon.
  1430.        
  1431.         The, we check if that ball is belove, above, right of, or left of the brick,
  1432.         and we read its direction.
  1433.        
  1434.         Using a logic chain from this data, we determine the direction that the ball should next
  1435.         take, when it bounces.
  1436.        
  1437.         */
  1438.         //HitBy[]
  1439.        
  1440.         //if ( a->HitBy[HIT_BY_LWEAPON] )
  1441.         //{
  1442.         //  TraceNL(); TraceS("a->HitBy[HIT_BY_LWEAPON] id: "); Trace(a->HitBy[HIT_BY_LWEAPON]);
  1443.         //  TraceNL();
  1444.         //  TraceS("Our Link->Misc scratch value `is: "); Trace((Link->Misc[0]+1));
  1445.         //}
  1446.        
  1447.         //! We'll use this method again when we add UIDs to HitBy[] ! -Z
  1448.         //return ( a->HitBy[HIT_BY_LWEAPON] == temp_UID );
  1449.         //return ( a->HitBy[HIT_BY_LWEAPON] == indx ); //(Link->Misc[0]+1) );
  1450.        
  1451.     }
  1452.     bool hit_below(npc a, lweapon v)
  1453.     {
  1454.         if ( v->Y == (a->Y + 8) ) return true; //we could do bounce here.
  1455.     }
  1456.     bool hit_above(npc a, lweapon v)
  1457.     {
  1458.         if ( v->Y == (a->Y - 4) ) return true; //we could do bounce here.
  1459.     }
  1460.     bool hit_left(npc a, lweapon v)
  1461.     {
  1462.         if ( v->X == (a->X - 4) ) return true; //we could do bounce here.
  1463.     }
  1464.     bool hit_right(npc a, lweapon v)
  1465.     {
  1466.         if ( v->X == (a->X + 16 ) ) return true; //we could do bounce here.
  1467.     }
  1468.    
  1469.     void take_hit(npc a, lweapon b)
  1470.     {
  1471.         if ( hit(a,b) )
  1472.         {
  1473.             //TraceNL(); TraceS("Brick hit!");
  1474.             b->DeadState = WDS_ALIVE;
  1475.             //TraceNL(); TraceS("brick->X = "); Trace(a->X);
  1476.             //TraceNL(); TraceS("brick->Y = "); Trace(a->Y);
  1477.             //TraceNL(); TraceS("ball->X = "); Trace(v->X);
  1478.             //TraceNL(); TraceS("ball->Y = "); Trace(v->Y);
  1479.             if ( hit_below(a,b) )
  1480.             {
  1481.                 //check the corners:
  1482.                 //lower-left corner
  1483.                 if ( hit_left(a,b) )
  1484.                 {
  1485.                    
  1486.                     if ( b->Angular )
  1487.                     {
  1488.                         switch(b->Angle)
  1489.                         {
  1490.                             case DIR_RRU:
  1491.                             {
  1492.                                 b->Angular = false;
  1493.                                 b->Dir = DIR_RIGHTDOWN;
  1494.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1495.                                 break;
  1496.                             }
  1497.                             case DIR_RRD:
  1498.                             {
  1499.                                 b->Angular = false;
  1500.                                 b->Dir = DIR_RIGHTUP;
  1501.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1502.                                 break;
  1503.                             }
  1504.                             case DIR_RUU:
  1505.                             {
  1506.                                 b->Angular = false;
  1507.                                 b->Dir = DIR_RIGHTDOWN;
  1508.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1509.                                 break;
  1510.                             }
  1511.                             case DIR_RDD:
  1512.                             {
  1513.                                 b->Angular = false;
  1514.                                 b->Dir = DIR_RIGHTUP;
  1515.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1516.                                 break;
  1517.                             }
  1518.                             case DIR_LLU:
  1519.                             {
  1520.                                 b->Angular = false;
  1521.                                 b->Dir = DIR_RIGHTDOWN;
  1522.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1523.                                 break;
  1524.                             }
  1525.                             case DIR_LUU:
  1526.                             {
  1527.                                 b->Angular = false;
  1528.                                 b->Dir = DIR_RIGHTDOWN;
  1529.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1530.                                 break;
  1531.                             }
  1532.                             case DIR_LLD:
  1533.                             {
  1534.                                 b->Angular = false;
  1535.                                 b->Dir = DIR_RIGHTUP;
  1536.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1537.                                 break;
  1538.                             }
  1539.                             case DIR_LDD:
  1540.                             {
  1541.                                 b->Angular = false;
  1542.                                 b->Dir = DIR_RIGHTUP;
  1543.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1544.                                 break;
  1545.                             }
  1546.                            
  1547.                         }
  1548.                     }
  1549.                     else
  1550.                     {
  1551.                         switch(b->Dir)
  1552.                         {
  1553.                             case DIR_DOWNRIGHT:
  1554.                             {
  1555.                                 b->Angular = false;
  1556.                                 b->Dir = DIR_UPLEFT;
  1557.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1558.                                 break;
  1559.                             }
  1560.                             case DIR_DOWNLEFT:
  1561.                             {
  1562.                                 b->Angular = false;
  1563.                                 b->Dir = DIR_UPRIGHT;
  1564.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1565.                                 break;
  1566.                             }
  1567.                             case DIR_UPRIGHT:
  1568.                             {
  1569.                                 b->Angular = false;
  1570.                                 b->Dir = DIR_DOWNLEFT;
  1571.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1572.                                 break;
  1573.                             }
  1574.                             case DIR_UPLEFT:
  1575.                             {
  1576.                                 b->Angular = false;
  1577.                                 b->Dir = DIR_DOWNRIGHT;
  1578.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1579.                                 break;
  1580.                             }  
  1581.                            
  1582.                         }
  1583.                     }
  1584.                    
  1585.                 }//end lower-left corner
  1586.                
  1587.                 else if ( hit_right(a,b) )
  1588.                     //lower-right corner
  1589.                 {
  1590.                    
  1591.                     if ( b->Angular )
  1592.                     {
  1593.                         switch(b->Angle)
  1594.                         {
  1595.                             case DIR_LLU:
  1596.                             {
  1597.                                 b->Angular = false;
  1598.                                 b->Dir = DIR_RIGHTDOWN;
  1599.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1600.                                 break;
  1601.                             }
  1602.                             case DIR_LLD:
  1603.                             {
  1604.                                 b->Angular = false;
  1605.                                 b->Dir = DIR_RIGHTDOWN;
  1606.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1607.                                 break;
  1608.                             }
  1609.                             case DIR_RUU:
  1610.                             {
  1611.                                 b->Angular = false;
  1612.                                 b->Dir = DIR_RIGHTDOWN;
  1613.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1614.                                 break;
  1615.                             }
  1616.                             case DIR_RDD:
  1617.                             {
  1618.                                 b->Angular = false;
  1619.                                 b->Dir = DIR_LEFTUP;
  1620.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1621.                                 break;
  1622.                             }
  1623.                             case DIR_LLU:
  1624.                             {
  1625.                                 b->Angular = false;
  1626.                                 b->Dir = DIR_RIGHTDOWN;
  1627.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1628.                                 break;
  1629.                             }
  1630.                             case DIR_LUU:
  1631.                             {
  1632.                                 b->Angular = false;
  1633.                                 b->Dir = DIR_RIGHTDOWN;
  1634.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1635.                                 break;
  1636.                             }
  1637.                             case DIR_LLD:
  1638.                             {
  1639.                                 b->Angular = false;
  1640.                                 b->Dir = DIR_LEFTUP;
  1641.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1642.                                 break;
  1643.                             }
  1644.                             case DIR_LDD:
  1645.                             {
  1646.                                 b->Angular = false;
  1647.                                 b->Dir = DIR_LEFTUP;
  1648.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1649.                                 break;
  1650.                             }
  1651.                            
  1652.                         }
  1653.                     }
  1654.                     else
  1655.                     {
  1656.                         switch(b->Dir)
  1657.                         {
  1658.                             case DIR_DOWNRIGHT:
  1659.                             {
  1660.                                 b->Angular = false;
  1661.                                 b->Dir = DIR_UPLEFT;
  1662.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1663.                                 break;
  1664.                             }
  1665.                             case DIR_DOWNLEFT:
  1666.                             {
  1667.                                 b->Angular = false;
  1668.                                 b->Dir = DIR_UPRIGHT;
  1669.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1670.                                 break;
  1671.                             }
  1672.                             case DIR_UPRIGHT:
  1673.                             {
  1674.                                 b->Angular = false;
  1675.                                 b->Dir = DIR_DOWNLEFT;
  1676.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1677.                                 break;
  1678.                             }
  1679.                             case DIR_UPLEFT:
  1680.                             {
  1681.                                 b->Angular = false;
  1682.                                 b->Dir = DIR_DOWNRIGHT;
  1683.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1684.                                 break;
  1685.                             }  
  1686.                            
  1687.                         }
  1688.                     }
  1689.                    
  1690.                    
  1691.                 }//end lower-right corner
  1692.                
  1693.                
  1694.                 else
  1695.                 {
  1696.                
  1697.                     if ( b->Angular )
  1698.                     {
  1699.                         switch(b->Angle)
  1700.                         {
  1701.                             case DIR_LLU:
  1702.                             {
  1703.                                 b->Angular = false;
  1704.                                 b->Dir = DIR_LEFTDOWN;
  1705.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1706.                                 break;
  1707.                             }
  1708.                             case DIR_LUU:
  1709.                             {
  1710.                                 b->Angular = false;
  1711.                                 b->Dir = DIR_LEFTDOWN;
  1712.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1713.                                 break;
  1714.                             }
  1715.                             case DIR_RRU:
  1716.                             {
  1717.                                 b->Angular = false;
  1718.                                 b->Dir = DIR_RIGHTDOWN;
  1719.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1720.                                 break;
  1721.                             }
  1722.                             case DIR_RUU:
  1723.                             {
  1724.                                 b->Angular = false;
  1725.                                 b->Dir = DIR_RIGHTDOWN;
  1726.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1727.                                 break;
  1728.                             }
  1729.                            
  1730.                         }
  1731.                     }
  1732.                     else
  1733.                     {
  1734.                         switch(b->Dir)
  1735.                         {
  1736.                             case DIR_RIGHTUP: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1737.                             case DIR_LEFTUP: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1738.                             default: { TraceNL(); TraceS("Ball direction invalid for brick.take_hit(hit_below()).");
  1739.                                 TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  1740.                                 b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1741.                         }
  1742.                     }
  1743.                 }
  1744.                 /*
  1745.                 switch ( v->Dir )
  1746.                 {
  1747.                     case DIR_UPRIGHT: { v->Dir = DIR_DOWNRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1748.                     case DIR_UPLEFT: { v->Dir = DIR_DOWNLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1749.                     default: { TraceS("hit_below() found an illegal ball direction"); break; }
  1750.                 }
  1751.                 */
  1752.                 if ( a->HP <= 0 )
  1753.                 {
  1754.                     //TraceS("Brick is dead. "); TraceNL();
  1755.                     //TraceS("a->Misc[NPCM_AWARDED_POINTS] is: "); Trace(a->Misc[NPCM_AWARDED_POINTS]); TraceNL();
  1756.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  1757.                     {
  1758.                         //TraceS("Can award points!"); TraceNL();
  1759.                         a->Misc[18] = 1;
  1760.                         //TraceS("The points for this brick are: "); Trace(a->Attributes[NPC_ATTRIB_POINTS]); TraceNL();
  1761.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  1762.                     }
  1763.                 }
  1764.             }
  1765.            
  1766.             else if ( hit_above(a,b) )
  1767.             {
  1768.                 //upper-left corner
  1769.                 if ( hit_left(a,b) )
  1770.                 {
  1771.                    
  1772.                     if ( b->Angular )
  1773.                     {
  1774.                         switch(b->Angle)
  1775.                         {
  1776.                             case DIR_RRD:
  1777.                             {
  1778.                                 b->Angular = false;
  1779.                                 b->Dir = DIR_LEFTDOWN;
  1780.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1781.                                 break;
  1782.                             }
  1783.                             case DIR_RDD:
  1784.                             {
  1785.                                 b->Angular = false;
  1786.                                 b->Dir = DIR_LEFTDOWN;
  1787.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1788.                                 break;
  1789.                             }
  1790.                             case DIR_RUU:
  1791.                             {
  1792.                                 b->Angular = false;
  1793.                                 b->Dir = DIR_LEFTUP;
  1794.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1795.                                 break;
  1796.                             }
  1797.                             case DIR_RDD:
  1798.                             {
  1799.                                 b->Angular = false;
  1800.                                 b->Dir = DIR_LEFTUP;
  1801.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1802.                                 break;
  1803.                             }
  1804.                             case DIR_LLU:
  1805.                             {
  1806.                                 b->Angular = false;
  1807.                                 b->Dir = DIR_LEFTDOWN;
  1808.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1809.                                 break;
  1810.                             }
  1811.                             case DIR_LUU:
  1812.                             {
  1813.                                 b->Angular = false;
  1814.                                 b->Dir = DIR_LEFTDOWN;
  1815.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1816.                                 break;
  1817.                             }
  1818.                             case DIR_LLD:
  1819.                             {
  1820.                                 b->Angular = false;
  1821.                                 b->Dir = DIR_RIGHTDOWN;
  1822.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1823.                                 break;
  1824.                             }
  1825.                             case DIR_LDD:
  1826.                             {
  1827.                                 b->Angular = false;
  1828.                                 b->Dir = DIR_RIGHTDOWN;
  1829.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1830.                                 break;
  1831.                             }
  1832.                            
  1833.                         }
  1834.                     }
  1835.                     else
  1836.                     {
  1837.                         switch(b->Dir)
  1838.                         {
  1839.                             case DIR_DOWNRIGHT:
  1840.                             {
  1841.                                 b->Angular = false;
  1842.                                 b->Dir = DIR_UPLEFT;
  1843.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1844.                                 break;
  1845.                             }
  1846.                             case DIR_DOWNLEFT:
  1847.                             {
  1848.                                 b->Angular = false;
  1849.                                 b->Dir = DIR_UPRIGHT;
  1850.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1851.                                 break;
  1852.                             }
  1853.                             case DIR_UPRIGHT:
  1854.                             {
  1855.                                 b->Angular = false;
  1856.                                 b->Dir = DIR_DOWNLEFT;
  1857.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1858.                                 break;
  1859.                             }
  1860.                             case DIR_UPLEFT:
  1861.                             {
  1862.                                 b->Angular = false;
  1863.                                 b->Dir = DIR_DOWNRIGHT;
  1864.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1865.                                 break;
  1866.                             }
  1867.                            
  1868.                         }
  1869.                     }
  1870.                    
  1871.                 }//end upper-left corner
  1872.                
  1873.                 //upper-right corner
  1874.                 else if ( hit_right(a,b) )
  1875.                 {
  1876.                    
  1877.                     if ( b->Angular )
  1878.                     {
  1879.                         switch(b->Angle)
  1880.                         {
  1881.                             case DIR_RRD:
  1882.                             {
  1883.                                 b->Angular = false;
  1884.                                 b->Dir = DIR_RIGHTUP;
  1885.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1886.                                 break;
  1887.                             }
  1888.                             case DIR_RDD:
  1889.                             {
  1890.                                 b->Angular = false;
  1891.                                 b->Dir = DIR_RIGHTUP;
  1892.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1893.                                 break;
  1894.                             }
  1895.                             case DIR_RUU:
  1896.                             {
  1897.                                 b->Angular = false;
  1898.                                 b->Dir = DIR_RIGHTDOWN;
  1899.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1900.                                 break;
  1901.                             }
  1902.                             case DIR_RDD:
  1903.                             {
  1904.                                 b->Angular = false;
  1905.                                 b->Dir = DIR_RIGHTDOWN;
  1906.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1907.                                 break;
  1908.                             }
  1909.                             case DIR_LLU:
  1910.                             {
  1911.                                 b->Angular = false;
  1912.                                 b->Dir = DIR_RIGHTUP;
  1913.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1914.                                 break;
  1915.                             }
  1916.                             case DIR_LUU:
  1917.                             {
  1918.                                 b->Angular = false;
  1919.                                 b->Dir = DIR_RIGHTUP;
  1920.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1921.                                 break;
  1922.                             }
  1923.                             case DIR_LLD:
  1924.                             {
  1925.                                 b->Angular = false;
  1926.                                 b->Dir = DIR_LEFTUP;
  1927.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1928.                                 break;
  1929.                             }
  1930.                             case DIR_LDD:
  1931.                             {
  1932.                                 b->Angular = false;
  1933.                                 b->Dir = DIR_LEFTUP;
  1934.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1935.                                 break;
  1936.                             }
  1937.                            
  1938.                         }
  1939.                     }
  1940.                     else
  1941.                     {
  1942.                         switch(b->Dir)
  1943.                         {
  1944.                             case DIR_DOWNRIGHT:
  1945.                             {
  1946.                                 b->Angular = false;
  1947.                                 b->Dir = DIR_UPLEFT;
  1948.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1949.                                 break;
  1950.                             }
  1951.                             case DIR_DOWNLEFT:
  1952.                             {
  1953.                                 b->Angular = false;
  1954.                                 b->Dir = DIR_UPRIGHT;
  1955.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1956.                                 break;
  1957.                             }
  1958.                             case DIR_UPRIGHT:
  1959.                             {
  1960.                                 b->Angular = false;
  1961.                                 b->Dir = DIR_DOWNLEFT;
  1962.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1963.                                 break;
  1964.                             }
  1965.                             case DIR_UPLEFT:
  1966.                             {
  1967.                                 b->Angular = false;
  1968.                                 b->Dir = DIR_DOWNRIGHT;
  1969.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1970.                                 break;
  1971.                             }
  1972.                            
  1973.                         }
  1974.                     }
  1975.                    
  1976.                 }
  1977.                 //end upper-right corners
  1978.                
  1979.                 //
  1980.                 else
  1981.                 {
  1982.                     if ( b->Angular )
  1983.                     {
  1984.                         switch(b->Angle)
  1985.                         {
  1986.                             case DIR_LLD:
  1987.                             {
  1988.                                 b->Angular = false;
  1989.                                 b->Dir = DIR_LEFTUP;
  1990.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1991.                                 break;
  1992.                             }
  1993.                             case DIR_LDD:
  1994.                             {
  1995.                                 b->Angular = false;
  1996.                                 b->Dir = DIR_LEFTUP;
  1997.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1998.                                 break;
  1999.                             }
  2000.                             case DIR_RRD:
  2001.                             {
  2002.                                 b->Angular = false;
  2003.                                 b->Dir = DIR_RIGHTUP;
  2004.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2005.                                 break;
  2006.                             }
  2007.                             case DIR_RDD:
  2008.                             {
  2009.                                 b->Angular = false;
  2010.                                 b->Dir = DIR_RIGHTUP;
  2011.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2012.                                 break;
  2013.                             }
  2014.                            
  2015.                         }
  2016.                     }
  2017.                     else
  2018.                     {
  2019.                         switch(b->Dir)
  2020.                         {
  2021.                             case DIR_DOWNLEFT: { b->Dir = DIR_UPLEFT; b->Step = bound(b->Step+2, 0, MAX_BALL_SPEED); break; }
  2022.                             case DIR_DOWNRIGHT: { b ->Dir = DIR_UPRIGHT; b->Step = bound(b->Step+2, 0, MAX_BALL_SPEED); break; }
  2023.                             default: {
  2024.                                 TraceNL(); TraceS("Ball direction invalid for brick.take_hit(hit_above()).");
  2025.                                 TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  2026.                                
  2027.                                 b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  2028.                         }
  2029.                     }
  2030.                    
  2031.                     if ( a->HP <= 0 )
  2032.                     {
  2033.                         if ( !a->Misc[NPCM_AWARDED_POINTS] )
  2034.                         {
  2035.                             a->Misc[NPCM_AWARDED_POINTS] = 1;
  2036.                             Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  2037.                         }
  2038.                     }
  2039.                 }
  2040.             }
  2041.            
  2042.             else if ( hit_left(a,b) )
  2043.             {
  2044.                 //upper corners
  2045.                
  2046.                 //upper-left corner
  2047.                 if ( hit_above(a,b) )
  2048.                 {
  2049.                    
  2050.                     if ( b->Angular )
  2051.                     {
  2052.                         switch(b->Angle)
  2053.                         {
  2054.                             case DIR_RRD:
  2055.                             {
  2056.                                 b->Angular = false;
  2057.                                 b->Dir = DIR_LEFTDOWN;
  2058.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2059.                                 break;
  2060.                             }
  2061.                             case DIR_RDD:
  2062.                             {
  2063.                                 b->Angular = false;
  2064.                                 b->Dir = DIR_LEFTDOWN;
  2065.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2066.                                 break;
  2067.                             }
  2068.                             case DIR_RUU:
  2069.                             {
  2070.                                 b->Angular = false;
  2071.                                 b->Dir = DIR_LEFTUP;
  2072.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2073.                                 break;
  2074.                             }
  2075.                             case DIR_RDD:
  2076.                             {
  2077.                                 b->Angular = false;
  2078.                                 b->Dir = DIR_LEFTUP;
  2079.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2080.                                 break;
  2081.                             }
  2082.                             case DIR_LLU:
  2083.                             {
  2084.                                 b->Angular = false;
  2085.                                 b->Dir = DIR_LEFTDOWN;
  2086.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2087.                                 break;
  2088.                             }
  2089.                             case DIR_LUU:
  2090.                             {
  2091.                                 b->Angular = false;
  2092.                                 b->Dir = DIR_LEFTDOWN;
  2093.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2094.                                 break;
  2095.                             }
  2096.                             case DIR_LLD:
  2097.                             {
  2098.                                 b->Angular = false;
  2099.                                 b->Dir = DIR_RIGHTDOWN;
  2100.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2101.                                 break;
  2102.                             }
  2103.                             case DIR_LDD:
  2104.                             {
  2105.                                 b->Angular = false;
  2106.                                 b->Dir = DIR_RIGHTDOWN;
  2107.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2108.                                 break;
  2109.                             }
  2110.                            
  2111.                         }
  2112.                     }
  2113.                     else
  2114.                     {
  2115.                         switch(b->Dir)
  2116.                         {
  2117.                             case DIR_DOWNRIGHT:
  2118.                             {
  2119.                                 b->Angular = false;
  2120.                                 b->Dir = DIR_UPLEFT;
  2121.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2122.                                 break;
  2123.                             }
  2124.                             case DIR_DOWNLEFT:
  2125.                             {
  2126.                                 b->Angular = false;
  2127.                                 b->Dir = DIR_UPRIGHT;
  2128.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2129.                                 break;
  2130.                             }
  2131.                             case DIR_UPRIGHT:
  2132.                             {
  2133.                                 b->Angular = false;
  2134.                                 b->Dir = DIR_DOWNLEFT;
  2135.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2136.                                 break;
  2137.                             }
  2138.                             case DIR_UPLEFT:
  2139.                             {
  2140.                                 b->Angular = false;
  2141.                                 b->Dir = DIR_DOWNRIGHT;
  2142.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2143.                                 break;
  2144.                             }
  2145.                            
  2146.                         }
  2147.                     }
  2148.                    
  2149.                 }//end upper-left corner
  2150.                
  2151.                 else if ( hit_below(a,b) )
  2152.                     //lower-left corner
  2153.                 {
  2154.                    
  2155.                     if ( b->Angular )
  2156.                     {
  2157.                         switch(b->Angle)
  2158.                         {
  2159.                             case DIR_RRU:
  2160.                             {
  2161.                                 b->Angular = false;
  2162.                                 b->Dir = DIR_RIGHTDOWN;
  2163.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2164.                                 break;
  2165.                             }
  2166.                             case DIR_RRD:
  2167.                             {
  2168.                                 b->Angular = false;
  2169.                                 b->Dir = DIR_RIGHTUP;
  2170.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2171.                                 break;
  2172.                             }
  2173.                             case DIR_RUU:
  2174.                             {
  2175.                                 b->Angular = false;
  2176.                                 b->Dir = DIR_RIGHTDOWN;
  2177.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2178.                                 break;
  2179.                             }
  2180.                             case DIR_RDD:
  2181.                             {
  2182.                                 b->Angular = false;
  2183.                                 b->Dir = DIR_RIGHTUP;
  2184.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2185.                                 break;
  2186.                             }
  2187.                             case DIR_LLU:
  2188.                             {
  2189.                                 b->Angular = false;
  2190.                                 b->Dir = DIR_RIGHTDOWN;
  2191.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2192.                                 break;
  2193.                             }
  2194.                             case DIR_LUU:
  2195.                             {
  2196.                                 b->Angular = false;
  2197.                                 b->Dir = DIR_RIGHTDOWN;
  2198.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2199.                                 break;
  2200.                             }
  2201.                             case DIR_LLD:
  2202.                             {
  2203.                                 b->Angular = false;
  2204.                                 b->Dir = DIR_RIGHTUP;
  2205.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2206.                                 break;
  2207.                             }
  2208.                             case DIR_LDD:
  2209.                             {
  2210.                                 b->Angular = false;
  2211.                                 b->Dir = DIR_RIGHTUP;
  2212.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2213.                                 break;
  2214.                             }
  2215.                            
  2216.                         }
  2217.                     }
  2218.                     else
  2219.                     {
  2220.                         switch(b->Dir)
  2221.                         {
  2222.                             case DIR_DOWNRIGHT:
  2223.                             {
  2224.                                 b->Angular = false;
  2225.                                 b->Dir = DIR_UPLEFT;
  2226.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2227.                                 break;
  2228.                             }
  2229.                             case DIR_DOWNLEFT:
  2230.                             {
  2231.                                 b->Angular = false;
  2232.                                 b->Dir = DIR_UPRIGHT;
  2233.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2234.                                 break;
  2235.                             }
  2236.                             case DIR_UPRIGHT:
  2237.                             {
  2238.                                 b->Angular = false;
  2239.                                 b->Dir = DIR_DOWNLEFT;
  2240.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2241.                                 break;
  2242.                             }
  2243.                             case DIR_UPLEFT:
  2244.                             {
  2245.                                 b->Angular = false;
  2246.                                 b->Dir = DIR_DOWNRIGHT;
  2247.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2248.                                 break;
  2249.                             }  
  2250.                            
  2251.                         }
  2252.                     }
  2253.                                    
  2254.                 }//end lower-left corner
  2255.                
  2256.                 else
  2257.                 {
  2258.                     if ( b->Angular )
  2259.                     {
  2260.                         switch(b->Angle)
  2261.                         {
  2262.                             case DIR_LLU:
  2263.                             {
  2264.                                 b->Angular = false;
  2265.                                 b->Dir = DIR_RIGHTUP;
  2266.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2267.                                 break;
  2268.                             }
  2269.                             case DIR_LUU:
  2270.                             {
  2271.                                 b->Angular = false;
  2272.                                 b->Dir = DIR_RIGHTUP;
  2273.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2274.                                 break;
  2275.                             }
  2276.                             case DIR_LLD:
  2277.                             {
  2278.                                 b->Angular = false;
  2279.                                 b->Dir = DIR_RIGHTDOWN;
  2280.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2281.                                 break;
  2282.                             }
  2283.                             case DIR_LDD:
  2284.                             {
  2285.                                 b->Angular = false;
  2286.                                 b->Dir = DIR_RIGHTDOWN;
  2287.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2288.                                 break;
  2289.                             }
  2290.                            
  2291.                         }
  2292.                     }
  2293.                     else
  2294.                     {
  2295.                         switch(b->Dir)
  2296.                         {
  2297.                             case DIR_RIGHTDOWN: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  2298.                             case DIR_RIGHTUP: { b->Dir = DIR_LEFTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  2299.                             default: {
  2300.                                 TraceNL(); TraceS("Ball direction invalid for brick.take_hit(hit(left)).");
  2301.                                 TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  2302.                                 b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  2303.                         }
  2304.                     }
  2305.                     /*
  2306.                     switch ( v->Dir )
  2307.                     {
  2308.                         case DIR_UPRIGHT: { v->Dir = DIR_UPLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  2309.                         case DIR_DOWNRIGHT: { v->Dir = DIR_DOWNLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED);  break; }
  2310.                         default: { TraceS("hit_left() found an illegal ball direction"); break; }
  2311.                     }
  2312.                     */
  2313.                 }
  2314.                 if ( a->HP <= 0 )
  2315.                 {
  2316.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  2317.                     {
  2318.                         a->Misc[NPCM_AWARDED_POINTS] = 1;
  2319.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  2320.                     }
  2321.                 }
  2322.             }
  2323.             else if ( hit_right(a,b) )
  2324.             {
  2325.                 //lower-right corners
  2326.                 if ( hit_below(a,b) )
  2327.                     //lower-right corner
  2328.                 {
  2329.                    
  2330.                     if ( b->Angular )
  2331.                     {
  2332.                         switch(b->Angle)
  2333.                         {
  2334.                             case DIR_LLU:
  2335.                             {
  2336.                                 b->Angular = false;
  2337.                                 b->Dir = DIR_RIGHTDOWN;
  2338.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2339.                                 break;
  2340.                             }
  2341.                             case DIR_LLD:
  2342.                             {
  2343.                                 b->Angular = false;
  2344.                                 b->Dir = DIR_RIGHTDOWN;
  2345.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2346.                                 break;
  2347.                             }
  2348.                             case DIR_RUU:
  2349.                             {
  2350.                                 b->Angular = false;
  2351.                                 b->Dir = DIR_RIGHTDOWN;
  2352.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2353.                                 break;
  2354.                             }
  2355.                             case DIR_RDD:
  2356.                             {
  2357.                                 b->Angular = false;
  2358.                                 b->Dir = DIR_LEFTUP;
  2359.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2360.                                 break;
  2361.                             }
  2362.                             case DIR_LLU:
  2363.                             {
  2364.                                 b->Angular = false;
  2365.                                 b->Dir = DIR_RIGHTDOWN;
  2366.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2367.                                 break;
  2368.                             }
  2369.                             case DIR_LUU:
  2370.                             {
  2371.                                 b->Angular = false;
  2372.                                 b->Dir = DIR_RIGHTDOWN;
  2373.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2374.                                 break;
  2375.                             }
  2376.                             case DIR_LLD:
  2377.                             {
  2378.                                 b->Angular = false;
  2379.                                 b->Dir = DIR_LEFTUP;
  2380.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2381.                                 break;
  2382.                             }
  2383.                             case DIR_LDD:
  2384.                             {
  2385.                                 b->Angular = false;
  2386.                                 b->Dir = DIR_LEFTUP;
  2387.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2388.                                 break;
  2389.                             }
  2390.                            
  2391.                         }
  2392.                     }
  2393.                     else
  2394.                     {
  2395.                         switch(b->Dir)
  2396.                         {
  2397.                             case DIR_DOWNRIGHT:
  2398.                             {
  2399.                                 b->Angular = false;
  2400.                                 b->Dir = DIR_UPLEFT;
  2401.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2402.                                 break;
  2403.                             }
  2404.                             case DIR_DOWNLEFT:
  2405.                             {
  2406.                                 b->Angular = false;
  2407.                                 b->Dir = DIR_UPRIGHT;
  2408.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2409.                                 break;
  2410.                             }
  2411.                             case DIR_UPRIGHT:
  2412.                             {
  2413.                                 b->Angular = false;
  2414.                                 b->Dir = DIR_DOWNLEFT;
  2415.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2416.                                 break;
  2417.                             }
  2418.                             case DIR_UPLEFT:
  2419.                             {
  2420.                                 b->Angular = false;
  2421.                                 b->Dir = DIR_DOWNRIGHT;
  2422.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2423.                                 break;
  2424.                             }  
  2425.                            
  2426.                         }
  2427.                     }
  2428.                    
  2429.                 }//end lower-right corner
  2430.                
  2431.                 //upper-right corner
  2432.                 else if ( hit_above(a,b) )
  2433.                 {
  2434.                    
  2435.                     if ( b->Angular )
  2436.                     {
  2437.                         switch(b->Angle)
  2438.                         {
  2439.                             case DIR_RRD:
  2440.                             {
  2441.                                 b->Angular = false;
  2442.                                 b->Dir = DIR_RIGHTUP;
  2443.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2444.                                 break;
  2445.                             }
  2446.                             case DIR_RDD:
  2447.                             {
  2448.                                 b->Angular = false;
  2449.                                 b->Dir = DIR_RIGHTUP;
  2450.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2451.                                 break;
  2452.                             }
  2453.                             case DIR_RUU:
  2454.                             {
  2455.                                 b->Angular = false;
  2456.                                 b->Dir = DIR_RIGHTDOWN;
  2457.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2458.                                 break;
  2459.                             }
  2460.                             case DIR_RDD:
  2461.                             {
  2462.                                 b->Angular = false;
  2463.                                 b->Dir = DIR_RIGHTDOWN;
  2464.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2465.                                 break;
  2466.                             }
  2467.                             case DIR_LLU:
  2468.                             {
  2469.                                 b->Angular = false;
  2470.                                 b->Dir = DIR_RIGHTUP;
  2471.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2472.                                 break;
  2473.                             }
  2474.                             case DIR_LUU:
  2475.                             {
  2476.                                 b->Angular = false;
  2477.                                 b->Dir = DIR_RIGHTUP;
  2478.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2479.                                 break;
  2480.                             }
  2481.                             case DIR_LLD:
  2482.                             {
  2483.                                 b->Angular = false;
  2484.                                 b->Dir = DIR_LEFTUP;
  2485.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2486.                                 break;
  2487.                             }
  2488.                             case DIR_LDD:
  2489.                             {
  2490.                                 b->Angular = false;
  2491.                                 b->Dir = DIR_LEFTUP;
  2492.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2493.                                 break;
  2494.                             }
  2495.                            
  2496.                         }
  2497.                     }
  2498.                     else
  2499.                     {
  2500.                         switch(b->Dir)
  2501.                         {
  2502.                             case DIR_DOWNRIGHT:
  2503.                             {
  2504.                                 b->Angular = false;
  2505.                                 b->Dir = DIR_UPLEFT;
  2506.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2507.                                 break;
  2508.                             }
  2509.                             case DIR_DOWNLEFT:
  2510.                             {
  2511.                                 b->Angular = false;
  2512.                                 b->Dir = DIR_UPRIGHT;
  2513.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2514.                                 break;
  2515.                             }
  2516.                             case DIR_UPRIGHT:
  2517.                             {
  2518.                                 b->Angular = false;
  2519.                                 b->Dir = DIR_DOWNLEFT;
  2520.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2521.                                 break;
  2522.                             }
  2523.                             case DIR_UPLEFT:
  2524.                             {
  2525.                                 b->Angular = false;
  2526.                                 b->Dir = DIR_DOWNRIGHT;
  2527.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2528.                                 break;
  2529.                             }
  2530.                            
  2531.                         }
  2532.                     }
  2533.                 }
  2534.                 //end upper-right corners
  2535.                 else
  2536.                 {
  2537.                     if ( b->Angular )
  2538.                     {
  2539.                         switch(b->Angle)
  2540.                         {
  2541.                             case DIR_RRD:
  2542.                             {
  2543.                                 b->Angular = false;
  2544.                                 b->Dir = DIR_LEFTDOWN;
  2545.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2546.                                 break;
  2547.                             }
  2548.                             case DIR_RDD:
  2549.                             {
  2550.                                 b->Angular = false;
  2551.                                 b->Dir = DIR_LEFTDOWN;
  2552.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2553.                                 break;
  2554.                             }
  2555.                             case DIR_RRU:
  2556.                             {
  2557.                                 b->Angular = false;
  2558.                                 b->Dir = DIR_LEFTUP;
  2559.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2560.                                 break;
  2561.                             }
  2562.                             case DIR_RUU:
  2563.                             {
  2564.                                 b->Angular = false;
  2565.                                 b->Dir = DIR_LEFTUP;
  2566.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  2567.                                 break;
  2568.                             }
  2569.                            
  2570.                         }
  2571.                     }
  2572.                     else
  2573.                     {
  2574.                         switch(b->Dir)
  2575.                         {
  2576.                             case DIR_LEFTDOWN: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  2577.                             case DIR_LEFTUP: { b->Dir = DIR_RIGHTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  2578.                             default: {
  2579.                                 TraceNL(); TraceS("Ball direction invalid for brick.take_hit(hit_right()).");
  2580.                                 TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  2581.                                 b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  2582.                         }
  2583.                     }
  2584.                     /*
  2585.                     switch ( v->Dir )
  2586.                     {
  2587.                         case DIR_UPLEFT: { v->Dir = DIR_UPRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  2588.                         case DIR_DOWNLEFT: { v->Dir = DIR_DOWNRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  2589.                         default: { TraceS("hit_below() found an illegal ball direction"); break; }
  2590.                     }
  2591.                     */
  2592.                     if ( a->HP <= 0 )
  2593.                     {
  2594.                         if ( !a->Misc[NPCM_AWARDED_POINTS] )
  2595.                         {
  2596.                             a->Misc[NPCM_AWARDED_POINTS] = 1;
  2597.                             Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  2598.                         }
  2599.                     }
  2600.                 }
  2601.             }
  2602.            
  2603.             else
  2604.             {
  2605.                 TraceS("brick.hit() returned true, but couldn't determine a valid ball location!");
  2606.                 return;
  2607.             }
  2608.         }
  2609.                    
  2610.            
  2611.     }
  2612.     //turns layer objects into npc bricks.
  2613.     void setup()
  2614.     {
  2615.         int tempenem; npc bricks[1024]; int temp;
  2616.         for ( int q = 0; q < 176; ++q )
  2617.         {
  2618.             //bricks on layer 1
  2619.             //Trace(GetLayerComboD(1,q));
  2620.             //while(!Input->Press[CB_A]) Waitframe();
  2621.             tempenem = brick_to_npc(GetLayerComboD(1,q),false);
  2622.             //TraceS("tempenem is: "); Trace(tempenem);
  2623.             //while(!Input->Press[CB_A]) Waitframe();
  2624.             if ( tempenem )
  2625.             {
  2626.                 bricks[temp] = Screen->CreateNPC(tempenem);
  2627.                 //TraceS("Created npc: "); Trace(tempenem);
  2628.                 bricks[temp]->X = ComboX(q);
  2629.                 bricks[temp]->Y = ComboY(q);
  2630.                 //TraceS("Brick defence is: "); Trace(bricks[temp]->Defense[20]);
  2631.                 tempenem = 0; ++temp;
  2632.                
  2633.             }
  2634.             //bricks on layer 2, Y+8px
  2635.             tempenem = brick_to_npc(GetLayerComboD(2,q),true);
  2636.             //Trace(tempenem);
  2637.             if ( tempenem )
  2638.             {
  2639.                 bricks[temp] = Screen->CreateNPC(tempenem);
  2640.                 //TraceS("Created npc: "); Trace(tempenem);
  2641.                 bricks[temp]->X = ComboX(q);
  2642.                 bricks[temp]->Y = ComboY(q)+8;
  2643.                 //TraceS("Brick defence is: "); Trace(bricks[temp]->Defense[20]);
  2644.                 tempenem = 0; ++temp;
  2645.             }
  2646.         }
  2647.        
  2648.     }
  2649.     void clear_combos()
  2650.     {
  2651.         templayer[0] = Screen->LayerOpacity[0];
  2652.         templayer[1] = Screen->LayerOpacity[1];
  2653.         templayer[2] = Screen->LayerMap[0];
  2654.         templayer[3] = Screen->LayerMap[1];
  2655.         Screen->LayerOpacity[0] = 0;
  2656.         Screen->LayerOpacity[1] = 0;
  2657.         Screen->LayerMap[0] = 0;
  2658.         Screen->LayerMap[1] = 0;
  2659.     }
  2660.    
  2661.     int brick_to_npc(int combo_id, bool layer2)
  2662.     {
  2663.        
  2664.         if ( !layer2 )
  2665.         {
  2666.             int brick_to_enemy[BRICK_MAX*2] =
  2667.             {   CMB_BRICK_RED, CMB_BRICK_WHITE, CMB_BRICK_BLUE, CMB_BRICK_ORANGE, CMB_BRICK_TEAL,
  2668.                 CMB_BRICK_VIOLET, CMB_BRICK_GREEN, CMB_BRICK_YELLOW, CMB_BRICK_SILVER1, CMB_BRICK_SILVER2,
  2669.                 CMB_BRICK_SILVER3, CMB_BRICK_SILVER4, CMB_BRICK_GOLD,
  2670.  
  2671.                 NPC_BRICK_RED, NPC_BRICK_WHITE, NPC_BRICK_BLUE, NPC_BRICK_ORANGE, NPC_BRICK_TEAL,
  2672.                 NPC_BRICK_VIOLET, NPC_BRICK_GREEN, NPC_BRICK_YELLOW, NPC_BRICK_SILVER1, NPC_BRICK_SILVER2,
  2673.                 NPC_BRICK_SILVER3, NPC_BRICK_SILVER4, NPC_BRICK_GOLD
  2674.             };
  2675.             for ( int q = 0; q < BRICK_MAX; ++q )
  2676.             {
  2677.                 if ( brick_to_enemy[q] == combo_id )
  2678.                 {
  2679.                     //  TraceS("brick_to_npc : combo input: "); Trace(combo_id);
  2680.                     //TraceS("brick_to_npc : enemy output: "); Trace(brick_to_enemy[BRICK_MAX+q]);
  2681.                    
  2682.                     return ( brick_to_enemy[BRICK_MAX+q-1] );
  2683.                 }
  2684.             }
  2685.         }
  2686.         else
  2687.         {
  2688.             int brick_to_enemy2[BRICK_MAX*2] =
  2689.             {   CMB_BRICK_RED_LOW, CMB_BRICK_WHITE_LOW, CMB_BRICK_BLUE_LOW, CMB_BRICK_ORANGE_LOW, CMB_BRICK_TEAL_LOW,
  2690.                 CMB_BRICK_VIOLET_LOW, CMB_BRICK_GREEN_LOW, CMB_BRICK_YELLOW_LOW, CMB_BRICK_SILVER1_LOW, CMB_BRICK_SILVER2_LOW,
  2691.                 CMB_BRICK_SILVER3_LOW, CMB_BRICK_SILVER4_LOW, CMB_BRICK_GOLD_LOW,
  2692.  
  2693.                 NPC_BRICK_RED, NPC_BRICK_WHITE, NPC_BRICK_BLUE, NPC_BRICK_ORANGE, NPC_BRICK_TEAL,
  2694.                 NPC_BRICK_VIOLET, NPC_BRICK_GREEN, NPC_BRICK_YELLOW, NPC_BRICK_SILVER1, NPC_BRICK_SILVER2,
  2695.                 NPC_BRICK_SILVER3, NPC_BRICK_SILVER4, NPC_BRICK_GOLD
  2696.             };
  2697.             for ( int q = 0; q < BRICK_MAX; ++q )
  2698.             {
  2699.                 if ( brick_to_enemy2[q] == combo_id )
  2700.                 {
  2701.                     //TraceS("brick_to_npc : combo input: "); Trace(combo_id);
  2702.                     //TraceS("brick_to_npc : enemy output: "); Trace(brick_to_enemy2[BRICK_MAX+q-1]);
  2703.                     return ( brick_to_enemy2[BRICK_MAX+q-1] );
  2704.                 }
  2705.             }
  2706.         }
  2707.         return 0; //error
  2708.     }
  2709. }
  2710.  
  2711. global script onExit
  2712. {
  2713.     void run()
  2714.     {
  2715.         Screen->LayerOpacity[0] = templayer[0];
  2716.         Screen->LayerOpacity[1] = templayer[1];
  2717.         Screen->LayerMap[0] = templayer[2];
  2718.         Screen->LayerMap[1] = templayer[3];
  2719.         newstage = true;
  2720.         //vaus->Misc[MISC_DEAD] = 0;
  2721.  
  2722.     }
  2723. }  
  2724.  
  2725. global script init
  2726. {
  2727.     void run()
  2728.     {
  2729.         quit = 0;
  2730.         frame = -1;
  2731.         Game->Counter[CR_LIVES] = 5;
  2732.         Link->CollDetection = false;
  2733.         Link->DrawYOffset = -32768;
  2734.     }
  2735. }
  2736.  
  2737. global script Init
  2738. {
  2739.     void run()
  2740.     {
  2741.         quit = 0;
  2742.         frame = -1;
  2743.         Game->Counter[CR_LIVES] = 5;
  2744.         Link->CollDetection = false;
  2745.         Link->DrawYOffset = -32768;
  2746.     }
  2747. }
  2748.  
  2749. global script onContinue
  2750. {
  2751.     void run()
  2752.     {
  2753.         quit = 0;
  2754.         frame = -1;
  2755.         Game->Counter[CR_LIVES] = 5;
  2756.         Link->Invisible = true;
  2757.         Link->CollDetection = false;
  2758.         Link->DrawYOffset = -32768;
  2759.     }
  2760. }
  2761.  
  2762. /////////////////////////
  2763. /// DEAD Script Bugs: ///
  2764. /////////////////////////
  2765.  
  2766. /*
  2767. //FIXED with ball.clamp().
  2768. //There's a step speed at which the ball phases *through* the vaus!
  2769.                     //Perhaps we should make the vaus an enemy, too? An invisible enemy to act as a failsafe?
  2770.                     //if the ball hits the vaus, it bounces.
  2771.                     //Or just scrap the vaus ffc, and use an npc for it in general?
  2772.  
  2773. //BALL NEEDS TO HAVE A 6PX BY 6PX HITBOX, AND THUS A HIT OFFSET OF -1,-1, so that ->HitBy[] returns when the ball hits a block, and
  2774. //the ball is still not yet inside that object
  2775. */
  2776.  
  2777. //////////////////////
  2778. /// DEAD ZC Issues //////////////////////////////////////////////////////////////////////////////
  2779. /// I fixed these issues, in specific Alphas of ZC 2.54, noted below for historical purposes: ///
  2780. /////////////////////////////////////////////////////////////////////////////////////////////////
  2781.  
  2782.  
  2783. /*
  2784. FIXED in Alpha 32
  2785. I forgot to expand ->Misc[] in sprite.cpp, which should be fixed int he source for Alpha 32.
  2786.     This meant that r/w to ptr->Misc[>15] would use invalid data, or overwrite other data. bad, bad, bad.
  2787.    
  2788.     FIXED in Alpha 32
  2789.     //Note: We also need to store the UID of each ball, as HitBy[] works from the UID, not the pointer.
  2790.    
  2791. */
  2792.  
  2793. ffc script TestGetPixel
  2794. {
  2795.     void run()
  2796.     {
  2797.         while(1)
  2798.         {
  2799.            
  2800.             if ( Input->Key[KEY_8] )
  2801.             {
  2802.                 bitmap bmp = Game->LoadBitmapID(RT_SCREEN);
  2803.                 int col[20];
  2804.                 for ( int q = 0; q < 20; ++ q )
  2805.                 {
  2806.                     col[q] = bmp->GetPixel(40, 0+q*8);
  2807.                 }
  2808.                 TraceNL();
  2809.                 for ( int q = 0; q < 20; ++q )
  2810.                 {
  2811.                     TraceS("Bitmap col: "); Trace(col[q]);
  2812.                 }
  2813.                
  2814.                 Screen->SetRenderTarget(2);
  2815.                 Screen->Rectangle(0, 0, 0, 256, 256, 0x55, 100, 0, 0, 0, true, 128);
  2816.                 Screen->SetRenderTarget(RT_SCREEN);
  2817.                 Waitframe();
  2818.                
  2819.                 bitmap offscreen = Game->LoadBitmapID(2);
  2820.                 int col2[20];
  2821.                 for ( int q = 0; q < 20; ++ q )
  2822.                 {
  2823.                     col2[q] = offscreen->GetPixel(10+q*8,10+q*8);
  2824.                 }
  2825.                 TraceNL();
  2826.                 for ( int q = 0; q < 20; ++q )
  2827.                 {
  2828.                     TraceS("Offscreen Bitmap col: "); Trace(col2[q]);
  2829.                 }
  2830.             }  
  2831.             Waitframe();
  2832.         }
  2833.     }
  2834. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement