Guest User

Untitled

a guest
Sep 9th, 2013
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /************************************************************************
  2.  *  @actor-enemyBoss.js
  3.  *  @version: 1.00
  4.  *  @author:  Dave Voyles
  5.  *  @date:    August 2013
  6.  *  @copyright (c) 2013 Dave Voyles, under The MIT License (see LICENSE)
  7.  *  @First level boss
  8.  ***********************************************************************/
  9. ig.module(
  10.     'game.entities.actor-enemyBoss'
  11. )
  12. .requires(
  13.     'game.entities.base-enemy'
  14.     )
  15. .defines(function () {
  16.  
  17. EntityActorEnemyBoss = EntityBaseEnemy.extend({
  18.  
  19.     /*********************
  20.     * Property Definitions
  21.     *********************/
  22.     animSheet: new ig.AnimationSheet('media/textures/animBossShipLg.png', 248, 362),
  23.     size: {
  24.         x: 248,
  25.         y: 362
  26.     },
  27.     offset: {
  28.         x: 0,
  29.         y: 0
  30.     },
  31.     vel: {
  32.         x: -85,
  33.         y: 0
  34.     },
  35.     health:            400,
  36.     bWPExposed:        false,
  37.     canTakeDmg:        false,
  38.     shootTimer:        null,
  39.     moveTimer:         null,
  40.     initTimer:         null,
  41.     animTimer:         null,
  42.     animTime:          4,
  43.     newSpawnTimer:     null,
  44.     xModifier:         100,
  45.     initTime:          2,
  46.     shootSpeed:        0.09,
  47.     rotation:          1.4,
  48.     rotTime:           1,
  49.     spawnTime:         3,
  50.     rotateTime:        1,
  51.     statTurretsArr:    [],
  52.     rotTurretsArr:     [],
  53.     WPArr:             [],
  54.     bSpawnWeakPt:      true,
  55.     bSpawnRot:         true,
  56.     type:              ig.Entity.TYPE.A,
  57.     checkAgainst:      ig.Entity.TYPE.A,
  58.  
  59.  
  60.     init: function (x, y, settings) {
  61.         this.parent(x, y, settings);
  62.         this.addAnim('idle',  0.1, [0]), true;
  63.         this.initTimer      = new ig.Timer(this.initTime);
  64.         this.animTimer      = new ig.Timer(this.animTime);
  65.         this.shootTimer     = new ig.Timer(this.randomFromTo(3, 5));
  66.         this.moveTimer      = new ig.Timer(this.randomFromTo(2, 4));
  67.         this.newSpawnTimer  = new ig.Timer(this.spawnTime);
  68.         this.lastShootTimer = new ig.Timer(0);
  69.         this.rotateTimer    = new ig.Timer(this.rotateTime);
  70.         ig.game.boss        = this;
  71.         this.pos.y          = ig.system.height / 3;
  72.        
  73.         /* vars for gun */
  74.         this.startAngle    = this.ownAngle;
  75.         this._angle        = -500;
  76.         this._increase     = 60;
  77.         this.bullets       = 4  
  78.         this.radius        = 10;
  79.         this._entityBullet = EntityObjectEnemyBulletGreen;
  80.     },
  81.     update: function () {
  82.         this.parent();
  83.         this.parental = ig.game.enemySpawner;
  84.  
  85.         // Perform different manuevers based on current HP
  86.         this.checkHealth();
  87.  
  88.         // Stop when on screen
  89.         if (this.pos.x + 300  <= this.parental.pos.x) {
  90.             this.stop()
  91.             this.checkAnims();
  92.         }
  93.        
  94.         // Boss can take damage if weak points are killed
  95.         this.checkCanTakeDmg();
  96.     },
  97.     /* change behaviour based on current health */      
  98.     checkHealth: function(){
  99.         switch (this.health) {
  100.             case 400:
  101.                 /*          this.spawnRotTurrets(); */
  102.                 this.spawnWeakPoints(); // Keep this here, so that it draws on TOP of boss
  103.                 break;
  104.             case 300:
  105.                 break;
  106.             case 200:
  107.                 this.spawnEnemy();
  108.                 break;
  109.             case 100:
  110.                 this.spray();
  111.                 break;
  112.             default:
  113.                 break;
  114.         }
  115.     },
  116.     receiveDamage: function (value) {
  117.         if (!this.canTakeDmg) {
  118.             return; // If weak points are alive, don't take dmg
  119.         }
  120.     },
  121.     spawnStatTurrets: function(){
  122.         if (statTurrets.length === 0) {
  123.             var statTurrets = ig.game.getEntitiesByType(EntityBossTurret);
  124.             this.statTurretsArr.push(ig.game.spawnEntity(EntityBossTurret, this.pos.x - 50, this.pos.y - 50));
  125.             this.statTurretsArr.push(ig.game.spawnEntity(EntityBossTurret, this.pos.x - 50, this.pos.y + 50,
  126.                 {shotDir: 'down'}));
  127.         }
  128.     },
  129.     spawnRotTurrets: function () {
  130.         if (this.bSpawnRot) {
  131.             var rotTurrets = ig.game.getEntitiesByType(EntityRotTurret);
  132.             if (rotTurrets.length === 0) {
  133.                 this.rotTurretsArr.push(ig.game.spawnEntity(EntityRotTurret, this.pos.x - 50, this.pos.y + 50,
  134.                     { shotDir: 'down' }));
  135.             }
  136.         this.bSpawnRot = false;
  137.         }
  138.     },
  139.     spawnWeakPoints: function () {
  140.         if (this.bSpawnWeakPt) {
  141.             var EntityWeakPoints = ig.game.getEntitiesByType(EntityWeakPoint);
  142.             if (EntityWeakPoints.length === 0) {
  143. /*              var topWP = this.WPArr.push(ig.game.spawnEntity(    EntityWeakPoint, this.pos.x,                        this.pos.y, { xOffset: +140, yOffset: -6 })); */
  144.              var centerWP = this.WPArr.push(ig.game.spawnEntity(EntityWeakPoint, this.pos.x,                        this.pos.y, { xOffset: +75, yOffset:  +130 }));
  145.              var bottomWP = this.WPArr.push(ig.game.spawnEntity(EntityWeakPoint, this.pos.x,                        this.pos.y, { xOffset: +140, yOffset: +246 }));
  146.            }
  147.         }
  148.         this.bSpawnWeakPt = false;
  149.     },  
  150.     /* Show weak points based on animTimer. If visible, then can take DMG */
  151.     checkAnims: function(){
  152.         this.checkWPDmg();
  153.         if (!this.bWPExposed && this.animTimer.delta() > 0 ){
  154.               this.currentAnim = this.addAnim('opening',  0.3, [0, 1, 2, 3, 4], true);
  155.               this.bWPExposed = true;
  156.               this.animTimer.set(4);
  157.         }
  158.         if (this.bWPExposed && this.animTimer.delta() > 0 ){
  159.               this.currentAnim = this.addAnim('closing',  0.3, [4, 3, 2, 1, 0], true);
  160.               this.bWPExposed = false;
  161.               this.animTimer.set(4);
  162.         }    
  163.     },
  164.     /* check if weak points are killed -- if so, take DMG */
  165.     checkCanTakeDmg: function() {
  166.         var EntityWeakPoints = ig.game.getEntitiesByType(EntityWeakPoint);
  167.         if (EntityWeakPoints.length === 0) {
  168.             this.canTakeDmg == true;
  169.         }
  170.     },
  171.     checkWPDmg: function () {
  172.         var EntityWP = ig.game.getEntitiesByType(EntityWeakPoint);
  173.         for (var i = 0; i < EntityWP.length; i++); {
  174.             if (this.bWPExposed === true) {
  175.                 EntityWP[i].canTakeDmg = true;
  176.             } else {
  177.                 EntityWP[i].canTakeDmg = false;
  178.             }
  179.         }
  180.     },
  181. });
RAW Paste Data