Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package game_objects
  2. {
  3.     import flash.display.BitmapData;
  4.     import game_ui.gameworld;
  5.     import net.flashpunk.Entity;
  6.     import net.flashpunk.graphics.Image;
  7.     import net.flashpunk.graphics.Spritemap;
  8.     import net.flashpunk.tweens.misc.VarTween;
  9.     import net.flashpunk.utils.Ease;
  10.     import com.oaxoa.fx.Lightning;
  11.     import com.oaxoa.fx.LightningFadeType;
  12.     import net.flashpunk.FP;
  13.     import flash.filters.GlowFilter;
  14.     import flash.display.Shape;
  15.     import flash.display.BlendMode;
  16.     import net.flashpunk.graphics.Emitter;
  17.    
  18.     /**
  19.      * ...
  20.      * @author Matt McFarland
  21.      */
  22.     public class boltWeapon extends Entity
  23.     {
  24.         public var enabled:Boolean = false;
  25.         public var maxChains:int;
  26.         public var chainIndex:int;
  27.         public var bolts:Array = [];
  28.        
  29.         public function boltWeapon()
  30.         {
  31.             maxChains = 3;
  32.             x = gameworld.Player.x;
  33.             y = gameworld.Player.y;
  34.             setHitbox(46, 480,21,480);
  35.            
  36.         }
  37.        
  38.         override public function update():void
  39.         {
  40.             for each (var b:bolt in bolts)
  41.             {
  42.                 if (!enabled) b.ll.alpha = 0;
  43.                 if (enabled) b.ll.alpha = 1;
  44.             }
  45.             if (!enabled) return;
  46.            
  47.             x = gameworld.Player.x;
  48.             y = gameworld.Player.y;
  49.             if (!bolts[0])
  50.             {
  51.                 bolts[0] = new bolt(gameworld.Player.x, gameworld.Player.y, gameworld.Player.x, 0, "free");
  52.                 FP.world.add(bolts[0]);
  53.             }
  54.             bolts[0].x = x;
  55.             bolts[0].y = y;
  56.                
  57.             checkCollisions();
  58.         }
  59.        
  60.  
  61.        
  62.         protected function checkCollisions():void
  63.         {
  64.             var firstLink:bolt = bolts[0] as bolt;
  65.             var b:baddie = world.nearestToEntityinRect("baddie", gameworld.Player, [x - 90, 0, x + 90, 480]) as baddie;
  66.             trace("First baddie: " + b);
  67.            
  68.             if (b)
  69.             {
  70.                 b.collidable = false;
  71.                 b.takeDamage(0, .1);
  72.                 firstLink.eX = b.x;
  73.                 firstLink.eY = b.y;
  74.                 firstLink.style = "focused";
  75.                 FP.world.add(firstLink);
  76.                
  77.                 var nb:baddie = world.nearestCollidableToEntity("baddie", b) as baddie;
  78.                 trace("Second baddie: " + nb);
  79.                
  80.                 if (nb)
  81.                 {
  82.                     var i:int = 1;
  83.                    
  84.                     while (i < maxChains)
  85.                     {
  86.                         bolts[i] = new bolt(b.x, b.y, nb.x, nb.y, "link");
  87.                        
  88.                         FP.world.add(bolts[i]);
  89.                        
  90.                         nb.takeDamage(0, .1);
  91.                         nb.collidable = false;
  92.                        
  93.                         b = nb;
  94.                        
  95.                         nb = world.nearestCollidableToEntity("baddie", b) as baddie;
  96.                         trace("Next baddie: " + nb);
  97.                         if (!nb)
  98.                             break;
  99.                        
  100.                         i++;
  101.                     }
  102.                 }
  103.                
  104.                 return;
  105.             }
  106.            
  107.             //No Targets
  108.             //Remove links
  109.             var links:Array = [];
  110.             FP.world.getClass(bolt, links);
  111.             for each (var l:bolt in links)
  112.             {
  113.                 if (l.style == "link") {
  114.                     FP.world.remove(l);
  115.                 }
  116.                 trace ("Bolt array: ["+bolts+"]");
  117.             }
  118.             //Untag baddies .
  119.             var baddies:Array = []
  120.             FP.world.getClass(baddie, baddies);
  121.             for each (var bb:baddie in baddies)
  122.             {
  123.                 bb.collidable = true;
  124.             }
  125.             //Reset the bolt weapon.
  126.             firstLink.style = "free";
  127.             firstLink.eX = gameworld.Player.x;
  128.             firstLink.eY = 0;
  129.            
  130.         }
  131.        
  132.         public function remove():void
  133.         {
  134.             if (this.world != null) this.world.remove(this);
  135.            
  136.         }
  137.        
  138.     }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement