Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
60
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.            
  50.             bolts[0] = new bolt(gameworld.Player.x, gameworld.Player.y, gameworld.Player.x, gameworld.Player.y, "focused");
  51.             checkCollisions();
  52.         }
  53.        
  54.  
  55.        
  56.         protected function checkCollisions():void
  57.         {
  58.             var firstLink:bolt = bolts[0] as bolt;
  59.            
  60.             var b:baddie = world.nearestToEntityinRect("baddie", gameworld.Player, [x - 90, 0, x + 90, 480]) as baddie;
  61.            
  62.             if (b)
  63.             {
  64.                 b.collidable = false;
  65.                 b.takeDamage(0, .1);
  66.                 firstLink.eX = b.x;
  67.                 firstLink.eY = b.y;
  68.                 firstLink.style = "focused";
  69.                 FP.world.add(firstLink);
  70.                
  71.                 var nb:baddie = world.nearestCollidableToEntity("baddie", b) as baddie;
  72.                
  73.                 if (nb)
  74.                 {
  75.                     var i:int = 1;
  76.                    
  77.                     while (i < maxChains)
  78.                     {
  79.                         bolts[i] = new bolt(b.x, b.y, nb.x, nb.y, "link");
  80.                        
  81.                         FP.world.add(bolts[i]);
  82.                        
  83.                         nb.takeDamage(0, .1);
  84.                         nb.collidable = false;
  85.                        
  86.                         b = nb;
  87.                        
  88.                         nb = world.nearestCollidableToEntity("baddie", b) as baddie;
  89.                        
  90.                         if (!nb)
  91.                             break;
  92.                        
  93.                         i++;
  94.                     }
  95.                 }
  96.                
  97.                 return;
  98.             }
  99.            
  100.             //No Targets
  101.             //Remove links
  102.             var links:Array = [];
  103.             FP.world.getClass(bolt, links);
  104.             for each (var l:bolt in links)
  105.             {
  106.                 if (l.style == "link") {
  107.                     FP.world.remove(l);
  108.                     bolts.pop();
  109.                 }
  110.                 trace ("Bolt array: ["+bolts+"]");
  111.             }
  112.             //Untag baddies .
  113.             var baddies:Array = []
  114.             FP.world.getClass(baddie, baddies);
  115.             for each (var bb:baddie in baddies)
  116.             {
  117.                 bb.collidable = true;
  118.             }
  119.             //Reset the bolt weapon.
  120.             firstLink.style = "free";
  121.             firstLink.eX = gameworld.Player.x;
  122.             firstLink.eY = 0;
  123.            
  124.         }
  125.        
  126.         public function remove():void
  127.         {
  128.             if (this.world != null) this.world.remove(this);
  129.            
  130.         }
  131.        
  132.     }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement