Advertisement
ZoriaRPG

Arkanoid.zs (Alpha 0.23)

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