From 9f6480e7cae175a04b8859c48bb19ff52c904677 Mon Sep 17 00:00:00 2001 From: MegaBrutal Date: Mon, 24 Apr 2017 02:20:50 +0200 Subject: [PATCH] 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 --- gem.png | Bin 0 -> 453 bytes gem.svg | 113 ++++++++++++++++++++++++++++ gem_active.png | Bin 0 -> 451 bytes gem_active.svg | 113 ++++++++++++++++++++++++++++ index.html | 21 ++++++ ld38.html | 16 ++++ ld38.js | 197 +++++++++++++++++++++++++++++++++++++++++++++++++ player.png | Bin 0 -> 391 bytes player.svg | 73 ++++++++++++++++++ wall.png | Bin 0 -> 84 bytes 10 files changed, 533 insertions(+) create mode 100644 gem.png create mode 100644 gem.svg create mode 100644 gem_active.png create mode 100644 gem_active.svg create mode 100644 index.html create mode 100644 ld38.html create mode 100644 ld38.js create mode 100644 player.png create mode 100644 player.svg create mode 100644 wall.png diff --git a/gem.png b/gem.png new file mode 100644 index 0000000000000000000000000000000000000000..d1e50db14b9c4b9290e997353424bb110e291ab1 GIT binary patch literal 453 zcmV;$0XqJPP)Rldy-s_85o$o+5a^&d)6>Ck{gl@$--dW z3~)}eDVfyyRWd#=JTKYq!N>EXWa)qKqGYE*KQgg*LS$F6*hfkazKEB&4G!@J!76UH z%J+Dvl;1F_@EGqJ{0*-w4Es1}0&93CxzL@U>+ok>rLOk>amD+s3bvH;q)0aK9DKl+ zfgTk+z?GI+8R2IOFX?yX>V^CY?YjfAAP@!7^5Q@H(!w=o9WJ<>>4#oso8%arUa2rbgO1ZKPQuOVzfgt-LLn vABLwQ + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/gem_active.png b/gem_active.png new file mode 100644 index 0000000000000000000000000000000000000000..8cff838918159d6ae65497c6b68ae4cb4212426e GIT binary patch literal 451 zcmV;!0X+VRP);DqcjcL8%k|jN9ts_#an%(l%YhPEnqh$R=LG2YeZr zQNdH(>b8~}oVC>ry`fBr;CyoHW>b_C?5N6*2Lx7dzbjAirm4jiUU6~9wJGqbiI@0} zM@1PoP?Xs002ovPDHLkV1mg?zy<&S literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..7081815f947d53594c4b2a380e25f4f5fcbb9845 GIT binary patch literal 391 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4z0jTU$~~3Epp$$8CAiuSV8TW z&1}OQv%H{=%{*_a?|=VWdDushCm^9gv{nCeSjNJBwPTv?3-=rFw4Uc_m|}3wH98`S zgX46@^QbN%?C{a`7Z+16Rb i4COnHSm(X+xu2Lc>&ovx8jQd|WAJqKb6Mw<&;$V5OrHt> literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..aa512b712f85b3706a833423098838fb16b2537f GIT binary patch literal 84 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blmSQK*5Dp-y;YjHK^0_@-978x} dCja1PVc`7D{P%I_r#V1j22WQ%mvv4FO#oL>5={UA literal 0 HcmV?d00001 -- 2.34.1