Advertisement
nutter666

Arc Blaster code prototype

Oct 11th, 2014
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var maxDist:int = MathX.getDist(ship,y,screenTopY) // the max distance the primary arc beam can travel
  2.     var moveHops:Number = 3; // the number of pixels between each collision check, pixel by pixel would be expensive and unnecessary
  3.     var arcPoint:Point; // a temporary point to represent where the arc bolt currently is whilst moving
  4.      
  5.     var secondaryRadius:int 60; // the max radius a secondary arc can jump to.
  6.     var maxSecondaryTargets:int = 3; // max number of secondary targets an arc bolt can jump to
  7.      
  8.     // test primary bolt - handles the movement and collision test of the main bolt and calls the secondary test if the primary on hits an enemy target
  9.  
  10.     function primaryArcBoltCalculation(){
  11.     arcPoint = new Point(ship.x,ship.y)
  12.     for(var i:int = maxDist / moveHops;i>0;i--){
  13.     arcPoint.y -= moveHops
  14.      
  15.     // test collision against enemies
  16.      
  17.     for(var e:int = enemies.length-1;e>=0;e--){
  18.     if(enemies[e].hitTestPoint(arcPoint.x,arcPoint.y,true)){
  19.     // enemy has been hit, damage it
  20.     enemies[e].takeDamage();
  21.      
  22.     // set i to 0 to stop the bolt moving any further
  23.     i = 0
  24.      
  25.     // set off the test for secondary points
  26.     secondaryArcBoltsCaluclation(arcPoint)
  27.      
  28.     // create visual special effect of the arc bolt
  29.     effectsMan.createArcLightning(ship,arcPoint)
  30.     }
  31.      
  32.     else if(arcPoint.y <= screenTopY){
  33.  // arcPoint has reached the top without hitting anything, create missed bolt effect
  34.  effectsMan.createArcLightning(ship,screenTopY)
  35.      
  36.     i = 0;
  37.     // player has missed the shot
  38.     }
  39.      
  40.     }
  41.      
  42.     // test secondary bolts
  43.     function secondaryArcBoltsCaluclation(testPoint:Point){
  44.      
  45.     var secondaryTargets = Math.min(maxSecondaryTargets,enemies.length) // check the number of targets to test against
  46.      
  47.     for(var i:int = secondaryTargets;i>0;i--){
  48.     for(var e:int = enemies.length-1;e>=0;e--){
  49.     if(MathX.getDist(testPoint,enemies[e]) <= secondaryRadius){
  50.      
  51.     // enemy is within arc jump radius, damage it
  52.      
  53.     // show visual effect
  54.     effectsMan.createArcLightning(testPoint,enemies[e])
  55.      
  56.     enemies[e].takeDamage();
  57.      
  58.     }
  59.     }
  60.      
  61.     }
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement