Advertisement
ZoriaRPG

Arkanoid.zs (Alpha 0.27)

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