Advertisement
ZoriaRPG

Arkanoid.zh (Alpha 0.20)

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