Initial commit
authorMegaBrutal <code+git@megabrutal.com>
Tue, 5 Dec 2017 22:40:00 +0000 (23:40 +0100)
committerMegaBrutal <code+git@megabrutal.com>
Tue, 5 Dec 2017 22:40:00 +0000 (23:40 +0100)
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

determination.png [new file with mode: 0644]
determination.svg [new file with mode: 0644]
determination_shot1.png [new file with mode: 0644]
determination_shot2.png [new file with mode: 0644]
index.html [new file with mode: 0644]
ld40.html [new file with mode: 0644]
ld40.js [new file with mode: 0644]
monster.png [new file with mode: 0644]
projectile.png [new file with mode: 0644]
projectile.svg [new file with mode: 0644]
wall.png [new file with mode: 0644]

diff --git a/determination.png b/determination.png
new file mode 100644 (file)
index 0000000..27f5d32
Binary files /dev/null and b/determination.png differ
diff --git a/determination.svg b/determination.svg
new file mode 100644 (file)
index 0000000..454277d
--- /dev/null
@@ -0,0 +1,3 @@
+<svg height="32" width="32">
+  <polygon points="0,16 12,12 16,0 20,12 32,16 20,20 16,32 12,20" style="fill:yellow;stroke:yellow;stroke-width:1" />
+</svg>
diff --git a/determination_shot1.png b/determination_shot1.png
new file mode 100644 (file)
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 (file)
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 (file)
index 0000000..81a13f0
--- /dev/null
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+       <meta charset="utf-8"/>
+       <title>Ludum Dare 40 – DETERMINATION</title>
+       <meta name="description" content="" />
+       <style>
+               @font-face { font-family: "Ubuntu Mono"; src: url(UbuntuMono-R.ttf); }
+               h1 { text-decoration: underline; }
+               body { font-family: "Ubuntu Mono", monospace; color: #FFFFFF; background: #000000; }
+       </style>
+</head>
+<body>
+       <div align="center">
+       <h1>Ludum Dare 40 – DETERMINATION</h1>
+       <h2>(Game for Ludum Dare 40)</h2>
+       <iframe width=800 height=600 frameborder="0" scrolling="no" src="ld40.html" seamless>Sorry, your browser is not supported. :(</iframe>
+       <h2>By MegaBrutal</h2>
+       </div>
+</body>
+</html>
diff --git a/ld40.html b/ld40.html
new file mode 100644 (file)
index 0000000..0b6167a
--- /dev/null
+++ b/ld40.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="UTF-8" />
+        <title>Ludum Dare 40 – DETERMINATION</title>
+        <script src="phaser.min.js"></script>
+       <style>
+               @font-face { font-family: "Ubuntu Mono"; src: url(UbuntuMono-R.ttf); }
+               body { font-family: "Ubuntu Mono", monospace; color: #000000; background: #000000; }
+       </style>
+    </head>
+    <body>
+
+    <script src="ld40.js"></script>
+    </body>
+</html>
diff --git a/ld40.js b/ld40.js
new file mode 100644 (file)
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 (file)
index 0000000..42827bd
Binary files /dev/null and b/monster.png differ
diff --git a/projectile.png b/projectile.png
new file mode 100644 (file)
index 0000000..8c9d262
Binary files /dev/null and b/projectile.png differ
diff --git a/projectile.svg b/projectile.svg
new file mode 100644 (file)
index 0000000..54e8bdf
--- /dev/null
@@ -0,0 +1,3 @@
+<svg height="10" width="10">
+  <circle cx="5" cy="5" r="2.5" stroke="black" stroke-width="0" fill="yellow" />
+</svg> 
diff --git a/wall.png b/wall.png
new file mode 100644 (file)
index 0000000..aa512b7
Binary files /dev/null and b/wall.png differ