From: MegaBrutal Date: Tue, 5 Dec 2017 22:40:00 +0000 (+0100) Subject: Initial commit X-Git-Url: http://git.megabrutal.com/?p=ld40.git;a=commitdiff_plain;h=5552258b72f6a572f6baae3c33214b095780c64c Initial commit First version published at LD40. new file: determination.png new file: determination.svg new file: determination_shot1.png new file: determination_shot2.png new file: index.html new file: ld40.html new file: ld40.js new file: monster.png new file: projectile.png new file: projectile.svg new file: wall.png --- 5552258b72f6a572f6baae3c33214b095780c64c diff --git a/determination.png b/determination.png new file mode 100644 index 0000000..27f5d32 Binary files /dev/null and b/determination.png differ diff --git a/determination.svg b/determination.svg new file mode 100644 index 0000000..454277d --- /dev/null +++ b/determination.svg @@ -0,0 +1,3 @@ + + + diff --git a/determination_shot1.png b/determination_shot1.png new file mode 100644 index 0000000..5efcf6e Binary files /dev/null and b/determination_shot1.png differ diff --git a/determination_shot2.png b/determination_shot2.png new file mode 100644 index 0000000..69ef9e7 Binary files /dev/null and b/determination_shot2.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..81a13f0 --- /dev/null +++ b/index.html @@ -0,0 +1,21 @@ + + + + + Ludum Dare 40 – DETERMINATION + + + + +
+

Ludum Dare 40 – DETERMINATION

+

(Game for Ludum Dare 40)

+ +

By MegaBrutal

+
+ + diff --git a/ld40.html b/ld40.html new file mode 100644 index 0000000..0b6167a --- /dev/null +++ b/ld40.html @@ -0,0 +1,16 @@ + + + + + Ludum Dare 40 – DETERMINATION + + + + + + + + diff --git a/ld40.js b/ld40.js new file mode 100644 index 0000000..5c84a99 --- /dev/null +++ b/ld40.js @@ -0,0 +1,306 @@ + var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); + var player; + var walls; + var determinations; // I know it's grammatically incorrect. :P + var monsters; + var nexttime_monsterspawn; + var nexttime_determination; + + const WAIT_KEY = 200; + const WAIT_SHOOT = 200; + const WAIT_INVINCIBILITY = 800; + const WAIT_SOULMODE = 10000; + const WAIT_MONSTERSHOOT = 500; + const WAIT_MONSTERSPAWN = 20000; + const WAIT_DETERMINATION = 4000; + const WALL_THICKNESS = 16; + const WALL_BORDER = 8; + const WALL_BORDERBOTTOM = 48; + const HB_THICKNESS = 20; + const MAX_HEALTH = 20; + const MONSTER_HEALTH = 20; + const MODE_DETERMINATION = 0; + const MODE_JUSTICE = 1; + const SPEED_PLAYER = 150; + const SPEED_PROJECTILE = 500; + + window.addEventListener("keydown", function(e) { + // Prevent default browser action for arrows and spacebar + if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) { + e.preventDefault(); + } + }, false); + + + class Player extends Phaser.Text { + constructor(x, y) { + super(game, x, y, "♥️", { align: 'center', fill: 'red', font: 'Ubuntu Mono', fontSize: 32, fontWeight: 'bold' }); + this.anchor.setTo(0.5, 0.5); + this.maxHealth = MAX_HEALTH; + this.health = this.maxHealth; + this.love = 1; + this.lastmovetime = 0; + this.lasttime_shoot = 0; + this.lasttime_mode = 0; + this.lasttime_damage = 0; + this.speed = 150; + this.switchmode(MODE_DETERMINATION); + this.projectiles = game.add.group(); + this.healthBar = new HealthBar(60, game.world.height - (WALL_BORDERBOTTOM / 2)); + } + + enablePhysics() { + game.physics.arcade.enable(this); + this.body.bounce.y = 0.2; + this.body.bounce.x = 0.2; + this.body.collideWorldBounds = true; + } + + overlap_determination(determination) { + determination.kill(); + this.heal(2); + this.speed += 50; + this.switchmode(MODE_JUSTICE); + } + + damage(amount) { + if ((game.time.now - this.lasttime_damage) > WAIT_INVINCIBILITY) + { + super.damage(amount); + this.lasttime_damage = game.time.now; + } + } + + loveUp() { + this.love++ + this.maxHealth += this.love; + this.heal(this.love); + } + + control() { + if (this.alive) + { + if (cursors.left.isDown) + { + player.body.velocity.x = -player.speed; + player.lastmovetime = game.time.now; + } + else if (cursors.right.isDown) + { + player.body.velocity.x = player.speed; + player.lastmovetime = game.time.now; + } + if (cursors.up.isDown) + { + player.body.velocity.y = -player.speed; + player.lastmovetime = game.time.now; + } + else if (cursors.down.isDown) + { + player.body.velocity.y = player.speed; + player.lastmovetime = game.time.now; + } + 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); + } + } + } + + switchmode(soulmode) { + switch(soulmode) + { + case MODE_DETERMINATION: + this.addColor('red', 0); + break; + case MODE_JUSTICE: + this.addColor('yellow', 0); + this.lasttime_mode = game.time.now; + break; + } + this.mode = soulmode; + } + + shoot(velocityx, velocityy) { + var projectile = new Justice(this.x, this.y, velocityx, velocityy); + projectile.enablePhysics(); + this.projectiles.add(projectile); + this.lasttime_shoot = game.time.now; + } + + update() { + super.update(); + this.control(); + this.healthBar.update(this.love, this.maxHealth, this.health); + if ((game.time.now - this.lasttime_mode) > WAIT_SOULMODE) { this.switchmode(MODE_DETERMINATION); } + } + } + + class Monster extends Phaser.Sprite { + constructor(x, y) { + super(game, x, y, 'monster'); + 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'); + } + + enablePhysics() { + game.physics.arcade.enable(this); + } + + kill() { + super.kill(); + player.loveUp(); + } + + overlap_player(player) { + player.damage(10); + player.switchmode(MODE_DETERMINATION); + } + + update() { + super.update(); + if (this.alive && player.alive && (game.time.now > this.nexttime_shoot)) + { + 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); }); + } + } + + class Determination extends Phaser.Sprite { + constructor(x, y) { + super(game, x, y, 'determination'); + this.anchor.setTo(0.5, 0.5); + } + + enablePhysics() { + game.physics.arcade.enable(this); + } + } + + class Justice extends Phaser.Sprite { + constructor(x, y, velocityx, velocityy) { + 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(entity) { + entity.damage(player.love); + this.kill(); + } + } + + class HealthBar { + constructor(x, y) { + this.mhealth = game.add.tileSprite(x + 10, y, 0, HB_THICKNESS, 'wall'); + this.ahealth = game.add.tileSprite(x + 10, y, 0, HB_THICKNESS, 'wall'); + this.mhealth.anchor.setTo(0, 0.5); + this.ahealth.anchor.setTo(0, 0.5); + this.mhealth.tint = '0xff0000'; + this.ahealth.tint = '0xffff00'; + this.text_love = new Phaser.Text(game, x - 50, y + 2, null, { align: 'center', fill: 'white', font: 'Ubuntu Mono', fontSize: 16, fontWeight: 'bold' }); + this.text_love.anchor.setTo(0, 0.5); + game.add.existing(this.text_love); + } + + update(love, mhealth, ahealth) { + this.mhealth.width = mhealth; + this.ahealth.width = ahealth; + this.text_love.text = "LV " + love; + } + } + + 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'); + + } + + function create () { + + 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(); + monsters.add(new Monster(400, 500)); + monsters.children.forEach(function(monster) { monster.enablePhysics(); }); + nexttime_monsterspawn = WAIT_MONSTERSPAWN; + + 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(); + + keyboard_handler = keyPress_default; + + } + + function 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); }); + game.physics.arcade.overlap(monsters, player.projectiles, function(m,j) { j.overlap(m); }); + + 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); + } + + 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); + nexttime_monsterspawn = game.time.now + (WAIT_MONSTERSPAWN / player.love) + (Math.random() * WAIT_MONSTERSPAWN); + } + + 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. + + } diff --git a/monster.png b/monster.png new file mode 100644 index 0000000..42827bd Binary files /dev/null and b/monster.png differ diff --git a/projectile.png b/projectile.png new file mode 100644 index 0000000..8c9d262 Binary files /dev/null and b/projectile.png differ diff --git a/projectile.svg b/projectile.svg new file mode 100644 index 0000000..54e8bdf --- /dev/null +++ b/projectile.svg @@ -0,0 +1,3 @@ + + + diff --git a/wall.png b/wall.png new file mode 100644 index 0000000..aa512b7 Binary files /dev/null and b/wall.png differ