Advertisement
ZoriaRPG

Arkanoid (Alpha 16, Stable)

Aug 17th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 35.94 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.  
  33.  
  34. const int MIN_ZC_ALPHA_BUILD = 32; //Alphas are negatives, so we neex to check maximum, not minimum.
  35.  
  36.  
  37. const float ARKANOID_VERSION = 0.16;
  38.  
  39. int GAME[256];
  40. const int GAME_MISC_FLAGS = 0;
  41. const int GMFS_PLAYED_GAME_OVER_MUSIC = 0x01;
  42.  
  43. const int FFC_VAUS = 1;
  44. const int CMB_VAUS_EXTENDED = 1528;
  45. const int CMB_VAUS = 1524;
  46. const int CMB_VAUS_DEAD = 1520;
  47.  
  48. const int MID_STAGE_START = 4;
  49. const int NPCM_AWARDED_POINTS = 3; //brick->Misc[], flag to mark if points were awarded to the player.
  50. const int NPC_ATTRIB_POINTS = 0; //brick->Attributes[], value for score.
  51.  
  52. //Counters
  53. const int CR_SCORE = 7; //script 1
  54. const int CR_LIVES = 8;
  55.  
  56. int quit;
  57.  
  58. const int QUIT_TITLE = -1;
  59. const int QUIT_GAME_RUNNING = 0; //i.e., !quit
  60. const int QUIT_GAMEOVER = 1;
  61.  
  62. const int MAX_BALL_SPEED = 300;
  63.  
  64. int caught;
  65. int frame;
  66. bool newstage = true;
  67. bool revive_vaus = false;
  68.  
  69. int ball_x;
  70. int ball_y;
  71. int ball_dir;
  72. int ball_angle;
  73. int ball_speed;
  74. int ball_vx;
  75. int ball_vy;
  76. int paddle_x;
  77. int paddle_y;
  78. int paddle_width = 16;
  79. int paddle_speed = 2;
  80. int extended;
  81.  
  82. int ball_uid;
  83.  
  84. //animation
  85. int death_frame;
  86.  
  87. int death_anim[DEATH_ANIM_MAX];
  88. const int DEATH_ANIM_TIMER = 0;
  89. const int DEATH_ANIM_1 = 1; //1-7 Unused
  90. const int DEATH_ANIM_2 = 2;
  91. const int DEATH_ANIM_3 = 3;
  92. const int DEATH_ANIM_4 = 4;
  93. const int DEATH_ANIM_5 = 5;
  94. const int DEATH_ANIM_6 = 6;
  95. const int DEATH_ANIM_COUNTDOWN_TO_QUIT = 7;
  96.  
  97. const int DEATH_ANIM_MAX = 8;
  98.  
  99. const int COUNTDOWN_TO_QUIT_FRAMES = 289; //36*8+1;
  100.  
  101. int templayer[4];
  102.  
  103. int input_accel; //pressing left and right for multiple frames increases this
  104. int frames_pressed[18];
  105.  
  106. //ffc paddle;
  107.  
  108. int hit_zones[5]; //angle offsets for where the ball strikes the paddle
  109.  
  110. const int WALL_LEFT = 24;
  111. const int WALL_TOP = 8; //Mix Ball Y
  112. const int WALL_RIGHT = 232;
  113.  
  114. const int BALL_MIN_Y = 9; //ceiling +1
  115. const int BALL_MAX_Y = 145; //one pixel under paddle top
  116. const int BALL_MIN_X = 25; //left wall +1
  117. const int BALL_MAX_X = 229; //right wall -1
  118.  
  119.  
  120.  
  121. const int START_PADDLE_X = 62;
  122. const int START_PADDLE_Y = 160;
  123. const int START_PADDLE_WIDTH = 32;
  124. const int START_PADDLE_HEIGHT = 8;
  125. const int BALL_WIDTH = 4;
  126. const int BALL_HEIGHT = 4;
  127. const int START_BALL_X = 98; //(START_PADDLE_X + 36);
  128. const int START_BALL_Y = 156; //START_PADDLE_Y - 4;
  129. const int START_BALL_DIR = 5; //DIR_UPRIGHT;
  130. const int START_BALL_RADS = 220; //angle in radians
  131. const int START_BALL_SPEED = 45;
  132. const int START_BALL_VX = 0;
  133. const int START_BALL_VY = 0;
  134.  
  135. const int PADDLE_MIN_X = 25;
  136. const int PADDLE_MAX_X = 200; //WALL_RIGHT -32; //This one varies as the paddle width may change.
  137. const int PADDLE_MAX_X_EXTENDED = 184; //WALL_RIGHT - 48; //This one varies as the paddle width may change.
  138. const int PADDLE_MIN_X_EXTENDED = 25;
  139.  
  140. const int _MOUSE_X = 0;
  141. const int _MOUSE_Y = 1;
  142. const int _MOUSE_LCLICK = 2;
  143.  
  144. //const float ACCEL_FACTOR = 0.25;
  145.  
  146. const int FRAMES_PER_MOVEMENT = 10;
  147. int USE_ACCEL = 0; //Do we accelerate KB/JP input?
  148. int USE_MOUSE = 0; //Are we using the mouse?
  149.  
  150.  
  151. /*
  152. const int CB_UP     = 0;
  153. const int CB_DOWN   = 1;
  154. const int CB_LEFT   = 2;
  155. const int CB_RIGHT  = 3;
  156. const int CB_A      = 4;
  157. const int CB_B      = 5;
  158. const int CB_L      = 7;
  159. const int CB_R      = 8;
  160. const int CB_START  = 6;
  161. const int CB_MAP    = 9;
  162. const int CB_EX1    = 10;
  163. const int CB_EX2    = 11;
  164. const int CB_EX3    = 12;
  165. const int CB_EX4    = 13;
  166. const int CB_AXIS_UP    = 14;
  167. const int CB_AXIS_DOWN  = 15;
  168. const int CB_AXIS_LEFT  = 16;
  169. const int CB_AXIS_RIGHT = 17;
  170.  
  171. */
  172.  
  173. ffc script paddle
  174. {
  175.     void run(){}
  176.    
  177.     bool move(bool mouse, bool accel, ffc p)
  178.     {
  179.         int dir; int dist;
  180.         if ( mouse )
  181.         {
  182.             //get the mouse movement this frame and apply a relative amount to the paddle
  183.             //set the dir here
  184.             //set the dist here
  185.             //if moving left
  186.             //if ( p->X > PADDLE_MIN_X )
  187.             //{
  188.             //  p->X = Input->Mouse[_MOUSE_X];
  189.                 //apply change -- ZC has no special mouse tracking.
  190.             //}
  191.             //if moving right
  192.             if ( !extended )
  193.             {
  194.                 if ( Input->Mouse[_MOUSE_X] <= PADDLE_MAX_X )
  195.                 {
  196.                     if ( Input->Mouse[_MOUSE_X] >= PADDLE_MIN_X )
  197.                     {
  198.                         //apply change
  199.                         p->X = Input->Mouse[_MOUSE_X];
  200.                     }
  201.                 }
  202.             }
  203.             else
  204.             {
  205.                 if ( Input->Mouse[_MOUSE_X] <= PADDLE_MAX_X_EXTENDED )
  206.                 {
  207.                     if ( Input->Mouse[_MOUSE_X] >= PADDLE_MIN_X_EXTENDED )
  208.                     {
  209.                         //apply change
  210.                         p->X = Input->Mouse[_MOUSE_X];
  211.                     }
  212.                 }
  213.             }
  214.         }
  215.         else //using a KB or joypad
  216.         {
  217.             //check how long the dir button is held
  218.             if ( accel ) //if we allow acceleratiopn, move N pixeld * accel factor * frames held
  219.             {
  220.                
  221.                 if ( !extended )
  222.                 {
  223.                     if (  Input->Button[CB_LEFT] )
  224.                     {
  225.                         for ( int q = frames_pressed[CB_LEFT]; q > 0 ; --q )
  226.                         {
  227.                             if ( p->X > PADDLE_MIN_X )
  228.                             {
  229.                                 --p->X;
  230.                                 --p->X;
  231.                             }
  232.                         }
  233.                     }
  234.                     if (  Input->Button[CB_RIGHT] )
  235.                     {
  236.                         for ( int q = frames_pressed[CB_RIGHT]; q > 0; --q )
  237.                         {
  238.                             if ( p->X < PADDLE_MAX_X )
  239.                             {
  240.                                 ++p->X;
  241.                             }
  242.                         }
  243.                     }
  244.                 }
  245.                
  246.             }
  247.            
  248.             else //no accel offered, move a static number of pixels
  249.             {
  250.                
  251.                 if ( !extended )
  252.                 {
  253.                     if (  Input->Button[CB_LEFT] )
  254.                     {
  255.                         for ( int q = 0; q < paddle_speed; ++q )
  256.                         {
  257.                             if ( p->X > PADDLE_MIN_X )
  258.                             {
  259.                                 --p->X;
  260.                             }
  261.                         }
  262.                     }
  263.                     if (  Input->Button[CB_RIGHT] )
  264.                     {
  265.                         for ( int q = 0; q < paddle_speed; ++q )
  266.                         {
  267.                             if ( p->X < PADDLE_MAX_X )
  268.                             {
  269.                                 ++p->X;
  270.                             }
  271.                         }
  272.                     }
  273.                 }
  274.                 else
  275.                 {
  276.                     if (  Input->Button[CB_LEFT] )
  277.                     {
  278.                         if ( p->X > PADDLE_MIN_X_EXTENDED )
  279.                         {
  280.                             --p->X;
  281.                         }
  282.                     }
  283.                     if (  Input->Button[CB_RIGHT] ) {
  284.                         if ( p->X < PADDLE_MAX_X_EXTENDED )
  285.                         {
  286.                             ++p->X;
  287.                         }
  288.                     }
  289.                    
  290.                 }
  291.             }
  292.         }
  293.        
  294.     }
  295.  
  296.     void check_input()
  297.     {
  298.         if ( Input->Button[CB_LEFT] ) ++frames_pressed[CB_LEFT];
  299.         else frames_pressed[CB_LEFT] = 0;
  300.         if ( Input->Button[CB_RIGHT] ) ++frames_pressed[CB_RIGHT];
  301.         else frames_pressed[CB_RIGHT] = 0;
  302.        
  303.     }
  304.    
  305.     void extend(ffc p)
  306.     {
  307.         if ( extended )
  308.         {
  309.             if ( p->TileWidth < 3 )
  310.             {
  311.                 p->Data = CMB_VAUS_EXTENDED;
  312.                 p->TileWidth = 3;
  313.             }
  314.         }
  315.         else
  316.         {
  317.             if ( p->TileWidth > 2 )
  318.             {
  319.                 p->Data = CMB_VAUS;
  320.                 p->TileWidth = 2;
  321.             }
  322.         }
  323.     }
  324.     void setup(ffc p)
  325.     {
  326.         p->Y = START_PADDLE_Y;
  327.         p->X = START_PADDLE_X;
  328.         p->Data = CMB_VAUS;
  329.         p->TileWidth = 2;
  330.        
  331.     }
  332.     void dead(ffc p)
  333.     {
  334.         p->Data = CMB_VAUS_DEAD;
  335.         p->TileWidth = 2;
  336.         death_frame = frame;
  337.     }
  338.    
  339.  
  340. }
  341.  
  342. const int MISC_BALLID = 0; //Misc index of Vaud->Misc[]
  343. const int MISC_DEAD = 1; //Misc index of Vaud->Misc[]
  344. const int MISC_LAUNCHED = 0; //Misc index of ball->Misc[]
  345.  
  346. const int BALL_MINIMUM_Y = 24; //Invisible line at which point, ball is lost.
  347.  
  348. ffc script holdlink
  349. {
  350.     void run()
  351.     {
  352.         while(1)
  353.         {
  354.             Link->Y = START_PADDLE_Y - 4;
  355.             Waitframe();
  356.         }
  357.     }
  358. }
  359.        
  360.  
  361. global script arkanoid
  362. {
  363.    
  364.     void run()
  365.     {
  366.         check_min_zc_build();
  367.        
  368.         TraceNL(); TraceS("Starting Arkanoid"); TraceNL(); TraceS("Game 'quit' state: "); Trace(quit);
  369.         TraceNL(); TraceS("Game version, Alpha "); Trace(ARKANOID_VERSION);
  370.        
  371.         //frame = -1;
  372.         ffc vaus = Screen->LoadFFC(FFC_VAUS);
  373.         lweapon movingball;
  374.         npc vaus_guard;
  375.         bool ext;
  376.         Link->CollDetection = false;
  377.         Link->DrawYOffset = -32768;
  378.        
  379.         ball.setup_sprite(SPR_BALL);
  380.         while(true)
  381.         {
  382.             while(!quit)
  383.             {
  384.                 ++frame;
  385.                 if ( Input->Key[KEY_L] ) ++Game->Counter[CR_LIVES];
  386.                 hold_Link_y(); //Don't allow Link to leave the screen, bt
  387.                     //keep his X and Y matched to the Vaus!
  388.                 hold_Link_x(vaus); //Link is used to cause floating enemies to home in on the vaus.
  389.                 if ( newstage )
  390.                 {
  391.                     //vaus_guard = Screen->CreateNPC(NPC_VAUSGUARD);
  392.                     Game->PlayMIDI(MID_STAGE_START);
  393.                     brick.setup();
  394.                     Waitframes(6);
  395.                    
  396.                     brick.clear_combos();
  397.                    
  398.                     newstage = false;
  399.                     paddle.setup(vaus);
  400.                     ball.create(vaus);
  401.                     movingball = vaus->Misc[MISC_BALLID];
  402.                     /*
  403.                     TraceS("Checking lwpn->Misc[16-32] for junk data: ");
  404.                     for ( int q = 16; q < 32; ++q )
  405.                     {
  406.                         TraceNL(); TraceS("index: "); Trace(q); TraceS(" value: "); Trace(movingball->Misc[q]);
  407.                     }
  408.                    
  409.                     TraceS("Setting valid data to lwpn->Misc[16-32] to validate data: ");
  410.                     for ( int q = 16; q < 32; ++q )
  411.                     {
  412.                         movingball->Misc[q] = q*2;
  413.                         TraceNL(); TraceS("index: "); Trace(q); TraceS(" value: "); Trace(movingball->Misc[q]);
  414.                     }
  415.                     //Huzzah, another 2.54 bug bites the dust as of 254a32!!
  416.                     */
  417.                 }
  418.                 if ( revive_vaus ) //when this is called, the ball breaks through all bricks. Something isn't being set.
  419.                 {
  420.                     Game->PlayMIDI(MID_STAGE_START);
  421.                     vaus->Misc[MISC_DEAD] = 0;
  422.                     revive_vaus = false;
  423.                    
  424.                     paddle.setup(vaus);
  425.                     ball.create(vaus);
  426.                     movingball = vaus->Misc[MISC_BALLID];
  427.                 }
  428.                
  429.                 if ( !vaus->Misc[MISC_DEAD] )
  430.                 {
  431.                     //if ( Input->Key[KEY_P] ) Trace(movingball->UID); //Frick, I'm an idiot. HIT_BY_LWEAPON is the SCREEN INDEX< not the UID!!
  432.                         //2.54 Absolutely needs HitBy_UID!
  433.                     if ( Input->Key[KEY_1] ) Trace(frame);
  434.                     //if ( frame%60 == 0 ) { Trace(movingball->Step); }
  435.                     //Trace(movingball->Step);
  436.                     change_setting(); //check for a setting change_setting
  437.                     paddle.extend(vaus);
  438.                     paddle.check_input();
  439.                     paddle.move(USE_MOUSE, USE_ACCEL, vaus);
  440.                    
  441.                     ball.launch(movingball);
  442.                     if ( !ball.launched(movingball) )
  443.                     {
  444.                         ball.move_with_vaus(movingball, vaus);
  445.                     }
  446.                    
  447.                    
  448.                     //clamp within bounds - MANDATORY because very fast Step speeds can cause the ball
  449.                     //to *phase* through pseudo-solid objects, such as walls and the Vaus.
  450.                     ball.clamp_rightwall(movingball);
  451.                     ball.clamp_ceiling(movingball);
  452.                     ball.clamp_leftwall(movingball);
  453.                     ball.clamp_bottom(movingball, vaus);
  454.                    
  455.                    
  456.                     //ball wall bounce checks
  457.                     ball.check_ceiling(movingball);
  458.                     ball.check_leftwall(movingball);
  459.                     ball.check_rightwall(movingball);
  460.                     ball.check_hitvaus(movingball, vaus);
  461.                     //ball.set_speed(movingball);
  462.                     /*
  463.                    
  464.                     I moved this to after Waitdraw, because I wanted the post-draw timing for ball bounce, and to ensure that
  465.                     the movingball lweapon stayed alive. -Z (Alpha 0.10)
  466.                     //Bounce ball on bricks.
  467.                     for ( int q = Screen->NumNPCs(); q > 0; --q )
  468.                     {
  469.                         npc b = Screen->LoadNPC(q);
  470.                         if ( b->Type != NPCT_OTHERFLOAT ) continue;
  471.                         TraceNL(); TraceS("movingball->X = "); Trace(movingball->X);
  472.                         TraceNL(); TraceS("movingball->Y = "); Trace(movingball->Y);
  473.                         brick.take_hit(b, movingball);
  474.                     }
  475.                     */
  476.                     movingball->DeadState = WDS_ALIVE; //Force it alive at all times if the vaus is alive.
  477.                         //We'll need another solition once we do the 3-way split ball. Bleah.
  478.                 }
  479.                
  480.                 //It's probably unwise to run this block twice! Where do I want it, before or after Waitdraw() ? -Z
  481.                 else
  482.                 {
  483.                     paddle.dead(vaus); //Set the death animation here.
  484.                    
  485.                     /*
  486.                     while ( (frame - 100) < death_frame )
  487.                     {
  488.                         //we should hide the vaus, and restart the stage here.
  489.                         ++frame;
  490.                         Waitdraw(); //Something is preventing the vaus from changing into the explosion style. S
  491.                         Waitframe();
  492.                     }
  493.                     lweapon deadball = movingball;
  494.                     deadball->DeadState = WDS_DEAD;
  495.                     movingball = vaus->Misc[10];
  496.                     if ( Game->Counter[CR_LIVES] )
  497.                     {
  498.                         --Game->Counter[CR_LIVES];
  499.                         revive_vaus = true;
  500.                     }
  501.                     */
  502.                    
  503.                 }
  504.                
  505.                
  506.                 Waitdraw();
  507.                
  508.                 hold_Link_y();
  509.                
  510.                 if ( !vaus->Misc[MISC_DEAD] )
  511.                 {
  512.                     movingball->DeadState = WDS_ALIVE;
  513.                    
  514.                     //Bounce ball on bricks.
  515.                     for ( int q = Screen->NumNPCs(); q > 0; --q )
  516.                     {
  517.                         npc b = Screen->LoadNPC(q);
  518.                         if ( b->Type != NPCT_OTHERFLOAT ) continue;
  519.                         //TraceNL(); TraceS("movingball->X = "); Trace(movingball->X);
  520.                         //TraceNL(); TraceS("movingball->Y = "); Trace(movingball->Y);
  521.                         movingball->DeadState = WDS_ALIVE;
  522.                         //TraceNL(); TraceS("movingball ptr: "); Trace(movingball);
  523.                         brick.take_hit(b, movingball);
  524.                     }
  525.                    
  526.                 }
  527.                 else
  528.                 {
  529.                     paddle.dead(vaus);
  530.                     while ( (frame - 100) < death_frame )
  531.                     {
  532.                         //we should hide the vaus, and restart the stage here.
  533.                         ++frame;
  534.                         Waitdraw();
  535.                         Waitframe();
  536.                     }
  537.                     lweapon deadball = movingball;
  538.                     deadball->DeadState = WDS_DEAD;
  539.                     movingball = vaus->Misc[10]; //Because = NULL() requires alpha 32. :D
  540.                     if ( Game->Counter[CR_LIVES] )
  541.                     {
  542.                         --Game->Counter[CR_LIVES];
  543.                         revive_vaus = true;
  544.                     }
  545.                     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.
  546.                     {
  547.                         if ( !death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT] )
  548.                         {
  549.                             death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT] = COUNTDOWN_TO_QUIT_FRAMES;
  550.                             continue;
  551.                         }
  552.                         else
  553.                         {
  554.                             --death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT];
  555.                             if ( death_anim[DEATH_ANIM_COUNTDOWN_TO_QUIT] == 1 )
  556.                             {
  557.                                 quit = QUIT_GAMEOVER; //Game over state.
  558.                                 TraceNL(); TraceS("Game 'quit' state is now: "); Trace(quit);
  559.                             }
  560.                         }
  561.                     }
  562.                        
  563.                 }
  564.                
  565.                 Waitframe();
  566.             }
  567.            
  568.             while (quit == QUIT_GAMEOVER) //Game Over
  569.             {
  570.                 if ( !(GAME[GAME_MISC_FLAGS]&GMFS_PLAYED_GAME_OVER_MUSIC) )
  571.                 {
  572.                     GAME[GAME_MISC_FLAGS]|=GMFS_PLAYED_GAME_OVER_MUSIC;
  573.                     //Play Game over MIDI
  574.                     Game->PlayMIDI(1);
  575.                 }
  576.                    
  577.                 Screen->DrawString(6, 96, 80, 1, 0x51, 0x00, 0, "GAME OVER", 128);
  578.                
  579.                 Waitdraw();
  580.                 Waitframe();
  581.             }
  582.             //We should never reach here.
  583.             Waitframe();
  584.         }
  585.     }
  586.     void change_setting()
  587.     {
  588.         if ( Input->Key[KEY_M] ) USE_MOUSE = 1;
  589.         if ( Input->Key[KEY_N] ) USE_MOUSE = 0;
  590.         if ( Input->Key[KEY_F] ) USE_ACCEL = 1;
  591.         if ( Input->Key[KEY_G] ) USE_ACCEL = 0;
  592.         if ( Input->Key[KEY_T] ) --paddle_speed; // paddle_speed = vbound(paddle_speed
  593.         if ( Input->Key[KEY_Y] ) ++paddle_speed; // paddle_speed = vbound(paddle_speed
  594.     }
  595.     void hold_Link_x(ffc v)
  596.     {
  597.         Link->X = v->X+(v->TileWidth*8);
  598.     }
  599.     void hold_Link_y()
  600.     {
  601.         Link->Y = START_PADDLE_Y - 4;
  602.     }
  603.     bool quit() { return ( quit ); }
  604.    
  605.     void check_min_zc_build()
  606.     {
  607.         if ( Game->Beta < MIN_ZC_ALPHA_BUILD )
  608.         {
  609.             Game->PlayMIDI(9);
  610.             int v_too_early = 600; int req_vers[3]; itoa(req_vers, MIN_ZC_ALPHA_BUILD);
  611.             TraceNL(); int vers[3]; itoa(vers,Game->Beta);
  612.             TraceS("This version of Arkanoid.qst requires Zelda Classic v2.54, Alpha (");
  613.             TraceS(req_vers);
  614.             TraceS("), or later.");
  615.             TraceNL();
  616.             TraceS("I'm detecting Zelda Classic v2.54, Alpha (");
  617.             TraceS(vers);
  618.             TraceS(") and therefore, I must refuse to run. :) ");
  619.             TraceNL();
  620.            
  621.             while(v_too_early--)
  622.             {
  623.                 //Screen->DrawString(7, 4, 40, 1, 0x04, 0x5F, 0,
  624.                 //"This version of Arkanoid.qst requires Zelda Classic 2.54, Alpha 32",
  625.                 //128);
  626.                 Screen->DrawString(7, 15, 40, 1, 0x04, 0x5F, 0,
  627.                 "You are not using a version of ZC adequate to run         ",
  628.                 128);
  629.                
  630.                 Screen->DrawString(7, 15, 55, 1, 0x04, 0x5F, 0,
  631.                 "this quest. Please see allegro.log for details.                   ",
  632.                 128);
  633.            
  634.                 Waitdraw();
  635.                 WaitNoAction();
  636.             }
  637.             Game->End();
  638.            
  639.         }
  640.     }
  641.    
  642. }
  643.  
  644. const int TILE_BALL = 50512;
  645. const int SPR_BALL = 100;
  646.  
  647.  
  648.  
  649. //preliminary ball
  650. ffc script ball
  651. {
  652.     void run(){}
  653.     void setup_sprite(int sprite_id)
  654.     {
  655.         spritedata sd = Game->LoadSpriteData(sprite_id);
  656.         sd->Tile = TILE_BALL;
  657.     }
  658.     void set_speed(lweapon b, int speed)
  659.     {
  660.         //Trace(bounces);
  661.         b->Step = speed; // bound(bounces,0,MAX_BOUNCES);
  662.         //Trace(b->Step);
  663.     }
  664.     void create(ffc vaus_id) //send the ball lweapon pointer back to the vaus
  665.     {
  666.         lweapon ball = Screen->CreateLWeapon(LW_SCRIPT1);
  667.         TraceNL(); TraceS("Creating ball with Script UID: "); Trace(ball->UID);
  668.         ball->HitWidth = 6; //Not 4, so that the ball bounces when its edges touch a brick.
  669.         ball->HitHeight = 6; //Not 4, so that the ball bounces when its edges touch a brick.
  670.         ball->UseSprite(SPR_BALL);
  671.         ball->X = vaus_id->X+18;
  672.         ball->Y = vaus_id->Y-2;
  673.         ball->Damage = 1;
  674.         ball_uid = ball->UID;
  675.         ball->HitXOffset = -1; //so that the ball bounces when its edges touch a brick.
  676.         ball->HitYOffset = -1; //so that the ball bounces when its edges touch a brick.
  677.         vaus_id->Misc[MISC_BALLID] = ball;
  678.     }
  679.     void launch(lweapon b)
  680.     {
  681.         if ( b->Misc[MISC_LAUNCHED] ) return;
  682.         bool launched;
  683.         for ( int q = CB_A; q < CB_R; ++q )
  684.         {
  685.             if ( Input->Press[q] ) { launched = true; break; }
  686.         }
  687.         if ( launched )
  688.         {
  689.             //b->Angular = true;
  690.             Game->PlaySound(6);
  691.             b->Dir = DIR_RIGHTUP;  
  692.             b->Step = 90;
  693.             b->Misc[MISC_LAUNCHED] = 1;
  694.         }
  695.     }
  696.     bool launched(lweapon b)
  697.     {
  698.         return (b->Misc[MISC_LAUNCHED]);
  699.     }
  700.     void move(lweapon b)
  701.     {
  702.        
  703.     }
  704.     float bound(int val, int min, int max)
  705.     {
  706.         if ( val < min ) return min;
  707.         if ( val > max ) return max;
  708.         return val;
  709.     }
  710.     //Not launched yet.
  711.     void move_with_vaus(lweapon b, ffc v)
  712.     {
  713.         b->X = v->X+18;
  714.     }
  715.     //ball.clamp*() are needed for when the step speed is so great that the ball skips past the equality checks.
  716.     void clamp_ceiling(lweapon b)
  717.     {
  718.         if ( b->Y < BALL_MIN_Y )           
  719.         {
  720.             b->Y = BALL_MIN_Y;
  721.         }
  722.     }
  723.     void clamp_leftwall(lweapon b)
  724.     {
  725.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  726.         if ( b->X < BALL_MIN_X ) b ->X = BALL_MIN_X;
  727.     }
  728.     void clamp_rightwall(lweapon b)
  729.     {
  730.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  731.         if ( b->X > BALL_MAX_X ) b->X = BALL_MAX_X;
  732.     }
  733.     /*
  734.     void clamp_bottom(lweapon b, ffc v)
  735.     {
  736.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  737.         if ( b->Y+4 > v->Y+8 ) dead(b,v);
  738.     }
  739.     */
  740.     //A function to check of the bounding will prevent the ball from falling out of field.
  741.     void clamp_bottom(lweapon b, ffc v)
  742.     {
  743.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  744.         if ( b->Y+4 > v->Y ) b->Y = v->Y-4;
  745.     }
  746.     void check_ceiling(lweapon b)
  747.     {
  748.         if ( b->Y == BALL_MIN_Y )          
  749.         {
  750.             Game->PlaySound(7);
  751.             switch(b->Dir)
  752.             {
  753.                 case DIR_RIGHTUP: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  754.                 case DIR_LEFTUP: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  755.                 default: { b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  756.             }
  757.         }
  758.     }
  759.     void check_leftwall(lweapon b)
  760.     {
  761.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  762.         if ( b->X == BALL_MIN_X )
  763.         {
  764.             Game->PlaySound(7);
  765.             switch(b->Dir)
  766.             {
  767.                 case DIR_LEFTDOWN: { b->Dir = DIR_RIGHTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  768.                 case DIR_LEFTUP: { b->Dir = DIR_RIGHTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  769.                 default: { b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  770.             }
  771.         }
  772.     }
  773.     void check_rightwall(lweapon b)
  774.     {
  775.         if ( caught ) return; //don't do anything while the vaus is holding the ball
  776.         if ( b->X == BALL_MAX_X )
  777.         {
  778.             Game->PlaySound(7);
  779.             switch(b->Dir)
  780.             {
  781.                 case DIR_RIGHTDOWN: { b->Dir = DIR_LEFTDOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  782.                 case DIR_RIGHTUP: { b->Dir = DIR_LEFTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  783.                 default: { b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  784.             }
  785.         }
  786.     }
  787.     void check_hitvaus(lweapon b, ffc v)
  788.     {
  789.         if ( launched(b) )
  790.         {
  791.             if ( b->Dir == DIR_RIGHTUP ) return;
  792.             if ( b->Dir == DIR_LEFTUP ) return;
  793.             //if ( Collision(b,v) ) //We'll refine this, later.
  794.            
  795.             int hit_position; int vaus_midpoint =  v->X+(((v->TileWidth*16)/2)-1);
  796.             int midpoint_segment = v->X+(((v->TileWidth*16)/6));
  797.             int ball_midpoint = b->X+3;
  798.            
  799.             if ( b->Y+4 == v->Y )
  800.                 //Now we need to check here, if the paddle is under the ball:
  801.             {
  802.                 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
  803.                 {
  804.                     if ( b->X <= v->X+(v->TileWidth*16) ) //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.
  805.                     {
  806.                         Game->PlaySound(6);
  807.                         b->Y = v->Y-1;
  808.                        
  809.                         if ( ball_midpoint <= vaus_midpoint ) //hit left side of vaus
  810.                         {
  811.                            
  812.                                 //hit the centre midpoint
  813.                                 //set angular = false
  814.                                 //set DIR_UL
  815.                                 TraceNL(); TraceS("Setting ball dir to DIGITAL Left-Up");
  816.                                 b->Y = v->Y-1;
  817.                                 b->Angular = false;
  818.                                 b->Dir = DIR_UPLEFT;
  819.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  820.                                 return;
  821.                            
  822.                         }
  823.                         else if ( ball_midpoint > vaus_midpoint ) //hit right side of vaus
  824.                         {
  825.                            
  826.                                 //hit the centre midpoint
  827.                                 //set angular = false
  828.                                 //set DIR_UR
  829.                                 TraceNL(); TraceS("Setting ball dir to DIGITAL Right-Up");
  830.                                 b->Y = v->Y-6;
  831.                                 b->Angular = false;
  832.                                 b->Dir = DIR_UPRIGHT;
  833.                                 //b->Dir = DIR_UPRIGHT;
  834.                                 b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED);
  835.                                 return;
  836.                            
  837.                            
  838.                         }
  839.                            
  840.                         else
  841.                         {
  842.                             switch(b->Dir)
  843.                             {
  844.                                 case DIR_LEFTDOWN: { b->Dir = DIR_LEFTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  845.                                 case DIR_RIGHTDOWN: { b->Dir = DIR_RIGHTUP; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  846.                                 default: { b->Dir = DIR_DOWN; b->Step = bound(b->Step+1, 0, MAX_BALL_SPEED); break; }
  847.                             }
  848.                         }
  849.                     }
  850.                     else
  851.                     {
  852.                         dead(b,v);
  853.                     }
  854.                 }
  855.                 else
  856.                 {
  857.                     dead(b,v);
  858.                 }
  859.             }
  860.            
  861.         }
  862.     }
  863.     void dead(lweapon b, ffc v)
  864.     {
  865.        
  866.         Game->PlayMIDI(5);
  867.         //remove the ball
  868.         b->Y = -32768; b->Step = 0;
  869.         v->Misc[MISC_DEAD] = 1;
  870.         //if there are more balls in play, switch movingball to one of those
  871.         //otherwise,
  872.         //check next life
  873.         //if more lives, reset playfield
  874.         //otherwise game over
  875.        
  876.     }
  877.    
  878.    
  879.    
  880. }
  881.  
  882. ffc script ball_controller
  883. {
  884.     void run()
  885.     {
  886.         lweapon ball;
  887.         lweapon active_ball; //will be used for when we have multiple balls.
  888.         lweapon balls[3]; //for divide
  889.         ball = Screen->CreateLWeapon(LW_SCRIPT1);
  890.         ball->X = START_BALL_X;
  891.         ball->Y = START_BALL_Y;
  892.         this->Vx = START_BALL_VX;
  893.         this->Vy = START_BALL_VY;
  894.         bool alive = true;
  895.         int num_balls = 1;
  896.         while(alive)
  897.         {
  898.             if ( ball->Y <= BALL_MIN_Y )
  899.             {
  900.                 bounce();
  901.             }
  902.             if ( ball->X <= BALL_MIN_X )
  903.             {
  904.                 bounce();
  905.             }
  906.             if ( ball->X >= BALL_MAX_X )
  907.             {
  908.                 bounce();
  909.             }
  910.                
  911.             if ( ball->Y >= BALL_MAX_Y )
  912.             {
  913.                 if ( num_balls < 2 )
  914.                 {
  915.                     alive = false;
  916.                 }
  917.                 else
  918.                 {
  919.                     kill_ball(ball); //removes this ball, and sets another ball to be the active one
  920.                     --num_balls;
  921.                 }
  922.             }
  923.             Waitframe();
  924.         }
  925.     }
  926.     void bounce(){}
  927.     void kill_ball(lweapon b){}
  928.    
  929. }
  930.  
  931. const int BRICK_MAX = 14;
  932.  
  933. //Layer 1
  934. const int CMB_BRICK_RED     = 1488;
  935. const int CMB_BRICK_WHITE   = 1490;
  936. const int CMB_BRICK_BLUE    = 1492;
  937. const int CMB_BRICK_ORANGE  = 1494;
  938. const int CMB_BRICK_TEAL    = 1496;
  939. const int CMB_BRICK_VIOLET  = 1498;
  940. const int CMB_BRICK_GREEN   = 1500;
  941. const int CMB_BRICK_YELLOW  = 1502;
  942. const int CMB_BRICK_SILVER1 = 1504;
  943. const int CMB_BRICK_SILVER2 = 1506;
  944. const int CMB_BRICK_SILVER3 = 1508;
  945. const int CMB_BRICK_SILVER4 = 1510;
  946. const int CMB_BRICK_GOLD    = 1516;
  947.  
  948.  
  949. //layer 2
  950. const int CMB_BRICK_RED_LOW     = 1489;
  951. const int CMB_BRICK_WHITE_LOW   = 1491;
  952. const int CMB_BRICK_BLUE_LOW    = 1493;
  953. const int CMB_BRICK_ORANGE_LOW  = 1495;
  954. const int CMB_BRICK_TEAL_LOW    = 1497;
  955. const int CMB_BRICK_VIOLET_LOW  = 1499;
  956. const int CMB_BRICK_GREEN_LOW   = 1501;
  957. const int CMB_BRICK_YELLOW_LOW  = 1503;
  958. const int CMB_BRICK_SILVER1_LOW = 1505;
  959. const int CMB_BRICK_SILVER2_LOW = 1507;
  960. const int CMB_BRICK_SILVER3_LOW = 1509;
  961. const int CMB_BRICK_SILVER4_LOW = 1511;
  962. const int CMB_BRICK_GOLD_LOW    = 1517;
  963.  
  964. //enemies
  965. const int NPC_BRICK_RED     = 181;
  966. const int NPC_BRICK_WHITE   = 182;
  967. const int NPC_BRICK_BLUE    = 183;
  968. const int NPC_BRICK_ORANGE  = 184;
  969. const int NPC_BRICK_TEAL    = 185;
  970. const int NPC_BRICK_VIOLET  = 186;
  971. const int NPC_BRICK_GREEN   = 187;
  972. const int NPC_BRICK_YELLOW  = 188;
  973. const int NPC_BRICK_SILVER1     = 189;
  974. const int NPC_BRICK_SILVER2     = 190;
  975. const int NPC_BRICK_SILVER3     = 255; //not set up yet;
  976. const int NPC_BRICK_SILVER4     = 255; //not set up yet
  977. const int NPC_BRICK_GOLD    = 191;
  978.  
  979.  
  980. const int HIT_BY_LWEAPON = 2;
  981. const int HIT_BY_LWEAPON_UID = 6;
  982.  
  983. ffc script brick
  984. {
  985.     void run()
  986.     {
  987.     }
  988.     float bound(int val, int min, int max)
  989.     {
  990.         if ( val < min ) return min;
  991.         if ( val > max ) return max;
  992.         return val;
  993.     }
  994.     bool hit(npc a, lweapon v)
  995.     {
  996.         /*
  997.         if ( a->HitBy[HIT_BY_LWEAPON] < 1 ) return false;
  998.         a->Misc[12] = Screen->LoadLWeapon(a->HitBy[HIT_BY_LWEAPON]);
  999.         lweapon hitwpn = a->Misc[12];
  1000.         return ( hitwpn->UID == v->UID );
  1001.         */
  1002.         return ( a->HitBy[HIT_BY_LWEAPON_UID] == v->UID );
  1003.         //int indx; //Until we have UIDs working for HitBy[], we need to do it this way.
  1004.         //for ( int q = Screen->NumLWeapons(); q > 0; --q )
  1005.         //{
  1006.         //  lweapon temp = Screen->LoadLWeapon(q);
  1007.         //  if ( temp->UID == v->UID )
  1008.         //  {
  1009.         //      indx = q; break;
  1010.         //  }
  1011.         //}
  1012.         //Link->Misc[0] = v; //We'll use this as scratch untyped space for the moment. -Z
  1013.         //TraceS("brick.hit() Link->Misc[] is: "); Trace(Link->Misc[0]);
  1014.         //TraceS("brick.hit() v is: "); Trace(v);
  1015.         //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.
  1016.             //as UID is not, and NEVER should be!!!
  1017.         //TraceNL(); TraceS("v->UID is: "); Trace(v->UID);
  1018.         /*
  1019.         To determine where a brick was hit, we first scan each brick and look to see which was
  1020.         hit at all, by our lweapon.
  1021.        
  1022.         The, we check if that ball is belove, above, right of, or left of the brick,
  1023.         and we read its direction.
  1024.        
  1025.         Using a logic chain from this data, we determine the direction that the ball should next
  1026.         take, when it bounces.
  1027.        
  1028.         */
  1029.         //HitBy[]
  1030.        
  1031.         //if ( a->HitBy[HIT_BY_LWEAPON] )
  1032.         //{
  1033.         //  TraceNL(); TraceS("a->HitBy[HIT_BY_LWEAPON] id: "); Trace(a->HitBy[HIT_BY_LWEAPON]);
  1034.         //  TraceNL();
  1035.         //  TraceS("Our Link->Misc scratch value `is: "); Trace((Link->Misc[0]+1));
  1036.         //}
  1037.        
  1038.         //! We'll use this method again when we add UIDs to HitBy[] ! -Z
  1039.         //return ( a->HitBy[HIT_BY_LWEAPON] == temp_UID );
  1040.         //return ( a->HitBy[HIT_BY_LWEAPON] == indx ); //(Link->Misc[0]+1) );
  1041.        
  1042.     }
  1043.     bool hit_below(npc a, lweapon v)
  1044.     {
  1045.         if ( v->Y == (a->Y + 8) ) return true; //we could do bounce here.
  1046.     }
  1047.     bool hit_above(npc a, lweapon v)
  1048.     {
  1049.         if ( v->Y == (a->Y - 4) ) return true; //we could do bounce here.
  1050.     }
  1051.     bool hit_left(npc a, lweapon v)
  1052.     {
  1053.         if ( v->X == (a->X - 4) ) return true; //we could do bounce here.
  1054.     }
  1055.     bool hit_right(npc a, lweapon v)
  1056.     {
  1057.         if ( v->X == (a->X + 16 ) ) return true; //we could do bounce here.
  1058.     }
  1059.    
  1060.     void take_hit(npc a, lweapon v)
  1061.     {
  1062.         if ( hit(a,v) )
  1063.         {
  1064.             //TraceNL(); TraceS("Brick hit!");
  1065.             v->DeadState = WDS_ALIVE;
  1066.             //TraceNL(); TraceS("brick->X = "); Trace(a->X);
  1067.             //TraceNL(); TraceS("brick->Y = "); Trace(a->Y);
  1068.             //TraceNL(); TraceS("ball->X = "); Trace(v->X);
  1069.             //TraceNL(); TraceS("ball->Y = "); Trace(v->Y);
  1070.             if ( hit_below(a,v) )
  1071.             {
  1072.                 switch ( v->Dir )
  1073.                 {
  1074.                     case DIR_UPRIGHT: { v->Dir = DIR_DOWNRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1075.                     case DIR_UPLEFT: { v->Dir = DIR_DOWNLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1076.                     default: { TraceS("hit_below() found an illegal ball direction"); break; }
  1077.                 }
  1078.                 if ( a->HP <= 0 )
  1079.                 {
  1080.                     //TraceS("Brick is dead. "); TraceNL();
  1081.                     //TraceS("a->Misc[NPCM_AWARDED_POINTS] is: "); Trace(a->Misc[NPCM_AWARDED_POINTS]); TraceNL();
  1082.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  1083.                     {
  1084.                         //TraceS("Can award points!"); TraceNL();
  1085.                         a->Misc[18] = 1;
  1086.                         //TraceS("The points for this brick are: "); Trace(a->Attributes[NPC_ATTRIB_POINTS]); TraceNL();
  1087.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  1088.                     }
  1089.                 }
  1090.             }
  1091.            
  1092.             else if ( hit_above(a,v) )
  1093.             {
  1094.                 switch ( v->Dir )
  1095.                 {
  1096.                     case DIR_DOWNLEFT: { v->Dir = DIR_UPLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1097.                     case DIR_DOWNRIGHT: { v->Dir = DIR_UPRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1098.                     default: { TraceS("hit_above() found an illegal ball direction"); break; }
  1099.                 }
  1100.                 if ( a->HP <= 0 )
  1101.                 {
  1102.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  1103.                     {
  1104.                         a->Misc[NPCM_AWARDED_POINTS] = 1;
  1105.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  1106.                     }
  1107.                 }
  1108.             }
  1109.            
  1110.             else if ( hit_left(a,v) )
  1111.             {
  1112.                 switch ( v->Dir )
  1113.                 {
  1114.                     case DIR_UPRIGHT: { v->Dir = DIR_UPLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1115.                     case DIR_DOWNRIGHT: { v->Dir = DIR_DOWNLEFT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED);  break; }
  1116.                     default: { TraceS("hit_left() found an illegal ball direction"); break; }
  1117.                 }
  1118.                 if ( a->HP <= 0 )
  1119.                 {
  1120.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  1121.                     {
  1122.                         a->Misc[NPCM_AWARDED_POINTS] = 1;
  1123.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  1124.                     }
  1125.                 }
  1126.             }
  1127.             else if ( hit_right(a,v) )
  1128.             {
  1129.                 switch ( v->Dir )
  1130.                 {
  1131.                     case DIR_UPLEFT: { v->Dir = DIR_UPRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1132.                     case DIR_DOWNLEFT: { v->Dir = DIR_DOWNRIGHT; v->Step = bound(v->Step+2, 0, MAX_BALL_SPEED); break; }
  1133.                     default: { TraceS("hit_below() found an illegal ball direction"); break; }
  1134.                 }
  1135.                 if ( a->HP <= 0 )
  1136.                 {
  1137.                     if ( !a->Misc[NPCM_AWARDED_POINTS] )
  1138.                     {
  1139.                         a->Misc[NPCM_AWARDED_POINTS] = 1;
  1140.                         Game->Counter[CR_SCRIPT1] += a->Attributes[NPC_ATTRIB_POINTS];
  1141.                     }
  1142.                 }
  1143.             }
  1144.            
  1145.             else
  1146.             {
  1147.                 TraceS("brick.hit() returned true, but couldn't determine a valid ball location!");
  1148.                 return;
  1149.             }
  1150.         }
  1151.                    
  1152.            
  1153.     }
  1154.     //turns layer objects into npc bricks.
  1155.     void setup()
  1156.     {
  1157.         int tempenem; npc bricks[1024]; int temp;
  1158.         for ( int q = 0; q < 176; ++q )
  1159.         {
  1160.             //bricks on layer 1
  1161.             //Trace(GetLayerComboD(1,q));
  1162.             //while(!Input->Press[CB_A]) Waitframe();
  1163.             tempenem = brick_to_npc(GetLayerComboD(1,q),false);
  1164.             //TraceS("tempenem is: "); Trace(tempenem);
  1165.             //while(!Input->Press[CB_A]) Waitframe();
  1166.             if ( tempenem )
  1167.             {
  1168.                 bricks[temp] = Screen->CreateNPC(tempenem);
  1169.                 //TraceS("Created npc: "); Trace(tempenem);
  1170.                 bricks[temp]->X = ComboX(q);
  1171.                 bricks[temp]->Y = ComboY(q);
  1172.                 TraceS("Brick defence is: "); Trace(bricks[temp]->Defense[20]);
  1173.                 tempenem = 0; ++temp;
  1174.                
  1175.             }
  1176.             //bricks on layer 2, Y+8px
  1177.             tempenem = brick_to_npc(GetLayerComboD(2,q),true);
  1178.             //Trace(tempenem);
  1179.             if ( tempenem )
  1180.             {
  1181.                 bricks[temp] = Screen->CreateNPC(tempenem);
  1182.                 //TraceS("Created npc: "); Trace(tempenem);
  1183.                 bricks[temp]->X = ComboX(q);
  1184.                 bricks[temp]->Y = ComboY(q)+8;
  1185.                 TraceS("Brick defence is: "); Trace(bricks[temp]->Defense[20]);
  1186.                 tempenem = 0; ++temp;
  1187.             }
  1188.         }
  1189.        
  1190.     }
  1191.     void clear_combos()
  1192.     {
  1193.         templayer[0] = Screen->LayerOpacity[0];
  1194.         templayer[1] = Screen->LayerOpacity[1];
  1195.         templayer[2] = Screen->LayerMap[0];
  1196.         templayer[3] = Screen->LayerMap[1];
  1197.         Screen->LayerOpacity[0] = 0;
  1198.         Screen->LayerOpacity[1] = 0;
  1199.         Screen->LayerMap[0] = 0;
  1200.         Screen->LayerMap[1] = 0;
  1201.     }
  1202.    
  1203.     int brick_to_npc(int combo_id, bool layer2)
  1204.     {
  1205.        
  1206.         if ( !layer2 )
  1207.         {
  1208.             int brick_to_enemy[BRICK_MAX*2] =
  1209.             {   CMB_BRICK_RED, CMB_BRICK_WHITE, CMB_BRICK_BLUE, CMB_BRICK_ORANGE, CMB_BRICK_TEAL,
  1210.                 CMB_BRICK_VIOLET, CMB_BRICK_GREEN, CMB_BRICK_YELLOW, CMB_BRICK_SILVER1, CMB_BRICK_SILVER2,
  1211.                 CMB_BRICK_SILVER3, CMB_BRICK_SILVER4, CMB_BRICK_GOLD,
  1212.  
  1213.                 NPC_BRICK_RED, NPC_BRICK_WHITE, NPC_BRICK_BLUE, NPC_BRICK_ORANGE, NPC_BRICK_TEAL,
  1214.                 NPC_BRICK_VIOLET, NPC_BRICK_GREEN, NPC_BRICK_YELLOW, NPC_BRICK_SILVER1, NPC_BRICK_SILVER2,
  1215.                 NPC_BRICK_SILVER3, NPC_BRICK_SILVER4, NPC_BRICK_GOLD
  1216.             };
  1217.             for ( int q = 0; q < BRICK_MAX; ++q )
  1218.             {
  1219.                 if ( brick_to_enemy[q] == combo_id )
  1220.                 {
  1221.                     //  TraceS("brick_to_npc : combo input: "); Trace(combo_id);
  1222.                     //TraceS("brick_to_npc : enemy output: "); Trace(brick_to_enemy[BRICK_MAX+q]);
  1223.                    
  1224.                     return ( brick_to_enemy[BRICK_MAX+q-1] );
  1225.                 }
  1226.             }
  1227.         }
  1228.         else
  1229.         {
  1230.             int brick_to_enemy2[BRICK_MAX*2] =
  1231.             {   CMB_BRICK_RED_LOW, CMB_BRICK_WHITE_LOW, CMB_BRICK_BLUE_LOW, CMB_BRICK_ORANGE_LOW, CMB_BRICK_TEAL_LOW,
  1232.                 CMB_BRICK_VIOLET_LOW, CMB_BRICK_GREEN_LOW, CMB_BRICK_YELLOW_LOW, CMB_BRICK_SILVER1_LOW, CMB_BRICK_SILVER2_LOW,
  1233.                 CMB_BRICK_SILVER3_LOW, CMB_BRICK_SILVER4_LOW, CMB_BRICK_GOLD_LOW,
  1234.  
  1235.                 NPC_BRICK_RED, NPC_BRICK_WHITE, NPC_BRICK_BLUE, NPC_BRICK_ORANGE, NPC_BRICK_TEAL,
  1236.                 NPC_BRICK_VIOLET, NPC_BRICK_GREEN, NPC_BRICK_YELLOW, NPC_BRICK_SILVER1, NPC_BRICK_SILVER2,
  1237.                 NPC_BRICK_SILVER3, NPC_BRICK_SILVER4, NPC_BRICK_GOLD
  1238.             };
  1239.             for ( int q = 0; q < BRICK_MAX; ++q )
  1240.             {
  1241.                 if ( brick_to_enemy2[q] == combo_id )
  1242.                 {
  1243.                     //TraceS("brick_to_npc : combo input: "); Trace(combo_id);
  1244.                     //TraceS("brick_to_npc : enemy output: "); Trace(brick_to_enemy2[BRICK_MAX+q-1]);
  1245.                     return ( brick_to_enemy2[BRICK_MAX+q-1] );
  1246.                 }
  1247.             }
  1248.         }
  1249.         return 0; //error
  1250.     }
  1251. }
  1252.  
  1253. global script onExit
  1254. {
  1255.     void run()
  1256.     {
  1257.         Screen->LayerOpacity[0] = templayer[0];
  1258.         Screen->LayerOpacity[1] = templayer[1];
  1259.         Screen->LayerMap[0] = templayer[2];
  1260.         Screen->LayerMap[1] = templayer[3];
  1261.         newstage = true;
  1262.         //vaus->Misc[MISC_DEAD] = 0;
  1263.  
  1264.     }
  1265. }  
  1266.  
  1267. global script init
  1268. {
  1269.     void run()
  1270.     {
  1271.         quit = 0;
  1272.         frame = -1;
  1273.         Game->Counter[CR_LIVES] = 5;
  1274.         Link->CollDetection = false;
  1275.         Link->DrawYOffset = -32768;
  1276.     }
  1277. }
  1278.  
  1279. global script Init
  1280. {
  1281.     void run()
  1282.     {
  1283.         quit = 0;
  1284.         frame = -1;
  1285.         Game->Counter[CR_LIVES] = 5;
  1286.         Link->CollDetection = false;
  1287.         Link->DrawYOffset = -32768;
  1288.     }
  1289. }
  1290.  
  1291. global script onContinue
  1292. {
  1293.     void run()
  1294.     {
  1295.         quit = 0;
  1296.         frame = -1;
  1297.         Game->Counter[CR_LIVES] = 5;
  1298.         Link->Invisible = true;
  1299.         Link->CollDetection = false;
  1300.         Link->DrawYOffset = -32768;
  1301.     }
  1302. }
  1303.  
  1304. /////////////////////////
  1305. /// DEAD Script Bugs: ///
  1306. /////////////////////////
  1307.  
  1308. /*
  1309. //FIXED with ball.clamp().
  1310. //There's a step speed at which the ball phases *through* the vaus!
  1311.                     //Perhaps we should make the vaus an enemy, too? An invisible enemy to act as a failsafe?
  1312.                     //if the ball hits the vaus, it bounces.
  1313.                     //Or just scrap the vaus ffc, and use an npc for it in general?
  1314.  
  1315. //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
  1316. //the ball is still not yet inside that object
  1317. */
  1318.  
  1319. //////////////////////
  1320. /// DEAD ZC Issues //////////////////////////////////////////////////////////////////////////////
  1321. /// I fixed these issues, in specific Alphas of ZC 2.54, noted below for historical purposes: ///
  1322. /////////////////////////////////////////////////////////////////////////////////////////////////
  1323.  
  1324.  
  1325. /*
  1326. FIXED in Alpha 32
  1327. I forgot to expand ->Misc[] in sprite.cpp, which should be fixed int he source for Alpha 32.
  1328.     This meant that r/w to ptr->Misc[>15] would use invalid data, or overwrite other data. bad, bad, bad.
  1329.    
  1330.     FIXED in Alpha 32
  1331.     //Note: We also need to store the UID of each ball, as HitBy[] works from the UID, not the pointer.
  1332.    
  1333. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement