Advertisement
ZoriaRPG

Arkanoid (Alpha 17, Experimental, Angles, Brick Corners)

Aug 17th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 51.36 KB | None | 0 0
  1. import "std.zh"
  2.  
  3.  
  4. //Arkanoid script
  5. //v0.16
  6. //17th August, 2018
  7.  
  8. //////////////////////
  9. /// Script issues: ///
  10. //////////////////////
  11.  
  12. // We need to either re-arrange the living/dead/death logic, or add another animation phase.
  13. // May as well set up the Vaus explosion and add it with a SPARKLE LWeapon.
  14.  
  15.  
  16.  
  17. //# QUEST ISSUE: Bricks Break playing the wrong sound, despite being set. Might be a 2.54 bug? -Z
  18.  
  19. /* ZC issues:
  20.     Continue script does not run when Init script runs. It NEEDS to do that! Otherwise, settings that affect things such as Link's tile
  21.     don't happen before the opening wipe.
  22.    
  23. */
  24.  
  25. /// Changes, Revision History
  26. ///
  27. ///
  28. /// Alpha 0.16: Reverted Alpha 0.15 changes back to before adding any angular physics.
  29. ///     Then, re-implemented ONLY the Vaus midpoint physics.
  30. ///     Fixed the hack for UID in brick.take_hit(). This means that ZC 2.54 Alpha **32** is now the minimum ZC version.
  31.  
  32. //Radians for special directions.
  33. const float DIR_UUL = 4.3197;
  34. const float DIR_LUU = 4.3197;
  35. const float DIR_LLU = 3.5343;
  36. const float DIR_ULL = 3.5343;
  37. const float DIR_LLD = 2.7489;
  38. const float DIR_DLL = 2.7489;
  39. const float DIR_DDL = 1.9635;
  40. const float DIR_LDD = 1.9635;
  41. const float DIR_DDR = 1.1781;
  42. const float DIR_RDD = 1.1781;
  43. const float DIR_RRD = 0.3927;
  44. const float DIR_DRR = 0.3927;
  45. const float DIR_RRU = 5.1051;
  46. const float DIR_URR = 5.1051;
  47. const float DIR_RUU = 5.1141;
  48. const float DIR_UUR = 5.1141;
  49.  
  50.  
  51.  
  52. const int MIN_ZC_ALPHA_BUILD = 32; //Alphas are negatives, so we neex to check maximum, not minimum.
  53.  
  54.  
  55. const float ARKANOID_VERSION = 0.16;
  56.  
  57. int GAME[256];
  58. const int GAME_MISC_FLAGS = 0;
  59. const int GMFS_PLAYED_GAME_OVER_MUSIC = 0x01;
  60.  
  61. const int FFC_VAUS = 1;
  62. const int CMB_VAUS_EXTENDED = 1528;
  63. const int CMB_VAUS = 1524;
  64. const int CMB_VAUS_DEAD = 1520;
  65.  
  66. const int MID_STAGE_START = 4;
  67. const int NPCM_AWARDED_POINTS = 3; //brick->Misc[], flag to mark if points were awarded to the player.
  68. const int NPC_ATTRIB_POINTS = 0; //brick->Attributes[], value for score.
  69.  
  70. //Counters
  71. const int CR_SCORE = 7; //script 1
  72. const int CR_LIVES = 8;
  73.  
  74. int quit;
  75.  
  76. const int QUIT_TITLE = -1;
  77. const int QUIT_GAME_RUNNING = 0; //i.e., !quit
  78. const int QUIT_GAMEOVER = 1;
  79.  
  80. const int MAX_BALL_SPEED = 300;
  81.  
  82. int caught;
  83. int frame;
  84. bool newstage = true;
  85. bool revive_vaus = false;
  86.  
  87. int ball_x;
  88. int ball_y;
  89. int ball_dir;
  90. int ball_angle;
  91. int ball_speed;
  92. int ball_vx;
  93. int ball_vy;
  94. int paddle_x;
  95. int paddle_y;
  96. int paddle_width = 16;
  97. int paddle_speed = 2;
  98. int extended;
  99.  
  100. int ball_uid;
  101.  
  102. //animation
  103. int death_frame;
  104.  
  105. int death_anim[DEATH_ANIM_MAX];
  106. const int DEATH_ANIM_TIMER = 0;
  107. const int DEATH_ANIM_1 = 1; //1-7 Unused
  108. const int DEATH_ANIM_2 = 2;
  109. const int DEATH_ANIM_3 = 3;
  110. const int DEATH_ANIM_4 = 4;
  111. const int DEATH_ANIM_5 = 5;
  112. const int DEATH_ANIM_6 = 6;
  113. const int DEATH_ANIM_COUNTDOWN_TO_QUIT = 7;
  114.  
  115. const int DEATH_ANIM_MAX = 8;
  116.  
  117. const int COUNTDOWN_TO_QUIT_FRAMES = 289; //36*8+1;
  118.  
  119. int templayer[4];
  120.  
  121. int input_accel; //pressing left and right for multiple frames increases this
  122. int frames_pressed[18];
  123.  
  124. //ffc paddle;
  125.  
  126. int hit_zones[5]; //angle offsets for where the ball strikes the paddle
  127.  
  128. const int WALL_LEFT = 24;
  129. const int WALL_TOP = 8; //Mix Ball Y
  130. const int WALL_RIGHT = 232;
  131.  
  132. const int BALL_MIN_Y = 9; //ceiling +1
  133. const int BALL_MAX_Y = 145; //one pixel under paddle top
  134. const int BALL_MIN_X = 25; //left wall +1
  135. const int BALL_MAX_X = 229; //right wall -1
  136.  
  137.  
  138.  
  139. const int START_PADDLE_X = 62;
  140. const int START_PADDLE_Y = 160;
  141. const int START_PADDLE_WIDTH = 32;
  142. const int START_PADDLE_HEIGHT = 8;
  143. const int BALL_WIDTH = 4;
  144. const int BALL_HEIGHT = 4;
  145. const int START_BALL_X = 98; //(START_PADDLE_X + 36);
  146. const int START_BALL_Y = 156; //START_PADDLE_Y - 4;
  147. const int START_BALL_DIR = 5; //DIR_UPRIGHT;
  148. const int START_BALL_RADS = 220; //angle in radians
  149. const int START_BALL_SPEED = 45;
  150. const int START_BALL_VX = 0;
  151. const int START_BALL_VY = 0;
  152.  
  153. const int PADDLE_MIN_X = 25;
  154. const int PADDLE_MAX_X = 200; //WALL_RIGHT -32; //This one varies as the paddle width may change.
  155. const int PADDLE_MAX_X_EXTENDED = 184; //WALL_RIGHT - 48; //This one varies as the paddle width may change.
  156. const int PADDLE_MIN_X_EXTENDED = 25;
  157.  
  158. const int _MOUSE_X = 0;
  159. const int _MOUSE_Y = 1;
  160. const int _MOUSE_LCLICK = 2;
  161.  
  162. //const float ACCEL_FACTOR = 0.25;
  163.  
  164. const int FRAMES_PER_MOVEMENT = 10;
  165. int USE_ACCEL = 0; //Do we accelerate KB/JP input?
  166. int USE_MOUSE = 0; //Are we using the mouse?
  167.  
  168.  
  169. /*
  170. const int CB_UP     = 0;
  171. const int CB_DOWN   = 1;
  172. const int CB_LEFT   = 2;
  173. const int CB_RIGHT  = 3;
  174. const int CB_A      = 4;
  175. const int CB_B      = 5;
  176. const int CB_L      = 7;
  177. const int CB_R      = 8;
  178. const int CB_START  = 6;
  179. const int CB_MAP    = 9;
  180. const int CB_EX1    = 10;
  181. const int CB_EX2    = 11;
  182. const int CB_EX3    = 12;
  183. const int CB_EX4    = 13;
  184. const int CB_AXIS_UP    = 14;
  185. const int CB_AXIS_DOWN  = 15;
  186. const int CB_AXIS_LEFT  = 16;
  187. const int CB_AXIS_RIGHT = 17;
  188.  
  189. */
  190.  
  191. ffc script paddle
  192. {
  193.     void run(){}
  194.    
  195.     bool move(bool mouse, bool accel, ffc p)
  196.     {
  197.         int dir; int dist;
  198.         if ( mouse )
  199.         {
  200.             //get the mouse movement this frame and apply a relative amount to the paddle
  201.             //set the dir here
  202.             //set the dist here
  203.             //if moving left
  204.             //if ( p->X > PADDLE_MIN_X )
  205.             //{
  206.             //  p->X = Input->Mouse[_MOUSE_X];
  207.                 //apply change -- ZC has no special mouse tracking.
  208.             //}
  209.             //if moving right
  210.             if ( !extended )
  211.             {
  212.                 if ( Input->Mouse[_MOUSE_X] <= PADDLE_MAX_X )
  213.                 {
  214.                     if ( Input->Mouse[_MOUSE_X] >= PADDLE_MIN_X )
  215.                     {
  216.                         //apply change
  217.                         p->X = Input->Mouse[_MOUSE_X];
  218.                     }
  219.                 }
  220.             }
  221.             else
  222.             {
  223.                 if ( Input->Mouse[_MOUSE_X] <= PADDLE_MAX_X_EXTENDED )
  224.                 {
  225.                     if ( Input->Mouse[_MOUSE_X] >= PADDLE_MIN_X_EXTENDED )
  226.                     {
  227.                         //apply change
  228.                         p->X = Input->Mouse[_MOUSE_X];
  229.                     }
  230.                 }
  231.             }
  232.         }
  233.         else //using a KB or joypad
  234.         {
  235.             //check how long the dir button is held
  236.             if ( accel ) //if we allow acceleratiopn, move N pixeld * accel factor * frames held
  237.             {
  238.                
  239.                 if ( !extended )
  240.                 {
  241.                     if (  Input->Button[CB_LEFT] )
  242.                     {
  243.                         for ( int q = frames_pressed[CB_LEFT]; q > 0 ; --q )
  244.                         {
  245.                             if ( p->X > PADDLE_MIN_X )
  246.                             {
  247.                                 --p->X;
  248.                                 --p->X;
  249.                             }
  250.                         }
  251.                     }
  252.                     if (  Input->Button[CB_RIGHT] )
  253.                     {
  254.                         for ( int q = frames_pressed[CB_RIGHT]; q > 0; --q )
  255.                         {
  256.                             if ( p->X < PADDLE_MAX_X )
  257.                             {
  258.                                 ++p->X;
  259.                             }
  260.                         }
  261.                     }
  262.                 }
  263.                
  264.             }
  265.            
  266.             else //no accel offered, move a static number of pixels
  267.             {
  268.                
  269.                 if ( !extended )
  270.                 {
  271.                     if (  Input->Button[CB_LEFT] )
  272.                     {
  273.                         for ( int q = 0; q < paddle_speed; ++q )
  274.                         {
  275.                             if ( p->X > PADDLE_MIN_X )
  276.                             {
  277.                                 --p->X;
  278.                             }
  279.                         }
  280.                     }
  281.                     if (  Input->Button[CB_RIGHT] )
  282.                     {
  283.                         for ( int q = 0; q < paddle_speed; ++q )
  284.                         {
  285.                             if ( p->X < PADDLE_MAX_X )
  286.                             {
  287.                                 ++p->X;
  288.                             }
  289.                         }
  290.                     }
  291.                 }
  292.                 else
  293.                 {
  294.                     if (  Input->Button[CB_LEFT] )
  295.                     {
  296.                         if ( p->X > PADDLE_MIN_X_EXTENDED )
  297.                         {
  298.                             --p->X;
  299.                         }
  300.                     }
  301.                     if (  Input->Button[CB_RIGHT] ) {
  302.                         if ( p->X < PADDLE_MAX_X_EXTENDED )
  303.                         {
  304.                             ++p->X;
  305.                         }
  306.                     }
  307.                    
  308.                 }
  309.             }
  310.         }
  311.        
  312.     }
  313.  
  314.     void check_input()
  315.     {
  316.         if ( Input->Button[CB_LEFT] ) ++frames_pressed[CB_LEFT];
  317.         else frames_pressed[CB_LEFT] = 0;
  318.         if ( Input->Button[CB_RIGHT] ) ++frames_pressed[CB_RIGHT];
  319.         else frames_pressed[CB_RIGHT] = 0;
  320.        
  321.     }
  322.    
  323.     void extend(ffc p)
  324.     {
  325.         if ( extended )
  326.         {
  327.             if ( p->TileWidth < 3 )
  328.             {
  329.                 p->Data = CMB_VAUS_EXTENDED;
  330.                 p->TileWidth = 3;
  331.             }
  332.         }
  333.         else
  334.         {
  335.             if ( p->TileWidth > 2 )
  336.             {
  337.                 p->Data = CMB_VAUS;
  338.                 p->TileWidth = 2;
  339.             }
  340.         }
  341.     }
  342.     void setup(ffc p)
  343.     {
  344.         p->Y = START_PADDLE_Y;
  345.         p->X = START_PADDLE_X;
  346.         p->Data = CMB_VAUS;
  347.         p->TileWidth = 2;
  348.        
  349.     }
  350.     void dead(ffc p)
  351.     {
  352.         p->Data = CMB_VAUS_DEAD;
  353.         p->TileWidth = 2;
  354.         death_frame = frame;
  355.     }
  356.    
  357.  
  358. }
  359.  
  360. const int MISC_BALLID = 0; //Misc index of Vaud->Misc[]
  361. const int MISC_DEAD = 1; //Misc index of Vaud->Misc[]
  362. const int MISC_LAUNCHED = 0; //Misc index of ball->Misc[]
  363.  
  364. const int BALL_MINIMUM_Y = 24; //Invisible line at which point, ball is lost.
  365.  
  366. ffc script holdlink
  367. {
  368.     void run()
  369.     {
  370.         while(1)
  371.         {
  372.             Link->Y = START_PADDLE_Y - 4;
  373.             Waitframe();
  374.         }
  375.     }
  376. }
  377.        
  378.  
  379. global script arkanoid
  380. {
  381.    
  382.     void run()
  383.     {
  384.         check_min_zc_build();
  385.        
  386.         TraceNL(); TraceS("Starting Arkanoid"); TraceNL(); TraceS("Game 'quit' state: "); Trace(quit);
  387.         TraceNL(); TraceS("Game version, Alpha "); Trace(ARKANOID_VERSION);
  388.        
  389.         //frame = -1;
  390.         ffc vaus = Screen->LoadFFC(FFC_VAUS);
  391.         lweapon movingball;
  392.         npc vaus_guard;
  393.         bool ext;
  394.         Link->CollDetection = false;
  395.         Link->DrawYOffset = -32768;
  396.        
  397.         ball.setup_sprite(SPR_BALL);
  398.         while(true)
  399.         {
  400.             while(!quit)
  401.             {
  402.                 ++frame;
  403.                 if ( Input->Key[KEY_L] ) ++Game->Counter[CR_LIVES];
  404.                 hold_Link_y(); //Don't allow Link to leave the screen, bt
  405.                     //keep his X and Y matched to the Vaus!
  406.                 hold_Link_x(vaus); //Link is used to cause floating enemies to home in on the vaus.
  407.                 if ( newstage )
  408.                 {
  409.                     //vaus_guard = Screen->CreateNPC(NPC_VAUSGUARD);
  410.                     Game->PlayMIDI(MID_STAGE_START);
  411.                     brick.setup();
  412.                     Waitframes(6);
  413.                    
  414.                     brick.clear_combos();
  415.                    
  416.                     newstage = false;
  417.                     paddle.setup(vaus);
  418.                     ball.create(vaus);
  419.                     movingball = vaus->Misc[MISC_BALLID];
  420.                     /*
  421.                     TraceS("Checking lwpn->Misc[16-32] for junk data: ");
  422.                     for ( int q = 16; q < 32; ++q )
  423.                     {
  424.                         TraceNL(); TraceS("index: "); Trace(q); TraceS(" value: "); Trace(movingball->Misc[q]);
  425.                     }
  426.                    
  427.                     TraceS("Setting valid data to lwpn->Misc[16-32] to validate data: ");
  428.                     for ( int q = 16; q < 32; ++q )
  429.                     {
  430.                         movingball->Misc[q] = q*2;
  431.                         TraceNL(); TraceS("index: "); Trace(q); TraceS(" value: "); Trace(movingball->Misc[q]);
  432.                     }
  433.                     //Huzzah, another 2.54 bug bites the dust as of 254a32!!
  434.                     */
  435.                 }
  436.                 if ( revive_vaus ) //when this is called, the ball breaks through all bricks. Something isn't being set.
  437.                 {
  438.                     Game->PlayMIDI(MID_STAGE_START);
  439.                     vaus->Misc[MISC_DEAD] = 0;
  440.                     revive_vaus = false;
  441.                    
  442.                     paddle.setup(vaus);
  443.                     ball.create(vaus);
  444.                     movingball = vaus->Misc[MISC_BALLID];
  445.                 }
  446.                
  447.                 if ( !vaus->Misc[MISC_DEAD] )
  448.                 {
  449.                     //if ( Input->Key[KEY_P] ) Trace(movingball->UID); //Frick, I'm an idiot. HIT_BY_LWEAPON is the SCREEN INDEX< not the UID!!
  450.                         //2.54 Absolutely needs HitBy_UID!
  451.                     if ( Input->Key[KEY_1] ) Trace(frame);
  452.                     //if ( frame%60 == 0 ) { Trace(movingball->Step); }
  453.                     //Trace(movingball->Step);
  454.                     change_setting(); //check for a setting change_setting
  455.                     paddle.extend(vaus);
  456.                     paddle.check_input();
  457.                     paddle.move(USE_MOUSE, USE_ACCEL, vaus);
  458.                    
  459.                     ball.launch(movingball);
  460.                     if ( !ball.launched(movingball) )
  461.                     {
  462.                         ball.move_with_vaus(movingball, vaus);
  463.                     }
  464.                    
  465.                    
  466.                     //clamp within bounds - MANDATORY because very fast Step speeds can cause the ball
  467.                     //to *phase* through pseudo-solid objects, such as walls and the Vaus.
  468.                     ball.clamp_rightwall(movingball);
  469.                     ball.clamp_ceiling(movingball);
  470.                     ball.clamp_leftwall(movingball);
  471.                     ball.clamp_bottom(movingball, vaus);
  472.                    
  473.                    
  474.                     //ball wall bounce checks
  475.                     ball.check_ceiling(movingball);
  476.                     ball.check_leftwall(movingball);
  477.                     ball.check_rightwall(movingball);
  478.                     ball.check_hitvaus(movingball, vaus);
  479.                     //ball.set_speed(movingball);
  480.                     /*
  481.                    
  482.                     I moved this to after Waitdraw, because I wanted the post-draw timing for ball bounce, and to ensure that
  483.                     the movingball lweapon stayed alive. -Z (Alpha 0.10)
  484.                     //Bounce ball on bricks.
  485.                     for ( int q = Screen->NumNPCs(); q > 0; --q )
  486.                     {
  487.                         npc b = Screen->LoadNPC(q);
  488.                         if ( b->Type != NPCT_OTHERFLOAT ) continue;
  489.                         TraceNL(); TraceS("movingball->X = "); Trace(movingball->X);
  490.                         TraceNL(); TraceS("movingball->Y = "); Trace(movingball->Y);
  491.                         brick.take_hit(b, movingball);
  492.                     }
  493.                     */
  494.                     movingball->DeadState = WDS_ALIVE; //Force it alive at all times if the vaus is alive.
  495.                         //We'll need another solition once we do the 3-way split ball. Bleah.
  496.                 }
  497.                
  498.                 //It's probably unwise to run this block twice! Where do I want it, before or after Waitdraw() ? -Z
  499.                 else
  500.                 {
  501.                     paddle.dead(vaus); //Set the death animation here.
  502.                    
  503.                     /*
  504.                     while ( (frame - 100) < death_frame )
  505.                     {
  506.                         //we should hide the vaus, and restart the stage here.
  507.                         ++frame;
  508.                         Waitdraw(); //Something is preventing the vaus from changing into the explosion style. S
  509.                         Waitframe();
  510.                     }
  511.                     lweapon deadball = movingball;
  512.                     deadball->DeadState = WDS_DEAD;
  513.                     movingball = vaus->Misc[10];
  514.                     if ( Game->Counter[CR_LIVES] )
  515.                     {
  516.                         --Game->Counter[CR_LIVES];
  517.                         revive_vaus = true;
  518.                     }
  519.                     */
  520.                    
  521.                 }
  522.                
  523.                
  524.                 Waitdraw();
  525.                
  526.                 hold_Link_y();
  527.                
  528.                 if ( !vaus->Misc[MISC_DEAD] )
  529.                 {
  530.                     movingball->DeadState = WDS_ALIVE;
  531.                    
  532.                     //Bounce ball on bricks.
  533.                     for ( int q = Screen->NumNPCs(); q > 0; --q )
  534.                     {
  535.                         npc b = Screen->LoadNPC(q);
  536.                         if ( b->Type != NPCT_OTHERFLOAT ) continue;
  537.                         //TraceNL(); TraceS("movingball->X = "); Trace(movingball->X);
  538.                         //TraceNL(); TraceS("movingball->Y = "); Trace(movingball->Y);
  539.                         movingball->DeadState = WDS_ALIVE;
  540.                         //TraceNL(); TraceS("movingball ptr: "); Trace(movingball);
  541.                         brick.take_hit(b, movingball);
  542.                     }
  543.                    
  544.                 }
  545.                 else
  546.                 {
  547.                     paddle.dead(vaus);
  548.                     while ( (frame - 100) < death_frame )
  549.                     {
  550.                         //we should hide the vaus, and restart the stage here.
  551.                         ++frame;
  552.                         Waitdraw();
  553.                         Waitframe();
  554.                     }
  555.                     lweapon deadball = movingball;
  556.                     deadball->DeadState = WDS_DEAD;
  557.                     movingball = vaus->Misc[10]; //Because = NULL() requires alpha 32. :D
  558.                     if ( Game->Counter[CR_LIVES] )
  559.                     {
  560.                         --Game->Counter[CR_LIVES];
  561.                         revive_vaus = true;
  562.                     }
  563.                     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.
  564.                     {
  565.                         if ( !death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT] )
  566.                         {
  567.                             death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT] = COUNTDOWN_TO_QUIT_FRAMES;
  568.                             continue;
  569.                         }
  570.                         else
  571.                         {
  572.                             --death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT];
  573.                             if ( death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT] == 1 )
  574.                             {
  575.                                 quit = QUIT_GAMEOVER; //Game over state.
  576.                                 TraceNL(); TraceS("Game 'quit' state is now: "); Trace(quit);
  577.                             }
  578.                         }
  579.                     }
  580.                        
  581.                 }
  582.                
  583.                 Waitframe();
  584.             }
  585.            
  586.             while (quit == QUIT_GAMEOVER) //Game Over
  587.             {
  588.                 if ( !(GAME[GAME_MISC_FLAGS]&GMFS_PLAYED_GAME_OVER_MUSIC) )
  589.                 {
  590.                     GAME[GAME_MISC_FLAGS]|=GMFS_PLAYED_GAME_OVER_MUSIC;
  591.                     //Play Game over MIDI
  592.                     Game->PlayMIDI(1);
  593.                 }
  594.                    
  595.                 Screen->DrawString(6, 96, 80, 1, 0x51, 0x00, 0, "GAME OVER", 128);
  596.                
  597.                 Waitdraw();
  598.                 Waitframe();
  599.             }
  600.             //We should never reach here.
  601.             Waitframe();
  602.         }
  603.     }
  604.     void change_setting()
  605.     {
  606.         if ( Input->Key[KEY_M] ) USE_MOUSE = 1;
  607.         if ( Input->Key[KEY_N] ) USE_MOUSE = 0;
  608.         if ( Input->Key[KEY_F] ) USE_ACCEL = 1;
  609.         if ( Input->Key[KEY_G] ) USE_ACCEL = 0;
  610.         if ( Input->Key[KEY_T] ) --paddle_speed; // paddle_speed = vbound(paddle_speed
  611.         if ( Input->Key[KEY_Y] ) ++paddle_speed; // paddle_speed = vbound(paddle_speed
  612.     }
  613.     void hold_Link_x(ffc v)
  614.     {
  615.         Link->X = v->X+(v->TileWidth*8);
  616.     }
  617.     void hold_Link_y()
  618.     {
  619.         Link->Y = START_PADDLE_Y - 4;
  620.     }
  621.     bool quit() { return ( quit ); }
  622.    
  623.     void check_min_zc_build()
  624.     {
  625.         if ( Game->Beta < MIN_ZC_ALPHA_BUILD )
  626.         {
  627.             Game->PlayMIDI(9);
  628.             int v_too_early = 600; int req_vers[3]; itoa(req_vers, MIN_ZC_ALPHA_BUILD);
  629.             TraceNL(); int vers[3]; itoa(vers,Game->Beta);
  630.             TraceS("This version of Arkanoid.qst requires Zelda Classic v2.54, Alpha (");
  631.             TraceS(req_vers);
  632.             TraceS("), or later.");
  633.             TraceNL();
  634.             TraceS("I'm detecting Zelda Classic v2.54, Alpha (");
  635.             TraceS(vers);
  636.             TraceS(") and therefore, I must refuse to run. :) ");
  637.             TraceNL();
  638.            
  639.             while(v_too_early--)
  640.             {
  641.                 //Screen->DrawString(7, 4, 40, 1, 0x04, 0x5F, 0,
  642.                 //"This version of Arkanoid.qst requires Zelda Classic 2.54, Alpha 32",
  643.                 //128);
  644.                 Screen->DrawString(7, 15, 40, 1, 0x04, 0x5F, 0,
  645.                 "You are not using a version of ZC adequate to run         ",
  646.                 128);
  647.                
  648.                 Screen->DrawString(7, 15, 55, 1, 0x04, 0x5F, 0,
  649.                 "this quest. Please see allegro.log for details.                   ",
  650.                 128);
  651.            
  652.                 Waitdraw();
  653.                 WaitNoAction();
  654.             }
  655.             Game->End();
  656.            
  657.         }
  658.     }
  659.    
  660. }
  661.  
  662. const int TILE_BALL = 50512;
  663. const int SPR_BALL = 100;
  664.  
  665.  
  666.  
  667. //preliminary ball
  668. ffc script ball
  669. {
  670.     void run(){}
  671.     void setup_sprite(int sprite_id)
  672.     {
  673.         spritedata sd = Game->LoadSpriteData(sprite_id);
  674.         sd->Tile = TILE_BALL;
  675.     }
  676.     void set_speed(lweapon b, int speed)
  677.     {
  678.         //Trace(bounces);
  679.         b->Step = speed; // bound(bounces,0,MAX_BOUNCES);
  680.         //Trace(b->Step);
  681.     }
  682.     void create(ffc vaus_id) //send the ball lweapon pointer back to the vaus
  683.     {
  684.         lweapon ball = Screen->CreateLWeapon(LW_SCRIPT1);
  685.         TraceNL(); TraceS("Creating ball with Script UID: "); Trace(ball->UID);
  686.         ball->HitWidth = 6; //Not 4, so that the ball bounces when its edges touch a brick.
  687.         ball->HitHeight = 6; //Not 4, so that the ball bounces when its edges touch a brick.
  688.         ball->UseSprite(SPR_BALL);
  689.         ball->X = vaus_id->X+18;
  690.         ball->Y = vaus_id->Y-2;
  691.         ball->Damage = 1;
  692.         ball_uid = ball->UID;
  693.         ball->HitXOffset = -1; //so that the ball bounces when its edges touch a brick.
  694.         ball->HitYOffset = -1; //so that the ball bounces when its edges touch a brick.
  695.         vaus_id->Misc[MISC_BALLID] = ball;
  696.     }
  697.     void launch(lweapon b)
  698.     {
  699.         if ( b->Misc[MISC_LAUNCHED] ) return;
  700.         bool launched;
  701.         for ( int q = CB_A; q < CB_R; ++q )
  702.         {
  703.             if ( Input->Press[q] ) { launched = true; break; }
  704.         }
  705.         if ( launched )
  706.         {
  707.             //b->Angular = true;
  708.             Game->PlaySound(6);
  709.             b->Dir = DIR_RIGHTUP;  
  710.             b->Step = 90;
  711.             b->Misc[MISC_LAUNCHED] = 1;
  712.         }
  713.     }
  714.     bool launched(lweapon b)
  715.     {
  716.         return (b->Misc[MISC_LAUNCHED]);
  717.     }
  718.     void move(lweapon b)
  719.     {
  720.        
  721.     }
  722.     float bound(int val, int min, int max)
  723.     {
  724.         if ( val < min ) return min;
  725.         if ( val > max ) return max;
  726.         return val;
  727.     }
  728.     //Not launched yet.
  729.     void move_with_vaus(lweapon b, ffc v)
  730.     {
  731.         b->X = v->X+18;
  732.     }
  733.     //ball.clamp*() are needed for when the step speed is so great that the ball skips past the equality checks.
  734.     void clamp_ceiling(lweapon b)
  735.     {
  736.         if ( b->Y < BALL_MIN_Y )           
  737.         {
  738.             b->Y = BALL_MIN_Y;
  739.         }
  740.     }
  741.     void clamp_leftwall(lweapon b)
  742.     {
  743.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  744.         if ( b->X < BALL_MIN_X ) b ->X = BALL_MIN_X;
  745.     }
  746.     void clamp_rightwall(lweapon b)
  747.     {
  748.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  749.         if ( b->X > BALL_MAX_X ) b->X = BALL_MAX_X;
  750.     }
  751.     /*
  752.     void clamp_bottom(lweapon b, ffc v)
  753.     {
  754.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  755.         if ( b->Y+4 > v->Y+8 ) dead(b,v);
  756.     }
  757.     */
  758.     //A function to check of the bounding will prevent the ball from falling out of field.
  759.     void clamp_bottom(lweapon b, ffc v)
  760.     {
  761.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  762.         if ( b->Y+4 > v->Y ) b->Y = v->Y-4;
  763.     }
  764.     void check_ceiling(lweapon b)
  765.     {
  766.         if ( b->Y == BALL_MIN_Y )          
  767.         {
  768.             Game->PlaySound(7);
  769.             if ( b->Angular )
  770.             {
  771.                 switch(b->Angle)
  772.                 {
  773.                     case DIR_LLU:
  774.                     {
  775.                         b->Angular = false;
  776.                         b->Dir = DIR_LEFTDOWN;
  777.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  778.                         break;
  779.                     }
  780.                     case DIR_LUU:
  781.                     {
  782.                         b->Angular = false;
  783.                         b->Dir = DIR_LEFTDOWN;
  784.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  785.                         break;
  786.                     }
  787.                     case DIR_RRU:
  788.                     {
  789.                         b->Angular = false;
  790.                         b->Dir = DIR_RIGHTDOWN;
  791.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  792.                         break;
  793.                     }
  794.                     case DIR_RUU:
  795.                     {
  796.                         b->Angular = false;
  797.                         b->Dir = DIR_RIGHTDOWN;
  798.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  799.                         break;
  800.                     }
  801.                    
  802.                 }
  803.             }
  804.             else
  805.             {
  806.                 switch(b->Dir)
  807.                 {
  808.                     case DIR_RIGHTUP: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  809.                     case DIR_LEFTUP: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  810.                     default: {
  811.                         TraceNL(); TraceS("Ball direction invalid for ball.check_ceiling().");
  812.                             TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  813.                         b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  814.                 }
  815.             }
  816.         }
  817.     }
  818.     void check_leftwall(lweapon b)
  819.     {
  820.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  821.         if ( b->X == BALL_MIN_X )
  822.         {
  823.             Game->PlaySound(7);
  824.             if ( b->Angular )
  825.             {
  826.                 switch(b->Angle)
  827.                 {
  828.                     case DIR_LLU:
  829.                     {
  830.                         b->Angular = false;
  831.                         b->Dir = DIR_RIGHTUP;
  832.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  833.                         break;
  834.                     }
  835.                     case DIR_LUU:
  836.                     {
  837.                         b->Angular = false;
  838.                         b->Dir = DIR_RIGHTUP;
  839.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  840.                         break;
  841.                     }
  842.                     case DIR_LLD:
  843.                     {
  844.                         b->Angular = false;
  845.                         b->Dir = DIR_RIGHTDOWN;
  846.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  847.                         break;
  848.                     }
  849.                     case DIR_LDD:
  850.                     {
  851.                         b->Angular = false;
  852.                         b->Dir = DIR_RIGHTDOWN;
  853.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  854.                         break;
  855.                     }
  856.                    
  857.                 }
  858.             }
  859.             else
  860.             {
  861.                 switch(b->Dir)
  862.                 {
  863.                     case DIR_LEFTDOWN: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  864.                     case DIR_LEFTUP: { b->Dir = DIR_RIGHTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  865.                     default: {
  866.                         TraceNL(); TraceS("Ball direction invalid for ball.check_leftwall().");
  867.                             TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  868.                         b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  869.                 }
  870.             }
  871.         }
  872.     }
  873.     void check_rightwall(lweapon b)
  874.     {
  875.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  876.         if ( b->X == BALL_MAX_X )
  877.         {
  878.             Game->PlaySound(7);
  879.             if ( b->Angular )
  880.             {
  881.                 switch(b->Angle)
  882.                 {
  883.                     case DIR_RRD:
  884.                     {
  885.                         b->Angular = false;
  886.                         b->Dir = DIR_LEFTDOWN;
  887.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  888.                         break;
  889.                     }
  890.                     case DIR_RDD:
  891.                     {
  892.                         b->Angular = false;
  893.                         b->Dir = DIR_LEFTDOWN;
  894.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  895.                         break;
  896.                     }
  897.                     case DIR_RRU:
  898.                     {
  899.                         b->Angular = false;
  900.                         b->Dir = DIR_RIGHTUP;
  901.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  902.                         break;
  903.                     }
  904.                     case DIR_RUU:
  905.                     {
  906.                         b->Angular = false;
  907.                         b->Dir = DIR_RIGHTUP;
  908.                         b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  909.                         break;
  910.                     }
  911.                    
  912.                 }
  913.             }
  914.             else
  915.             {
  916.                 switch(b->Dir)
  917.                 {
  918.                     case DIR_RIGHTDOWN: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  919.                     case DIR_RIGHTUP: { b->Dir = DIR_LEFTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  920.                     default: {
  921.                         TraceNL(); TraceS("Ball direction invalid for ball.check_rightwall().");
  922.                             TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  923.                         b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  924.                 }
  925.             }
  926.         }
  927.     }
  928.     void check_hitvaus(lweapon b, ffc v)
  929.     {
  930.         if ( launched(b) )
  931.         {
  932.            
  933.             if ( b->Angular )
  934.             {
  935.                 if ( b->Angle == DIR_UUR ){ return; }
  936.                 if ( b->Angle == DIR_UUL ) { return; }
  937.                 if ( b->Angle == DIR_ULL ) { return; }
  938.                 if ( b->Angle == DIR_URR ) { return; }
  939.             }
  940.             else
  941.             {
  942.                 if ( b->Dir == DIR_RIGHTUP ) { return; }
  943.                 if ( b->Dir == DIR_LEFTUP ) { return; }
  944.             }
  945.             //if ( Collision(b,v) ) //We'll refine this, later.
  946.            
  947.             //else
  948.             //{
  949.                 int hit_position; int vaus_midpoint =  v->X+(((v->TileWidth*16)/2)-1);
  950.                 int midpoint_segment = v->X+(((v->TileWidth*16)/6));
  951.                 int ball_midpoint = b->X+3;
  952.                
  953.                 if ( b->Y+4 == v->Y )
  954.                     //Now we need to check here, if the paddle is under the ball:
  955.                 {
  956.                     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
  957.                     {
  958.                         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.
  959.                         {
  960.                             Game->PlaySound(6);
  961.                             //b->Y = v->Y-1;
  962.                            
  963.                             if ( ball_midpoint <= vaus_midpoint ) //hit left side of vaus
  964.                             {
  965.                                 //more left than up, hit end of Vaus
  966.                                 if ( b->X <= (v->X-1) )
  967.                                 //if ( Abs(ball_midpoint-vaus_midpoint) <= 2 )
  968.                                 {
  969.                                     //angular up
  970.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR Left-left-Up");
  971.                                    
  972.                                     b->Angular = true;
  973.                                     b->Angle = DIR_LLU;
  974.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_LUU);
  975.                                     return;
  976.                                 }
  977.                                
  978.                                 //more up than left, hit close to centre
  979.                                 //else if ( (Abs(b->X+2)-vaus_midpoint) <= 3 )
  980.                                 //if ( Abs(ball_midpoint-vaus_midpoint) <= 2 )
  981.                                 if ( (Abs(vaus_midpoint - b->X+2)) <= 3 )
  982.                                 {
  983.                                     //angular up
  984.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR Left-Up-Up");
  985.                                    
  986.                                     b->Angular = true;
  987.                                     b->Angle = DIR_LUU;
  988.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  989.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_LUU);
  990.                                     return;
  991.                                 }
  992.                                 //hit between the zones, normal left-up
  993.                                 else
  994.                                 {
  995.                                
  996.                                     //hit the centre midpoint
  997.                                     //set angular = false
  998.                                     //set DIR_UL
  999.                                     TraceNL(); TraceS("Setting ball dir to DIGITAL Left-Up");
  1000.                                     //b->Y = v->Y-1;
  1001.                                     b->Angular = false;
  1002.                                     b->Dir = DIR_UPLEFT;
  1003.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1004.                                     return;
  1005.                                 }
  1006.                                
  1007.                             }
  1008.                             else if ( ball_midpoint > vaus_midpoint ) //hit right side of vaus
  1009.                             {
  1010.                                 /*
  1011.                                 if ( Abs(ball_midpoint-vaus_midpoint) <= 2 )
  1012.                                 {
  1013.                                     //angular up
  1014.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR RIGHT-Up-Up");
  1015.                                     --b->Y;
  1016.                                     b->Angular = true;
  1017.                                     b->Angle = DIR_RUU;
  1018.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_RUU);
  1019.                        
  1020.                                 }
  1021.                                 if ( b->X >= (v->X+(v->TileWidth*16)-2) )
  1022.                                 {
  1023.                                     //angular, sideways
  1024.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR right-right-Up");
  1025.                                     --b->Y;
  1026.                                     b->Angular = true;
  1027.                                     b->Angle = DIR_RRU;
  1028.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_RRU);
  1029.                        
  1030.                                 }
  1031.                                 */
  1032.                                 //more up then right, hit vaus close to centre
  1033.                                 if ( (Abs(vaus_midpoint - b->X)) <= 3 )
  1034.                                 {
  1035.                                     //angular up
  1036.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR RIGHT-Up-Up");
  1037.                                    
  1038.                                     b->Angular = true;
  1039.                                     b->Angle = DIR_RUU;
  1040.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1041.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_RUU);
  1042.                                     return;
  1043.                                 }
  1044.                                 //more right than up, hit end of vaus
  1045.                                 else if ( b->X > ( vaus_midpoint + ((v->TileWidth*16)/2)-4) )
  1046.                                 //else if ( (Abs(vaus_midpoint - b->X)) >= v->X+((v->TileWidth*16)/2)-1 )
  1047.                                 {
  1048.                                     //angular up
  1049.                                     TraceNL(); TraceS("Setting ball dir to ANGULAR RIGHT-right-Up");
  1050.                                    
  1051.                                     b->Angular = true;
  1052.                                     b->Angle = DIR_RRU;
  1053.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1054.                                     TraceNL(); TraceS("Checking if set angle evals true when compared against: "); TraceB(b->Angle == DIR_RUU);
  1055.                                     return;
  1056.                                 }
  1057.                                 else
  1058.                                 {
  1059.                                     //hit the centre midpoint
  1060.                                     //set angular = false
  1061.                                     //set DIR_UR
  1062.                                     TraceNL(); TraceS("Setting ball dir to DIGITAL Right-Up");
  1063.                                     //b->Y = v->Y-6;
  1064.                                     b->Angular = false;
  1065.                                     b->Dir = DIR_UPRIGHT;
  1066.                                     //b->Dir = DIR_UPRIGHT;
  1067.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1068.                                     return;
  1069.                                 }
  1070.                                
  1071.                             }
  1072.                                
  1073.                             else //catchall
  1074.                             {
  1075.                                 switch(b->Dir)
  1076.                                 {
  1077.                                     case DIR_LEFTDOWN: { b->Dir = DIR_LEFTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1078.                                     case DIR_RIGHTDOWN: { b->Dir = DIR_RIGHTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1079.                                     default: { b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1080.                                 }
  1081.                             }
  1082.                         }
  1083.                         else
  1084.                         {
  1085.                             dead(b,v);
  1086.                         }
  1087.                     }
  1088.                     else
  1089.                     {
  1090.                         dead(b,v);
  1091.                     }
  1092.                 }
  1093.             //}
  1094.            
  1095.         }
  1096.     }
  1097.     void dead(lweapon b, ffc v)
  1098.     {
  1099.        
  1100.         Game->PlayMIDI(5);
  1101.         //remove the ball
  1102.         b->Y = -32768; b->Step = 0;
  1103.         v->Misc[MISC_DEAD] = 1;
  1104.         //if there are more balls in play, switch movingball to one of those
  1105.         //otherwise,
  1106.         //check next life
  1107.         //if more lives, reset playfield
  1108.         //otherwise game over
  1109.        
  1110.     }
  1111.    
  1112.    
  1113.    
  1114. }
  1115.  
  1116. ffc script ball_controller
  1117. {
  1118.     void run()
  1119.     {
  1120.         lweapon ball;
  1121.         lweapon active_ball; //will be used for when we have multiple balls.
  1122.         lweapon balls[3]; //for divide
  1123.         ball = Screen->CreateLWeapon(LW_SCRIPT1);
  1124.         ball->X = START_BALL_X;
  1125.         ball->Y = START_BALL_Y;
  1126.         this->Vx = START_BALL_VX;
  1127.         this->Vy = START_BALL_VY;
  1128.         bool alive = true;
  1129.         int num_balls = 1;
  1130.         while(alive)
  1131.         {
  1132.             if ( ball->Y <= BALL_MIN_Y )
  1133.             {
  1134.                 bounce();
  1135.             }
  1136.             if ( ball->X <= BALL_MIN_X )
  1137.             {
  1138.                 bounce();
  1139.             }
  1140.             if ( ball->X >= BALL_MAX_X )
  1141.             {
  1142.                 bounce();
  1143.             }
  1144.                
  1145.             if ( ball->Y >= BALL_MAX_Y )
  1146.             {
  1147.                 if ( num_balls < 2 )
  1148.                 {
  1149.                     alive = false;
  1150.                 }
  1151.                 else
  1152.                 {
  1153.                     kill_ball(ball); //removes this ball, and sets another ball to be the active one
  1154.                     --num_balls;
  1155.                 }
  1156.             }
  1157.             Waitframe();
  1158.         }
  1159.     }
  1160.     void bounce(){}
  1161.     void kill_ball(lweapon b){}
  1162.    
  1163. }
  1164.  
  1165. const int BRICK_MAX = 14;
  1166.  
  1167. //Layer 1
  1168. const int CMB_BRICK_RED     = 1488;
  1169. const int CMB_BRICK_WHITE   = 1490;
  1170. const int CMB_BRICK_BLUE    = 1492;
  1171. const int CMB_BRICK_ORANGE  = 1494;
  1172. const int CMB_BRICK_TEAL    = 1496;
  1173. const int CMB_BRICK_VIOLET  = 1498;
  1174. const int CMB_BRICK_GREEN   = 1500;
  1175. const int CMB_BRICK_YELLOW  = 1502;
  1176. const int CMB_BRICK_SILVER1 = 1504;
  1177. const int CMB_BRICK_SILVER2 = 1506;
  1178. const int CMB_BRICK_SILVER3 = 1508;
  1179. const int CMB_BRICK_SILVER4 = 1510;
  1180. const int CMB_BRICK_GOLD    = 1516;
  1181.  
  1182.  
  1183. //layer 2
  1184. const int CMB_BRICK_RED_LOW     = 1489;
  1185. const int CMB_BRICK_WHITE_LOW   = 1491;
  1186. const int CMB_BRICK_BLUE_LOW    = 1493;
  1187. const int CMB_BRICK_ORANGE_LOW  = 1495;
  1188. const int CMB_BRICK_TEAL_LOW    = 1497;
  1189. const int CMB_BRICK_VIOLET_LOW  = 1499;
  1190. const int CMB_BRICK_GREEN_LOW   = 1501;
  1191. const int CMB_BRICK_YELLOW_LOW  = 1503;
  1192. const int CMB_BRICK_SILVER1_LOW = 1505;
  1193. const int CMB_BRICK_SILVER2_LOW = 1507;
  1194. const int CMB_BRICK_SILVER3_LOW = 1509;
  1195. const int CMB_BRICK_SILVER4_LOW = 1511;
  1196. const int CMB_BRICK_GOLD_LOW    = 1517;
  1197.  
  1198. //enemies
  1199. const int NPC_BRICK_RED     = 181;
  1200. const int NPC_BRICK_WHITE   = 182;
  1201. const int NPC_BRICK_BLUE    = 183;
  1202. const int NPC_BRICK_ORANGE  = 184;
  1203. const int NPC_BRICK_TEAL    = 185;
  1204. const int NPC_BRICK_VIOLET  = 186;
  1205. const int NPC_BRICK_GREEN   = 187;
  1206. const int NPC_BRICK_YELLOW  = 188;
  1207. const int NPC_BRICK_SILVER1     = 189;
  1208. const int NPC_BRICK_SILVER2     = 190;
  1209. const int NPC_BRICK_SILVER3     = 255; //not set up yet;
  1210. const int NPC_BRICK_SILVER4     = 255; //not set up yet
  1211. const int NPC_BRICK_GOLD    = 191;
  1212.  
  1213.  
  1214. const int HIT_BY_LWEAPON = 2;
  1215. const int HIT_BY_LWEAPON_UID = 6;
  1216.  
  1217. ffc script brick
  1218. {
  1219.     void run()
  1220.     {
  1221.     }
  1222.     float bound(int val, int min, int max)
  1223.     {
  1224.         if ( val < min ) return min;
  1225.         if ( val > max ) return max;
  1226.         return val;
  1227.     }
  1228.     bool hit(npc a, lweapon v)
  1229.     {
  1230.         /*
  1231.         if ( a->HitBy[HIT_BY_LWEAPON] < 1 ) return false;
  1232.         a->Misc[12] = Screen->LoadLWeapon(a->HitBy[HIT_BY_LWEAPON]);
  1233.         lweapon hitwpn = a->Misc[12];
  1234.         return ( hitwpn->UID == v->UID );
  1235.         */
  1236.         return ( a->HitBy[HIT_BY_LWEAPON_UID] == v->UID );
  1237.         //int indx; //Until we have UIDs working for HitBy[], we need to do it this way.
  1238.         //for ( int q = Screen->NumLWeapons(); q > 0; --q )
  1239.         //{
  1240.         //  lweapon temp = Screen->LoadLWeapon(q);
  1241.         //  if ( temp->UID == v->UID )
  1242.         //  {
  1243.         //      indx = q; break;
  1244.         //  }
  1245.         //}
  1246.         //Link->Misc[0] = v; //We'll use this as scratch untyped space for the moment. -Z
  1247.         //TraceS("brick.hit() Link->Misc[] is: "); Trace(Link->Misc[0]);
  1248.         //TraceS("brick.hit() v is: "); Trace(v);
  1249.         //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.
  1250.             //as UID is not, and NEVER should be!!!
  1251.         //TraceNL(); TraceS("v->UID is: "); Trace(v->UID);
  1252.         /*
  1253.         To determine where a brick was hit, we first scan each brick and look to see which was
  1254.         hit at all, by our lweapon.
  1255.        
  1256.         The, we check if that ball is belove, above, right of, or left of the brick,
  1257.         and we read its direction.
  1258.        
  1259.         Using a logic chain from this data, we determine the direction that the ball should next
  1260.         take, when it bounces.
  1261.        
  1262.         */
  1263.         //HitBy[]
  1264.        
  1265.         //if ( a->HitBy[HIT_BY_LWEAPON] )
  1266.         //{
  1267.         //  TraceNL(); TraceS("a->HitBy[HIT_BY_LWEAPON] id: "); Trace(a->HitBy[HIT_BY_LWEAPON]);
  1268.         //  TraceNL();
  1269.         //  TraceS("Our Link->Misc scratch value `is: "); Trace((Link->Misc[0]+1));
  1270.         //}
  1271.        
  1272.         //! We'll use this method again when we add UIDs to HitBy[] ! -Z
  1273.         //return ( a->HitBy[HIT_BY_LWEAPON] == temp_UID );
  1274.         //return ( a->HitBy[HIT_BY_LWEAPON] == indx ); //(Link->Misc[0]+1) );
  1275.        
  1276.     }
  1277.     bool hit_below(npc a, lweapon v)
  1278.     {
  1279.         if ( v->Y == (a->Y + 8) ) return true; //we could do bounce here.
  1280.     }
  1281.     bool hit_above(npc a, lweapon v)
  1282.     {
  1283.         if ( v->Y == (a->Y - 4) ) return true; //we could do bounce here.
  1284.     }
  1285.     bool hit_left(npc a, lweapon v)
  1286.     {
  1287.         if ( v->X == (a->X - 4) ) return true; //we could do bounce here.
  1288.     }
  1289.     bool hit_right(npc a, lweapon v)
  1290.     {
  1291.         if ( v->X == (a->X + 16 ) ) return true; //we could do bounce here.
  1292.     }
  1293.    
  1294.     void take_hit(npc a, lweapon b)
  1295.     {
  1296.         if ( hit(a,b) )
  1297.         {
  1298.             //TraceNL(); TraceS("Brick hit!");
  1299.             b->DeadState = WDS_ALIVE;
  1300.             //TraceNL(); TraceS("brick->X = "); Trace(a->X);
  1301.             //TraceNL(); TraceS("brick->Y = "); Trace(a->Y);
  1302.             //TraceNL(); TraceS("ball->X = "); Trace(v->X);
  1303.             //TraceNL(); TraceS("ball->Y = "); Trace(v->Y);
  1304.             if ( hit_below(a,b) )
  1305.             {
  1306.                 //check the corners:
  1307.                 if ( hit_left(a,b) )
  1308.                     //lower-left corner
  1309.                 {
  1310.                    
  1311.                     if ( b->Angular )
  1312.                     {
  1313.                         switch(b->Angle)
  1314.                         {
  1315.                             case DIR_RRU:
  1316.                             {
  1317.                                 b->Angular = false;
  1318.                                 b->Dir = DIR_RIGHTDOWN;
  1319.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1320.                                 break;
  1321.                             }
  1322.                             case DIR_RRD:
  1323.                             {
  1324.                                 b->Angular = false;
  1325.                                 b->Dir = DIR_RIGHTUP;
  1326.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1327.                                 break;
  1328.                             }
  1329.                             case DIR_RUU:
  1330.                             {
  1331.                                 b->Angular = false;
  1332.                                 b->Dir = DIR_RIGHTDOWN;
  1333.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1334.                                 break;
  1335.                             }
  1336.                             case DIR_RDD:
  1337.                             {
  1338.                                 b->Angular = false;
  1339.                                 b->Dir = DIR_RIGHTUP;
  1340.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1341.                                 break;
  1342.                             }
  1343.                             case DIR_LLU:
  1344.                             {
  1345.                                 b->Angular = false;
  1346.                                 b->Dir = DIR_RIGHTDOWN;
  1347.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1348.                                 break;
  1349.                             }
  1350.                             case DIR_LUU:
  1351.                             {
  1352.                                 b->Angular = false;
  1353.                                 b->Dir = DIR_RIGHTDOWN;
  1354.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1355.                                 break;
  1356.                             }
  1357.                             case DIR_LLD:
  1358.                             {
  1359.                                 b->Angular = false;
  1360.                                 b->Dir = DIR_RIGHTUP;
  1361.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1362.                                 break;
  1363.                             }
  1364.                             case DIR_LDD:
  1365.                             {
  1366.                                 b->Angular = false;
  1367.                                 b->Dir = DIR_RIGHTUP;
  1368.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1369.                                 break;
  1370.                             }
  1371.                            
  1372.                         }
  1373.                         else
  1374.                         {
  1375.                             switch(b->Dir)
  1376.                             {
  1377.                                 case DIR_RIGHTUP:
  1378.                                 {
  1379.                                     b->Angular = false;
  1380.                                     b->Dir = DIR_LEFTDOWN;
  1381.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1382.                                     break;
  1383.                                 }  
  1384.                                    
  1385.                                 case DIR_RIGHTDOWN:
  1386.                                 {
  1387.                                     b->Angular = false;
  1388.                                     b->Dir = DIR_LEFTUP;
  1389.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1390.                                     break;
  1391.                                 }  
  1392.                                
  1393.                             }
  1394.                         }
  1395.                     }
  1396.                    
  1397.                 }//end lower-left corner
  1398.                
  1399.                 if ( hit_right(a,b) )
  1400.                     //lower-right corner
  1401.                 {
  1402.                    
  1403.                     if ( b->Angular )
  1404.                     {
  1405.                         switch(b->Angle)
  1406.                         {
  1407.                             case DIR_LLU:
  1408.                             {
  1409.                                 b->Angular = false;
  1410.                                 b->Dir = DIR_RIGHTDOWN;
  1411.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1412.                                 break;
  1413.                             }
  1414.                             case DIR_LLD:
  1415.                             {
  1416.                                 b->Angular = false;
  1417.                                 b->Dir = DIR_RIGHTDOWN;
  1418.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1419.                                 break;
  1420.                             }
  1421.                             case DIR_RUU:
  1422.                             {
  1423.                                 b->Angular = false;
  1424.                                 b->Dir = DIR_RIGHTDOWN;
  1425.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1426.                                 break;
  1427.                             }
  1428.                             case DIR_RDD:
  1429.                             {
  1430.                                 b->Angular = false;
  1431.                                 b->Dir = DIR_LEFTUP;
  1432.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1433.                                 break;
  1434.                             }
  1435.                             case DIR_LLU:
  1436.                             {
  1437.                                 b->Angular = false;
  1438.                                 b->Dir = DIR_RIGHTDOWN;
  1439.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1440.                                 break;
  1441.                             }
  1442.                             case DIR_LUU:
  1443.                             {
  1444.                                 b->Angular = false;
  1445.                                 b->Dir = DIR_RIGHTDOWN;
  1446.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1447.                                 break;
  1448.                             }
  1449.                             case DIR_LLD:
  1450.                             {
  1451.                                 b->Angular = false;
  1452.                                 b->Dir = DIR_LEFTUP;
  1453.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1454.                                 break;
  1455.                             }
  1456.                             case DIR_LDD:
  1457.                             {
  1458.                                 b->Angular = false;
  1459.                                 b->Dir = DIR_LEFTUP;
  1460.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1461.                                 break;
  1462.                             }
  1463.                            
  1464.                         }
  1465.                         else
  1466.                         {
  1467.                             switch(b->Dir)
  1468.                             {
  1469.                                 case DIR_LEFTUP:
  1470.                                 {
  1471.                                     b->Angular = false;
  1472.                                     b->Dir = DIR_RIGHTDOWN;
  1473.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1474.                                     break;
  1475.                                 }  
  1476.                                    
  1477.                                 case DIR_LEFTDOWN:
  1478.                                 {
  1479.                                     b->Angular = false;
  1480.                                     b->Dir = DIR_RIGHTUP;
  1481.                                     b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1482.                                     break;
  1483.                                 }  
  1484.                                
  1485.                             }
  1486.                         }
  1487.                     }
  1488.                    
  1489.                 }//end lower-right corner
  1490.                
  1491.                
  1492.                 else
  1493.                 {
  1494.                
  1495.                     if ( b->Angular )
  1496.                     {
  1497.                         switch(b->Angle)
  1498.                         {
  1499.                             case DIR_LLU:
  1500.                             {
  1501.                                 b->Angular = false;
  1502.                                 b->Dir = DIR_LEFTDOWN;
  1503.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1504.                                 break;
  1505.                             }
  1506.                             case DIR_LUU:
  1507.                             {
  1508.                                 b->Angular = false;
  1509.                                 b->Dir = DIR_LEFTDOWN;
  1510.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1511.                                 break;
  1512.                             }
  1513.                             case DIR_RRU:
  1514.                             {
  1515.                                 b->Angular = false;
  1516.                                 b->Dir = DIR_RIGHTDOWN;
  1517.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1518.                                 break;
  1519.                             }
  1520.                             case DIR_RUU:
  1521.                             {
  1522.                                 b->Angular = false;
  1523.                                 b->Dir = DIR_RIGHTDOWN;
  1524.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1525.                                 break;
  1526.                             }
  1527.                            
  1528.                         }
  1529.                     }
  1530.                     else
  1531.                     {
  1532.                         switch(b->Dir)
  1533.                         {
  1534.                             case DIR_RIGHTUP: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1535.                             case DIR_LEFTUP: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1536.                             default: { TraceNL(); TraceS("Ball direction invalid for brick.take_hit(hit_below()).");
  1537.                                 TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  1538.                                 b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1539.                         }
  1540.                     }
  1541.                 }
  1542.                 /*
  1543.                 switch ( v->Dir )
  1544.                 {
  1545.                     case DIR_UPRIGHT: { v->Dir = DIR_DOWNRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1546.                     case DIR_UPLEFT: { v->Dir = DIR_DOWNLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1547.                     default: { TraceS("hit_below() found an illegal ball direction"); break; }
  1548.                 }
  1549.                 */
  1550.                 if ( a->HP <= 0 )
  1551.                 {
  1552.                     //TraceS("Brick is dead. "); TraceNL();
  1553.                     //TraceS("a->Misc[NPCM_AWARDED_POINTS] is: "); Trace(a->Misc[NPCM_AWARDED_POINTS]); TraceNL();
  1554.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  1555.                     {
  1556.                         //TraceS("Can award points!"); TraceNL();
  1557.                         a->Misc[18] = 1;
  1558.                         //TraceS("The points for this brick are: "); Trace(a->Attributes[NPC_ATTRIB_POINTS]); TraceNL();
  1559.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  1560.                     }
  1561.                 }
  1562.             }
  1563.            
  1564.             else if ( hit_above(a,b) )
  1565.             {
  1566.                 if ( b->Angular )
  1567.                 {
  1568.                     switch(b->Angle)
  1569.                     {
  1570.                         case DIR_LLD:
  1571.                         {
  1572.                             b->Angular = false;
  1573.                             b->Dir = DIR_LEFTUP;
  1574.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1575.                             break;
  1576.                         }
  1577.                         case DIR_LDD:
  1578.                         {
  1579.                             b->Angular = false;
  1580.                             b->Dir = DIR_LEFTUP;
  1581.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1582.                             break;
  1583.                         }
  1584.                         case DIR_RRD:
  1585.                         {
  1586.                             b->Angular = false;
  1587.                             b->Dir = DIR_RIGHTUP;
  1588.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1589.                             break;
  1590.                         }
  1591.                         case DIR_RDD:
  1592.                         {
  1593.                             b->Angular = false;
  1594.                             b->Dir = DIR_RIGHTUP;
  1595.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1596.                             break;
  1597.                         }
  1598.                        
  1599.                     }
  1600.                 }
  1601.                 else
  1602.                 {
  1603.                     switch(b->Dir)
  1604.                     {
  1605.                         case DIR_DOWNLEFT: { b->Dir = DIR_UPLEFT; b->Step = bound(b->Step+2, 0, MAX_BALL_SPEED); break; }
  1606.                         case DIR_DOWNRIGHT: { b ->Dir = DIR_UPRIGHT; b->Step = bound(b->Step+2, 0, MAX_BALL_SPEED); break; }
  1607.                         default: {
  1608.                             TraceNL(); TraceS("Ball direction invalid for brick.take_hit(hit_above()).");
  1609.                             TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  1610.                            
  1611.                             b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1612.                     }
  1613.                 }
  1614.                
  1615.                 if ( a->HP <= 0 )
  1616.                 {
  1617.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  1618.                     {
  1619.                         a->Misc[NPCM_AWARDED_POINTS] = 1;
  1620.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  1621.                     }
  1622.                 }
  1623.             }
  1624.            
  1625.             else if ( hit_left(a,b) )
  1626.             {
  1627.                 if ( b->Angular )
  1628.                 {
  1629.                     switch(b->Angle)
  1630.                     {
  1631.                         case DIR_LLU:
  1632.                         {
  1633.                             b->Angular = false;
  1634.                             b->Dir = DIR_RIGHTUP;
  1635.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1636.                             break;
  1637.                         }
  1638.                         case DIR_LUU:
  1639.                         {
  1640.                             b->Angular = false;
  1641.                             b->Dir = DIR_RIGHTUP;
  1642.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1643.                             break;
  1644.                         }
  1645.                         case DIR_LLD:
  1646.                         {
  1647.                             b->Angular = false;
  1648.                             b->Dir = DIR_RIGHTDOWN;
  1649.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1650.                             break;
  1651.                         }
  1652.                         case DIR_LDD:
  1653.                         {
  1654.                             b->Angular = false;
  1655.                             b->Dir = DIR_RIGHTDOWN;
  1656.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1657.                             break;
  1658.                         }
  1659.                        
  1660.                     }
  1661.                 }
  1662.                 else
  1663.                 {
  1664.                     switch(b->Dir)
  1665.                     {
  1666.                         case DIR_RIGHTDOWN: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1667.                         case DIR_RIGHTUP: { b->Dir = DIR_LEFTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1668.                         default: {
  1669.                             TraceNL(); TraceS("Ball direction invalid for brick.take_hit(hit(left)).");
  1670.                             TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  1671.                             b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1672.                     }
  1673.                 }
  1674.                 /*
  1675.                 switch ( v->Dir )
  1676.                 {
  1677.                     case DIR_UPRIGHT: { v->Dir = DIR_UPLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1678.                     case DIR_DOWNRIGHT: { v->Dir = DIR_DOWNLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED);  break; }
  1679.                     default: { TraceS("hit_left() found an illegal ball direction"); break; }
  1680.                 }
  1681.                 */
  1682.                 if ( a->HP <= 0 )
  1683.                 {
  1684.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  1685.                     {
  1686.                         a->Misc[NPCM_AWARDED_POINTS] = 1;
  1687.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  1688.                     }
  1689.                 }
  1690.             }
  1691.             else if ( hit_right(a,b) )
  1692.             {
  1693.                 if ( b->Angular )
  1694.                 {
  1695.                     switch(b->Angle)
  1696.                     {
  1697.                         case DIR_RRD:
  1698.                         {
  1699.                             b->Angular = false;
  1700.                             b->Dir = DIR_LEFTDOWN;
  1701.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1702.                             break;
  1703.                         }
  1704.                         case DIR_RDD:
  1705.                         {
  1706.                             b->Angular = false;
  1707.                             b->Dir = DIR_LEFTDOWN;
  1708.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1709.                             break;
  1710.                         }
  1711.                         case DIR_RRU:
  1712.                         {
  1713.                             b->Angular = false;
  1714.                             b->Dir = DIR_LEFTUP;
  1715.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1716.                             break;
  1717.                         }
  1718.                         case DIR_RUU:
  1719.                         {
  1720.                             b->Angular = false;
  1721.                             b->Dir = DIR_LEFTUP;
  1722.                             b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  1723.                             break;
  1724.                         }
  1725.                        
  1726.                     }
  1727.                 }
  1728.                 else
  1729.                 {
  1730.                     switch(b->Dir)
  1731.                     {
  1732.                         case DIR_LEFTDOWN: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1733.                         case DIR_LEFTUP: { b->Dir = DIR_RIGHTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1734.                         default: {
  1735.                             TraceNL(); TraceS("Ball direction invalid for brick.take_hit(hit_right()).");
  1736.                             TraceNL(); TraceS("Ball Dir is: "); Trace(b->Dir); TraceNL();
  1737.                             b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  1738.                     }
  1739.                 }
  1740.                 /*
  1741.                 switch ( v->Dir )
  1742.                 {
  1743.                     case DIR_UPLEFT: { v->Dir = DIR_UPRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1744.                     case DIR_DOWNLEFT: { v->Dir = DIR_DOWNRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1745.                     default: { TraceS("hit_below() found an illegal ball direction"); break; }
  1746.                 }
  1747.                 */
  1748.                 if ( a->HP <= 0 )
  1749.                 {
  1750.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  1751.                     {
  1752.                         a->Misc[NPCM_AWARDED_POINTS] = 1;
  1753.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  1754.                     }
  1755.                 }
  1756.             }
  1757.            
  1758.             else
  1759.             {
  1760.                 TraceS("brick.hit() returned true, but couldn't determine a valid ball location!");
  1761.                 return;
  1762.             }
  1763.         }
  1764.                    
  1765.            
  1766.     }
  1767.     //turns layer objects into npc bricks.
  1768.     void setup()
  1769.     {
  1770.         int tempenem; npc bricks[1024]; int temp;
  1771.         for ( int q = 0; q < 176; ++q )
  1772.         {
  1773.             //bricks on layer 1
  1774.             //Trace(GetLayerComboD(1,q));
  1775.             //while(!Input->Press[CB_A]) Waitframe();
  1776.             tempenem = brick_to_npc(GetLayerComboD(1,q),false);
  1777.             //TraceS("tempenem is: "); Trace(tempenem);
  1778.             //while(!Input->Press[CB_A]) Waitframe();
  1779.             if ( tempenem )
  1780.             {
  1781.                 bricks[temp] = Screen->CreateNPC(tempenem);
  1782.                 //TraceS("Created npc: "); Trace(tempenem);
  1783.                 bricks[temp]->X = ComboX(q);
  1784.                 bricks[temp]->Y = ComboY(q);
  1785.                 TraceS("Brick defence is: "); Trace(bricks[temp]->Defense[20]);
  1786.                 tempenem = 0; ++temp;
  1787.                
  1788.             }
  1789.             //bricks on layer 2, Y+8px
  1790.             tempenem = brick_to_npc(GetLayerComboD(2,q),true);
  1791.             //Trace(tempenem);
  1792.             if ( tempenem )
  1793.             {
  1794.                 bricks[temp] = Screen->CreateNPC(tempenem);
  1795.                 //TraceS("Created npc: "); Trace(tempenem);
  1796.                 bricks[temp]->X = ComboX(q);
  1797.                 bricks[temp]->Y = ComboY(q)+8;
  1798.                 TraceS("Brick defence is: "); Trace(bricks[temp]->Defense[20]);
  1799.                 tempenem = 0; ++temp;
  1800.             }
  1801.         }
  1802.        
  1803.     }
  1804.     void clear_combos()
  1805.     {
  1806.         templayer[0] = Screen->LayerOpacity[0];
  1807.         templayer[1] = Screen->LayerOpacity[1];
  1808.         templayer[2] = Screen->LayerMap[0];
  1809.         templayer[3] = Screen->LayerMap[1];
  1810.         Screen->LayerOpacity[0] = 0;
  1811.         Screen->LayerOpacity[1] = 0;
  1812.         Screen->LayerMap[0] = 0;
  1813.         Screen->LayerMap[1] = 0;
  1814.     }
  1815.    
  1816.     int brick_to_npc(int combo_id, bool layer2)
  1817.     {
  1818.        
  1819.         if ( !layer2 )
  1820.         {
  1821.             int brick_to_enemy[BRICK_MAX*2] =
  1822.             {   CMB_BRICK_RED, CMB_BRICK_WHITE, CMB_BRICK_BLUE, CMB_BRICK_ORANGE, CMB_BRICK_TEAL,
  1823.                 CMB_BRICK_VIOLET, CMB_BRICK_GREEN, CMB_BRICK_YELLOW, CMB_BRICK_SILVER1, CMB_BRICK_SILVER2,
  1824.                 CMB_BRICK_SILVER3, CMB_BRICK_SILVER4, CMB_BRICK_GOLD,
  1825.  
  1826.                 NPC_BRICK_RED, NPC_BRICK_WHITE, NPC_BRICK_BLUE, NPC_BRICK_ORANGE, NPC_BRICK_TEAL,
  1827.                 NPC_BRICK_VIOLET, NPC_BRICK_GREEN, NPC_BRICK_YELLOW, NPC_BRICK_SILVER1, NPC_BRICK_SILVER2,
  1828.                 NPC_BRICK_SILVER3, NPC_BRICK_SILVER4, NPC_BRICK_GOLD
  1829.             };
  1830.             for ( int q = 0; q < BRICK_MAX; ++q )
  1831.             {
  1832.                 if ( brick_to_enemy[q] == combo_id )
  1833.                 {
  1834.                     //  TraceS("brick_to_npc : combo input: "); Trace(combo_id);
  1835.                     //TraceS("brick_to_npc : enemy output: "); Trace(brick_to_enemy[BRICK_MAX+q]);
  1836.                    
  1837.                     return ( brick_to_enemy[BRICK_MAX+q-1] );
  1838.                 }
  1839.             }
  1840.         }
  1841.         else
  1842.         {
  1843.             int brick_to_enemy2[BRICK_MAX*2] =
  1844.             {   CMB_BRICK_RED_LOW, CMB_BRICK_WHITE_LOW, CMB_BRICK_BLUE_LOW, CMB_BRICK_ORANGE_LOW, CMB_BRICK_TEAL_LOW,
  1845.                 CMB_BRICK_VIOLET_LOW, CMB_BRICK_GREEN_LOW, CMB_BRICK_YELLOW_LOW, CMB_BRICK_SILVER1_LOW, CMB_BRICK_SILVER2_LOW,
  1846.                 CMB_BRICK_SILVER3_LOW, CMB_BRICK_SILVER4_LOW, CMB_BRICK_GOLD_LOW,
  1847.  
  1848.                 NPC_BRICK_RED, NPC_BRICK_WHITE, NPC_BRICK_BLUE, NPC_BRICK_ORANGE, NPC_BRICK_TEAL,
  1849.                 NPC_BRICK_VIOLET, NPC_BRICK_GREEN, NPC_BRICK_YELLOW, NPC_BRICK_SILVER1, NPC_BRICK_SILVER2,
  1850.                 NPC_BRICK_SILVER3, NPC_BRICK_SILVER4, NPC_BRICK_GOLD
  1851.             };
  1852.             for ( int q = 0; q < BRICK_MAX; ++q )
  1853.             {
  1854.                 if ( brick_to_enemy2[q] == combo_id )
  1855.                 {
  1856.                     //TraceS("brick_to_npc : combo input: "); Trace(combo_id);
  1857.                     //TraceS("brick_to_npc : enemy output: "); Trace(brick_to_enemy2[BRICK_MAX+q-1]);
  1858.                     return ( brick_to_enemy2[BRICK_MAX+q-1] );
  1859.                 }
  1860.             }
  1861.         }
  1862.         return 0; //error
  1863.     }
  1864. }
  1865.  
  1866. global script onExit
  1867. {
  1868.     void run()
  1869.     {
  1870.         Screen->LayerOpacity[0] = templayer[0];
  1871.         Screen->LayerOpacity[1] = templayer[1];
  1872.         Screen->LayerMap[0] = templayer[2];
  1873.         Screen->LayerMap[1] = templayer[3];
  1874.         newstage = true;
  1875.         //vaus->Misc[MISC_DEAD] = 0;
  1876.  
  1877.     }
  1878. }  
  1879.  
  1880. global script init
  1881. {
  1882.     void run()
  1883.     {
  1884.         quit = 0;
  1885.         frame = -1;
  1886.         Game->Counter[CR_LIVES] = 5;
  1887.         Link->CollDetection = false;
  1888.         Link->DrawYOffset = -32768;
  1889.     }
  1890. }
  1891.  
  1892. global script Init
  1893. {
  1894.     void run()
  1895.     {
  1896.         quit = 0;
  1897.         frame = -1;
  1898.         Game->Counter[CR_LIVES] = 5;
  1899.         Link->CollDetection = false;
  1900.         Link->DrawYOffset = -32768;
  1901.     }
  1902. }
  1903.  
  1904. global script onContinue
  1905. {
  1906.     void run()
  1907.     {
  1908.         quit = 0;
  1909.         frame = -1;
  1910.         Game->Counter[CR_LIVES] = 5;
  1911.         Link->Invisible = true;
  1912.         Link->CollDetection = false;
  1913.         Link->DrawYOffset = -32768;
  1914.     }
  1915. }
  1916.  
  1917. /////////////////////////
  1918. /// DEAD Script Bugs: ///
  1919. /////////////////////////
  1920.  
  1921. /*
  1922. //FIXED with ball.clamp().
  1923. //There's a step speed at which the ball phases *through* the vaus!
  1924.                     //Perhaps we should make the vaus an enemy, too? An invisible enemy to act as a failsafe?
  1925.                     //if the ball hits the vaus, it bounces.
  1926.                     //Or just scrap the vaus ffc, and use an npc for it in general?
  1927.  
  1928. //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
  1929. //the ball is still not yet inside that object
  1930. */
  1931.  
  1932. //////////////////////
  1933. /// DEAD ZC Issues //////////////////////////////////////////////////////////////////////////////
  1934. /// I fixed these issues, in specific Alphas of ZC 2.54, noted below for historical purposes: ///
  1935. /////////////////////////////////////////////////////////////////////////////////////////////////
  1936.  
  1937.  
  1938. /*
  1939. FIXED in Alpha 32
  1940. I forgot to expand ->Misc[] in sprite.cpp, which should be fixed int he source for Alpha 32.
  1941.     This meant that r/w to ptr->Misc[>15] would use invalid data, or overwrite other data. bad, bad, bad.
  1942.    
  1943.     FIXED in Alpha 32
  1944.     //Note: We also need to store the UID of each ball, as HitBy[] works from the UID, not the pointer.
  1945.    
  1946. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement