Advertisement
ZoriaRPG

Arkanoid Alpha 0.14

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