Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************8
- * StationaryShip.js
- * Small ship that helps the player and remains stationary
- * @copyright (c) 2013 Dave Voyles, under The MIT License (see LICENSE)
- *********************************************************************/
- // PROBLEM: The "else" statement is always spawning the ship. Why is it defaulting to bCanSpawnShips to
- // false? It *should* spawn the top shop (the "if") statement, THEN if pressed again, spawn the "else"
- ig.module(
- 'game.entities.StationaryShip'
- )
- .requires(
- 'game.entities.player'
- )
- .defines(function()
- {
- EntityStationaryShip = EntityPlayer.extend({
- name: 'StationaryShip',
- parental:null,
- type:ig.Entity.TYPE.NONE,
- checkAgainst: ig.Entity.TYPE.B, // Check Against B - our evil enemy group
- collides: ig.Entity.COLLIDES.PASSIVE,
- angle:0,
- bShipExists: false,
- maxShips: 2,
- currentShips: 0,
- bCanSpawnShips: true,
- /******************************************8
- * Initialize
- ******************************************/
- init: function(x,y,settings){
- this.parent( x, y, settings );
- bShipExists = false;
- currentShips = 0;
- maxShips = 2;
- bCanSpawnShips = true;
- },
- /******************************************8
- * Update
- ******************************************/
- update:function(x,y,settings){
- this.parental = ig.game.getEntitiesByType(EntityPlayer)[0];
- // Spawning location of ships
- var offsetX = 20;
- var offsetY = 40;
- // Spawn ships when "X" button is hit
- if (bCanSpawnShips == true){
- x = this.parental.pos.x + offsetX;
- y = this.parental.pos.y + offsetY;
- bShipExists = true;
- currentShips++;
- }
- else{
- x = this.parental.pos.x + offsetX;
- y = this.parental.pos.y - offsetY;
- currentShips++;
- }
- if (currentShips > maxShips){
- canSpawnShips = false;
- currentShips = maxShips;
- }
- // Sets current position
- this.pos.x = x;
- this.pos.y = y;
- },
- /******************************************8
- * Handle Movements
- ******************************************/
- handleMovementTrace: function( res ) {
- this.parent( res );
- },
- // This function is called when this entity overlaps anonther entity of the
- // checkAgainst group. I.e. for this entity, all entities in the B group.
- check: function( other ) {
- other.receiveDamage( 0, this );
- this.kill();
- // canSpawnShips = true;
- // currentShips --;
- }
- });
- });
RAW Paste Data