Advertisement
Guest User

Untitled

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