cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              .container
  h1 Kid Erebus
  h2 (Kid Tartarus in dev)
  h3 Good luck...lol
  #data
    #hud
    #rates
  #game
  
  
  #tweet <a id="tweetLink" href="https://twitter.com/share?url=http://codepen.io/ebrewe/full/myVmgN/" target="_blank"><i class="fa fa-twitter"></i> Tweet This Score!</a>

  .controls
    h2 Use Arrow Keys & Spacebar
    .row
      .control.up.clearfix
        i.fa.fa-arrow-up
    .row
      .control.cleft
        i.fa.fa-arrow-left
      .control.down
        i.fa.fa-arrow-down
      .control.cright
        i.fa.fa-arrow-right
      span.plus +
      .control.spacebar SPACE
    .row.directions
      div <i class="fa fa-arrow-left"></i> Left & <i class="fa fa-arrow-right"></i> Right to move, <br>
      | <i class="fa fa-arrow-up"></i> Up to Jump<br>
      | <i class="fa fa-arrow-down"></i> Down to power up when you have 10 * current power in souls (40 souls to raise to power 5)<br>
      |Spacebar to shoot
      | <br>
      | <span># of Bosses remaining, if any, is shown at top-right, KILL THEM ALL!</span><br><br>
      |Souls serve as hit points and power ups, so upgrade wisely. <br>
      |Once time runs to 0, your souls will drain until you die. Run run!!
      
  .hints
    <h3>Hints:</h3>
    p - If time is running low, stock up on souls to buffer your health against the ensuing drain.
    p - Souls are the source of your defense as well as your offense; you can be the most powerful man in the underworld, but if your souls are too low, you'll die with one hit.
    p - Some enemies(like bosses) have armor ratings (like around 5ish) so you can't even hurt them if your power is too low.
    p -... you won't be able to hurt the bosses unless your power is over 5, is basically what I'm saying.
    p - BUT! If your power is way higher than an enemy's vitality, you can drive arrows right through them and damage multiple enemies! 

    p ---------
    

  
script(src="//cdnjs.cloudflare.com/ajax/libs/phaser/2.1.3/custom/pixi.min.js")
script(src="//cdnjs.cloudflare.com/ajax/libs/phaser/2.1.3/phaser.min.js")

            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Press+Start+2P);

$font: 'press start 2p';

body{
  background:#444;
}

.container{
  display:block;
  position:relative;
  width:90%;
  max-width:600px;
  margin:60px auto 60px;
}

.hints{
  margin-top:2em;
  font:16px/22px 'press start 2p';
  
}

  h3{
    font-family:'press start 2p';
    font-size:18px;
  }

.directions {
  margin-top:2em;
  font:16px/22px 'press start 2p';
  span{
    color:#efefef;
  }
}

#tweet{
  display:none;
  position:absolute;
  top:360px;
  width:500px;
  font:16px 'press start 2p';
  text-align:center;
  a{
    color:white;
    border-bottom:1px solid white; 
    padding-bottom:10px;
    &:focus, &:hover{
      color:#e07719;
      border-bottom-color:#e07719;
    }
  }
}

h1{
  margin-bottom:10px;
  font-family:$font;
  font-size:20px;
}
h2{
  font-family:$font;
  font-size:17px;
  margin:10px 0;
}
.control{
  display:block;
  float:left;
  position:relative;
  padding:8px 20px;
  background:#e8e8e8;
  border-radius:4px;
  color:#4d4d4d;
  //border-bottom:8px solid #ccc;
  box-shadow:0 8px 0 #aaa;
  z-index:2;
  
  &.up{
    left:55px;
    //margin-bottom:1px;
    z-index:-1;
  }
  
  &.spacebar{
    font-weight:bold;
    padding:8px 50px;
  }
}
.plus{
  display:block;
  float:left;
  margin:0 20px;
  font:bold 20px $font;
  line-height:60px;
}


#fi{
  transition: all .2s linear;
}
#fi.hide {
  opacity:0;
}
            
          
!
            
              

(function(){
  
  //be cool, support game development!
  var supportTimer = setTimeout((function(){
    $('#fi').removeClass('hide');
  }), 3000);
  
  var game, gameState
// --------- boot ---------------
var bootState = function(game){
	console.log("%c " +String.fromCharCode(9835) + " Hear me, oh Muses, and pray sing the myth / of the Hero known as Kid Tartarus "  +String.fromCharCode(9835) +" ", "color:white; background:#e07719")
};

bootState.prototype={
	preload: function(){
		var preloadImage = new Image();
     var preloadDataUri = preloadData
    	  preloadImage.src = preloadDataUri;
    
    game.cache.addImage('preload', preloadDataUri, preloadImage);
	},
	create: function(){
		this.game.state.start('Preload');
	}
}
// --------- end of boot -------

// --------- preload -----------
    //game.load.tilemap('lvOneMap', 'https://dl.dropbox.com/s/q2bslcl9rwnm0y3/levelOne.json?dl=1', null, Phaser.Tilemap.TILED_JSON)
var preloadState = function(game){};

preloadState.prototype = {
	preload:function(){
		var loadText = this.game.add.text(this.game.world.centerX, 200, 'Loading...', {fill:'#fff', font:'bold 16px Arial', align:'center'});
		loadText.anchor.setTo(.5);


		var loadingBar = this.game.add.sprite(this.game.world.centerX - 50, 240, 'preload');
		loadingBar.anchor.setTo(0, .5);
		this.load.setPreloadSprite(loadingBar);

		//images
		
    
    
    var playerImage = new Image(),
        orbImage = new Image(),
        arrowImage = new Image(),
        skeletonImage = new Image(),
        tileImage = new Image(),
        allTileImage = new Image(),
        iconImage = new Image(),
        titleImage = new Image()
        
    
    var playerDataUri = playerData,
        orbDataUri = orbData,
        arrowDataUri = arrowData,
        skeletonDataUri = skeletonData,
        tileDataUri = tileData,
        allTileDataUri = allTileData,
        iconDataUri = iconData,
        titleDataUri = titleData
    
    playerImage.src = playerDataUri;
    orbImage.src = orbDataUri;
    arrowImage.src = arrowDataUri;
    skeletonImage.src = skeletonDataUri;
    tileImage.src = tileDataUri;
    allTileImage.src = allTileDataUri;
    iconImage.src = iconDataUri;
    titleImage.src = titleDataUri;
    
    game.cache.addImage('playerData', playerDataUri, playerImage);
    game.cache.addImage('orbData', orbDataUri, orbImage);
    game.cache.addImage('arrow', arrowDataUri, arrowImage);
    game.cache.addImage('skeletonData', skeletonDataUri, skeletonImage);
    game.cache.addImage('tileData', tileDataUri, tileImage)
    game.cache.addImage('allTileData', allTileDataUri, allTileImage)
    game.cache.addImage('iconData', iconDataUri, iconImage)
    game.cache.addImage('title', titleDataUri, titleImage);
    
    var cachedPlayerImage = game.cache.getImage('playerData').src;
    
    var cachedOrbImage = game.cache.getImage('orbData').src;
    
    var cachedSkeletonImage = game.cache.getImage('skeletonData').src;
    
    var cachedAllTileImage = game.cache.getImage('allTileData').src;
    this.cachedAllTileImage = game.cache.getImage('allTileData').src;
    
    var cachedIconImage = game.cache.getImage('iconData').src;
    
    game.load.spritesheet('playerSheet', cachedPlayerImage, 26, 36, 13);
    
    game.load.spritesheet('soulSheet', cachedOrbImage, 14,14,16);
    
    game.load.spritesheet('skeletonSheet', cachedSkeletonImage, 26,36,10);
    game.load.spritesheet('tileSheet', cachedAllTileImage, 22, 22, 40);
    
    game.load.spritesheet('iconSheet', cachedIconImage, 15,15,20)

		//sounds
     game.load.audio('step', ['https://dl.dropbox.com/s/ad6axbebd2ene9n/kidRun.mp3?dl=1','https://dl.dropbox.com/s/suft89a6oxc11wo/kidRun.ogg?dl=1']);
    game.load.audio('item', ['https://dl.dropbox.com/s/c7sm23nodqkmdwl/item.mp3?dl=1', 'https://dl.dropbox.com/s/7jo0snxrbzyxowj/item.ogg?dl=1'])
    game.load.audio('enemyHit',['https://dl.dropbox.com/s/jw0yedtkf1w6dfx/enemyHit.mp3?dl=1','https://dl.dropbox.com/s/g51roiqzdh19o0w/enemyHit.ogg?dl=1']);
    game.load.audio('enemyHitBang', ['https://dl.dropbox.com/s/vom1u7kp36bdhfl/enemyHitBang.mp3?dl=1','https://dl.dropbox.com/s/r8697ec8uqdnnec/enemyHitBang.ogg?dl=1']);
    game.load.audio('powerUp', ['https://dl.dropbox.com/s/8nabd3njqzd3dra/Powerup.mp3?dl=1','https://dl.dropbox.com/s/25ec4kzsens23g5/Powerup.ogg?dl=1']);
    game.load.audio('tenSouls', ['https://dl.dropbox.com/s/0f37jlcelc0dsqz/tenSouls.mp3?dl=1','https://dl.dropbox.com/s/uvuk6udj95fxci5/tenSouls.ogg?dl=1']);
    game.load.audio('counter', ['https://dl.dropbox.com/s/m471wegxgdvmun4/counter.mp3?dl=1', 'https://dl.dropbox.com/s/ev37mi1l9nwf6hn/counter.ogg?dl=1']);

	},
	create: function(){
		this.game.state.start('Title');
	}
}
 // ----------- end preload ------

// -------- load ---------
var loadLevelState = function(game){};

loadLevelState.prototype = {
	init: function(stats){
		this.stats = stats
		this.stats.scene = stats.to
	},
	preload: function(){
		console.log('loading ' + this.stats.scene);
	},
	create: function(){
		this.game.state.start('Scene', false, true, this.stats);
	}
}
// --------- end load ------

// --------- title -----------

var titleState = function(game){};

titleState.prototype = {
	preload:function(){
		console.log('title started');
	},
	create: function(){
		var titleImage = this.game.add.sprite(this.game.world.centerX, 50, 'title');
		titleImage.anchor.setTo(.5, 0);

		//this.cursor = this.game.input.keyboard.createCursorKeys();
		this.startButton = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
	    this.game.input.keyboard.addKeyCapture(Phaser.Keyboard.SPACEBAR);
    
	    this.startButton.onDown.add( this.startGame, this);
	},
	startGame: function(){
		
		this.game.state.start('Scene', true, false, {scene: 'intro'});
		
   //debug //this.game.state.start('LevelSummary', true, false, {time:23, power:8, souls:22});
	}
}
// --------- end title -----------

// --------- scene -----------
var sceneState = function(game){ };

sceneState.prototype = {
	init: function(sceneData){
		this.scene = sceneData.scene;
		this.entrance = sceneData.toPoint;
		console.log(sceneData)
		this.levelTime = sceneData.toPoint ? sceneData.score.time : 150
		this.stats = sceneData.score || false;
	},
	preload: function(){
		var maps = {
      'intro': 'https://dl.dropbox.com/s/7ovn7hhyw4orf7d/intro.json?dl=1',
      'introCaverns': 'https://dl.dropbox.com/s/cwfav5mygarakhf/introCaverns.json?dl=1',
      'entrance':'https://dl.dropbox.com/s/wfbnsdfbwk7ji3w/entrance.json?dl=1'
      
    };
		
			this.game.load.tilemap('sceneMap', maps[this.scene], null, Phaser.Tilemap.TILED_JSON);
    	this.map = '';
    	//this.loadingText = this.game.add.text(this.game.camera.width - 10, this.game.camera.height - 10, '...Loading', {fill:'#fff', font:'italic 16px Arial'});
	},
	create: function(){
		this.freeSouls = new Array();
		this.bossCount = 0;
		this.game.stage.backgroundColor = '#220404';
		this.game.physics.startSystem(Phaser.Physics.ARCADE);

		//stats & settings
		this.defaultStats = {
			soulCount: 0,
			power: 1
		}

		this.settings = {
			playerSpeed: 150,
			playerHeight: 36,
			playerWidth: 20,
			playerJump: 240,
			playerScale: 1,
			attackDelay: 300,
			invincible: false,
			invicibleDelay: 1500
		}

		//sounds
		this.stepSound = this.game.add.audio('step');
		this.itemSound = this.game.add.audio('item');
		this.enemyHitSound = this.game.add.audio('enemyHit');
		this.enemyHitBangSound = this.game.add.audio('enemyHitBang');
		this.powerUpSound = this.game.add.audio('powerUp');
		this.tenSoulsSound = this.game.add.audio('tenSouls');

    	//add items for later
    	this.arrows = this.game.add.group();
    	this.arrows.enableBody = true;
    	this.arrows.createMultiple(15, 'arrow', 0, false);
    	this.arrows.setAll('anchor.x', 0.5);
    	this.arrows.setAll('anchor.y', 1);
    	this.arrows.setAll('outOfBoundsKill', true);
    	this.arrows.setAll('checkWorldBounds', true);
    	this.arrows.forEach(function(arrow){
    		arrow.kill();
    	})

    	this.redSouls = this.game.add.group();
    	this.redSouls.enableBody = true;
    	this.redSouls.createMultiple(20, 'soulSheet', 0);
    	this.redSouls.setAll('anchor.x', 0.5);
    	this.redSouls.setAll('anchor.y', 1);
    	this.redSouls.callAll('animations.add', 'animations', 'float', [0,1,2,3,4,5,6,7], 10);
    	this.redSouls.setAll('body.customSeparateX', true);
    	this.redSouls.forEach( function(soul){
    		soul.type = 'soul';
    		soul.kill();
    	});

    	this.blueSouls = this.game.add.group();
    	this.blueSouls.enableBody = true;
    	this.blueSouls.createMultiple(20, 'soulSheet', 8);
    	this.blueSouls.setAll('anchor.x', 0.5);
    	this.blueSouls.setAll('anchor.y', 1);
    	this.blueSouls.callAll('animations.add', 'animations', 'float', [8,9,10,11,12,13,14,15], 10);
    	this.blueSouls.setAll('body.customSeparateX', true);
    	this.blueSouls.forEach( function(soul){
    		soul.type='soul';
    		soul.kill();
    	});
    	this.freeSouls.push(this.blueSouls);
    	this.freeSouls.push(this.redSouls);

		//input
		this.cursor = this.game.input.keyboard.createCursorKeys();
    	this.game.input.keyboard.addKeyCapture(Phaser.Keyboard.SPACEBAR);
	    this.fireButton = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
    	this.levelUpButton = this.game.input.keyboard.addKey(Phaser.Keyboard.DOWN);

    	this.buildWorld();
	},
	buildWorld: function(){

		var layers, objects, tileIndex, tileWidth, tileHeight;

		this.tiles = this.game.add.group();
		this.fire = this.game.add.group();
		this.tiles.enableBody = true;
		this.fire.enableBody = true;

		//map
		this.map = this.game.add.tilemap('sceneMap');

		layers = this.map.layers[0].data;
		objects = this.map.objects.objects;
		tileIndex = new Array();

		//any tile that isn't fire should belong to the 
		//tiles group
		for(var i=0; i<41; i++){
			tileIndex[i] = this.tiles;
		}
		tileIndex[31] = this.fire;

		tileWidth = this.map.tileWidth;
		tileHeight = this.map.tileHeight;

		//add map tiles
		for(var i=0; i<layers.length; i++){
			var row = layers[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, tileIndex[tileI]);
					if(tileI == 31){
						tile.customSeparateX = true;
						tile.customSeparateY = true;
					}

				}
			}
		}

		//add map objects
		if(objects){
			this.addObjects(objects);
		}
		this.createHud()
		this.game.world.setBounds(0,0,this.map.widthInPixels, this.map.heightInPixels);

	},
	addObjects: function(objects){
		this.enemiesAtX = new Array();
		this.enemyId = new Array();
		this.enemiesAlive = new Array();
		this.enemiesToKill = new Array();
		this.enemies = new Array();
		this.skeletons = this.game.add.group();
		this.bumpers = this.game.add.group();
		this.doors = this.game.add.group();
		this.skeletons.enableBody = true;
		this.bumpers.enableBody = true;
		this.enemies.push(this.skeletons);
		this.doors.enableBody = true; 

		for(var i =0; i<objects.length; i++){
			var o, oX, oY, oType, oName, oProp;
			o = objects[i];
			oX = o.x;
			oY = o.y;
			oType = o.type;
			oName = o.name;
			oProp = o.properties;

			if(oName){
				//player
				if(oName == 'player'){
					this.addPlayer(oX, oY);
				}else 
				//bumpers
				if(oName == 'bumper'){
					this.game.add.sprite(oX, oY, '', 0, this.bumpers);
				}else
				//doors
				if(oName == 'door'){
					var toScene, fromScene, toPoint, point;
					fromScene = oProp.from;
					toScene = oProp.to; 
					toPoint = oProp.toPoint || 1;
					point = oProp.point;
					placeX = parseInt(oProp.placeX) || 40; 
					placeY = parseInt(oProp.placeY) || 0; 
					place = {x:placeX, y:placeY};


					var door = this.game.add.sprite(oX, oY, '', 0, this.doors);
					door.to = toScene;
					door.from = fromScene;
					door.point = point;
					door.toPoint = toPoint;
					door.place = place;

					//move player to appropriate entrance
					if(point == this.entrance){
						this.player.position.x = door.x + door.place.x;
						this.player.position.y = door.y - this.settings.playerHeight + door.place.y;
						if(door.place.x <0){
							this.player.scale.setTo(-1,1);
							this.settings.playerScale = -1;
						}
					}
				}else
				//items
				if(oName == 'item'){
					//souls
					if(oProp.type && oProp.type == 'soul'){
						var soul, value, deadCount, type, group;
						value = oProp.value;
						if(value < 5){
							type = 1;
							group = this.redSouls;
						}else{
							type == 2;
							group = this.blueSouls;
						}
						deadCount = group.countDead();
						//revive a new one if possible
						if(deadCount > 0){
							soul = group.getFirstDead();
							soul.reset(oX, oY);
							soul.value = value;
						}else{
							//new red
							if(type == 1){
								soul = this.game.add.sprite(oX, oY, 'soulSheet', 0, group);
							}else{
								soul = this.game.add.sprite(oX, oY, 'soulSheet', 8, group);
							}
							soul.value = value;
						}


					}
				}
				//enemies
				/**
					we're looping through the enemies and adding them to an array by x coord.
					then we kill them.
					then, in update(), if the camera is within range of the enemy, we respawn it
					if it isn't already alive. Got it?
				**/
				if( oName == 'enemy'){
					var id, e, type, reference, eref;
					id = this.enemyId.length;
					type = oProp.type;

					//enemy build reference
					reference = {
						'skeleton':{
							type: 'skeleton',
							animated: true,
							sheet: 'skeletonSheet',
							offsetX: 0,
							offsetY: -28,
							w: 20,
							h:36,
							defaultHealth:4,
							customSeparateX:true,
							customSeparateY:false,
							velocityX:-10,
							velocityY:0,
							anchorX:0.5,
							anchorY:0.5,
							animations:[
								{name: 'walk', frames:[0,1,2], framerate:3},
								{name:'die', frames: [3,4], framerate: 6}
							],
							defaultAnimation: 1
						}
					}
					eref = reference[type] ? reference[type] : {};
					e=eref;
					e.id = id;
					e.attack = oProp.attack;
					e.defense = oProp.defense;
					e.health = eref.defaultHealth ? eref.defaultHealth : oProp.health;
					e.defaultHealth = e.health;
					e.reward = oProp.reward;

					if(oProp.boss){
						this.bossCount ++;
						e.isBoss = true;
						if(type == 'skeleton'){
							e.defaultHealth = 20;
							e.health = 20;
							e.defense = 5;
							e.animations = [
								{name: 'walk', frames:[5,6,7], framerate:3},
								{name:'die', frames: [8,9], framerate: 6}
							]
						}
					}

					this.enemyId[id] = e;
					this.enemiesAtX[oX] = {
						y: oY,
						enemy: e
					}
					this.enemiesAlive[id] = false; 
					this.spawnEnemy(type, oX, oY, e);

				}//end of enemy


			}//end of object
		}
		//kill ALL THE ENEMIES!!
		this.enemiesToKill.forEach(function(enemy){
			enemy.kill();
		})

		//initialize what needs initializin
		this.bumpers.setAll('width', 20);
		this.bumpers.setAll('height', 60);
		this.bumpers.setAll('anchor.y', .5);
		this.bumpers.setAll('anchor.x', .5);
		this.bumpers.setAll('body.immovable', true);
		this.tiles.setAll('body.immovable', true); 

		this.doors.setAll('width', 40);
		this.doors.setAll('height', 66);
		this.doors.setAll('anchor.x', .5);
		this.doors.setAll('anchor.y', 1);
		this.doors.setAll('body.immovable', true);

	},
	addPlayer:function(x, y){
		this.player = this.game.add.sprite(x, y-this.settings.playerHeight, 'playerSheet', 0);
		this.player.stats = this.stats ? this.stats : this.defaultStats;
		
		//animations
		this.player.animations.add('stand', [0], 1, true);
		this.player.animations.add('run', [1,2,3,4,5,6], 10, true);
		this.player.animations.add('jump', [4], 8, false);
		this.player.animations.add('fall', [6], 1, true);
		this.player.animations.add('attack', [7,8,9,9], 10, false);
		this.player.animations.add('die', [6,6, 5,4], 10, false);
		this.player.animations.add('airAttack', [11,12,13,13], 10, false);

		this.player.anchor.setTo(0.5,0.5);

		this.game.physics.arcade.enable(this.player);

		this.player.onGround = false;
		this.player.body.gravity.y = 700;
		this.player.body.collideWorldBounds = true; //change for wrap
		this.player.body.width = this.settings.playerWidth;
		this.player.body.height = this.settings.playerHeight;

	    //attack!
    	this.fireButton.onDown.add( this.attack, this);
    
    	//level up
    	this.levelUpButton.onDown.add(this.powerUp, this);


	},
	spawnEnemy:function(type, x, y, options){
		var enemyGroups, group, e, oX, oY;
		enemyGroups = {
			skeleton: this.skeletons
		}
		group = enemyGroups[type];
		oX = x + options.offsetX;
		oY = y + options.offsetY;
		e = this.game.add.sprite(oX, oY, options.sheet, 0);
		this.game.physics.arcade.enable(e);
		e.defaultX = oX;
		e.defaultY = oY;
		e.body.gravity.y = 700;
		e.enemyId = options.id;
		e.health = options.defaultHealth || 1;
		e.defaultHealth = e.health;
		e.defense = options.defense || 0;
		e.attack = options.attack || 1;
		e.reward = options.reward || 1;
		e.isBoss = options.isBoss ? true : false;
		if(options.w)
			e.body.width = options.w;
		if(options.h)
			e.body.height = options.h;
		e.body.customSeparateX = options.customSeparateX || false;
		e.body.customSeparateY = options.customSeparateY || false;
		e.body.velocity.x = e.scale.x * options.velocityX;
		e.body.velocity.y = options.velocityY;
		e.anchor.setTo(options.anchorX, options.anchorY);
		if(options.animations){
			for(var a=0; a<options.animations.length;a++){
				var ani = options.animations[a];

				e.animations.add(ani.name, ani.frames, ani.framerate, true);
			}
		}
		if(options.defaultAnimation){
			var ani = options.defaultAnimation - 1;
			e.play(options.animations[ani].name);
		}
		group.add(e);
		this.enemies.push(e);
		this.enemiesToKill[e.enemyId] = e;
	},
	powerUp:function(){
		var soulCount, power, next;
		soulCount = this.player.stats.soulCount;
		power     = this.player.stats.power;
		next      = (power * 10);
		if( soulCount >= next){
			this.player.stats.soulCount -= next;
			this.player.stats.power += 1;
			this.powerUpSound.play('', 0, 0.4, false, false);
		}
	},
	attack:function(){
		if(!this.player.attacking){
			var arrow, arrowDecayTime;
			this.player.attacking = true;
			//attack delay
			this.game.time.events.add(this.settings.attackDelay, (function(){
				this.player.attacking = false;
			}), this);
			//create arrow
			if(this.arrows.countDead() > 0){
				/*arrow = this.arrows.getFirstDead();
				arrow.reset(this.player.position.x, this.player.position.y - 7);*/
				arrow = this.game.add.sprite(this.player.position.x, this.player.position.y - 5, 'arrow', 0, arrow);
				this.arrows.add(arrow)
			}else{
				arrow = this.game.add.sprite(this.player.position.x, this.player.position.y-7, 'arrow', 0, this.arrows);
				arrow.body.customSeparateX = true;
			}
			arrow.defaultScale = this.settings.playerScale;
			arrow.scale.setTo(arrow.defaultScale, 1);
			arrow.body.velocity.x = 300 * arrow.defaultScale;
			arrow.power = this.player.stats.power;
			arrowDecayTime = 500 + (this.player.stats.soulCount * 2); //a reason not to power up?
			this.game.time.events.add(arrowDecayTime, (function(){
				arrow.kill();
			}), this);

			//animations
			if(this.player.onGround){
				this.player.play('attack');
			}else{
				this.player.play('airAttack');
			}
		}
	},
	playerHit:function(a,b){
		//a = player, b = hitter
		if(!this.settings.invincible && !b.isDead){
			if(a.stats.soulCount >= b.attack){
				a.hit = true;
				this.setInvicible(0);
				//timer for re-enabling control
				this.game.time.events.add(700, (function(){
					this.player.hit = false;
				}), this);

				a.body.velocity.y = -150;
				a.body.velocity.x = -1000 * a.scale.x;
				a.stats.soulCount -= b.attack;
			}else{
				a.hit = true;
				a.stats.soulCount = 0;
				a.kill();
				this.killed();
			}
		}
	},
	enemyHit:function(a, b){
		//a is enemy, b is hitter
		var dmg, reward;//, knockback;
		dmg = b.power - a.defense;
		if(dmg <= 0)
			dmg = 0;
		b.power = b.power - (a.health * 2);
		if(b.power <= 0){
			//kill the arrow if it didn't carry through
			b.kill();
			this.enemyHitSound.play('',0,1,false,false);
		}else{
			this.enemyHitBangSound.play('',0,1,false,false);
		}
		//knockback = dmg - a.health;
		a.health -=dmg;
		if(a.health <= 0){
			//killed
			a.body.velocity.x = 0;
			a.body.velocity.y = 0;
			if(a.isBoss && !a.isDead){
				this.bossCount -= 1;
				if(this.bossCount <= 0 && !this.levelWon){
					this.levelWon = true;
					this.levelWin();
				}
			}
			a.isDead = true;
			a.play('die', 6, false, true);
			if(a.reward && a.rewarded == false){
				a.rewarded = true;
				if(a.reward < 5){
					if(this.redSouls.countDead > 0){
						reward = this.redSouls.getFirstDead();
						reward.reset(a.x, a.y - 20);
					}else{
						reward = this.game.add.sprite(a.x, a.y - 20, 'soulSheet', 0, this.redSouls);
					}
				}else{
					if(this.blueSouls.countDead > 0){
						reward = this.blueSouls.getFirstDead();
						reward.reset(a.x, a.y - 20);
					}else{
						reward = this.game.add.sprite(a.x, a.y - 20, 'soulSheet', 8, this.blueSouls);
					}
				}//blue
				reward.value = a.reward;
				reward.type = 'soul';
			}//reward
		}

	},
	setInvicible: function(time){
		var delay = time ? time : this.settings.invicibleDelay;	
		this.settings.invincible = true;
		this.game.time.events.add(delay, (function(){
			this.settings.invincible = false;
		}),this);
	},
	enterDoor: function(a, b){
		//a player, b, door
		scoreData = {
				soulCount: this.player.stats.soulCount,
				power: this.player.stats.power,
				time: this.levelTime
			}
		this.game.state.start('LoadLevel', true, false, { to: b.to, from:b.from, toPoint:b.toPoint, score: scoreData});

	},
	getItem: function(a,b){
		//a player, b item'
		if(b.type == 'soul'){
			var value, passTen, next;
			next  = (this.player.stats.power * 10);
			value = parseInt(b.value) || 1;
			b.kill();
			if(this.player.stats.soulCount + value >= next){
				this.tenSoulsSound.play('', 0, 1, false, false);
			}else{
				this.itemSound.play('',0,1,false,false);
			}
			this.player.stats.soulCount += value;

		}//soul?
	},
	levelWin: function(){
		var scoreData;

		this.game.time.events.add(2000, (function(){

			scoreData = {
				souls: this.player.stats.soulCount,
				power: this.player.stats.power,
				time: this.levelTime
			}
			this.game.state.start('LevelSummary', true, false, scoreData);
		}), this)
	},
	killed:function(){
		this.player.play('die');
		this.input.enabled = false;
		this.game.time.events.add('2000', (function(){
			this.game.state.start('GameOver', true, false);
		}), this)
	},
	createHud: function(){
		this.hud = this.game.add.group();
		this.hudObjects = {};
		this.hud.x = 0;
		this.hud.y = 0;


		//timer
		/* actual date version: doesn't account for slowdown in game 
			so if the frame rate chugs, the player gets screwed*/
		this.levelStartTime = Date.now();
		this.currentLevelTime = this.levelStartTime;
		this.leveltimeInterval = 1000;

		//fps version, add every 60 frames.
		//this.levelTimer = 0;

		//boss counter
		this.bossIcons = new Array();
		for(var icons=0; icons < this.bossCount; icons++){
			var x, w, b;
			x = 430;
			w = 20 * icons;
			b = this.game.add.sprite(x - w, -100, 'iconSheet', 0);

			this.bossIcons.push(b);
			this.hud.add(b);
		}

		this.hudObjects.soulText = this.game.add.text(10,20,'0', {fill:'#fff', font:'10px "press start 2p"'});
		this.hudObjects.timeText = this.game.add.text(110,20,'TIME 0000', {fill:'#fff', font:'10px "press start 2p"'});
		this.hudObjects.powerText = this.game.add.text(240,20,'POWER 1', {fill:'#fff', font:'10px "press start 2p"'});

		this.hud.add(this.hudObjects.soulText);
		this.hud.add(this.hudObjects.timeText);
		this.hud.add(this.hudObjects.powerText);
	},
	update: function(){
		var cX, cY, cW, cH;

		this.updateHud();
		this.movePlayer();

		//collisions
		//player v tiles
		this.game.physics.arcade.collide(this.player, this.tiles);
		//enemy v tiles
		this.game.physics.arcade.collide(this.enemies, this.tiles);
		//player v doors
		this.game.physics.arcade.overlap(this.player, this.doors, this.enterDoor, null, this);
		//skeletons v bumpers
		this.game.physics.arcade.collide(this.skeletons, this.bumpers, (function(a,b){
	          var xscale = a.scale.x * -1
	          a.scale.setTo(xscale, 1);
	          a.body.velocity.x = -10 * a.scale.x
		}), null, this);
		//player v soul
		this.game.physics.arcade.collide(this.player, this.freeSouls, this.getItem, null, this);
		//enemy v arrow
		this.game.physics.arcade.collide(this.enemies, this.arrows, this.enemyHit, null, this);
		//fire v player
		this.game.physics.arcade.overlap(this.fire, this.player, (function(a,b){
			if( this.settings.invincible != true){
				this.player.hit = true;
				this.killed();
			}
		}),null,this);
		//player v enemy
		this.game.physics.arcade.overlap(this.player, this.enemies, this.playerHit, null, this);

		//player updates
		if(this.player.body.touching.down){
			this.player.onGround = true;
		}else{
			this.player.onGround = false;
		}

		//spawn/respawn enemies by x coordinate
		cX = this.camera.x;
		cY = this.camera.y;
		cW = this.camera.width;
		cH = this.camera.height;

		this.enemiesAtX.forEach( (function(enemy, index){
			//is enemy in X range?
			if(index >= cX && index <= cX + cW){
				//is enemy in Y range?
				var eY = enemy.y;
				if(eY >= cY + 50 && eY <= cY + cH - 50){
					var id;
					id = parseInt(enemy.enemy.id);
					//is the enemy still alive?
					if(!this.enemiesAlive[id]){
						//if not, reanimate!
						this.enemiesAlive[id] = true;
						this.enemiesToKill[id].revive(enemy.enemy.defaultHealth)
						this.enemiesToKill[id].isDead = false;
						this.enemiesToKill[id].rewarded = false;
						this.enemiesToKill[id].play(enemy.enemy.animations[enemy.enemy.defaultAnimation -1].name);
						this.enemiesToKill[id].body.velocity.x = enemy.enemy.velocityX * this.enemiesToKill[id].scale.x
					}
				}else{
					//kill the ones that aren't in range
					if(this.enemiesAlive[id]){
						this.enemiesToKill[id].kill();
						this.enemiesAlive[id] = false;
					}
				}
			}else{
				//kill the ones that aren't in range
				var id= enemy.enemy.id;
				if(this.enemiesAlive[id]){
					this.enemiesToKill[id].kill();
					this.enemiesAlive[id] = false;
				}

			}
		}), this);

		//camera!
		this.camera.follow(this.player);
	},
	updateHud: function(){
		var timeString, soulCount, timerText, worldX, worldY, rightNow;

		soulCount = this.player.stats.soulCount;
		//timer increment
		rightNow = Date.now();
		if(rightNow - this.currentLevelTime >= 1000){
			//full tick
			this.currentLevelTime = rightNow;
			this.levelTimer = 0;
			if(this.levelTime <=0){
				//drain souls if the timer is done
				this.levelTime = 0;
				if(this.player.stats.soulCount > 0){
					this.player.stats.soulCount -= 1;
				}else{
					this.player.hit=true;
					this.killed();
				}
			}else{
				if(!this.levelWon){
					this.levelTime -= 1;
				}
			}
		}

		//format time
		timeString = "0000" + this.levelTime;
		timeString = timeString.substr(timeString.length - 4);

		//update strings
		timerText = "TIME " + timeString;
		this.hudObjects.timeText.text = timerText;
		this.hudObjects.soulText.text = "SOULS " + soulCount;
		this.hudObjects.powerText.text = "POWER " + this.player.stats.power;

		this.hudObjects.timeText.fill = this.levelTime > 30 ? '#fff' : '#F00';

		//boss icons
		for(var i =0; i<this.bossIcons.length; i++){
			if(i + 1 <= this.bossCount)
				this.bossIcons[i].y = 0;
			else
				this.bossIcons[i].y = -100;
		}


		//move hud with screen
		worldX = this.game.world.x * -1;
		worldY = this.game.world.y * -1;

		this.hud.x = worldX + 10;
		this.hud.y = worldY + 10;


	},
	movePlayer: function(){
		var that = this;
		this.player.alpha = 1;
		if(this.settings.invincible){
			this.player.alpha = 0.5;
		}

		//controls!
				//right
		if(this.cursor.right.isDown && !this.player.attacking &&!this.player.hit){
			this.player.body.velocity.x = this.settings.playerSpeed;
			this.player.scale.setTo(1,1);
			this.settings.playerScale = 1;
			this.player.play('run');
		}else if(this.cursor.left.isDown && !this.player.attacking &&!this.player.hit){
			this.player.body.velocity.x = -this.settings.playerSpeed;
			this.player.scale.setTo(-1,1);
			this.settings.playerScale = -1;
			this.player.play('run');
		}else{
			this.player.body.velocity.x = 0;
			if(this.player.onGround &&!this.player.attacking){
				this.player.play('stand');
			}
		}


    	this.input.keyboard.onUpCallback = function(e){
	      if(e.keyCode == Phaser.Keyboard.UP){
	        that.holdingUp = false;
	        //controlled jumping
	        if(that.player.body.velocity.y< 0){
	          that.player.body.velocity.y = 0;
	        }
	      }
	    }

		//jump
		if(this.cursor.up.isDown && !this.holdingUp &&this.player.onGround &&!this.player.hit){
			this.player.body.y -= 2;
			this.player.body.velocity.y =  -this.settings.playerJump;
			this.stepSound.play('', 0,.1, false, false);
			this.holdingUp = true;
		}
		if(!this.player.onGround){
			if(this.player.body.velocity.y <= 0){
				
				if(!this.player.attacking){
					this.player.play('jump');
				}
			}else{
				if(!this.player.attacking){
					this.player.play('fall');
				}
			}
		}
	}
}
//--------- end scene ------

//---------- game over --------
var gameOverState = function(game){};

gameOverState.prototype = {
	preload:function(){
	
		this.game.world.height = this.camera.height;
		this.game.world.width = this.camera.width;
	},
	create:function(){
	 this.game.stage.backgroundColor = '#181818';
    var gameOverText = this.game.add.text(this.game.world.centerX, this.game.world.centerY - 50, 'GAME OVER', 
                       {fill: '#ededed',
			font: '26px "Press Start 2p"', align: 'center'});
    
    gameOverText.anchor.setTo(0.5);
    
	}
}
// ---------- end game over ---


// ---------- level summary ---

var levelSummaryState = function(game){};

levelSummaryState.prototype = {
	init:function(score){
		this.stats = score;
	},
	preload:function(){
		this.game.world.height = this.camera.height;
		this.game.world.width = this.camera.width;

	},
	create:function(){
		this.counterSound = this.game.add.audio('counter');
		this.font = {
			fill: '#ededed',
			font: '14px "Press Start 2p"',
		}
		this.font2 = {
			fill: '#d1cd32',
			font: '14px "Press Start 2p"',
		}
		this.pts = {
			'time': 700,
			'power': 500,
			'soul': 15
		}
    this.tweetable = true;

		this.game.stage.backgroundColor = '#181818';

		this.timeRem = parseInt(this.stats.time) || "0";
		this.powerRem = parseInt(this.stats.power) || "0";
		this.soulRem = parseInt(this.stats.souls) || "0";
		this.score = 0;


		this.timeText = this.game.add.text(70, 50, 'Time Remaining: ', this.font);
		this.powerText = this.game.add.text(70, 100, 'Power Attained: ', this.font);
		this.soulText = this.game.add.text(70, 150, 'Souls Held: ', this.font);
		this.scoreText = this.game.add.text(70, 200, 'Score: ', this.font2);

		this.timeCountText = this.game.add.text(350, 50, this.timeRem, this.font2);
		this.powerCountText = this.game.add.text(350, 100, this.powerRem, this.font2);
		this.soulCountText = this.game.add.text(350, 150, this.soulRem, this.font2);
		this.scoreCountText = this.game.add.text(350, 200, this.score, this.font);

		this.currentLevelTime = Date.now();
	},
	update:function(){

			if(this.timeRem > 0){
				this.countdown('time');
			}else if(this.powerRem > 0){
				this.countdown('power');
			}else if(this.soulRem > 0){
				this.countdown('soul')
			}else{
   			//tweet results
        if(this.tweetable){
          this.tweetable = false;
          this.tweetLink();
        }
  
        
      }
			this.timeCountText.text = this.timeRem || '0';
			this.powerCountText.text = this.powerRem || '0';
			this.soulCountText.text = this.soulRem || '0';
			this.scoreCountText.text = this.score || '0';

	},
	countdown: function(ref){
		var timeNow;
		timeNow = Date.now();
		if(timeNow - this.currentLevelTime >= 100){
			this.currentLevelTime = timeNow;
			if( ref == 'time'){
				this.timeRem -= 1;
			}else if(ref == 'power'){
				this.powerRem -= 1;
			}else{
				this.soulRem -= 1;
			}
			this.score += this.pts[ref];
			this.counterSound.play('', 0,1,false,false);
		}

	},
  tweetLink: function(){
    document.getElementById('tweet')
    tweet.style.display='block';
    this.tweetLink = document.getElementById('tweetLink');
    var tweetText ="&text=I just scored "+this.score+" on Kid Erebus - an NES style codepen game by @ebrewe";
    tweetLink.href+=tweetText;
  }
} 
// ---------- end level summary ---

  
 var game = new Phaser.Game(500, 340, Phaser.AUTO, 'game')
		  	game.state.add('Boot', bootState);
		  	game.state.add('Preload', preloadState);
  		  game.state.add('LoadLevel', loadLevelState);
		  	game.state.add('Title', titleState);
		  	game.state.add('LevelSummary', levelSummaryState);
		  	game.state.add('GameOver', gameOverState);
		  	game.state.add('Scene', sceneState);
		  	game.state.start('Boot');
  
})();
            
          
!
999px
Loading ..................

Console