From: MegaBrutal Date: Mon, 24 Apr 2017 00:20:50 +0000 (+0200) Subject: Initial commit X-Git-Url: http://git.megabrutal.com/?p=ld38.git;a=commitdiff_plain;h=9f6480e7cae175a04b8859c48bb19ff52c904677;ds=sidebyside Initial commit First version to be submitted for LD38. new file: gem.png new file: gem.svg new file: gem_active.png new file: gem_active.svg new file: index.html new file: ld38.html new file: ld38.js new file: player.png new file: player.svg new file: wall.png --- 9f6480e7cae175a04b8859c48bb19ff52c904677 diff --git a/gem.png b/gem.png new file mode 100644 index 0000000..d1e50db Binary files /dev/null and b/gem.png differ diff --git a/gem.svg b/gem.svg new file mode 100644 index 0000000..b3498d4 --- /dev/null +++ b/gem.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/gem_active.png b/gem_active.png new file mode 100644 index 0000000..8cff838 Binary files /dev/null and b/gem_active.png differ diff --git a/gem_active.svg b/gem_active.svg new file mode 100644 index 0000000..7d97a5c --- /dev/null +++ b/gem_active.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/index.html b/index.html new file mode 100644 index 0000000..93b54ff --- /dev/null +++ b/index.html @@ -0,0 +1,21 @@ + + + + + Ludum Dare 38 – Working Title + + + + +
+

Ludum Dare 38 – Working Title

+

(Game for Ludum Dare 38)

+ +

By MegaBrutal

+
+ + diff --git a/ld38.html b/ld38.html new file mode 100644 index 0000000..5762b3d --- /dev/null +++ b/ld38.html @@ -0,0 +1,16 @@ + + + + + Ludum Dare 38 – Working Title + + + + + + + + diff --git a/ld38.js b/ld38.js new file mode 100644 index 0000000..3b58c48 --- /dev/null +++ b/ld38.js @@ -0,0 +1,197 @@ + var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); + var walls; + var gems; + var shrinklevel = 0; + + const WAIT_KEY = 200; + const WAIT_GEM = 2000; + const WALL_THICKNESS = 32; + const MAX_GEMS = 16; + + var newWorldStartX; + var newWorldEndX; + var newWorldStartY; + var newWorldEndY; + + 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 Entity extends Phaser.Sprite { + constructor(x, y, sprite) { + super(game, x, y, sprite); + this.anchor.setTo(.5,.5); + } + + enablePhysics() { + game.physics.arcade.enable(this); + this.body.bounce.y = 0.2; + this.body.bounce.x = 0.2; + this.body.collideWorldBounds = true; + } + } + + class Player extends Entity { + constructor(x, y, sprite) { + super(x, y, sprite); + this.lastmovetime = 0; + } + } + + class Gem extends Entity { + constructor(x, y) { + super(x, y, 'gem'); + this.lastInteraction = 0; + this.isActivated = false; + } + + activate() { + this.isActivated = true; + this.loadTexture('gem_active'); + } + + deactivate() { + this.isActivated = false; + this.loadTexture('gem'); + } + } + + function sign(n) { + if (n >= 0) { return 1 } else { return -1 }; + } + + function preload () { + + game.load.image('wall', 'wall.png'); + game.load.image('player', 'player.png'); + game.load.image('gem', 'gem.png'); + game.load.image('gem_active', 'gem_active.png'); + + } + + function create () { + + game.world.setBounds(0, 0, 800, 600); + game.stage.backgroundColor = 'black'; + game.physics.startSystem(Phaser.Physics.ARCADE); + + walls = game.add.group(); + walls.classType = Phaser.TileSprite; + walls.enableBody = true; + + walls.add(game.add.tileSprite(0, 0, game.world.width, WALL_THICKNESS, 'wall')); + walls.add(game.add.tileSprite(0, game.world.height - WALL_THICKNESS, game.world.width, WALL_THICKNESS, 'wall')); + walls.add(game.add.tileSprite(0, 0, WALL_THICKNESS, game.world.height, 'wall')); + walls.add(game.add.tileSprite(game.world.width - WALL_THICKNESS, 0, WALL_THICKNESS, game.world.height, 'wall')); + walls.children.forEach(function(wall) { wall.body.immovable = true; }); + + gems = game.add.group(); + for (var i = 0; i <= MAX_GEMS; i++) + gems.add(new Gem((Math.random() * (game.world.width - (WALL_THICKNESS * 4))) + (WALL_THICKNESS * 2), (Math.random() * (game.world.height - (WALL_THICKNESS * 4))) + (WALL_THICKNESS * 2))); + gems.children.forEach(function(gem) { gem.enablePhysics(); }); + + player = new Player(64, game.world.height - 200, 'player'); + player.enablePhysics(); + game.add.existing(player); + game.camera.follow(player); + cursors = game.input.keyboard.createCursorKeys(); + + keyboard_handler = keyPress_default; + + newWorldStartX = WALL_THICKNESS; + newWorldEndX = game.world.width - WALL_THICKNESS; + newWorldStartY = WALL_THICKNESS; + newWorldEndY = game.world.height - WALL_THICKNESS; + + helptext = game.add.text(10, 10, "Move with arrows, activate dimension crystals to shrink the world.", { align: 'left', fill: '#000000', fontSize: 14 }); + helptext.font = "Ubuntu Mono"; + + } + + function update () { + + game.physics.arcade.collide(player, walls); + game.physics.arcade.overlap(player, gems, gem_overlap, gem_isInteractable); + + var isAllActive = true; + gems.children.forEach(function(gem) { if (!gem.isActivated) { isAllActive = false; }}); + if (isAllActive) { + world_shrink(); + }; + + 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() { + + if (cursors.left.isDown) + { + player.body.velocity.x = -150; + player.angle = -90; + player.lastmovetime = game.time.now; + } + else if (cursors.right.isDown) + { + player.body.velocity.x = 150; + player.angle = 90; + player.lastmovetime = game.time.now; + } + if (cursors.up.isDown) + { + player.body.velocity.y = -150; + player.angle = 0; + player.lastmovetime = game.time.now; + } + else if (cursors.down.isDown) + { + player.body.velocity.y = 150; + player.angle = 180; + player.lastmovetime = game.time.now; + } + + } + + function gem_isInteractable(player, gem) { + return (game.time.now - gem.lastInteraction) > WAIT_GEM; + } + + function gem_overlap(player, gem) { + + gem.lastInteraction = game.time.now; + gem.activate(); + + } + + function world_shrink() { + + if (player.x < (newWorldStartX + (newWorldEndX - newWorldStartX) / 2)) + newWorldEndX -= (newWorldEndX - newWorldStartX) / 2; + else + newWorldStartX += (newWorldEndX - newWorldStartX) / 2; + if (player.y < (newWorldStartY + (newWorldEndY - newWorldStartY) / 2)) + newWorldEndY -= (newWorldEndY - newWorldStartY) / 2; + else + newWorldStartY += (newWorldEndY - newWorldStartY) / 2; + + // Draw a wall around the new world bounds. + walls.add(game.add.tileSprite(newWorldStartX - WALL_THICKNESS, newWorldStartY - WALL_THICKNESS, newWorldEndX - newWorldStartX + WALL_THICKNESS * 2, WALL_THICKNESS, 'wall')); + walls.add(game.add.tileSprite(newWorldStartX - WALL_THICKNESS, newWorldEndY, newWorldEndX - newWorldStartX + WALL_THICKNESS * 2, WALL_THICKNESS, 'wall')); + walls.add(game.add.tileSprite(newWorldStartX - WALL_THICKNESS, newWorldStartY - WALL_THICKNESS, WALL_THICKNESS, newWorldEndY - newWorldStartY + WALL_THICKNESS * 2, 'wall')); + walls.add(game.add.tileSprite(newWorldEndX, newWorldStartY - WALL_THICKNESS, WALL_THICKNESS, newWorldEndY - newWorldStartY + WALL_THICKNESS * 2, 'wall')); + walls.children.forEach(function(wall) { wall.body.immovable = true; }); + + function relocateGem(gem) { + if (gem.x < newWorldStartX) gem.x = newWorldStartX + (newWorldStartX - gem.x); + else if (gem.x > newWorldEndX) gem.x = newWorldEndX + (newWorldEndX - gem.x); // Adding negative value is like substraction. + if (gem.y < newWorldStartY) gem.y = newWorldStartY + (newWorldStartY - gem.y); + else if (gem.y > newWorldEndY) gem.y = newWorldEndY + (newWorldEndY - gem.y); // Same. + gem.deactivate(); + } + gems.children.forEach(relocateGem); + + } diff --git a/player.png b/player.png new file mode 100644 index 0000000..7081815 Binary files /dev/null and b/player.png differ diff --git a/player.svg b/player.svg new file mode 100644 index 0000000..5dd6c77 --- /dev/null +++ b/player.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/wall.png b/wall.png new file mode 100644 index 0000000..aa512b7 Binary files /dev/null and b/wall.png differ