Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************************************************
- * @actor-enemyBoss.js
- * @version: 1.00
- * @author: Dave Voyles
- * @date: August 2013
- * @copyright (c) 2013 Dave Voyles, under The MIT License (see LICENSE)
- * @First level boss
- ***********************************************************************/
- ig.module(
- 'game.entities.actor-enemyBoss'
- )
- .requires(
- 'game.entities.base-enemy'
- )
- .defines(function () {
- EntityActorEnemyBoss = EntityBaseEnemy.extend({
- /*********************
- * Property Definitions
- *********************/
- animSheet: new ig.AnimationSheet('media/textures/animBossShipLg.png', 248, 362),
- size: {
- x: 248,
- y: 362
- },
- offset: {
- x: 0,
- y: 0
- },
- vel: {
- x: -85,
- y: 0
- },
- health: 400,
- bWPExposed: false,
- canTakeDmg: false,
- shootTimer: null,
- moveTimer: null,
- initTimer: null,
- animTimer: null,
- animTime: 4,
- newSpawnTimer: null,
- xModifier: 100,
- initTime: 2,
- shootSpeed: 0.09,
- rotation: 1.4,
- rotTime: 1,
- spawnTime: 3,
- rotateTime: 1,
- statTurretsArr: [],
- rotTurretsArr: [],
- WPArr: [],
- bSpawnWeakPt: true,
- bSpawnRot: true,
- type: ig.Entity.TYPE.A,
- checkAgainst: ig.Entity.TYPE.A,
- init: function (x, y, settings) {
- this.parent(x, y, settings);
- this.addAnim('idle', 0.1, [0]), true;
- this.initTimer = new ig.Timer(this.initTime);
- this.animTimer = new ig.Timer(this.animTime);
- this.shootTimer = new ig.Timer(this.randomFromTo(3, 5));
- this.moveTimer = new ig.Timer(this.randomFromTo(2, 4));
- this.newSpawnTimer = new ig.Timer(this.spawnTime);
- this.lastShootTimer = new ig.Timer(0);
- this.rotateTimer = new ig.Timer(this.rotateTime);
- ig.game.boss = this;
- this.pos.y = ig.system.height / 3;
- /* vars for gun */
- this.startAngle = this.ownAngle;
- this._angle = -500;
- this._increase = 60;
- this.bullets = 4
- this.radius = 10;
- this._entityBullet = EntityObjectEnemyBulletGreen;
- },
- update: function () {
- this.parent();
- this.parental = ig.game.enemySpawner;
- // Perform different manuevers based on current HP
- this.checkHealth();
- // Stop when on screen
- if (this.pos.x + 300 <= this.parental.pos.x) {
- this.stop()
- this.checkAnims();
- }
- // Boss can take damage if weak points are killed
- this.checkCanTakeDmg();
- },
- /* change behaviour based on current health */
- checkHealth: function(){
- switch (this.health) {
- case 400:
- /* this.spawnRotTurrets(); */
- this.spawnWeakPoints(); // Keep this here, so that it draws on TOP of boss
- break;
- case 300:
- break;
- case 200:
- this.spawnEnemy();
- break;
- case 100:
- this.spray();
- break;
- default:
- break;
- }
- },
- receiveDamage: function (value) {
- if (!this.canTakeDmg) {
- return; // If weak points are alive, don't take dmg
- }
- },
- spawnStatTurrets: function(){
- if (statTurrets.length === 0) {
- var statTurrets = ig.game.getEntitiesByType(EntityBossTurret);
- this.statTurretsArr.push(ig.game.spawnEntity(EntityBossTurret, this.pos.x - 50, this.pos.y - 50));
- this.statTurretsArr.push(ig.game.spawnEntity(EntityBossTurret, this.pos.x - 50, this.pos.y + 50,
- {shotDir: 'down'}));
- }
- },
- spawnRotTurrets: function () {
- if (this.bSpawnRot) {
- var rotTurrets = ig.game.getEntitiesByType(EntityRotTurret);
- if (rotTurrets.length === 0) {
- this.rotTurretsArr.push(ig.game.spawnEntity(EntityRotTurret, this.pos.x - 50, this.pos.y + 50,
- { shotDir: 'down' }));
- }
- this.bSpawnRot = false;
- }
- },
- spawnWeakPoints: function () {
- if (this.bSpawnWeakPt) {
- var EntityWeakPoints = ig.game.getEntitiesByType(EntityWeakPoint);
- if (EntityWeakPoints.length === 0) {
- /* var topWP = this.WPArr.push(ig.game.spawnEntity( EntityWeakPoint, this.pos.x, this.pos.y, { xOffset: +140, yOffset: -6 })); */
- var centerWP = this.WPArr.push(ig.game.spawnEntity(EntityWeakPoint, this.pos.x, this.pos.y, { xOffset: +75, yOffset: +130 }));
- var bottomWP = this.WPArr.push(ig.game.spawnEntity(EntityWeakPoint, this.pos.x, this.pos.y, { xOffset: +140, yOffset: +246 }));
- }
- }
- this.bSpawnWeakPt = false;
- },
- /* Show weak points based on animTimer. If visible, then can take DMG */
- checkAnims: function(){
- this.checkWPDmg();
- if (!this.bWPExposed && this.animTimer.delta() > 0 ){
- this.currentAnim = this.addAnim('opening', 0.3, [0, 1, 2, 3, 4], true);
- this.bWPExposed = true;
- this.animTimer.set(4);
- }
- if (this.bWPExposed && this.animTimer.delta() > 0 ){
- this.currentAnim = this.addAnim('closing', 0.3, [4, 3, 2, 1, 0], true);
- this.bWPExposed = false;
- this.animTimer.set(4);
- }
- },
- /* check if weak points are killed -- if so, take DMG */
- checkCanTakeDmg: function() {
- var EntityWeakPoints = ig.game.getEntitiesByType(EntityWeakPoint);
- if (EntityWeakPoints.length === 0) {
- this.canTakeDmg == true;
- }
- },
- checkWPDmg: function () {
- var EntityWP = ig.game.getEntitiesByType(EntityWeakPoint);
- for (var i = 0; i < EntityWP.length; i++); {
- if (this.bWPExposed === true) {
- EntityWP[i].canTakeDmg = true;
- } else {
- EntityWP[i].canTakeDmg = false;
- }
- }
- },
- });
RAW Paste Data