Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************8
- * EnemyBullet.js & EnemyGun.js
- * Creates bullet patterns for enemies, along with a bullet manager
- * Basis of this was found at: http://phoboslab.org/xtype/xtype.js
- * @copyright (c) 2013 Dave Voyles, under The MIT License (see LICENSE)
- *********************************************************/
- ig.module(
- 'game.entities.EnemyBullet'
- )
- .requires(
- 'game.entities.BaseWeapon'
- )
- .defines(function () {
- /******************************************8
- * Enemy Bullet
- ******************************************/
- EntityEnemyBullet = EntityBaseWeapon.extend({
- size: { x: 16, y: 2 },
- offset: { x: 1, y: 8 },
- animSheet: new ig.AnimationSheet('media/bullet_neon.png', 16, 16),
- maxVel: {x: 100, y: 70},
- health: 10,
- speed: 10,
- angle:60,
- maxSpeed: 80,
- type: ig.Entity.TYPE.B,
- checkAgainst: ig.Entity.TYPE.A,
- collides: ig.Entity.COLLIDES.PASSIVE,
- /******************************************8
- * Initialization
- ******************************************/
- init: function(x,y,settings){
- this.parent(x,y,settings);
- this.addAnim('idle', 1, [0]);
- this.angle = this.angle;
- },
- update: function () {
- this.parent();
- this.speed = Math.min(this.maxSpeed, this.speed + ig.system.tick * 100);
- this.vel.x = Math.cos(this.angle) * this.speed;
- this.vel.y = Math.sin(this.angle) * this.speed;
- },
- handleMovementTrace: function( res ) {
- this.parent( res );
- if( res.collision.y || res.collision.x ) {
- this.kill();
- }
- }
- });
- /******************************************8
- * Enemy Gun (Bullet Manager)
- ******************************************/
- EntityEnemyGun = ig.Entity.extend({
- bullets: 6,
- firingTimer: null,
- reloadTime: 2,
- /******************************************8
- * Initialization
- ******************************************/
- init: function (x, y, settings) {
- this.parent(x, y, settings);
- this.firingTimer = new ig.Timer(Math.random() * this.reloadTime * 2);
- this.shootTimer = new ig.Timer(3);
- },
- /******************************************8
- * Update
- ******************************************/
- update: function() {
- this.parent();
- if (this.shootTimer.delta() > 0) {
- var inc = 120 / (this.bullets - 1);
- // The angle which the bullet leaves the weapon/enemy
- var a2 = 110;
- var radius = 5;
- for (var i = 0; i < this.bullets; i++) {
- var angle = a2 * Math.PI / 180;
- var x = this.pos.x + 24 + Math.cos(angle) * radius;
- var y = this.pos.y + 44 + Math.sin(angle) * radius;
- // Attaches bullet to weapon
- ig.game.spawnEntity(EntityEnemyBullet, x-25, y -40, {
- angle: angle
- });
- a2 += inc;
- }
- this.shootTimer.reset();
- }
- }
- });
- });
RAW Paste Data