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;
- }
- }
- },
- });
- /*************************
- * @EntityBossTurret
- * @Turret attachd to boss
- ************************/
- EntityBossTurret = EntityBaseEnemy.extend({
- /*********************
- * Property Definitions
- *********************/
- animSheet: new ig.AnimationSheet('media/textures/actor-playerShip_R.png', 24, 24),
- soundShoot: new ig.Sound('media/sfx/Explode01.ogg' ),
- font: new ig.Font('media/fonts/xfinfont.png' ),
- size: {
- x: 20,
- y: 20
- },
- offset: {
- x: 0,
- y: 1
- },
- friction: {
- x: 800,
- y: 800
- },
- maxVel: {
- x: 300,
- y: 300
- },
- angle: -Math.PI / 2,
- speed: 200,
- health: 20,
- respawnDelay: 2,
- shootSpeed: 0.25,
- rotation: 0.5,
- rotDist: 1.2,
- rotSpeed: 2.5,
- lifeTimer: null,
- shotDir: 'up',
- type: ig.Entity.TYPE.B,
- checkAgainst: ig.Entity.TYPE.C,
- init: function (x, y, settings) {
- this.parent(x, y, settings);
- this.addAnim('idle', 60, [0]);
- this.addAnim('shoot', 0.05, [3, 2, 1, 0], true);
- this.lastShootTimer = new ig.Timer(0);
- this.shotDir = settings.shotDir || 'up';
- },
- update: function () {
- if (this.currentAnim.loopCount > 0) {
- this.currentAnim = this.anims.idle;
- }
- this.parent();
- this.parental = ig.game.boss;
- this.pos.x = this.parental.pos. x + 30
- if ((0 | (ig.Timer.time / this.rotSpeed * this.rotDist)) & 1) {
- this.currentAnim.angle += this.rotation * ig.system.tick;
- if (this.shotDir === 'up'){
- this.checkShoot();
- }
- }
- else {
- this.currentAnim.angle -= this.rotation * ig.system.tick;
- if (this.shotDir === 'down') {
- this.checkShoot();
- }
- }
- },
- checkShoot: function () {
- var isShooting = true;
- if (isShooting && this.lastShootTimer.delta() > 0) {
- this.shoot();
- this.lastShootTimer.set(this.shootSpeed);
- }
- },
- shoot: function () {
- ig.game.spawnEntity(EntityEnemyTurretBullet, this.pos.x, this.pos.y + 9, {
- angle: -this.currentAnim.angle,
- });
- },
- kill: function () {
- ig.game.spawnEntity(EntityExplosionParticleGrey, this.pos.x, this.pos.y, {
- count: 50,
- });
- ig.game.spawnEntity(EntityExplosionParticleRed, this.pos.x, this.pos.y, {
- count: 50,
- });
- this.MiniShipKill_sfx.play(); //TODO: Replace with new SFX
- this.parent();
- }
- });
- /*****************************
- * @EntityRotTurret
- * @Turret rotates around boss
- ****************************/
- EntityRotTurret = EntityBaseEnemy.extend({
- /*********************
- * Property Definitions
- *********************/
- animSheet: new ig.AnimationSheet('media/textures/actor-playerShip_R.png', 24, 24),
- soundShoot: new ig.Sound('media/sfx/Explode01.ogg' ),
- font: new ig.Font('media/fonts/xfinfont.png' ),
- size: {
- x: 20,
- y: 20
- },
- offset: {
- x: 0,
- y: 1
- },
- friction: {
- x: 800,
- y: 800
- },
- maxVel: {
- x: 300,
- y: 300
- },
- angle: -Math.PI / 2,
- speed: 200,
- health: 5,
- respawnDelay: 2,
- shootSpeed: 0.8,
- rotation: 0.5,
- rotDist: 1.2,
- rotSpeed: .1,
- lifeTimer: null,
- radius: 200, // How far away from center should hit area be positioned
- shotDir: 'up',
- type: ig.Entity.TYPE.B,
- checkAgainst: ig.Entity.TYPE.C,
- init: function (x, y, settings) {
- this.parent(x, y, settings);
- this.addAnim('idle', 60, [0]);
- this.addAnim('shoot', 0.05, [3, 2, 1, 0], true);
- this.lastShootTimer = new ig.Timer(0);
- this.shotDir = settings.shotDir || 'up';
- },
- update: function () {
- if (this.currentAnim.loopCount > 0) {
- this.currentAnim = this.anims.idle;
- }
- this.parent();
- this.parental = ig.game.boss;
- this.checkShoot();
- // Set position based on parental position
- var x = (this.parental.pos.x + this.parental.size.x / 2) + Math.cos(this.angle) * 70;
- var y = (this.parental.pos.y + this.parental.size.y / 2) + Math.sin(this.angle) * 70;
- // Rotate around boss
- this.pos.x = x;
- this.pos.y = y;
- this.angle += this.rotSpeed
- },
- checkShoot: function () {
- var isShooting = true;
- if (isShooting && this.lastShootTimer.delta() > 0) {
- this.shoot();
- this.lastShootTimer.set(this.shootSpeed);
- }
- },
- shoot: function () {
- ig.game.spawnEntity(EntityEnemyTurretBullet, this.pos.x, this.pos.y +9, {
- angle: -this.currentAnim.angle,
- });
- },
- kill: function () {
- ig.game.spawnEntity(EntityExplosionParticleGrey, this.pos.x, this.pos.y, {
- count: 50,
- });
- ig.game.spawnEntity(EntityExplosionParticleRed, this.pos.x, this.pos.y, {
- count: 50,
- });
- this.MiniShipKill_sfx.play(); //TODO: Replace with new SFX
- this.parent();
- }
- });
- /*********************************************************************************
- * @EntityWeakPoint
- * @Vulnerable spot on the boss for players to attack
- * @Params: accepts int to determine the X and Y pos offset based on boss location
- ********************************************************************************/
- EntityWeakPoint = EntityBaseEnemy.extend({
- animSheet: new ig.AnimationSheet('media/textures/hitBox.png', 40, 100),
- size:{
- x: 40,
- y: 100
- },
- xOffset: null,
- yOffset: null,
- health: 10,
- canTakeDmg: true,
- type: ig.Entity.TYPE.B,
- checkAgainst: ig.Entity.TYPE.C,
- collides: ig.Entity.COLLIDES.NEVER,
- init: function(x,y, settings) {
- this.parent(x,y, settings);
- this.addAnim('idle', 60, [0]);
- this.xOffset = settings.xOffset || this.xOffset;
- this.yOffset = settings.yOffset || this.yOffset;
- },
- update: function() {
- this.parent();
- this.parental = ig.game.boss;
- // Set position based on boss location + offset param passed in during init
- this.pos.x = this.parental.pos.x + this.xOffset;
- this.pos.y = this.parental.pos.y + this.yOffset;
- this.angle += this.rotSpeed
- },
- receiveDamage: function (value) {
- this.parent();
- if (!this.canTakeDmg) {
- return;
- }
- },
- });
- /**********************************
- * @window.EntityEnemyTurretBullet
- * @Shoots from enemy turret ships
- *********************************/
- EntityEnemyTurretBullet = ig.Entity.extend({
- image: new ig.Image('media/textures/plasma_b_R.png'),
- speed: {
- x: -30,
- y: 150
- },
- /* This looks pretty awesome */
- //speed: {
- // x: 0,
- // y: 100
- //},
- size: {
- x: 8,
- y: 6
- },
- offset: {
- x: 20,
- y: 16
- },
- friction: {
- x: 0,
- y: 15
- },
- speedModifier: 5,
- type: ig.Entity.TYPE.C,
- checkAgainst: ig.Entity.TYPE.A,
- collides: ig.Entity.COLLIDES.PASSIVE,
- init: function (x, y, settings) {
- this.parent(x, y, settings);
- this.vel.x = Math.cos(this.angle) * this.speed.y;
- this.vel.y = Math.sin(this.angle) * this.speed.y;
- },
- draw: function () {
- ig.system.context.save();
- ig.system.context.translate(this.pos.x - ig.game._rscreen.x, this.pos.y - ig.game._rscreen.y);
- ig.system.context.rotate(-this.angle);
- ig.system.context.drawImage(this.image.data, -this.offset.x, -this.offset.y);
- ig.system.context.restore();
- },
- update: function () {
- this.parent();
- this.pos.x -= this.vel.x * ig.system.tick * this.speedModifier;
- this.pos.y += this.vel.y * ig.system.tick / 2;
- if (this.pos.x > ig.system.width + 50 ||
- this.pos.y > ig.system.height + 50 ||
- this.pos.x < -50 || this.pos.y < -50) {
- this.kill();
- }
- },
- check: function (other) {
- if (other instanceof EntityActorPlayer) {
- other.receiveDamage(1, this);
- this.kill();
- }
- }
- });
- });
RAW Paste Data