Advertisement
Guest User

Untitled

a guest
Dec 30th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 10.42 KB | None | 0 0
  1. //Yes, each group needs it's own function. Dang it.
  2.     private function hitTower(enemy:Enemy, hitTower:Tower):Void
  3.     {  
  4.         //var hitTower:Tower = cast(hitTower);     
  5.         enemy.moneyGain = false;       
  6.         var enemTarget:Int = 0;        
  7.        
  8.         if (enemy.BacteriaType == 0)
  9.         {  
  10.             enemTarget = Random.int(0, 1);
  11.             //Head for player  
  12.             if (enemTarget == 0) FlxVelocity.moveTowardsObject(enemy, Astro, zombieSpeed);
  13.             //Head for home base
  14.             if (enemTarget == 1) FlxVelocity.moveTowardsObject(enemy, goal, zombieSpeed);
  15.         }      
  16.         hitTower.health -= 1; //CHANGE TO DAMAGE DEALT BY ENEMY
  17.         if (hitTower.health <= 0)
  18.         {
  19.             hitTower.kill();
  20.             //Each group ALSO needs to be removed from baseGroup.
  21.             towerGroup.remove(hitTower,false);         
  22.         }      
  23.         enemy.health -= 1;     
  24.     }
  25.     //////////////////////////////////////////////////
  26.     private function hitGateB(enemy:Enemy, hitGateB:GateB):Void
  27.     {  
  28.         //var hitGateB:GateB = cast(hitGateB);     
  29.         enemy.moneyGain = false;       
  30.         var enemTarget:Int = 0;        
  31.        
  32.         if (enemy.BacteriaType == 0)
  33.         {  
  34.             enemTarget = Random.int(0, 1);
  35.             //Head for player  
  36.             if (enemTarget == 0) FlxVelocity.moveTowardsObject(enemy, Astro, zombieSpeed);
  37.             //Head for home base
  38.             if (enemTarget == 1) FlxVelocity.moveTowardsObject(enemy, goal, zombieSpeed);
  39.         }      
  40.         hitGateB.health -= 1; //CHANGE TO DAMAGE DEALT BY ENEMY
  41.         if (hitGateB.health <= 0)
  42.         {
  43.             hitGateB.kill();
  44.             //Each group ALSO needs to be removed from baseGroup.
  45.             gateBGroup.remove(hitGateB,false);         
  46.         }      
  47.         enemy.health -= 1;     
  48.     }
  49.     /////////////////////////////////////////////////////////////////Test*
  50.     private function hitGate(enemy:Enemy, thingG:Gate):Void
  51.     {  
  52.         var hitGate:Gate = cast(thingG);       
  53.         enemy.moneyGain = false;       
  54.         var enemTarget:Int = 0;        
  55.        
  56.         if (enemy.BacteriaType == 0)
  57.         {  
  58.             enemTarget = Random.int(0, 1);
  59.             //Head for player  
  60.             if (enemTarget == 0) FlxVelocity.moveTowardsObject(enemy, Astro, zombieSpeed);
  61.             //Head for home base
  62.             if (enemTarget == 1) FlxVelocity.moveTowardsObject(enemy, goal, zombieSpeed);
  63.         }      
  64.         hitGate.health -= 1; //CHANGE TO DAMAGE DEALT BY ENEMY
  65.         if (hitGate.health <= 0)
  66.         {
  67.             hitGate.kill();
  68.             //Each group ALSO needs to be removed from basegroup.
  69.             gateGroup.remove(hitGate,false);
  70.            
  71.            
  72.         }      
  73.         enemy.health -= 1;     
  74.     }
  75.  
  76. //Tower Class
  77. package;
  78.  
  79. //////////////////////////////////////////
  80. //New
  81.  
  82. import flixel.group.FlxGroup;
  83. import flixel.FlxG;
  84. import flixel.FlxSprite;
  85.  
  86.  
  87. import flixel.math.FlxPoint;
  88. import flixel.math.FlxVelocity;
  89. import flixel.math.FlxMath;
  90.  
  91. import flixel.effects.particles.FlxParticle;
  92. import flixel.effects.particles.FlxEmitter;
  93.  
  94.  
  95. import flixel.ui.FlxBar;
  96. import flixel.util.FlxGradient;
  97.  
  98. class Tower extends Structure
  99. {  
  100.    
  101.     public var range:Int = 120;
  102.     public var fireRate:Float = 0.6;
  103.     public var damage:Int = 1;
  104.    
  105.     public var range_LEVEL:Int = 1;
  106.     public var firerate_LEVEL:Int = 1;
  107.     public var damage_LEVEL:Int = 1;
  108.    
  109.     public var range_PRIZE:Int = 10;
  110.     public var firerate_PRIZE:Int = 10;
  111.     public var damage_PRIZE:Int =  10;
  112.    
  113.     private var shootInvertall:Int = 1;
  114.     private var shootCounter:Int = 0;
  115.    
  116.     private var indicator:FlxSprite;
  117.     private var beaconSpot:FlxSprite;
  118.     public var index:Int;
  119.    
  120.     private static var HELPER_POINT:FlxPoint = new FlxPoint();
  121.     private static var HELPER_POINT_2:FlxPoint = new FlxPoint();
  122.    
  123.     public var deathBump:Bool = false;
  124.     public var intel:Int;
  125.    
  126.     public var upgradePoint:Int = 1;
  127.    
  128.     private var _healthBar:FlxBar;
  129.    
  130.     public function new(x:Float, y:Float)
  131.     {
  132.         super(x, y);
  133.         loadGraphic("assets/images/Turret.png", false, 12,12); 
  134.         intel = 0;
  135.        
  136.         health = 10;
  137.        
  138.         immovable = true;  
  139.        
  140.         Mode = 1;
  141.        
  142.         _healthBar = new FlxBar(x, y, FlxBarFillDirection.LEFT_TO_RIGHT, Std.int(width), 2, this, "health", 0, health, true);
  143.         _healthBar.createGradientBar([0xff800000], [0xffff0000,0xffFF0000], 1, 0, true, 0xcc333333);
  144.         _healthBar.scrollFactor.set();
  145.         _healthBar.trackParent(0, -4);
  146.         _healthBar.killOnEmpty;
  147.         R.PS.add(_healthBar);
  148.         //R.STATE.add(_healthBar);
  149.     }  
  150.    
  151.     override public function update(elapsed:Float):Void
  152.     {  
  153.         if (upgradePoint == 2)
  154.         {
  155.             loadGraphic("assets/images/Turret2.png", false, 12, 27);
  156.             y -= 15;
  157.         }
  158.        
  159.        
  160.         if (getNearestEnemy() == null)
  161.         {
  162.             intel = 0;
  163.         }
  164.         else
  165.         {  
  166.            
  167.             shootCounter += cast(FlxG.timeScale);
  168.             if (shootCounter > (shootInvertall * FlxG.updateFramerate) * fireRate)
  169.                 shoot();
  170.                
  171.         }
  172.        
  173.         if (FlxG.keys.justReleased.U && R.PS.money > R.PS.upgradePrice && upgradePoint < 7) upgradeLevel();
  174.        
  175.         super.update(elapsed); 
  176.        
  177.         //if (deathBump == true) kill();
  178.     }  
  179.    
  180.    
  181.    
  182.     override public function kill():Void
  183.     {
  184.        
  185.         //indicator.kill();
  186.         //FlxG.sound.play("LostTower2");
  187.        
  188.        
  189.         var emitter:FlxTypedEmitter<FlxParticle> = new FlxTypedEmitter(x, y,2);
  190.        
  191.         var speed:Int = 100;
  192.         emitter.focusOn(this);
  193.         emitter.velocity.set( -speed, -speed, speed, speed);
  194.        
  195.         var particles:Int = 2;
  196.         for (i in 0...(particles))
  197.         {
  198.             var particle:FlxParticle = new FlxParticle();
  199.             particle.makeGraphic(3, 3, 0xff8000FF);    
  200.             particle.exists = false;
  201.             particle.lifespan = 0.2;
  202.             emitter.add(particle);
  203.         }      
  204.        
  205.         R.PS.emitterGroup.add(emitter);
  206.         emitter.start(true);   
  207.        
  208.         R.PS.towerGroup.remove(this, true);
  209.        
  210.         _healthBar.kill();
  211.        
  212.         super.kill();
  213.     }  
  214.    
  215.     private function shoot():Void
  216.     {
  217.         var target:Enemy = getNearestEnemy();
  218.         if (target == null) return;
  219.        
  220.        
  221.         //var targeting:FlxSprite =  R.PS.targetCon;
  222.        
  223.         var bullet:Bullet = new Bullet(getMidpoint().x, getMidpoint().y, target, damage);
  224.         if (this.alive)
  225.         {
  226.             R.PS.bulletGroup.add(bullet);
  227.             //FlxG.sound.play("LaserShot2",0.2);
  228.         }
  229.        
  230.        
  231.         shootCounter = 0;
  232.     }
  233.    
  234.     private function getNearestEnemy():Enemy
  235.     {
  236.             var firstEnemy:Enemy = null;
  237.             var enemies:FlxTypedGroup<Enemy> = R.PS.enemyGroup;
  238.  
  239.             for (enemy in enemies.members)
  240.             {
  241.                 if (enemy != null && enemy.alive)
  242.                 {
  243.                     HELPER_POINT.x = x;
  244.                     HELPER_POINT.y = y;
  245.                        
  246.                     HELPER_POINT_2.x = enemy.x;
  247.                     HELPER_POINT_2.y = enemy.y;
  248.                        
  249.                    
  250.                     var distance:Float = getPosition(HELPER_POINT).distanceTo(HELPER_POINT_2);
  251.  
  252.                     if (distance <= range)
  253.                     {
  254.                         firstEnemy = enemy;
  255.                         break;
  256.                     }
  257.                 }
  258.             }
  259.  
  260.             return firstEnemy;     
  261.     }
  262.    
  263.     // Upgrades
  264.    
  265.     public function upgradeLevel():Void
  266.     {
  267.         upgradePoint += 1;
  268.        
  269.         range += 10;
  270.         range_LEVEL ++;
  271.         range_PRIZE = cast(range_PRIZE * 1.5);
  272.        
  273.         damage ++;
  274.         damage_LEVEL ++;
  275.         damage_PRIZE = cast(damage_PRIZE * 1.5);       
  276.     }
  277.    
  278. }
  279. ////////////////////////////
  280. Gate Class
  281. package;
  282.  
  283. //////////////////////////////////////////
  284. //New
  285.  
  286. import flixel.group.FlxGroup;
  287. import flixel.FlxG;
  288. import flixel.FlxSprite;
  289.  
  290.  
  291. import flixel.math.FlxPoint;
  292. import flixel.math.FlxVelocity;
  293. import flixel.math.FlxMath;
  294.  
  295. import flixel.effects.particles.FlxParticle;
  296. import flixel.effects.particles.FlxEmitter;
  297.  
  298. import flixel.util.FlxColor;
  299.  
  300. import flixel.ui.FlxBar;
  301. import flixel.util.FlxGradient;
  302.  
  303. class Gate extends Structure
  304. {  
  305.    
  306.    
  307.     public var index:Int;  
  308.    
  309.     private var _healthBar:FlxBar;
  310.    
  311.     public function new(x:Float, y:Float)
  312.     {
  313.         super(x, y);
  314.         loadGraphic("assets/images/Gate.png", false, 12, 12);  
  315.        
  316.         health = 3;
  317.        
  318.         Mode = 3;
  319.        
  320.         immovable = true;  
  321.        
  322.         _healthBar = new FlxBar(x, y, FlxBarFillDirection.LEFT_TO_RIGHT, Std.int(width), 2, this, "health", 0, health, true);
  323.         _healthBar.createGradientBar([0xff800000], [0xffff0000,0xffFF0000], 1, 0, true, 0xcc333333);
  324.         _healthBar.scrollFactor.set();
  325.         _healthBar.trackParent(0, -4);
  326.         _healthBar.killOnEmpty;
  327.         R.PS.add(_healthBar);
  328.     }  
  329.    
  330.     override public function update(elapsed:Float):Void
  331.     {  
  332.         //if (this.x == x + 12) loadGraphic("assets/images/Silo.png", false, 12,12);   
  333.         //if (this.x == x + 12) loadGraphic("assets/images/Silo.png", false, 12,12);   
  334.        
  335.         FlxG.watch.add(this, "Px", "Next");
  336.        
  337.         super.update(elapsed); 
  338.     }  
  339.    
  340.     override public function kill():Void
  341.     {
  342.        
  343.         var emitter:FlxTypedEmitter<FlxParticle> = new FlxTypedEmitter(x, y,2);
  344.        
  345.         var speed:Int = 100;
  346.         emitter.focusOn(this);
  347.         emitter.velocity.set( -speed, -speed, speed, speed);
  348.        
  349.         var particles:Int = 2;
  350.         for (i in 0...(particles))
  351.         {
  352.             var particle:FlxParticle = new FlxParticle();
  353.             particle.makeGraphic(3, 3, 0xff8000FF);    
  354.             particle.exists = false;
  355.             particle.lifespan = 0.2;
  356.             emitter.add(particle);
  357.         }      
  358.        
  359.         R.PS.emitterGroup.add(emitter);
  360.         emitter.start(true);   
  361.        
  362.         R.PS.gateGroup.remove(this, true);
  363.        
  364.         _healthBar.kill();
  365.        
  366.         super.kill();
  367.     }          
  368.    
  369. }
  370. ////////////
  371. Gate B Class
  372. package;
  373.  
  374. //////////////////////////////////////////
  375. //New
  376.  
  377. import flixel.group.FlxGroup;
  378. import flixel.FlxG;
  379. import flixel.FlxSprite;
  380.  
  381.  
  382. import flixel.math.FlxPoint;
  383. import flixel.math.FlxVelocity;
  384. import flixel.math.FlxMath;
  385.  
  386. import flixel.effects.particles.FlxParticle;
  387. import flixel.effects.particles.FlxEmitter;
  388.  
  389.  
  390. import flixel.ui.FlxBar;
  391. import flixel.util.FlxGradient;
  392.  
  393. class GateB extends Structure
  394. {  
  395.     public var index:Int;  
  396.     private var _healthBar:FlxBar;
  397.    
  398.     public function new(x:Float, y:Float)
  399.     {
  400.         super(x, y);
  401.         loadGraphic("assets/images/Gate.png", false, 12, 12);  
  402.        
  403.         color = 0xffFFFF00;
  404.          
  405.        
  406.        
  407.         health = 10;
  408.        
  409.         immovable = true;  
  410.        
  411.         Mode = 3;
  412.        
  413.         _healthBar = new FlxBar(x, y, FlxBarFillDirection.LEFT_TO_RIGHT, Std.int(width), 2, this, "health", 0, health, true);
  414.         _healthBar.createGradientBar([0xff800000], [0xffff0000,0xffFF0000], 1, 0, true, 0xcc333333);
  415.         _healthBar.scrollFactor.set();
  416.         _healthBar.trackParent(0, -4);
  417.         _healthBar.killOnEmpty;
  418.         R.PS.add(_healthBar);
  419.         //R.STATE.add(_healthBar);
  420.     }  
  421.    
  422.     override public function update(elapsed:Float):Void
  423.     {          
  424.        
  425.         super.update(elapsed); 
  426.     }  
  427.    
  428.    
  429.    
  430.     override public function kill():Void
  431.     {
  432.        
  433.         //indicator.kill();
  434.         //FlxG.sound.play("LostTower2");
  435.        
  436.        
  437.         var emitter:FlxTypedEmitter<FlxParticle> = new FlxTypedEmitter(x, y,2);
  438.        
  439.         var speed:Int = 100;
  440.         emitter.focusOn(this);
  441.         emitter.velocity.set( -speed, -speed, speed, speed);
  442.        
  443.         var particles:Int = 2;
  444.         for (i in 0...(particles))
  445.         {
  446.             var particle:FlxParticle = new FlxParticle();
  447.             particle.makeGraphic(3, 3, 0xff8000FF);    
  448.             particle.exists = false;
  449.             particle.lifespan = 0.2;
  450.             emitter.add(particle);
  451.         }      
  452.        
  453.         R.PS.emitterGroup.add(emitter);
  454.         emitter.start(true);   
  455.        
  456.         R.PS.gateBGroup.remove(this, true);
  457.        
  458.         _healthBar.kill();
  459.        
  460.         super.kill();
  461.     }  
  462.    
  463.    
  464.    
  465.    
  466. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement