Advertisement
Guest User

Untitled

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