X-Git-Url: http://git.megabrutal.com/?p=ld40.git;a=blobdiff_plain;f=ld40.js;h=f7954c2a7d4a0ae5239f12a0094744b2cafe8b7b;hp=892e1b1d62239d0ec497f90ce9ad7b69bee19f2f;hb=196048400fbe50d1f238f4385a0b3a85f45863a5;hpb=eef1b7028b56916c6dd0c91e538ebb12cbab13de diff --git a/ld40.js b/ld40.js index 892e1b1..f7954c2 100644 --- a/ld40.js +++ b/ld40.js @@ -21,8 +21,9 @@ const MONSTER_HEALTH = 20; const MODE_DETERMINATION = 0; const MODE_JUSTICE = 1; - const SPEED_PLAYER = 50; - const SPEED_PROJECTILE = 500; + const SPEED_PLAYER = 150; + const SPEED_PPROJECTILE = 500; + const SPEED_MPROJECTILE = 200; window.addEventListener("keydown", function(e) { // Prevent default browser action for arrows and spacebar @@ -45,7 +46,8 @@ this.lasttime_damage = 0; this.speed = SPEED_PLAYER; this.switchmode(MODE_DETERMINATION); - this.projectiles = game.add.group(); + this.weapon = new JusticeBlaster(game, this); + this.weapon.bulletSpeed = SPEED_PPROJECTILE; this.healthBar = new HealthBar(60, game.world.height - (WALL_BORDERBOTTOM / 2)); } @@ -102,10 +104,7 @@ } if ((this.mode == MODE_JUSTICE) && game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR) && ((game.time.now - this.lasttime_shoot) > WAIT_SHOOT)) { - this.shoot(0, SPEED_PROJECTILE); - this.shoot(0, -SPEED_PROJECTILE); - this.shoot(SPEED_PROJECTILE, 0); - this.shoot(-SPEED_PROJECTILE, 0); + this.shoot(); } } } @@ -124,10 +123,11 @@ this.mode = soulmode; } - shoot(velocityx, velocityy) { - var projectile = new Justice(this.x, this.y, velocityx, velocityy); - projectile.enablePhysics(); - this.projectiles.add(projectile); + shoot() { + this.weapon.fire(this, 0, this.y); + this.weapon.fire(this, this.x, 0); + this.weapon.fire(this, this.x, game.world.height); + this.weapon.fire(this, game.world.width, this.y); this.lasttime_shoot = game.time.now; } @@ -135,6 +135,7 @@ super.update(); this.control(); this.healthBar.update(this.love, this.maxHealth, this.health); + game.physics.arcade.overlap(monsters, this.weapon.bullets, function(m,b) { b.overlap_monster(m); }); if ((game.time.now - this.lasttime_mode) > WAIT_SOULMODE) { this.switchmode(MODE_DETERMINATION); } } } @@ -145,10 +146,9 @@ this.anchor.setTo(0.5, 0.5); this.health = MONSTER_HEALTH; this.nexttime_shoot = game.time.now; - this.weapon = new Phaser.Weapon(game, this); - this.weapon.x = x; - this.weapon.y = y; - this.weapon.createBullets(20, 'projectile'); + this.weapon = new JusticeBlaster(game, this); + this.weapon.bulletSpeed = SPEED_MPROJECTILE; + this.weapon.trackSprite(this); } enablePhysics() { @@ -172,7 +172,7 @@ this.weapon.fireAtSprite(player); this.nexttime_shoot = game.time.now + (WAIT_MONSTERSHOOT / 2) + (Math.random() * WAIT_MONSTERSHOOT); } - game.physics.arcade.overlap(player, this.weapon.bullets, function(p,b) { p.damage(p.love); }); + game.physics.arcade.overlap(player, this.weapon.bullets, function(p,b) { b.overlap_player(p); }); } } @@ -187,26 +187,32 @@ } } - class Justice extends Phaser.Sprite { - constructor(x, y, velocityx, velocityy) { + class Justice extends Phaser.Bullet { + constructor(game, x, y, key, frame) { super(game, x, y, 'projectile'); this.anchor.setTo(0.5, 0.5); - this.velocityx = velocityx; - this.velocityy = velocityy; } - enablePhysics() { - game.physics.arcade.enable(this); - this.body.velocity.x = this.velocityx; - this.body.velocity.y = this.velocityy; + overlap_monster(entity) { + entity.damage(player.love); + this.kill(); } - overlap(entity) { - entity.damage(player.love); + overlap_player(player) { + player.damage(player.love); this.kill(); } } + class JusticeBlaster extends Phaser.Weapon { + constructor(game, parent) { + super(game, parent); + this.bulletClass = Justice; + this.multiFire = true; + this.createBullets(100, null); + } + } + class HealthBar { constructor(x, y) { this.mhealth = game.add.tileSprite(x + 10, y, 0, HB_THICKNESS, 'wall'); @@ -265,8 +271,6 @@ game.camera.follow(player); cursors = game.input.keyboard.createCursorKeys(); - keyboard_handler = keyPress_default; - } function update () { @@ -274,7 +278,6 @@ 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); }); - game.physics.arcade.overlap(monsters, player.projectiles, function(m,j) { j.overlap(m); }); if (game.time.now > nexttime_determination) { @@ -295,12 +298,5 @@ } if ((game.time.now - player.lastmovetime) > WAIT_KEY) player.body.velocity.x = player.body.velocity.y = 0; - if (keyboard_handler) keyboard_handler(); - - } - - function keyPress_default() { - - // Maybe needed later. }