Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                h1 
.container
  #game
  p(style="color:white; font-weight:bold; margin-top:2em; font-size:18px;") Arrow keys to move, CTRL to shoot. Wall-jumping is on so try sliding on walls!

    
script(src="https://dl.dropbox.com/s/bbp1pq4nj678k93/pngData.js?dl=1")
script(src="//cdnjs.cloudflare.com/ajax/libs/phaser/2.1.3/custom/pixi.min.js")
script(src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.2.2/phaser.min.js")
script(src="https://dl.dropbox.com/s/g3bqtuukce9enx1/player.js?dl=1")
script(src="https://dl.dropbox.com/s/eb6fu5hvggd5prl/entities.js?dl=1")
script(src="https://dl.dropbox.com/s/1fdr67mqmpf22uz/slopeCollisions.js?dl=1")
script(src="https://dl.dropbox.com/s/2zhvn48ezpsff07/phaserStateTransitions.js?dl=1")
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=VT323);

body{
  background: #282828;
  
}
.container{
  width:650px;
  margin:0 auto;
  padding:10px;
}
#game{
  display:block;
  margin:0 auto;
  max-width:100%;
}
              
            
!

JS

              
                window.onload = (function(){
	"use strict";
	var game;
	var BootState = function(game){
		console.log("%c booting system; heart[startPumping[80]] ", "color:white; background:#3bcbe0");
	} 
	var PreloadState = function(game){};
	var TitleState = function(game){};
	var SceneState = function(game){};
	var GameOverState = function(game){};
  var TransitionState = function(game){};

	//bootstate
	BootState.prototype={
		preload: function(){
			this.game.load.image('preload', preloadData)
		},
		create: function(){
			this.game.state.start('Preload');
		}
	}

	//preload state
	PreloadState.prototype = {
		preload: function(){

      	//add images
      	this.pngImages = {};
     		this.cachedImages = {};
      	this.imageData = imageArray;
      
		this.addImage('andro', {w:32, h:33, frames:60});
    this.addImage('enemy', {w:32, h:32, frames: 64})
      	this.addImage('tile', {w:25, h:25, frames:240});
      this.addImage('particle', {w:2, h:2, frames:5});
      	this.addImage('atmospherics', {w:25, h:25, frames:240});
      this.addImage('pshot', {w:20, h:14, frames:8});
      this.addImage('roboPieces', {w:10, h:10, frames:10});
      this.addImage('hudIcons', {w:30, h:30, frames:1});
      this.game.load.image('androArm', this.imageData['androArm']);
      this.addImage('saw', {w:50, h:50, frames:4});
      

			//maps
			this.game.gameMaps = {
				'beginning': {tiles:'tileSheet', file:'https://dl.dropbox.com/s/lvtzt4njm29ceww/beginning.json?dl=1', background:''},
				'shaft': {tiles:'tileSheet', file:'https://dl.dropbox.com/s/xobcbso927v5aek/theShaft.json?dl=1', background:''},
			};
		},
		create: function(){
			this.studio = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'preload');
			this.studio.anchor.setTo(.5);
			this.timer = Date.now();
		},
    addImage: function(name, sheet){
        if(!sheet || sheet == undefined){
        sheet = false;
        }
        if(this.imageData.hasOwnProperty(name)){
          var imageName, imageDataURI, theImage;
          imageDataURI = this.imageData[name]
          this.pngImages[name] = new Image();
          this.pngImages[name].src = imageDataURI;
          imageName = ''+name;
          theImage = this.pngImages[name];
          this.game.cache.addImage(imageName, imageDataURI, theImage);
          //create spritesheet

          if(sheet){
            var sheetName, cachedImage;
            cachedImage = this.game.cache.getImage(imageName).src;
            sheetName = imageName + 'Sheet';
            this.game.load.spritesheet(sheetName, cachedImage, sheet.w, sheet.h, sheet.frames);
			}
		}
    },
		update: function(){
			var timeNow, fadeout;

			fadeout = false;
			timeNow = Date.now();

			if(timeNow - this.timer >= 1000){
				this.fadeout = true;
				this.timer = timeNow;
			}

			if(this.studio.alpha <= 0){
				this.game.time.events.add(500, (function(){
					this.game.state.start('Title');
				}), this)
			}

			if(this.fadeout){
				if(timeNow - this.timer >= 50){
					this.timer = timeNow;
					this.studio.alpha -= .05;
				}
			}

		}
	}

	//title state

	TitleState.prototype = {
		preload: function(){

		},
		create: function(){
			this.pressStartText = this.game.add.text(this.game.world.centerX, this.game.world.centerY + 100, "Press Spacebar to Start", {fill:'#fff', font:'16px arial'});
			this.pressStartText.anchor.setTo(.5);
			this.preloadTimer = Date.now();

			//capture and use spacebar
			this.game.input.keyboard.addKeyCapture(Phaser.Keyboard.SPACEBAR);
			this.startKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
		},
		update: function(){
			var nowTime = Date.now();
			if(nowTime - this.preloadTimer >= 200){
				this.preloadTimer = nowTime; 
				this.pressStartText.alpha = this.pressStartText.alpha == 1 ? .5 : 1; 
			}

			if(this.startKey.isDown){
				this.game.state.start('Scene', true, false, {scene:'beginning', type:'level'});
			}
		}
	}

	//scene state

	SceneState.prototype = {
		init: function(sceneData){
      console.log('start scene')
			this.sceneData = sceneData;
			this.scene = sceneData['scene'];
			this.followPlayer = sceneData['followPlayer'] || true;
			this.startPoint = sceneData['point'] || false;
		},
		preload: function(){
      
			this.map = this.game.gameMaps[this.scene];
      
			this.game.load.tilemap('currentMap', this.map.file, null, Phaser.Tilemap.TILED_JSON);

		},
		create: function(){
			var backgroundLayer, midgroundLayer, foregroundLayer, tiles, hazards, platforms, sprites, enemies, npcs, renderGroup;
			this.game.playerKilled = false;
			this.currentTime = Date.now();
			this.game.stage.backgroundColor = "#585858";
			this.backgroundSprite = this.game.add.tileSprite(0,0,600, 400, this.map.background);

			//physics
			this.game.physics.startSystem('Phaser.Physics.ARCADE');

			//inputs
			this.cursor = this.game.input.keyboard.createCursorKeys();
			this.game.input.keyboard.addKeyCapture(Phaser.Keyboard.SPACEBAR);
			this.game.input.keyboard.addKeyCapture(Phaser.Keyboard.CONTROL)
			this.cursor.jump = this.game.input.keyboard.addKey(Phaser.Keyboard.UP);
			this.cursor.power = this.game.input.keyboard.addKey(Phaser.Keyboard.DOWN);
			this.cursor.attack = this.game.input.keyboard.addKey(Phaser.Keyboard.CONTROL);

			this.altCursor = {
				left:this.game.input.keyboard.addKey(Phaser.Keyboard.A),
				right:this.game.input.keyboard.addKey(Phaser.Keyboard.D),
				jump:this.game.input.keyboard.addKey(Phaser.Keyboard.W),
				power:this.game.input.keyboard.addKey(Phaser.Keyboard.S),
				attack:this.game.input.keyboard.addKey(Phaser.Keyboard.J)
			}


			//Game Settings
			this.settings = {
				playerSpeed: 150,
				playerAirSpeed: 120,
				playerJump: 280,
        playerSecondJump:250,
				playerWidth: 15,
				playerHeight:31,
				playerGravity:750,
				playerAttackDelay: 400,
        hitDelay: 200,
				invincibleDelay: 1500,
			}

			//Player Stats
			this.defaultStats = {
        maxHealth: 10,
        health:10,
				defense:0,
				attack: 3,
        canDoubleJump:false,
        canDash:false,
        canClimb:true,
			}

			//create HUD including item messages
			this.hud = this.game.add.group();
      this.hudObjects = {};
			sprites = this.game.add.group();
      this.effects = this.game.add.group();
     

			//build world, place player
			this.backgroundLayer = this.game.add.group();
			this.atmosphericsLayer = this.game.add.group();
			this.midgroundLayer = this.game.add.group();
			this.foregroundLayer = this.game.add.group();
			this.nonColTiles = this.game.add.group();
			this.platforms = this.game.add.group();
			this.monoPlatforms = this.game.add.group();
      this.slopeTiles = this.game.add.group();
			this.possibleStartPoints = {};
		    this.playerX =0;
		    this.playerY= 0;
		    this.playerScale = 1;
			this.buildWorld();

			//add objects and entities
			this.enemies = this.game.add.group();
			this.npcs = this.game.add.group();
			this.hazards = this.game.add.group();
			this.pathFinders = this.game.add.group();
			this.doors = this.game.add.group();
			this.addGameObjects();

      
			if(this.startPoint){
				var sp = this.possibleStartPoints[this.startPoint];
				this.playerX = sp.x + (50*sp.direction);
				this.playerY = sp.y;
        this.playerScale =sp.direction;
			}
			//move player to appropriate start point
			this.player = new Player(this.game,this.playerX, this.playerY,'androSheet');
			this.player.build(this.settings, this.cursor, this.input.keyboard, this.hudObjects);
      this.player.scale.x = this.playerScale;
			sprites.add(this.player);
      
      //add hud
      this.addHUD();
      
      //add player stats
      
			if(this.sceneData.currentStats){
			
        this.player.setStats(this.sceneData.currentStats);
			}else{
				this.player.setStats(this.defaultStats)
			}

			//sort objects by zIndex and add to render group
			this.renderGroup = this.game.add.group();
     
this.renderGroup.add(this.backgroundLayer);
      this.renderGroup.add(this.hazards);	this.renderGroup.add(this.nonColTiles);
			this.renderGroup.add(this.enemies);
			this.renderGroup.add(sprites);
			this.renderGroup.add(this.foregroundLayer);
			this.renderGroup.add(this.atmosphericsLayer);
      //make laserblasts and stuff atmosphere-independant
      if(this.player){
        this.effects.add(this.player.bullets)
      }
      this.renderGroup.add(this.effects);
      this.renderGroup.add(this.hud);
		},
		buildWorld: function(){
		var layers, tileWidth, tileHeight, cIndex, tilesON;

		this.platforms.enableBody = true;
		this.monoPlatforms.enableBody = true;
    this.slopeTiles.enableBody = true;
		this.map.tileMap = this.game.add.tilemap('currentMap');
		tileWidth = this.map.tileMap.tileWidth;
		tileHeight = this.map.tileMap.tileHeight;
		layers = {};
		this.sceneObjects = {}; //to hold all the objects for later use in 'addObjects()'


	    //debug option for tile rendering
	    tilesON = true;
		this.wallSprite = tilesON ? '' : 'bleh';

		//set level world bounds
     	this.game.world.setBounds(0,0,this.map.tileMap.widthInPixels, this.map.tileMap.heightInPixels);
     	if(this.backgroundSprite){
     		this.backgroundSprite.width = this.map.tileMap.widthInPixels;
			this.backgroundSprite.height = this.map.tileMap.heightInPixels;
     	}

     	//parse out tile and collision layers
     	for(var i = 0; i < this.map.tileMap.layers.length; i++){
	        var l = this.map.tileMap.layers[i];
	        if(l.name == "Tile Layer 1" || l.name == 'tiles'){
	          layers.tiles = l.data;
	        }
        
          if(l.name == 'background'){
            layers.background = l.data;
          }

          	if(l.name == 'atmospherics' || l.name == 'atmospheric'){
          		layers.atmospherics = l.data;
          	}
	        
	        if(l.name == 'collision'){
	          layers.collision = l.data;
	        }

	        if(l.name == 'foreground'){
	        	layers.foreground = l.data;
	        }

	        if(l.name=='background'){
	        	layers.background = l.data;
	        }
	    }

	    //add the collision tiles
	    cIndex = {
	    	'full': 341,
	    	'mono': 347,
        'upRight': 343,
	    }
	    for(var i = 0; i < layers.collision.length; i++){
	    	var row = layers.collision[i];
	    	for(var c = 0; c < row.length; c++){
	    		var col, index;
	    		col = row[c];
	    		index = col.index;
	    		if(index == cIndex['full']){
	    			var cTile = this.game.add.sprite(col.worldX, col.worldY + 2, this.wallSprite);
	    			cTile.width = col.width;
	    			cTile.height = col.height;
	    			cTile.anchor.setTo(0)
	    			this.platforms.add(cTile);
	    		}
	    		//monodirectional tiles
	    		if(index == cIndex['mono']){
	    			var cTile = this.monoPlatforms.create(col.worldX, col.worldY + 4, '');
	    			cTile.width = col.width;
	    			cTile.height = col.height / 3;
	    			cTile.anchor.setTo(0)
	    		}
          //slopes
          if(index == cIndex['upRight']){
            var sTile =this.game.add.sprite(col.worldX, col.worldY + 4, '', 0, this.slopeTiles);
            sTile.width = col.width;
            sTile.height = col.height;
            sTile.anchor.setTo(0);
            sTile.slope = "HALF_TRIANGLE_BOTTOM_RIGHT";
          }
	    	}
	    }
      
      	//atmospheric tiles
	      if(layers.atmospherics){
	        for(var i=0; i< layers.atmospherics.length; i++){
	          var row = layers.atmospherics[i];

	          for(var j=0; j<row.length; j++){
	            var col = row[j];

		            if(col.index !== -1){
		              var tile, tileX , tileY, tileI;
		              tileX = col.worldX;
		              tileY = col.worldY;
		              tileI = col.index - 352;
		              tile = this.game.add.sprite(tileX, tileY, 'atmosphericsSheet', tileI - 1, this.atmosphericsLayer);
		          	}
	        	}
	       	}
         
	   	  }

		//background tiles
	      if(layers.background){
	        for(var i=0; i< layers.background.length; i++){
	          var row = layers.background[i];

	          for(var j=0; j<row.length; j++){
	            var col = row[j];

		            if(col.index !== -1){
		              var tile, tileX , tileY, tileI;
		              tileX = col.worldX;
		              tileY = col.worldY;
		              tileI = col.index;
		              tile = this.game.add.sprite(tileX, tileY, this.map.tiles, tileI - 1, this.backgroundLayer);
		          	}
	        	}
	       	}
	   	  }
	    //render tiles
	    if(tilesON){
	    	for(var i=0; i<layers.tiles.length; i++){
				var row = layers.tiles[i];

				for(var j=0; j<row.length; j++){
					var col = row[j];

					if(col.index !== -1){
						var tile, tileX , tileY, tileI;
						tileX = col.worldX;
						tileY = col.worldY;
						tileI = col.index;
						tile = this.game.add.sprite(tileX, tileY, this.map.tiles, tileI - 1, this.nonColTiles);
         
					}
				}
			}
	    }

	    //foreground 
	    if(tilesON && layers.foreground){
	    	for(var i=0; i<layers.foreground.length; i++){
				var row=layers.foreground[i];
				for(var j=0; j<row.length; j++){
					var col = row[j];
					if(col.index !== -1){
						var tile, tileX , tileY, tileI;
						tileX = col.worldX;
						tileY = col.worldY;
						tileI = col.index;
						tile = this.game.add.sprite(tileX, tileY, 'tileSheet', tileI - 1, this.foregroundLayer);
					}
				}
			}
	    }

	    //walls for uniform, read, no-edge walling
		layers.walls = this.map.tileMap.objects.walls;

        for(var o = 0; o < layers.walls.length; o++){
            var ob = layers.walls[o];
            //walls
            var w, h, wall;
            w = parseInt(ob.properties.width);
            h = parseInt(ob.properties.height);
            wall = this.game.add.sprite(ob.x, ob.y - tileHeight + 2, this.wallSprite, 0, this.platforms);
            wall.anchor.setTo(0,0);
            wall.width = w * tileWidth;
            wall.height = h * tileHeight;
        }

        //objects
        layers.objects = this.map.tileMap.objects.objects;
        for(var i = 0; i < layers.objects.length; i++){
        	var ob = layers.objects[i];

        	//playercoords
        	if(ob.name == "player"){
        		this.playerX = ob.x;
        		this.playerY = ob.y -
            this.settings.playerHeight; 
            console.log('setting player to '+ob.x, ob.y)
        	}

        	//enemies
        	if(ob.name == "enemy"){
        		if(!this.sceneObjects.enemies){
        			this.sceneObjects.enemies = new Array();
        		}
        		this.sceneObjects.enemies.push(
	        		{
	        			x: ob.x,
	        			y: ob.y,
	        			type: ob.properties.type	
	        		}
        		)
        	}
          //hazards
          if(ob.name == 'hazard'){
           if(!this.sceneObjects.hazards){
             this.sceneObjects.hazards = new Array();
           }
            this.sceneObjects.hazards.push(
            	{
                x:ob.x,
                y:ob.y,
                type: ob.properties.type
              }
            )
          }

        	//doors
        	if(ob.name == "door"){
        		if(!this.sceneObjects.doors){
        			this.sceneObjects.doors = new Array();
        		}
        		this.sceneObjects.doors.push(
        			{
        				x:ob.x,
        				y:ob.y,
        				toScene: ob.properties.toScene,
        				toPoint:ob.properties.toPoint,
        				point:ob.properties.point,
        				direction:ob.properties.direction,
        				width:parseInt(ob.properties.width) || 1,
        				height:parseInt(ob.properties.height) || 1
        			}
        		)
        	}

        	//enemy pathfinders
        	if(ob.name == 'pathfinder'){
        		if(!this.sceneObjects.pathFinders){
        			this.sceneObjects.pathFinders = new Array();
        		}
        		this.sceneObjects.pathFinders.push({
        			x:ob.x,
        			y:ob.y,
        			right:ob.properties.right || '',
        			left:ob.properties.left || ''
        		})
        	}


        }
		this.platforms.setAll('body.immovable', true);
		this.monoPlatforms.setAll('body.immovable', true);
		this.monoPlatforms.forEach((function(mp){
			mp.body.checkCollision.down = false;
			mp.body.checkCollision.left = false;
			mp.body.checkCollision.right = false;
		}), this)
    this.slopeTiles.setAll('body.immovable', true);
	},
	addGameObjects: function(){
		if(this.sceneObjects){
			//doors
			if(this.sceneObjects.doors){

			}
      
      //hazards
      if(this.sceneObjects.hazards){
        var hazardSheets = {
          'saw': 'sawSheet'
        }
        this.sceneObjects.hazards.forEach((function(hazard){
          var h = new hazards[hazard.type](this.game, hazard.x, hazard.y, hazardSheets[hazard.type]);
        h.build();
        this.hazards.add(h);
        }), this);
      }

			//enemies
			if(this.sceneObjects.enemies){
				this.sceneObjects.enemies.forEach((function(enemy){
					var b = new bestiary[enemy.type](this.game, enemy.x, enemy.y, 'enemySheet')
					b.build();
					this.enemies.add(b);
          b.setTextLayer(this.atmosphericsLayer);
				}), this);
			}
      
			//pathfinders
			if(this.sceneObjects.pathFinders){
				this.sceneObjects.pathFinders.forEach((function(pathFinder){
					var pf = new Pathfinder(this.game, pathFinder.x, pathFinder.y, this.wallSprite, 3);
					pf.build({left:pathFinder.left, right:pathFinder.right});
					this.pathFinders.add(pf);
				}), this)
			}

			//doors
			if(this.sceneObjects.doors){
				this.sceneObjects.doors.forEach((function(door){
					var d = new Door(this.game, door.x, door.y, this.wallSprite);
					d.build({
						point: door.point,
						toPoint: door.toPoint,
						toScene: door.toScene,
						direction: door.direction,
						width:door.width,
						height:door.height
					});
					this.doors.add(d);
					this.possibleStartPoints[d.point] = {x: parseInt(d.x), y:parseInt(d.y), direction:parseInt(d.direction)};
				}), this)
			}
		}//sceneobjects?
	},
  addHUD: function(){
    this.hudObjects.healthbarOutline = this.game.add.graphics(49, 19);
    this.hudObjects.healthbarOutline.beginFill(0xFFFFFF, 0.5);
    this.hudObjects.healthbarOutline.lineWidth = 2;
    this.hudObjects.healthbarOutline.drawRect(0,0,77,17);
    this.hudObjects.healthbarOutline.boundsPadding = 0;
    
    this.hudObjects.healthbarShadow = this.game.add.graphics(52, 23);
    this.hudObjects.healthbarShadow.beginFill(0x000000, 0.3);
    this.hudObjects.healthbarShadow.drawRect(0,0,75,15)
    this.hudObjects.healthbarShadow.boundsPadding = 0;
    
    //healthbar background
    this.hudObjects.healthbarBackground = this.game.add.graphics( 50, 20 );
		this.hudObjects.healthbarBackground.beginFill(0xFF0000, .6);
		this.hudObjects.healthbarBackground.drawRect(0, 0, 75, 15);
    this.hudObjects.healthbarBackground.boundsPadding = 0;
    
    //health
    this.hudObjects.healthbarHealth = this.game.add.graphics( 50, 20 );
		this.hudObjects.healthbarHealth.beginFill(0x07DEF8, 1);
		this.hudObjects.healthbarHealth.drawRect(0, 0, 75, 15);
    this.hudObjects.healthbarHealth.boundsPadding = 0;
    
    //health icon
    this.hudObjects.healthIcon = this.game.add.sprite(25, 12, 'hudIconsSheet', 0);
   
    
    
    

    this.hud.add(this.hudObjects.healthbarOutline);   
    this.hud.add(this.hudObjects.healthbarShadow);
    this.hud.add(this.hudObjects.healthbarBackground);
    this.hud.add(this.hudObjects.healthbarHealth);
    this.hud.add(this.hudObjects.healthIcon);
    
    this.hud.add(this.player.dmgTexts)
    
  },//HUD
	update:function(){
    var worldX, worldY;
		this.doCollisions();
    
    //check for gameover
    if(this.game.playerKilled){
      this.game.time.events.add(1000, (function(){	
        this.game.state.start('GameOver', true, false, this.sceneData);
      }), this);
    }

		//camera
		if(this.followPlayer){
			this.camera.focusOnXY(this.player.x, this.player.y -50 )
		}
    //move hud with screen
		worldX = this.game.world.x * -1;
		worldY = this.game.world.y * -1;
    
    this.hud.x = worldX;
    this.hud.y = worldY;
	},
	doCollisions: function(){
		this.game.physics.arcade.collide(this.player, this.platforms, (function(player, platform){
			if(this.player.highImpact){
				this.player.highImpact = false;
			}
		}), null, this);
	
this.player.onMono = false;    this.game.physics.arcade.collide(this.player, this.monoPlatforms, (function(player, platform){
			if(player.body.touching.down){
        this.player.onMono = true;
      }else{
        this.player.onMono = false;
      }
		}), (function(player, tile){
        player.body.moves = true;
        if(this.player.ghosting && tile.body.velocity.y <= 0){
          player.body.moves= false;
          player.y += 2;
          this.player.body.velocity.y = 120
        }else{
          player.moves = true;
        }
      }), this);
    
     this.player.body.onStairs = false; this.game.physics.arcade.collideSpriteVsSlopeLayer(this.player, this.slopeTiles)

		//enemies and platforms
		this.game.physics.arcade.collide(this.enemies, this.platforms);
    
    this.game.physics.arcade.collide(this.enemies, this.monoPlatforms);
    
    //pathfinders and enemies
		this.game.physics.arcade.collide(this.pathFinders, this.enemies, (function(a,b){
			var funcSet = b.body.velocity.x > 0 ? a.right : a.left;
			var match;
			for( var i = funcSet.length; i >= 0; i--){
				if(typeof b[funcSet[i]] === 'function'){
					match = funcSet[i];
				}
			}
			if(typeof b[match] === 'function'){
				b[match]();
			}else{
				return false;
			}
		}), null, this)


    //player and enemies
    this.game.physics.arcade.collide(this.player, this.enemies,(function(player, enemy){
      var x, y;
      x = player.x <= enemy.x ? 1 : -1;
      y = player.y >= enemy.y ? 1 : -1;
      player.takeDamage(enemy.attack, {x:x, y:y});
   }), null, this);
    
    //bullets and enemies
    this.game.physics.arcade.overlap(this.player.bullets, this.enemies, (function(bullet, enemy){
      var pow = bullet.power,
          type = bullet.type ? bullet.type : 'energy';
      enemy.enemyHit(pow);
      bullet.kill();
    }), null, this);
    
    //player and hazards
    this.game.physics.arcade.collide(this.player, this.hazards, (function(player, hazard){
       var dmg = hazard.damage;
      player.takeDamage(dmg);
    }), null, this)
    
    //bullets and walls
    this.game.physics.arcade.overlap(this.player.bullets, this.platforms, (function(bullet, platform){
      	bullet.kill();
    }), null, this)
    
    //player and doors
    this.game.physics.arcade.collide(this.player, this.doors, (function(player, door){
      this.transitionScene(door.toScene, door.toPoint);
    }), null, this)
    this.game.physics.arcade.collide(this.player.roboPiecesEmitter, this.platforms)
	},//do collisions
    
  //scene transitions
  transitionScene:function(scene, point){
    var stats = this.player.stats;
    this.game.state.start("Transition", true, false, {scene:scene, point:point, type:'level', currentStats:stats} )
   
  }//transition scene
    
    
 }

TransitionState.prototype={
   init:function(stateInfo){
     this.stateInfo = stateInfo;
   },
   create: function(){
      this.game.stage.backgroundColor = 0x282828;
      this.game.state.start('Scene', true, false, this.stateInfo);
   }
}

GameOverState.prototype = {
   init: function(sceneData){
       this.sceneData = sceneData
   },
  create: function(){
     this.game.world.setBounds(0,0,600,400);
     this.gameOverText = this.game.add.text(this.game.world.centerX, this.game.world.centerY, "You died.", {fill:"#FFF"});
    this.gameOverText.anchor.setTo(.5);
    
    this.pressSpaceText = this.game.add.text(this.game.world.centerX, this.game.world.centerY + 50, "Press space to continue, ok?", {fill:"#FFF", font:"bold 14px arial"});
    this.pressSpaceText.anchor.setTo(0.5);
    this.game.input.keyboard.addKeyCapture(Phaser.Keyboard.SPACEBAR);
			this.startKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
  },
  update: function(){
    this.pressSpaceText.alpha -= 0.01;
    if(this.pressSpaceText.alpha <= 0.4){
      this.pressSpaceText.alpha = 1; 
    }
    
    //restart
    if(this.startKey.isDown){
      this.game.state.start('Scene', true, false, this.sceneData)
    }
  }
  
}

	//START THE GAME
	game = new Phaser.Game(600, 400, Phaser.AUTO, 'game');

	game.state.add('Boot', BootState);
	game.state.add('Preload', PreloadState);
	game.state.add('Title', TitleState);
	game.state.add('Scene', SceneState);
  game.state.add('Transition', TransitionState);
	game.state.add('GameOver', GameOverState);

	game.state.start('Boot');
})
              
            
!
999px

Console