Guest User

Untitled

a guest
Oct 4th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.asfdfdfd.ld24.enemies
  2. {
  3.     import com.asfdfdfd.ld24.Coin;
  4.     import com.asfdfdfd.ld24.hero.Hero;
  5.     import com.asfdfdfd.ld24.upgrades.GunUpgradeEntity;
  6.     import com.asfdfdfd.ld24.upgrades.HealthUpgradeEntity;
  7.     import com.asfdfdfd.ld24.world.GameWorld;
  8.    
  9.     import net.flashpunk.Entity;
  10.     import net.flashpunk.FP;
  11.     import net.flashpunk.Graphic;
  12.     import net.flashpunk.Mask;
  13.     import net.flashpunk.Sfx;
  14.  
  15.     public class Enemy extends Entity
  16.     {
  17.         [Embed(source='assets/explosion.mp3')] private static const EXPLOSION_SOUND:Class;
  18.        
  19.         private var _health:Number;
  20.        
  21.         private static const DAMAGE:Number = 300;
  22.        
  23.         private var _explosionSfx:Sfx = new Sfx(EXPLOSION_SOUND);
  24.        
  25.         [Embed(source='assets/enemy_shoot.mp3')] private static const SHOOT_SOUND:Class;
  26.        
  27.         protected var _shootSfx:Sfx = new Sfx(SHOOT_SOUND);
  28.        
  29.         public function Enemy(health:Number, x:Number=0, y:Number=0, graphic:Graphic=null, mask:Mask=null)
  30.         {
  31.             super(x, y, graphic, mask);
  32.            
  33.             _health = health;
  34.            
  35.             type = "Enemy";
  36.         }
  37.        
  38.         public function hit(value:Number):void
  39.         {
  40.             _health -= value;
  41.            
  42.             if (_health <= 0)
  43.             {
  44.                 FP.rand(6) == 5 ? (FP.rand(2) == 0 ? FP.world.add(new GunUpgradeEntity(x, y)) : FP.world.add(new HealthUpgradeEntity(x, y))): FP.world.add(new Coin(x, y));
  45.                
  46.                 FP.world.remove(this);
  47.                
  48.                 GameWorld.Scores += scores;
  49.                
  50.                 FP.world.add(new EnemyExplosionEntity(x, y));
  51.                
  52.                 _explosionSfx.play();
  53.             }
  54.         }
  55.        
  56.         public function get scores():uint
  57.         {
  58.             return 0;
  59.         }
  60.        
  61.         override public function update():void
  62.         {
  63.             var hero:Entity = collide("Hero", x, y);
  64.            
  65.             if (hero)
  66.             {
  67.                 (hero as Hero).damage(DAMAGE);
  68.                
  69.                 FP.world.remove(this);
  70.                                
  71.                 _explosionSfx.play();
  72.                
  73.                 FP.world.add(new EnemyExplosionEntity(x, y));
  74.             }              
  75.         }
  76.     }
  77. }
Add Comment
Please, Sign In to add comment