X-Git-Url: http://git.megabrutal.com/?p=ld40.git;a=blobdiff_plain;f=ld40.js;h=01a65ce0f788eb5b318ca822f083dbbffcac5b34;hp=7bf03d71da756c446f15d2f52cc77f4de7abcdbe;hb=ec8eeabbaf8576510fcd67a78f56b7d94575e8f9;hpb=b69fd06095d7d61ccbcd237298aeb306331991c3 diff --git a/ld40.js b/ld40.js index 7bf03d7..01a65ce 100644 --- a/ld40.js +++ b/ld40.js @@ -1,4 +1,5 @@ - var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); + var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: function() { this.state.add('GamePlay', GamePlay, true); } }); + var cursors; var player; var walls; var determinations; // I know it's grammatically incorrect. :P @@ -80,6 +81,7 @@ this.health = 0; this.healthBar.update(this.love, this.maxHealth, this.health); super.kill(); + this.game.state.start('GameOver'); } loveUp() { @@ -248,70 +250,101 @@ } } - function preload () { - game.load.image('wall', 'wall.png'); - game.load.image('player', 'player.png'); - game.load.image('monster', 'monster.png'); - game.load.image('determination', 'determination.png'); - game.load.image('projectile', 'projectile.png'); + class GamePlay extends Phaser.State { - } + constructor() { - function create () { + super(); + game.state.add('GameOver', GameOver, false); - game.world.setBounds(0, 0, 800, 600); - game.stage.backgroundColor = '#000000'; - game.physics.startSystem(Phaser.Physics.ARCADE); + } - walls = game.add.group(); - walls.classType = Phaser.TileSprite; - walls.enableBody = true; + preload() { - walls.add(game.add.tileSprite(WALL_BORDER, WALL_BORDER, game.world.width - (WALL_BORDER * 2), WALL_THICKNESS, 'wall')); - walls.add(game.add.tileSprite(WALL_BORDER, game.world.height - WALL_THICKNESS - WALL_BORDERBOTTOM, game.world.width - (WALL_BORDER * 2), WALL_THICKNESS, 'wall')); - walls.add(game.add.tileSprite(WALL_BORDER, WALL_BORDER, WALL_THICKNESS, game.world.height - WALL_BORDER - WALL_BORDERBOTTOM, 'wall')); - walls.add(game.add.tileSprite(game.world.width - WALL_THICKNESS - WALL_BORDER, WALL_BORDER, WALL_THICKNESS, game.world.height - WALL_BORDER - WALL_BORDERBOTTOM, 'wall')); - walls.children.forEach(function(wall) { wall.body.immovable = true; }); + game.load.image('wall', 'wall.png'); + game.load.image('player', 'player.png'); + game.load.image('monster', 'monster.png'); + game.load.image('determination', 'determination.png'); + game.load.image('projectile', 'projectile.png'); - determinations = game.add.group(); - nexttime_determination = Math.random() * WAIT_DETERMINATION; + } - monsters = game.add.group(); - nexttime_monsterspawn = WAIT_MONSTERSPAWN / 4; + create() { - player = new Player(game.world.width / 2, game.world.height / 2); - player.enablePhysics(); - game.add.existing(player); - game.camera.follow(player); - cursors = game.input.keyboard.createCursorKeys(); + game.world.setBounds(0, 0, 800, 600); + game.stage.backgroundColor = '#000000'; + game.physics.startSystem(Phaser.Physics.ARCADE); - } + walls = game.add.group(); + walls.classType = Phaser.TileSprite; + walls.enableBody = true; + + walls.add(game.add.tileSprite(WALL_BORDER, WALL_BORDER, game.world.width - (WALL_BORDER * 2), WALL_THICKNESS, 'wall')); + walls.add(game.add.tileSprite(WALL_BORDER, game.world.height - WALL_THICKNESS - WALL_BORDERBOTTOM, game.world.width - (WALL_BORDER * 2), WALL_THICKNESS, 'wall')); + walls.add(game.add.tileSprite(WALL_BORDER, WALL_BORDER, WALL_THICKNESS, game.world.height - WALL_BORDER - WALL_BORDERBOTTOM, 'wall')); + walls.add(game.add.tileSprite(game.world.width - WALL_THICKNESS - WALL_BORDER, WALL_BORDER, WALL_THICKNESS, game.world.height - WALL_BORDER - WALL_BORDERBOTTOM, 'wall')); + walls.children.forEach(function(wall) { wall.body.immovable = true; }); + + determinations = game.add.group(); + nexttime_determination = Math.random() * WAIT_DETERMINATION; + + monsters = game.add.group(); + nexttime_monsterspawn = WAIT_MONSTERSPAWN / 4; + + player = new Player(game.world.width / 2, game.world.height / 2); + player.enablePhysics(); + game.add.existing(player); + game.camera.follow(player); + cursors = game.input.keyboard.createCursorKeys(); + + } + + update() { + + game.physics.arcade.collide(player, walls); + game.physics.arcade.overlap(player, determinations, function(p,d) { p.overlap_determination(d); }); + game.physics.arcade.overlap(player, monsters, function(p,m) { m.overlap_player(p); }); + + if (game.time.now > nexttime_determination) + { + var determination = new Determination((Math.random() * (game.world.width - ((WALL_THICKNESS + WALL_BORDER) * 4))) + ((WALL_THICKNESS + WALL_BORDER) * 2), (Math.random() * (game.world.height - ((WALL_THICKNESS + WALL_BORDER) * 4) - WALL_BORDERBOTTOM)) + ((WALL_THICKNESS + WALL_BORDER) * 2)); + determination.enablePhysics(); + determinations.add(determination); + nexttime_determination = game.time.now + (WAIT_DETERMINATION / 2) + (Math.random() * WAIT_DETERMINATION); + } - function update () { + if (game.time.now > nexttime_monsterspawn) + { + var monster = new Monster(Math.random() * game.world.width, Math.random() * game.world.height); + monster.enablePhysics(); + monsters.add(monster); + var waittime = WAIT_MONSTERSPAWN - ((Math.random() * 2000) * player.love); + nexttime_monsterspawn = game.time.now + waittime; + console.log('Next monster in ' + waittime); + } - game.physics.arcade.collide(player, walls); - game.physics.arcade.overlap(player, determinations, function(p,d) { p.overlap_determination(d); }); - game.physics.arcade.overlap(player, monsters, function(p,m) { m.overlap_player(p); }); + if ((game.time.now - player.lastmovetime) > WAIT_KEY) player.body.velocity.x = player.body.velocity.y = 0; - if (game.time.now > nexttime_determination) - { - var determination = new Determination((Math.random() * (game.world.width - ((WALL_THICKNESS + WALL_BORDER) * 4))) + ((WALL_THICKNESS + WALL_BORDER) * 2), (Math.random() * (game.world.height - ((WALL_THICKNESS + WALL_BORDER) * 4) - WALL_BORDERBOTTOM)) + ((WALL_THICKNESS + WALL_BORDER) * 2)); - determination.enablePhysics(); - determinations.add(determination); - nexttime_determination = game.time.now + (WAIT_DETERMINATION / 2) + (Math.random() * WAIT_DETERMINATION); } + } + + class GameOver extends Phaser.State { + + create() { + + this.game.add.text(this.game.world.width / 2, 0, "GAME\nOVER", { align: 'center', fill: 'white', font: 'Ubuntu Mono', fontSize: 160, fontWeight: 'bold' }).anchor.setTo(0.5, 0); + this.game.add.text(this.game.world.width / 2, this.game.world.height * 0.75, "Stay determined...", { align: 'center', fill: 'white', font: 'Ubuntu Mono', fontSize: 24, fontWeight: 'bold' }).anchor.setTo(0.5, 0); - if (game.time.now > nexttime_monsterspawn) - { - var monster = new Monster(Math.random() * game.world.width, Math.random() * game.world.height); - monster.enablePhysics(); - monsters.add(monster); - var waittime = WAIT_MONSTERSPAWN - ((Math.random() * 2000) * player.love); - nexttime_monsterspawn = game.time.now + waittime; - console.log('Next monster in ' + waittime); } - if ((game.time.now - player.lastmovetime) > WAIT_KEY) player.body.velocity.x = player.body.velocity.y = 0; + update() { + + if (this.game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) + { + this.game.state.start('GamePlay'); + } + + } }