SHARE
TWEET

Retro Vaders: Mothership Boss AI

nutter666 May 22nd, 2019 (edited) 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.     import flash.display.MovieClip;
  3.     import flash.filters.GlowFilter;
  4.    
  5.     public class BossVader3 extends MovieClip{
  6.        
  7.         public var health:Number = 120;
  8.         public var colour:String = "red";
  9.        
  10.         public var pointValue:int = 1000;
  11.        
  12.         public var isBoss:Boolean = true;
  13.        
  14.         public var dead:Boolean = false;
  15.        
  16.         var moveDir:Number = 1;
  17.         var speed:Number = 4;
  18.         var attackPattern:String = "normal";
  19.        
  20.         var hitTimer:int = 60; // 1 second (due to game running at 60 frames per second)
  21.         var canBeHit:Boolean = true;
  22.        
  23.         var fireTimer:int = 6;
  24.         var fireRate:int = 12;
  25.         var shotCount:int = 3;
  26.        
  27.         var parentClass:GameScreen;
  28.  
  29.         public function BossVader3() {
  30.             // constructor code
  31.         }
  32.        
  33.         public function doBossLogic(){
  34.         if(!canBeHit){
  35.         hitTimer --
  36.         this.alpha = 0.25
  37.         if(attackPattern != "critical"){
  38.         attackPattern = "hit"
  39.         }
  40.         if(hitTimer <= 0){
  41.         canBeHit = true;
  42.         hitTimer = 60;
  43.         this.alpha = 1;
  44.         if(health <= 60 && attackPattern != "critical"){
  45.         attackPattern = "triple"
  46.         }
  47.         else if(health > 60 && attackPattern != "critical"){
  48.         attackPattern = "normal"
  49.         }
  50.         }
  51.         }
  52.        
  53.         moveShip(attackPattern)
  54.         attackPlayer(attackPattern)
  55.         }
  56.        
  57.         function moveShip(atk){
  58.         switch(atk){
  59.         case "normal":
  60.         this.x += moveDir * speed
  61.         if(this.x > 550 && moveDir > 0){
  62.         moveDir = -1;
  63.         }
  64.         if(this.x < 50 && moveDir < 0){
  65.         moveDir = 1;
  66.         }
  67.         break;
  68.         case "triple":
  69.         this.x += moveDir * speed
  70.         if(this.x > 550 && moveDir > 0){
  71.         moveDir = -1;
  72.         }
  73.         if(this.x < 50 && moveDir < 0){
  74.         moveDir = 1;
  75.         }
  76.         break;
  77.         case "hit":
  78.         this.x += moveDir * (speed * 3)
  79.         if(this.x > 550 && moveDir > 0){
  80.         moveDir = -1;
  81.         }
  82.         if(this.x < 50 && moveDir < 0){
  83.         moveDir = 1;
  84.         }
  85.         break;
  86.         case "critical":
  87.         this.x += moveDir * speed
  88.         if(this.x > 550 && moveDir > 0){
  89.         moveDir = -1;
  90.         }
  91.         if(this.x < 50 && moveDir < 0){
  92.         moveDir = 1;
  93.         }
  94.         break;
  95.        
  96.         }
  97.         }
  98.        
  99.         function attackPlayer(atk){
  100.         if(!parentClass.gamePaused){
  101.         fireTimer --
  102.         if(fireTimer <= 0){
  103.        
  104.         switch(atk){
  105.         case "normal":
  106.         parentClass.createEnemyBullet(this.x,this.y+10)
  107.         fireTimer = fireRate;
  108.         break;
  109.         case "triple":
  110.         parentClass.createEnemyBullet(this.x,this.y+10)
  111.         parentClass.createEnemyBullet(this.x+20,this.y+10)
  112.         parentClass.createEnemyBullet(this.x-20,this.y+10)
  113.         fireTimer = fireRate;
  114.         break;
  115.         case "hit":
  116.         parentClass.createEnemyBullet(this.x,this.y+10)
  117.         fireTimer = 6;
  118.         break;
  119.         case "critical":
  120.         parentClass.createEnemyBullet(this.x+(Math.random()*40-20),this.y+10)
  121.         fireTimer = 6;
  122.         break;
  123.         }
  124.        
  125.         }
  126.         }
  127.         }
  128.        
  129.         public function init(pClass:GameScreen){
  130.         parentClass = pClass
  131.         this.health = 120
  132.         updateSkin();
  133.         }
  134.        
  135.         // takeDamage(amount)
  136.         function takeDamage(amount:Number){
  137.         if(this.health > 0 && canBeHit){
  138.         if(attackPattern == "critical"){
  139.         this.health -= 99
  140.         }
  141.         else{
  142.         this.health -= amount
  143.         }
  144.         parentClass.createExplosion(this.x-40,this.y-15,this.colour);
  145.         parentClass.createExplosion(this.x+40,this.y-15,this.colour);
  146.         parentClass.createExplosion(this.x-80,this.y,this.colour);
  147.         parentClass.createExplosion(this.x+80,this.y,this.colour);
  148.         parentClass.createExplosion(this.x,this.y-30,this.colour);
  149.         parentClass.createExplosion(this.x-40,this.y+15,this.colour);
  150.         parentClass.createExplosion(this.x+40,this.y+15,this.colour);
  151.         updateSkin();
  152.         canBeHit = false;
  153.         if(this.health <= 0){
  154.         parentClass.createExplosion(this.x,this.y-40,"red");
  155.         parentClass.createExplosion(this.x-40,this.y-30,"yellow");
  156.         parentClass.createExplosion(this.x+40,this.y-30,"yellow");
  157.         parentClass.createExplosion(this.x-80,this.y-30,"yellow");
  158.         parentClass.createExplosion(this.x+80,this.y-30,"yellow");
  159.         parentClass.challenges.boss3 = true;
  160.         this.dead = true;
  161.         }
  162.         }
  163.         }
  164.        
  165.         // updateSkin()
  166.         public function updateSkin(){
  167.         if(this.health <= 10){
  168.         this.colour = "yellow"
  169.         this.gotoAndStop("critical")
  170.         this.attackPattern = "critical"
  171.         speed = 15;
  172.         fireRate = 12;
  173.         }
  174.         else if(this.health <= 20){
  175.         this.colour = "yellow"
  176.         this.gotoAndStop("yellow")
  177.         speed = 4;
  178.         fireRate = 30;
  179.         this.attackPattern = "normal"
  180.         }
  181.         else if(this.health <= 30){
  182.         this.colour = "blue"
  183.         this.gotoAndStop("blue")
  184.         speed = 4;
  185.         fireRate = 22;
  186.         }
  187.         else if(this.health <= 40){
  188.         this.colour = "green"
  189.         this.gotoAndStop("green")
  190.         speed = 4;
  191.         fireRate = 24;
  192.         }
  193.         else if(this.health <= 50){
  194.         this.colour = "red"
  195.         this.gotoAndStop("green/red")
  196.         speed = 3.5;
  197.         fireRate = 24;
  198.         }
  199.         else if(this.health <= 60){
  200.         this.colour = "red"
  201.         this.gotoAndStop("red")
  202.         speed = 3;
  203.         fireRate = 24;
  204.         this.attackPattern = "triple"
  205.         }
  206.         else if(this.health <= 70){
  207.         this.colour = "white"
  208.         this.gotoAndStop("red/white")
  209.         speed = 5.25
  210.         fireRate = 12;
  211.         }
  212.         else if(this.health <= 80){
  213.         this.colour = "white"
  214.         this.gotoAndStop("white")
  215.         speed = 5.5;
  216.         fireRate = 12;
  217.         }
  218.         else if(this.health <= 90){
  219.         this.colour = "black"
  220.         this.gotoAndStop("white/black")
  221.         speed = 5.7
  222.         fireRate = 12;
  223.         }
  224.         else if(this.health <= 100){
  225.         this.colour = "black"
  226.         this.gotoAndStop("black/white")
  227.         speed = 5.8
  228.         fireRate = 12;
  229.         }
  230.         else if(this.health <= 110){
  231.         this.colour = "black"
  232.         this.gotoAndStop("black")
  233.         speed = 5.9
  234.         fireRate = 12;
  235.         }
  236.         else {
  237.         this.colour = "black"
  238.         this.gotoAndStop("max")
  239.         speed = 6
  240.         fireRate = 12;
  241.         }
  242.         }
  243.  
  244.     }
  245.    
  246. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top