├── favicon.png ├── data ├── image │ ├── logo.png │ ├── font │ │ ├── blue.png │ │ ├── black.png │ │ └── white.png │ ├── loading.png │ ├── main-menu.png │ ├── background.png │ ├── sprite │ │ ├── star.png │ │ ├── player.png │ │ ├── platform.png │ │ ├── checkpoint.png │ │ ├── enemy-square.png │ │ ├── teleporter.png │ │ ├── enemy-square2.png │ │ ├── enemy-square3.png │ │ ├── enemy-square4.png │ │ ├── enemy-square5.png │ │ ├── spike-vertical.png │ │ └── spike-horizontal.png │ └── tile │ │ ├── tiles.png │ │ └── metatiles.png └── audio │ ├── sfx │ ├── death.mp3 │ ├── death.ogg │ ├── jump.mp3 │ ├── jump.ogg │ ├── menu.mp3 │ ├── menu.ogg │ ├── checkpoint.mp3 │ └── checkpoint.ogg │ └── bgm │ ├── area000.mp3 │ ├── area000.ogg │ ├── main-menu.mp3 │ └── main-menu.ogg ├── robots.txt ├── .gitignore ├── manifest.webapp ├── humans.txt ├── package.json ├── js ├── entities │ ├── my-particle-emitter.js │ ├── teleporter.js │ ├── platform-.js │ ├── alerts.js │ ├── enemy-.js │ ├── messages.js │ ├── enemy-bouncy.js │ ├── checkpoint.js │ ├── star-background.js │ ├── spike.js │ ├── enemy-path.js │ ├── platform-movable.js │ ├── platform-vanishing.js │ └── player.js ├── gui │ ├── HUD.js │ ├── progress-bar.js │ ├── menu.js │ └── pause-handler.js ├── resources.js ├── repeatable-sprites.js ├── states │ ├── credits.js │ ├── game-over.js │ ├── loading.js │ ├── main-menu.js │ └── play.js └── game.js ├── css ├── index.css └── normalize.css ├── Gruntfile.js ├── index.html ├── README.md ├── lib └── plugins │ └── debugPanel.js └── LICENSE.md /favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/favicon.png -------------------------------------------------------------------------------- /data/image/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/logo.png -------------------------------------------------------------------------------- /data/audio/sfx/death.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/sfx/death.mp3 -------------------------------------------------------------------------------- /data/audio/sfx/death.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/sfx/death.ogg -------------------------------------------------------------------------------- /data/audio/sfx/jump.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/sfx/jump.mp3 -------------------------------------------------------------------------------- /data/audio/sfx/jump.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/sfx/jump.ogg -------------------------------------------------------------------------------- /data/audio/sfx/menu.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/sfx/menu.mp3 -------------------------------------------------------------------------------- /data/audio/sfx/menu.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/sfx/menu.ogg -------------------------------------------------------------------------------- /data/image/font/blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/font/blue.png -------------------------------------------------------------------------------- /data/image/loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/loading.png -------------------------------------------------------------------------------- /data/image/main-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/main-menu.png -------------------------------------------------------------------------------- /data/audio/bgm/area000.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/bgm/area000.mp3 -------------------------------------------------------------------------------- /data/audio/bgm/area000.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/bgm/area000.ogg -------------------------------------------------------------------------------- /data/image/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/background.png -------------------------------------------------------------------------------- /data/image/font/black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/font/black.png -------------------------------------------------------------------------------- /data/image/font/white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/font/white.png -------------------------------------------------------------------------------- /data/image/sprite/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/star.png -------------------------------------------------------------------------------- /data/image/tile/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/tile/tiles.png -------------------------------------------------------------------------------- /data/audio/bgm/main-menu.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/bgm/main-menu.mp3 -------------------------------------------------------------------------------- /data/audio/bgm/main-menu.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/bgm/main-menu.ogg -------------------------------------------------------------------------------- /data/audio/sfx/checkpoint.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/sfx/checkpoint.mp3 -------------------------------------------------------------------------------- /data/audio/sfx/checkpoint.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/audio/sfx/checkpoint.ogg -------------------------------------------------------------------------------- /data/image/sprite/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/player.png -------------------------------------------------------------------------------- /data/image/tile/metatiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/tile/metatiles.png -------------------------------------------------------------------------------- /robots.txt: -------------------------------------------------------------------------------- 1 | # www.robotstxt.org/ 2 | 3 | # Allow crawling of all content 4 | User-agent: * 5 | Disallow: 6 | -------------------------------------------------------------------------------- /data/image/sprite/platform.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/platform.png -------------------------------------------------------------------------------- /data/image/sprite/checkpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/checkpoint.png -------------------------------------------------------------------------------- /data/image/sprite/enemy-square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/enemy-square.png -------------------------------------------------------------------------------- /data/image/sprite/teleporter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/teleporter.png -------------------------------------------------------------------------------- /data/image/sprite/enemy-square2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/enemy-square2.png -------------------------------------------------------------------------------- /data/image/sprite/enemy-square3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/enemy-square3.png -------------------------------------------------------------------------------- /data/image/sprite/enemy-square4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/enemy-square4.png -------------------------------------------------------------------------------- /data/image/sprite/enemy-square5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/enemy-square5.png -------------------------------------------------------------------------------- /data/image/sprite/spike-vertical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/spike-vertical.png -------------------------------------------------------------------------------- /data/image/sprite/spike-horizontal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdantas/www/HEAD/data/image/sprite/spike-horizontal.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | 3 | .DS_Store 4 | 5 | node_modules/ 6 | 7 | .#*SPEEDBAR* 8 | 9 | webkit_build 10 | 11 | tmp 12 | /.project 13 | -------------------------------------------------------------------------------- /manifest.webapp: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "WWW", 3 | "launch_path" : "./index.html", 4 | "version" : "0.6.6", 5 | 6 | "developer": { 7 | "name" : "Alexandre Dantas", 8 | "url" : "http://alexdantas.net/" 9 | }, 10 | "fullscreen": true 11 | } -------------------------------------------------------------------------------- /humans.txt: -------------------------------------------------------------------------------- 1 | # humanstxt.org/ 2 | # The humans responsible for making this and technologies used 3 | 4 | # TEAM 5 | 6 | Lead Developer: Alexandre Dantas 7 | Contact: eu [at] alexdantas.net 8 | Website: http://alexdantas.net 9 | From: Brazil 10 | 11 | # THANKS 12 | 13 | 14 | 15 | # SITE 16 | 17 | ROOT: HTML5, CSS3 18 | LIBS: melonJS 19 | EDITOR: Emacs 20 | 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "WWW", 3 | "version" : "0.8.2", 4 | "author" : "Alexandre Dantas", 5 | "description" : "Low-resolution clone of the game VVVVVV", 6 | 7 | "repository" : "https://github.com/alexdantas/www", 8 | 9 | "main" : "index.html", 10 | "window" : { 11 | "toolbar" : false, 12 | "width" : 480, 13 | "height" : 480 14 | }, 15 | 16 | "devDependencies": { 17 | "grunt" : "~0.4.2", 18 | "grunt-processhtml" : "~0.3.0", 19 | "grunt-contrib-concat" : "~0.2.0", 20 | "grunt-contrib-clean" : "~0.4.0", 21 | "grunt-contrib-uglify" : "~0.2.7", 22 | "grunt-contrib-copy" : "~0.5.0", 23 | "grunt-rsync" : "~0.5.0", 24 | "grunt-node-webkit-builder" : "~0.1.21" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /js/entities/my-particle-emitter.js: -------------------------------------------------------------------------------- 1 | // Quick patch I did on melonJS's default ParticleEmitter 2 | 3 | /*global me,game*/ 4 | 5 | /** 6 | * My own class on top of melonJS' ParticleEmitter. 7 | * 8 | * The fucking irritating thing about melonJS's 9 | * ParticleEmitters is that they spawn OUTSIDE 10 | * of the bounds you specify. 11 | * 12 | * Here I'm overriding this obnoxious behavior, 13 | * making the Particle's random spawn points 14 | * be consistent with the ParticleEmitter's size. 15 | */ 16 | game.MyParticleEmitter = me.ParticleEmitter.extend({ 17 | 18 | getRandomPoint: function () { 19 | var vector = this.pos.clone(); 20 | vector.x += Number.prototype.random(0, this.width); 21 | vector.y += Number.prototype.random(0, this.height); 22 | return vector; 23 | } 24 | 25 | }); 26 | 27 | -------------------------------------------------------------------------------- /js/entities/teleporter.js: -------------------------------------------------------------------------------- 1 | /*global game,me*/ 2 | 3 | game.teleporter = game.teleporter || {}; 4 | 5 | /** 6 | * Teleporter that marks the end of the level. 7 | * 8 | * When the player touches it, he's supposed to handle the 9 | * level ending. 10 | * 11 | * You create an entity on Tiled, with the name 12 | * "teleporter" and then check for collisions with 13 | * the me.game.TELEPORTER_OBJECT inside the Player. 14 | */ 15 | game.teleporter.entity = me.CollectableEntity.extend({ 16 | 17 | init : function(x, y, settings) { 18 | 19 | // A dummy image - will never be used 20 | settings.image = "teleporter"; 21 | settings.spritewidth = 10; 22 | settings.spriteheight = 10; 23 | 24 | this.parent(x, y, settings); 25 | 26 | this.renderable.addAnimation("nothing", [0, 1], 1000); 27 | this.renderable.setCurrentAnimation("nothing"); 28 | 29 | this.type = me.game.TELEPORTER_OBJECT; 30 | }, 31 | 32 | onCollision : function () { 33 | // what...? 34 | } 35 | }); 36 | 37 | 38 | -------------------------------------------------------------------------------- /js/gui/HUD.js: -------------------------------------------------------------------------------- 1 | /** 2 | * HUDs (Head-Up Displays) show information to the 3 | * user above the actual game screen. 4 | * 5 | * For example, health, score, items and such... 6 | * 7 | * Each HUD shows a single information. 8 | * So we have a global container of HUDs, on which 9 | * we individually add each one to build the final 10 | * appearance. 11 | */ 12 | 13 | /*global game,me*/ 14 | 15 | // Here we make sure to create only if it wasn't 16 | // already created before 17 | game.HUD = game.HUD || {}; 18 | 19 | /** 20 | * Container for all the HUDs on the game. 21 | */ 22 | game.HUD.Container = me.ObjectContainer.extend({ 23 | 24 | init : function() { 25 | this.parent(); 26 | 27 | // Persistent across level changes 28 | this.isPersistent = true; 29 | 30 | // Non collidable 31 | this.collidable = false; 32 | 33 | // Makes sure to always draw on top of everything 34 | this.z = Infinity; 35 | 36 | // Give a cute name 37 | // NOTE: What for? 38 | this.name = "HUD"; 39 | 40 | // Add your HUDs here 41 | } 42 | }); 43 | 44 | -------------------------------------------------------------------------------- /js/entities/platform-.js: -------------------------------------------------------------------------------- 1 | // Le Platform 2 | 3 | /*global game,me*/ 4 | 5 | // Making sure this namespace exists 6 | game.platform = game.platform || {}; 7 | 8 | /** 9 | * Floating thing that you can step into. 10 | */ 11 | game.platform.entity = me.ObjectEntity.extend({ 12 | 13 | /** 14 | * Create a new Platform. 15 | * 16 | * @param settings A hash with options, defined on Tiled. 17 | */ 18 | init : function(x, y, settings) { 19 | 20 | settings.image = "platform"; 21 | 22 | settings.spritewidth = settings.width = 4; 23 | settings.spriteheight = settings.height = 1; 24 | 25 | // Creating the object (melonJS-specific stuff) 26 | this.parent(x, y, settings); 27 | 28 | // This is needed so it can be shown on the screen. 29 | this.renderable.addAnimation("stand-there-doing-nothing", [0]); 30 | this.renderable.setCurrentAnimation("stand-there-doing-nothing"); 31 | 32 | this.gravity = 0; 33 | this.collidable = true; 34 | this.type = me.game.PLATFORM_OBJECT; 35 | } 36 | 37 | // No need to overload more functions 38 | // since the entity will just stand there 39 | }); 40 | 41 | -------------------------------------------------------------------------------- /js/entities/alerts.js: -------------------------------------------------------------------------------- 1 | 2 | /*global game,me*/ 3 | 4 | /** 5 | * Alert dialogues that are called in-game. 6 | * 7 | * When the player touches it, creates a browser alert and 8 | * then destroy itself. 9 | * 10 | * Here's the catch: you create entities on Tiled, with the name 11 | * "alert" and an attribute "text" that contains 12 | * what will be shown. 13 | * Then it gets triggered when the player collides 14 | * with it! 15 | */ 16 | game.alertEntity = me.CollectableEntity.extend({ 17 | 18 | init : function(x, y, settings) { 19 | 20 | // A dummy image - will never be used 21 | settings.image = "spike-sprite-vertical"; 22 | settings.spritewidth = 2; 23 | settings.spriteheight = 2; 24 | 25 | this.parent(x, y, settings); 26 | 27 | this.renderable.addAnimation("nothing", [0]); 28 | this.renderable.setCurrentAnimation("nothing"); 29 | 30 | // The text that will be shown is defined on Tiled 31 | this.text = settings.text; 32 | }, 33 | 34 | onCollision : function () { 35 | 36 | alert(this.text); 37 | me.game.world.removeChild(this); 38 | 39 | }, 40 | 41 | draw : function(context) { 42 | 43 | // Won't draw! 44 | } 45 | }); 46 | 47 | 48 | -------------------------------------------------------------------------------- /js/entities/enemy-.js: -------------------------------------------------------------------------------- 1 | /*global game,me*/ 2 | 3 | // Making sure this namespace exists 4 | game.enemy = game.enemy || {}; 5 | 6 | /** 7 | * Enemy that simply stands there doing nothing. 8 | */ 9 | game.enemy.entity = me.ObjectEntity.extend({ 10 | 11 | /** 12 | * Create a new Enemy. 13 | * 14 | * @param settings A hash with options, defined on Tiled. 15 | */ 16 | init : function(x, y, settings) { 17 | 18 | // Randomly selecting between enemy-square[1-5] 19 | var sprite = Number.prototype.random(1, 5); 20 | 21 | settings.image = "enemy-square" + sprite; 22 | 23 | settings.spritewidth = settings.width = 2; 24 | settings.spriteheight = settings.height = 2; 25 | 26 | // Creating the object (melonJS-specific stuff) 27 | this.parent(x, y, settings); 28 | 29 | // This is needed so it can be shown on the screen. 30 | this.renderable.addAnimation("walking", [0, 1, 2, 3], 400); 31 | this.renderable.setCurrentAnimation("walking"); 32 | 33 | // This object doesn't respect the laws 34 | // of physics. 35 | this.gravity = 0; 36 | this.collidable = true; 37 | this.type = me.game.ENEMY_OBJECT; 38 | } 39 | 40 | // No need to overload more functions 41 | // since the entity will just stand there 42 | }); 43 | 44 | 45 | -------------------------------------------------------------------------------- /css/index.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Simple root CSS for the game. 3 | * Taken from the melonJS Boilerplate. 4 | * 5 | * Note: make sure to include `normalize.css` before this! 6 | */ 7 | body { 8 | background-color: #000; 9 | color: #fff; 10 | 11 | /* Allow mouse dragging. */ 12 | -moz-user-select: none; 13 | -ms-user-select: none; 14 | -o-user-select: none; 15 | -webkit-user-select: none; 16 | user-select: none; 17 | 18 | /* disable touch panning/zooming */ 19 | -ms-touch-action: none; 20 | touch-action: none; 21 | 22 | /* Allow canvas to hit the edges of the browser viewport. */ 23 | margin: 0; 24 | } 25 | #screen canvas { 26 | margin: auto; 27 | 28 | /* Hide the gap for font descenders. */ 29 | display: block; 30 | 31 | /* disable scaling interpolation */ 32 | image-rendering: optimizeSpeed; 33 | image-rendering: -moz-crisp-edges; 34 | image-rendering: -o-crisp-edges; 35 | image-rendering: -webkit-optimize-contrast; 36 | image-rendering: optimize-contrast; 37 | -ms-interpolation-mode: nearest-neighbor; 38 | } 39 | 40 | /* Now, hacks to make the description look good */ 41 | 42 | #description { 43 | position:absolute; 44 | bottom:0px; 45 | width:100%; 46 | margin: 0; 47 | left: 0; 48 | height:auto; 49 | background:#111; 50 | } 51 | #description h1, #description h5 { 52 | margin: 0; 53 | } 54 | #description ul { 55 | list-style-type: square 56 | } 57 | #description div { 58 | margin-left : 1%; 59 | width: 80%; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /js/entities/messages.js: -------------------------------------------------------------------------------- 1 | // Printable texts 2 | 3 | /*global game,me*/ 4 | 5 | /** 6 | * Texts that can appear on the maps. 7 | * 8 | * Here's the catch: you create entities on Tiled, with the name 9 | * "message" and an attribute "text" that contains 10 | * what will be shown. 11 | * Then it gets displayed on the map just like 12 | * any other thing :D 13 | */ 14 | game.messageEntity = me.Renderable.extend({ 15 | 16 | init : function(x, y, settings) { 17 | 18 | // Creating the parent Rectangle 19 | // Width/Height doesn't matter now 20 | this.parent(new me.Vector2d(x, y), 0, 0); 21 | 22 | // The text that will be shown is defined on Tiled 23 | // Since you can specify line breaks (\n), let's 24 | // split the text into lines here: 25 | // 26 | // @note Why the double \\ ? On the `states/credits.js` 27 | // file I don't need it, just a simple '\n'! 28 | this.text = settings.text.split('\\n'); 29 | }, 30 | 31 | update : function(delta) { 32 | // No need to redraw every frame 33 | return false; 34 | }, 35 | 36 | draw : function(context) { 37 | 38 | // To correctly draw the message on the screen 39 | // we need to know the width/height of the final 40 | // drawn text. 41 | var textScreenSize = game.font_white.measureText(context, this.text); 42 | 43 | this.width = textScreenSize.width; 44 | this.height = textScreenSize.height; 45 | 46 | // Drawing line by line 47 | for (var i = 0; i < this.text.length; i++) { 48 | 49 | game.font_white.draw( 50 | context, 51 | this.text[i], 52 | this.pos.x, 53 | this.pos.y + 4*i); // TEXT LINE SIZE, CHANGE HERE 54 | // IF YOU EVER CHANGE THE FONT 55 | } 56 | } 57 | }); 58 | 59 | 60 | -------------------------------------------------------------------------------- /js/entities/enemy-bouncy.js: -------------------------------------------------------------------------------- 1 | /*global game,me*/ 2 | 3 | game.enemy = game.enemy || {}; 4 | 5 | game.enemy.bouncy = game.enemy.bouncy || {}; 6 | 7 | game.enemy.bouncy.type = { 8 | HORIZONTAL : "horizontal", 9 | VERTICAL : "vertical", 10 | BOTH : "both" 11 | }; 12 | 13 | /** 14 | * Walks through an axis (vertical, horizontal or both) 15 | * bouncing on every tile on the map that's solid. 16 | */ 17 | game.enemy.bouncy.entity = game.enemy.entity.extend({ 18 | 19 | /** 20 | * Creates the enemy. 21 | * 22 | * @param settings Hash of options defined on Tiled. 23 | * 24 | * @note You MUST specify a type for this enemy. 25 | * It can be "horizontal", "vertical" or "both". 26 | */ 27 | init : function (x, y, settings) { 28 | 29 | // Defaulting to horizontal enemy 30 | this.walkType = settings.type || game.enemy.bouncy.type.HORIZONTAL; 31 | 32 | this.parent(x, y, settings); 33 | 34 | this.walkLeft = true; 35 | this.walkUp = true; 36 | 37 | this.setVelocity(0.12, 0.12); 38 | 39 | // THIS IS A "BUG" ON MELONJS 40 | // Since the player is 2 pixels large, it's 41 | // collision box actually is 3 pixels large! 42 | // Don't know why but I have to adjust it 43 | // manually here. 44 | if (this.walkType === game.enemy.bouncy.type.HORIZONTAL) { 45 | 46 | var shape = this.getShape(); 47 | shape.resize( 48 | shape.width - 1, 49 | shape.height 50 | ); 51 | } 52 | }, 53 | 54 | update : function (delta) { 55 | 56 | // Do nothing if not on the screen 57 | if (! this.inViewport) 58 | return false; 59 | 60 | if (this.alive) { 61 | 62 | if (this.walkType !== game.enemy.bouncy.type.HORIZONTAL) { 63 | // This is either VERTICAL or BOTH 64 | 65 | this.vel.y += ((this.walkUp) ? 66 | -this.accel.y : 67 | this.accel.y) * me.timer.tick; 68 | 69 | } 70 | if (this.walkType !== game.enemy.bouncy.type.VERTICAL) { 71 | // This is either HORIZONTAL or BOTH 72 | 73 | this.vel.x += ((this.walkLeft) ? 74 | -this.accel.x : 75 | this.accel.x) * me.timer.tick; 76 | } 77 | } 78 | else { 79 | this.vel.x = this.vel.y = 0; 80 | } 81 | 82 | // melonJS internal callback 83 | var collision = this.updateMovement(); 84 | 85 | // Collided vertically! 86 | if (collision.y != 0) 87 | if (this.walkType === game.enemy.bouncy.type.VERTICAL) 88 | this.walkUp = (! this.walkUp); 89 | 90 | // Collided horizontally 91 | if (collision.x != 0) 92 | if (this.walkType === game.enemy.bouncy.type.HORIZONTAL) 93 | this.walkLeft = (! this.walkLeft); 94 | 95 | this.parent(delta); 96 | return true; 97 | } 98 | }); 99 | 100 | -------------------------------------------------------------------------------- /js/entities/checkpoint.js: -------------------------------------------------------------------------------- 1 | // Le checkpoint 2 | 3 | /*global game,me*/ 4 | 5 | // Separate namespace (just for making things pretty) 6 | game.checkpoint = game.checkpoint || {}; 7 | 8 | /** 9 | * Type of this checkpoint: if it's on the roof 10 | * or on the ground. 11 | */ 12 | game.checkpoint.type = { 13 | TOP : "top", 14 | BOTTOM : "bottom" 15 | }; 16 | 17 | /** 18 | * Global reference to the current checkpoint. 19 | * 20 | * I know it's a terrible thing to do, but we need 21 | * to deactivate the previous checkpoint if we activate 22 | * another. 23 | */ 24 | game.checkpoint.current = null; 25 | 26 | /** 27 | * Thing that enables the player to return to it's position, 28 | * when collided. 29 | */ 30 | game.checkpointEntity = me.ObjectEntity.extend({ 31 | 32 | /** 33 | * Create a new Checkpoint. 34 | * 35 | * @param settings A hash with options, defined on Tiled. 36 | */ 37 | init : function(x, y, settings) { 38 | 39 | // If Tiled doesn't specify the checkpoint type, 40 | // let's default it to stick on the ground. 41 | this.checkpointType = settings.type || game.checkpoint.type.BOTTOM; 42 | 43 | settings.image = "checkpoint"; 44 | settings.spritewidth = settings.width = 2; 45 | settings.spriteheight = settings.height = 2; 46 | 47 | // Creating the object (melonJS-specific stuff) 48 | this.parent(x, y, settings); 49 | 50 | this.renderable.addAnimation("inactive", [0]); 51 | this.renderable.addAnimation("active", [1]); 52 | 53 | this.renderable.setCurrentAnimation("inactive"); 54 | 55 | this.active = false; 56 | 57 | this.collidable = true; 58 | this.type = me.game.CHECKPOINT_OBJECT; 59 | }, 60 | 61 | /** 62 | * Called when an object collides with us. 63 | */ 64 | onCollision : function(collisionVector, otherObject) { 65 | 66 | // Player hit us! 67 | if (otherObject.type === me.game.PLAYER_OBJECT) { 68 | this.activate(true); 69 | otherObject.checkpoint(this.pos.x, this.pos.y, this.checkpointType); 70 | } 71 | }, 72 | 73 | /** 74 | * Turns "on" or "off" this checkpoint. 75 | * 76 | * @param option Boolean with option activate. 77 | */ 78 | activate : function (option) { 79 | 80 | // If we're going to activate this checkpoint, 81 | // we need to deactivate the previous 82 | if (option) { 83 | 84 | // No need to activate if this checkpoint 85 | // is ourselves. 86 | if ((game.checkpoint.current) && 87 | (game.checkpoint.current !== this)) { 88 | 89 | game.checkpoint.current.activate(false); 90 | me.audio.play("checkpoint", false, null, me.save.sfxVolume); 91 | } 92 | game.checkpoint.current = this; 93 | } 94 | 95 | // Activatin' 96 | this.active = option; 97 | this.renderable.setCurrentAnimation((option) ? 98 | "active" : 99 | "inactive"); 100 | }, 101 | 102 | update : function (delta) { 103 | return true; 104 | } 105 | }); 106 | 107 | -------------------------------------------------------------------------------- /js/entities/star-background.js: -------------------------------------------------------------------------------- 1 | 2 | /*global me,game*/ 3 | 4 | /** 5 | * Shows a nice background full of stars spawning on random 6 | * places and moving right. 7 | * 8 | * It keeps spawning stars (Particles) that disappear when 9 | * outside the screen or when a certain timeout expires. 10 | * 11 | * How to use: 12 | * 13 | * Create it and add it to the world. 14 | * Make sure to add it's internal container too. 15 | * Like this: 16 | * 17 | * var stars = new me.starBackground(); 18 | * me.game.addChild(stars); 19 | * me.game.addChild(stars.container); 20 | * 21 | * Finally, order it to begin streaming particles: 22 | * 23 | * stars.streamParticles(); 24 | * 25 | * @note I've extended the melonJS' ParticleEmitter class. 26 | * See below. 27 | * 28 | * The fucking irritating thing about melonJS's 29 | * ParticleEmitters is that they spawn OUTSIDE 30 | * of the bounds you specify. 31 | * 32 | * Here I'm overriding this obnoxious behavior, 33 | * making the Particle's random spawn points 34 | * be consistent with the ParticleEmitter's size. 35 | * 36 | * See `getRandomPoint`. 37 | */ 38 | game.starBackground = me.ParticleEmitter.extend({ 39 | 40 | init : function() { 41 | 42 | // Here we create a melonJS ParticleEmitter and 43 | // tell how it's Particles should behave. 44 | // 45 | // NOTE TO SELF: 46 | // melonJS' ParticleEngines don't render 1 pixel-images. 47 | // At least not on a 32x32 resolution. 48 | // 49 | // It took me 2 hours to figure out this was the problem. 50 | // Damn, nigga. 51 | // 52 | // Thus, I'm using a 2x2 image with a 1x1 pixel inside. 53 | // 54 | var particleSettings = { 55 | 56 | // Complete vacuum! 57 | gravity : 0, 58 | wind : 0, 59 | angle : 0, 60 | 61 | // I need to fine-tune these 62 | // Need to better adjust according to the situation 63 | // or whatever. 64 | totalParticles : 15, 65 | frequency : 100, // ms 66 | speed : 0.6, 67 | speedVariation : 0.4, 68 | minLife : 2000, // ms 69 | maxLife : 3000, // ms 70 | onlyInViewport : true, 71 | floating : true, 72 | 73 | image : me.loader.getImage("star"), 74 | 75 | // Dimensions of the particle emitter! 76 | // Not of the particles! 77 | width : 2, 78 | height : 32 79 | }; 80 | 81 | // Creating the thing that will spawn the particles. 82 | // Remember, they will get spawned INSIDE it. 83 | this.parent(0, 0, particleSettings); 84 | }, 85 | 86 | /** 87 | * Overriding the melonJS function that generates 88 | * random Particles. 89 | * 90 | * See the class info for a better description. 91 | */ 92 | getRandomPoint: function () { 93 | var vector = this.pos.clone(); 94 | 95 | vector.x += Number.prototype.random(0, this.width); 96 | vector.y += Number.prototype.random(0, this.height); 97 | 98 | return vector; 99 | } 100 | }); 101 | 102 | -------------------------------------------------------------------------------- /js/entities/spike.js: -------------------------------------------------------------------------------- 1 | // Le Spike 2 | 3 | /*global game,me*/ 4 | 5 | // Creating a "Spike" namespace 6 | game.spike = game.spike || {}; 7 | 8 | /** 9 | * All possible spike types (positions). 10 | * 11 | * Check it out: 12 | * - TOP Horizontal spike, pointed down (\/) 13 | * - BOTTOM Horizontal spike, pointed up (/\) 14 | * - LEFT Vertical spike, pointed left (<) 15 | * - RIGHT Vertical spike, pointed right (>) 16 | */ 17 | game.spike.type = { 18 | TOP : "top", 19 | BOTTOM : "bottom", 20 | LEFT : "left", 21 | RIGHT : "right" 22 | }; 23 | 24 | /** 25 | * Single-tile spike that kills the player on contact. 26 | * 27 | * Check out `game.spike.type` right up there for the 28 | * possible spike types. 29 | * 30 | * @note When you create a `spike` on Tiled, if you 31 | * span a huge area the spike sprite will repeat 32 | * along it. 33 | */ 34 | game.spikeEntity = me.ObjectEntity.extend({ 35 | 36 | /** 37 | * Create a new Spike. 38 | * 39 | * @param settings A hash with options, defined on Tiled. 40 | */ 41 | init : function(x, y, settings) { 42 | 43 | // If Tiled doesn't specify the spike type, 44 | // let's default it to pointing up. 45 | this.type = settings.type || game.spike.type.TOP; 46 | 47 | // The Spike type will define the sprite. 48 | // Here we set which image will be used to show 49 | // the spike. 50 | 51 | if ((this.type === game.spike.type.TOP) || 52 | (this.type === game.spike.type.BOTTOM)) 53 | settings.image = "spike-sprite-vertical"; 54 | 55 | else if ((this.type === game.spike.type.LEFT) 56 | (this.type === game.spike.type.RIGHT)) 57 | settings.image = "spike-sprite-horizontal"; 58 | 59 | else 60 | // Sanity check: not allowing other kinds of spikes 61 | throw 'Unknown Spike type "' + this.type + '"!'; 62 | 63 | // Adjust the size setting to match the sprite size 64 | settings.spritewidth = 2; 65 | settings.spriteheight = 2; 66 | 67 | // Creating the object (melonJS-specific stuff) 68 | this.parent(x, y, settings); 69 | 70 | // Now, instead of having a single spike sprite 71 | // let's repeat it along the area defined by 72 | // the player. 73 | this.renderable = new me.RepeatableSpriteObject( 74 | this.pos.x, this.pos.y, 75 | me.loader.getImage(settings.image), 76 | settings.spritewidth, settings.spriteheight, 77 | this.width, this.height 78 | ); 79 | 80 | // These are the exceptions 81 | // Need to flip the sprite since we don't 82 | // have an image for each type 83 | if (this.type === game.spike.type.RIGHT) 84 | this.renderable.flipX(); 85 | 86 | else if (this.type === game.spike.type.TOP) 87 | this.renderable.flipY(); 88 | 89 | this.collidable = true; 90 | this.type = me.game.SPIKE_OBJECT; 91 | }, 92 | 93 | draw : function (context) { 94 | this.renderable.draw(context); 95 | } 96 | 97 | // No need to overload more functions 98 | // since the entity will just stand there 99 | }); 100 | 101 | 102 | -------------------------------------------------------------------------------- /js/resources.js: -------------------------------------------------------------------------------- 1 | /** 2 | * All resources that need to be loaded. 3 | * (images, fonts, maps and audio) 4 | */ 5 | 6 | /*global game*/ 7 | 8 | game.resources = [ 9 | 10 | // Tilesets 11 | { 12 | name : "tiles", 13 | type : "image", 14 | src : "data/image/tile/tiles.png" 15 | }, 16 | 17 | // Sprites 18 | { 19 | name : "player-spritesheet", 20 | type : "image", 21 | src : "data/image/sprite/player.png" 22 | }, 23 | { 24 | name : "spike-sprite-horizontal", 25 | type : "image", 26 | src : "data/image/sprite/spike-horizontal.png" 27 | }, 28 | { 29 | name : "spike-sprite-vertical", 30 | type : "image", 31 | src : "data/image/sprite/spike-vertical.png" 32 | }, 33 | { 34 | name : "checkpoint", 35 | type : "image", 36 | src : "data/image/sprite/checkpoint.png" 37 | }, 38 | { 39 | name : "enemy-square1", 40 | type : "image", 41 | src : "data/image/sprite/enemy-square.png" 42 | }, 43 | { 44 | name : "enemy-square2", 45 | type : "image", 46 | src : "data/image/sprite/enemy-square2.png" 47 | }, 48 | { 49 | name : "enemy-square3", 50 | type : "image", 51 | src : "data/image/sprite/enemy-square3.png" 52 | }, 53 | { 54 | name : "enemy-square4", 55 | type : "image", 56 | src : "data/image/sprite/enemy-square4.png" 57 | }, 58 | { 59 | name : "enemy-square5", 60 | type : "image", 61 | src : "data/image/sprite/enemy-square5.png" 62 | }, 63 | { 64 | name : "star", 65 | type : "image", 66 | src : "data/image/sprite/star.png" 67 | }, 68 | { 69 | name : "platform", 70 | type : "image", 71 | src : "data/image/sprite/platform.png" 72 | }, 73 | { 74 | name : "teleporter", 75 | type : "image", 76 | src : "data/image/sprite/teleporter.png" 77 | }, 78 | 79 | // Backgrounds 80 | { 81 | name : "background", 82 | type : "image", 83 | src : "data/image/background.png" 84 | }, 85 | { 86 | name : "loading-bg", 87 | type : "image", 88 | src : "data/image/loading.png" 89 | }, 90 | { 91 | name : "main-menu-bg", 92 | type : "image", 93 | src : "data/image/main-menu.png" 94 | }, 95 | { 96 | name : "logo", 97 | type : "image", 98 | src : "data/image/logo.png" 99 | }, 100 | 101 | // Font 102 | { 103 | name: "font-white", 104 | type: "image", 105 | src: "data/image/font/white.png" 106 | }, 107 | { 108 | name: "font-black", 109 | type: "image", 110 | src: "data/image/font/black.png" 111 | }, 112 | { 113 | name: "font-blue", 114 | type: "image", 115 | src: "data/image/font/blue.png" 116 | }, 117 | 118 | // Maps 119 | { 120 | name : "area000", 121 | type : "tmx", 122 | src : "data/map/area000.tmx" 123 | }, 124 | 125 | // Music 126 | { 127 | name : "main-menu", 128 | type : "audio", 129 | src : "data/audio/bgm/", 130 | channel : 1 131 | }, 132 | { 133 | name : "area000", 134 | type : "audio", 135 | src : "data/audio/bgm/", 136 | channel : 1 137 | }, 138 | 139 | // Sound Effects 140 | { 141 | name : "menu", 142 | type : "audio", 143 | src : "data/audio/sfx/", 144 | channel : 2 145 | }, 146 | { 147 | name : "jump", 148 | type : "audio", 149 | src : "data/audio/sfx/", 150 | channel : 2 151 | }, 152 | { 153 | name : "death", 154 | type : "audio", 155 | src : "data/audio/sfx/", 156 | channel : 2 157 | }, 158 | { 159 | name : "checkpoint", 160 | type : "audio", 161 | src : "data/audio/sfx/", 162 | channel : 2 163 | } 164 | ]; 165 | 166 | -------------------------------------------------------------------------------- /js/repeatable-sprites.js: -------------------------------------------------------------------------------- 1 | // This is an extension I did on the melonJS library. 2 | // That's why I don't place it along with my game entities. 3 | 4 | /*global game,me*/ 5 | 6 | /** 7 | * Displays a sprite on the screen, being able to repeat 8 | * the image along the vertical and horizontal axis. 9 | * @class 10 | * @extends me.SpriteObject 11 | * 12 | * It's just like a regular Sprite, but it can repeat an 13 | * image as much as you want. 14 | * 15 | * Here's the idea: 16 | * 17 | * You have several spikes on the Tiled map, 18 | * one right next to another, but it's such a pain 19 | * in the ass to put them individually... 20 | * 21 | * So you create a big `RepeatableSpriteObject` entity, 22 | * that's the size of all the spikes together, and it 23 | * will look to the player like it's a lot of spikes 24 | * when "actually it will be one". 25 | * 26 | */ 27 | me.RepeatableSpriteObject = me.SpriteObject.extend({ 28 | 29 | /** 30 | * Creates a repeatable sprite inside a specific area. 31 | * 32 | * @param spritewidth Width of the image you want to repeat. 33 | * @param spriteheight Height of the image you want to repeat. 34 | * @param width Width of the area that you want to repeat the sprites on. 35 | * @param height Height of the area that you want to repeat the sprites on. 36 | * 37 | * @note Other parameters are just like on `SpriteObject`. 38 | */ 39 | init : function (x, y, image, spritewidth, spriteheight, width, height) { 40 | this.parent(x, y, image, spritewidth, spriteheight); 41 | 42 | // Let's use this to know the area where 43 | // to repeat the sprites 44 | this.fullWidth = width; 45 | this.fullHeight = height; 46 | 47 | // These are the repeat area limits. 48 | // Just a simple visualization: 49 | // 50 | // this.pos.x _________________ this.limitX 51 | // this.pos.y | | 52 | // | | 53 | // | | 54 | // this.limitY |________________| this.limitX + this.limitY 55 | // 56 | this.limitX = this.pos.x + this.fullWidth; 57 | this.limitY = this.pos.y + this.fullHeight; 58 | }, 59 | 60 | draw : function(context) { 61 | 62 | // To draw the repeated sprites we'll change 63 | // our x and y positions. 64 | // 65 | // We're storing the original one so we can 66 | // restore them when done drawing. 67 | this.originalPos = this.originalPos || this.pos.clone(); 68 | 69 | // Finally, here we're repeating all the sprites. 70 | // Seems strange, but read calmly and you'll get it. 71 | // 72 | // Lemme show you the order of drawing. 73 | // [ ] are not-drawn-yet sprites 74 | // [X] are drawn sprite 75 | // 76 | // 1.[ ][ ] 2.[X][ ] 3.[X][ ] 4.[X][X] 5.[X][X] 77 | // [ ][ ] [ ][ ] [X][ ] [X][ ] [X][X] 78 | // 79 | // So we first draw all Y sprites on the first X. 80 | // Then we repeat for the next X and so on. 81 | 82 | while (this.pos.x < this.limitX) { 83 | 84 | // Need to reset Y here for each X 85 | this.pos.y = this.originalPos.y; 86 | 87 | while (this.pos.y < this.limitY) { 88 | 89 | // FINALLY drawing 90 | // Our parent (SpriteObject) is responsible 91 | // for placing the Image on the Canvas, 92 | // according to our `this.pos.x` and `this.pos.y` 93 | this.parent(context); 94 | 95 | this.pos.y += this.height; 96 | } 97 | 98 | this.pos.x += this.width; 99 | } 100 | 101 | // Restoring original position! 102 | this.pos.setV(this.originalPos); 103 | } 104 | }); 105 | -------------------------------------------------------------------------------- /js/states/credits.js: -------------------------------------------------------------------------------- 1 | // Aww yeah 2 | 3 | /*global game,me*/ 4 | 5 | /** 6 | * Text that can be scrolled on the screen, 7 | * both on vertical and horizontal axis. 8 | */ 9 | game.ScrollableText = me.Renderable.extend ({ 10 | 11 | init : function(text) { 12 | 13 | // Embracing all the screen size 14 | this.parent(new me.Vector2d(0, 0), 15 | me.game.viewport.width, 16 | me.game.viewport.height); 17 | 18 | // How much of the text was scrolled 19 | // until now. 20 | this.yScrollOffset = 0; 21 | this.xScrollOffset = 0; 22 | 23 | // How much to scroll at each step 24 | this.yScrollIncrement = 2; 25 | this.xScrollIncrement = 2; 26 | 27 | // Full text that will be shown on the screen 28 | this.text = text; 29 | 30 | // Array that contains the text, separated 31 | // by newlines (\n) 32 | this.array = this.text.split('\n'); 33 | }, 34 | 35 | update : function(dt) { 36 | // This will make it redraw every frame 37 | return true; 38 | }, 39 | 40 | draw : function(context) { 41 | 42 | me.video.clearSurface(context, 'black'); 43 | 44 | // Drawing each line 45 | for (var i = 0; i < this.array.length; i++) { 46 | 47 | game.font_white.draw( 48 | context, 49 | this.array[i], 50 | this.xScrollOffset, 51 | this.yScrollOffset + 4*i // TEXT LINE SIZE, CHANGE HERE 52 | // IF YOU EVER CHANGE THE FONT 53 | ); 54 | } 55 | } 56 | }); 57 | 58 | /** 59 | * Shows information on the game, scrollable text. 60 | * 61 | * Has static text, links and if any key is pressed 62 | * (except the arrow keys) it goes back to the main menu. 63 | */ 64 | game.CreditsState = me.ScreenObject.extend({ 65 | 66 | /** 67 | * Runs when entering the state. 68 | */ 69 | onResetEvent : function() { 70 | 71 | // Binding User Input 72 | me.input.bindKey(me.input.KEY.DOWN, "scroll-down", true); 73 | me.input.bindKey(me.input.KEY.UP, "scroll-up", true); 74 | me.input.bindKey(me.input.KEY.LEFT, "scroll-left", true); 75 | me.input.bindKey(me.input.KEY.RIGHT, "scroll-right", true); 76 | 77 | // Creating the static text 78 | this.text = new game.ScrollableText( 79 | "SCROLL\n" + 80 | "WITH\n" + 81 | "ARROW\n" + 82 | "KEYS\n" + 83 | "\n" + 84 | "GAME MADE\n" + 85 | "BY\n" + 86 | "ALEXANDRE\n" + 87 | "DANTAS\n" + 88 | "\n" + 89 | "FOR MORE\n" + 90 | "GO TO\n" + 91 | "GITHUB.COM/\n" + 92 | "ALEXDANTAS/\n" + 93 | "WWW" 94 | ); 95 | me.game.world.addChild(this.text); 96 | 97 | // If any key is pressed, go back 98 | // to the Main Menu 99 | this.handler = me.event.subscribe(me.event.KEYDOWN, function (action, keyCode, edge) { 100 | var state = me.state.current(); 101 | 102 | if (action === "scroll-down") 103 | state.text.yScrollOffset -= state.text.yScrollIncrement; 104 | 105 | else if (action === "scroll-up") 106 | state.text.yScrollOffset += state.text.yScrollIncrement; 107 | 108 | else if (action === "scroll-left") 109 | state.text.xScrollOffset += state.text.xScrollIncrement; 110 | 111 | else if (action === "scroll-right") 112 | state.text.xScrollOffset -= state.text.xScrollIncrement; 113 | 114 | // Aww jeez, ok, ok, you can go back to the game... 115 | else 116 | me.state.change(me.state.STATE_MAIN_MENU); 117 | }); 118 | }, 119 | 120 | /** 121 | * Action to perform when leaving the state (state change). 122 | */ 123 | onDestroyEvent : function() { 124 | me.event.unsubscribe(this.handler); 125 | me.game.world.removeChild(this.text); 126 | } 127 | }); 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /js/gui/progress-bar.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Simple progress bar that can be used for anything. 3 | * 4 | * It's a background rectangle with foreground rectangle 5 | * showing process. 6 | */ 7 | 8 | /*global me*/ 9 | 10 | me.ProgressBar = me.Renderable.extend({ 11 | 12 | /** 13 | * Creates a progress bar at specified position 14 | * and specified size. 15 | * 16 | * @param posVector Position of the overall progress bar 17 | * (melonJS' `Vector2d` class) 18 | * 19 | * @param padding Internal padding for the progress bar 20 | * (another melonJS' `Vector2d` class) 21 | * (optional) 22 | */ 23 | init: function(posVector, w, h, padding) { 24 | this.parent(posVector, w, h); 25 | 26 | // Internal flag to know when we 27 | // must redraw the progress bar 28 | this.forceRedraw = false; 29 | 30 | // Width of the top rectangle 31 | this.progressWidth = 0; 32 | 33 | // Padding of the internal progress rectangle 34 | this.progressPadding = ((typeof(padding) === "undefined") ? 35 | new me.Vector2d(0, 0) : 36 | padding); 37 | 38 | this.setColors('white', 'black'); 39 | 40 | // Optional text to display on top of the progress bar 41 | this.text = null; 42 | 43 | // Creating font just in case... 44 | // 45 | // TODO: Dynamically adjust the font size according 46 | // to our size 47 | // TODO: Default font name? 48 | this.font = new me.Font( 49 | "century gothic", 12, "white", "middle" 50 | ); 51 | }, 52 | 53 | /** 54 | * Adjusts the bar's internal size according to 55 | * `progress`. 56 | * 57 | * @param progress Number between 0 and 1 representing 58 | * the percentage of progress of the bar. 59 | */ 60 | onProgressUpdate : function(progress, text) { 61 | this.progressWidth = Math.floor(progress * this.width); 62 | this.forceRedraw = true; 63 | 64 | this.text = ((typeof(text) === "undefined") ? 65 | null : 66 | text); 67 | }, 68 | 69 | // make sure the screen is refreshed every frame 70 | update : function() { 71 | if (this.forceRedraw === true) { 72 | this.forceRedraw = false; 73 | return true; 74 | } 75 | return false; 76 | }, 77 | 78 | // draw function 79 | draw : function(context) { 80 | 81 | // Draw the bottom bar 82 | // (external rectangle) 83 | context.fillStyle = this.backgroundColor; 84 | context.fillRect( 85 | this.pos.x, 86 | this.pos.y, 87 | this.width, 88 | this.height 89 | ); 90 | 91 | // Draw the progress bar 92 | // (internal rectangle) 93 | context.fillStyle = this.foregroundColor; 94 | context.fillRect( 95 | this.pos.x + this.progressPadding.x, 96 | this.pos.y + this.progressPadding.y, 97 | this.progressWidth - this.progressPadding.x * 2, 98 | this.height - this.progressPadding.y * 2 99 | ); 100 | 101 | // Now we draw the OPTIONAL text. 102 | if (this.text === null) 103 | return; 104 | 105 | this.font.draw( 106 | context, 107 | this.text, 108 | this.pos.x + this.progressPadding.x + 2, 109 | this.pos.y + this.progressPadding.y 110 | ); 111 | }, 112 | 113 | /** 114 | * Sets the foreground and background colors of the 115 | * progress bar. 116 | * 117 | * @param foreground Color for the completed part 118 | * of the bar (string). 119 | * @param background Color for the incomplete part 120 | * of the bar (string). 121 | */ 122 | setColors : function(foreground, background) { 123 | this.foregroundColor = foreground; 124 | this.backgroundColor = background; 125 | } 126 | }); 127 | 128 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * - `Makefile` if for `make` 3 | * - `Rakefile` is for `rake`, 4 | * - `Gruntfile` is for `grunt` :) 5 | */ 6 | 7 | module.exports = function(grunt) { 8 | 9 | // Including all helpers 10 | grunt.loadNpmTasks('grunt-contrib-concat'); 11 | grunt.loadNpmTasks('grunt-contrib-uglify'); 12 | grunt.loadNpmTasks('grunt-contrib-copy'); 13 | grunt.loadNpmTasks('grunt-contrib-clean'); 14 | grunt.loadNpmTasks('grunt-processhtml'); 15 | grunt.loadNpmTasks('grunt-rsync'); 16 | grunt.loadNpmTasks('grunt-node-webkit-builder'); 17 | 18 | grunt.initConfig({ 19 | 20 | // Package variables 21 | pkg: grunt.file.readJSON('package.json'), 22 | 23 | // Files with metadata and stuff 24 | meta_files: [ 25 | 'favicon.png', 26 | 'humans.txt', 27 | 'LICENSE.md', 28 | 'manifest.webapp', 29 | 'package.json', 30 | 'README.md', 31 | 'robots.txt' 32 | ], 33 | 34 | // Concatenates all javascript files into one 35 | concat: { 36 | dist: { 37 | src: [ 38 | 'lib/melonJS-1.0.0-min.js', 39 | 'lib/plugins/*.js', 40 | 'js/game.js', 41 | 'js/resources.js', 42 | 'js/repeatable-sprites.js', 43 | 'js/**/*.js' 44 | ], 45 | dest: 'build/js/app.js' 46 | } 47 | }, 48 | 49 | // Copies files from one place to another 50 | copy: { 51 | dist: { 52 | files: [{ 53 | src: 'css/**/*', 54 | dest: 'build/' 55 | },{ 56 | src: 'data/**/*', 57 | dest: 'build/' 58 | }] 59 | } 60 | }, 61 | 62 | // Goes through the HTML file, performing actions 63 | // (on this case, compressing all 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /js/states/main-menu.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Main Menu game state. 3 | * 4 | * Shows the main menu and if the user presses 5 | * ENTER or clicks or taps the state, goes to 6 | * the Play state. 7 | */ 8 | 9 | /*global game,me*/ 10 | 11 | game.MainMenuState = me.ScreenObject.extend({ 12 | 13 | /** 14 | * Runs when entering the state. 15 | */ 16 | onResetEvent : function() { 17 | 18 | // When the game goes out of focus 19 | // (user switched tabs, clicked elsewhere) it 20 | // automatically pauses. 21 | // 22 | // This variable tells melonJS to resume the 23 | // game when the focus is gained back. 24 | // 25 | // Be warned, though, that there are cases when 26 | // you'd not want to automatically resume - that's 27 | // for instance on the `play` state. 28 | me.sys.resumeOnFocus = true; 29 | 30 | // Creating the Background image 31 | // for the main menu. 32 | me.game.world.addChild(new me.SpriteObject( 33 | 0, 0, 34 | me.loader.getImage("main-menu-bg") 35 | ), -1); 36 | 37 | 38 | // This creates the background that spawns 39 | // random stars, to keep things animated. 40 | // It should be between the background and 41 | // the menu. 42 | game.enableStars(me.save.stars); 43 | 44 | this.menu = new me.Menu(1, 12); 45 | this.menu.addItem( 46 | "START", 47 | function() { 48 | // It's very ugly to directly 49 | // access a game state... 50 | me.state.current().startGame(); 51 | } 52 | ); 53 | this.menu.addItem( 54 | ((me.save.sound)? 55 | "SOUND:Y" : 56 | "SOUND:N"), 57 | function () { 58 | 59 | var newLabel = ""; 60 | 61 | if (me.save.sound) { 62 | newLabel = "SOUND:N"; 63 | me.save.sound = false; 64 | me.audio.disable(); 65 | } 66 | else { 67 | newLabel = "SOUND:Y"; 68 | me.save.sound = true; 69 | me.audio.enable(); 70 | } 71 | 72 | // That's a VERY HACKISH THING TO DO 73 | // I should NEVER have to directly access 74 | // stuff like this! 75 | me.state.current().menu.children[1].label = newLabel; 76 | } 77 | ); 78 | this.menu.addItem( 79 | ((me.save.stars) ? 80 | "STARS:Y" : 81 | "STARS:N"), 82 | function() { 83 | 84 | var newLabel = ""; 85 | 86 | if (me.save.stars) { 87 | newLabel = "STARS:N"; 88 | me.save.stars = false; 89 | 90 | // Dynamically destroying stars 91 | game.enableStars(false); 92 | } 93 | else { 94 | newLabel = "STARS:Y"; 95 | me.save.stars = true; 96 | 97 | // Dynamically creating stars 98 | game.enableStars(true); 99 | } 100 | 101 | // That's a VERY HACKISH THING TO DO 102 | // I should NEVER have to directly access 103 | // stuff like this! 104 | me.state.current().menu.children[2].label = newLabel; 105 | } 106 | ); 107 | this.menu.addItem( 108 | "CREDITS", 109 | function() { 110 | // It's very ugly to directly 111 | // access a game state... 112 | me.state.change(me.state.STATE_CREDITS); 113 | } 114 | ); 115 | me.game.world.addChild(this.menu, 3); 116 | 117 | // Le logo 118 | me.game.world.addChild(new me.SpriteObject( 119 | 0, 0, 120 | me.loader.getImage("logo") 121 | ), 4); 122 | 123 | // Checking out the user input: 124 | // control the menu with arrow keys and 125 | // select with Enter. 126 | // Mouse over and click is handled by the menu itself. 127 | me.input.bindKey(me.input.KEY.DOWN, "down", true); 128 | me.input.bindKey(me.input.KEY.UP, "up", true); 129 | me.input.bindKey(me.input.KEY.ENTER, "enter", true); 130 | me.input.bindKey(me.input.KEY.SPACE, "enter", true); 131 | 132 | // Controlling the menu (up, down and activate) 133 | this.handler = me.event.subscribe(me.event.KEYDOWN, function (action, keyCode, edge) { 134 | if (action === "down") { 135 | me.state.current().menu.next(); 136 | me.audio.play("menu", false, null, me.save.sfxVolume); 137 | } 138 | else if (action === "up") { 139 | me.state.current().menu.previous(); 140 | me.audio.play("menu", false, null, me.save.sfxVolume); 141 | } 142 | else if (action === "enter") { 143 | me.state.current().menu.activate(); 144 | me.audio.play("menu", false, null, me.save.sfxVolume); 145 | } 146 | }); 147 | }, 148 | 149 | /** 150 | * Confirms the action to start the game. 151 | */ 152 | startGame : function() { 153 | 154 | me.state.change(me.state.STATE_PLAY); 155 | }, 156 | 157 | /** 158 | * Action to perform when leaving the state (state change). 159 | */ 160 | onDestroyEvent : function() { 161 | me.input.unbindKey(me.input.KEY.DOWN, "down"); 162 | me.input.unbindKey(me.input.KEY.UP, "up"); 163 | me.input.unbindKey(me.input.KEY.ENTER); 164 | me.input.unbindKey(me.input.KEY.SPACE); 165 | 166 | me.game.world.removeChild(this.menu); 167 | me.event.unsubscribe(this.handler); 168 | 169 | 170 | // Independently of having enabled stars or not 171 | // we should call this when the state finishes. 172 | // Remember to re-enable it on the next state, 173 | // though! 174 | game.enableStars(false); 175 | } 176 | }); 177 | 178 | -------------------------------------------------------------------------------- /js/entities/enemy-path.js: -------------------------------------------------------------------------------- 1 | /*global game,me*/ 2 | 3 | game.enemy = game.enemy || {}; 4 | 5 | game.enemy.path = game.enemy.path || {}; 6 | 7 | /** 8 | * Defines possible ways they can move. 9 | * 10 | * They can move up-down (vertical) or 11 | * left-right (horizontal). 12 | */ 13 | game.enemy.path.type = { 14 | HORIZONTAL : "horizontal", 15 | VERTICAL : "vertical" 16 | }; 17 | 18 | /** 19 | * Defines where the enemy will start movin'. 20 | * 21 | * If the enemy is HORIZONTAL: 22 | * - START: Begin from the left 23 | * - END: Begin from the right 24 | * 25 | * If the enemy is VERTICAL: 26 | * - START: Begin from the top 27 | * - END: Begin from the bottom 28 | */ 29 | game.enemy.path.path = { 30 | START : "start", 31 | END : "end" 32 | }; 33 | 34 | /** 35 | * Enemy that walks over a pre-determined path. 36 | * It can walk over a horizontal or vertical path. 37 | * 38 | * The path is specified on Tiled by the entity size. 39 | * 40 | * - If it's a vertical enemy, it's Tiled height 41 | * is the path. 42 | * - If it's a horizontal enemy, it's Tiled width 43 | * is the path. 44 | */ 45 | game.enemy.path.entity = game.enemy.entity.extend({ 46 | 47 | /** 48 | * Creates the enemy. 49 | * @param settings Hash of options defined on Tiled. 50 | * 51 | * @note You MUST specify a type for this enemy. 52 | * It can be "horizontal" or "vertical". 53 | */ 54 | init : function(x, y, settings) { 55 | 56 | // Defaulting to horizontal enemy that starts 57 | // from the right. 58 | this.path_type = settings.type || game.enemy.path.type.HORIZONTAL; 59 | this.path_start = settings.path || game.enemy.path.path.END; 60 | 61 | // There we specify `width` and `height`, 62 | // which we'll use as the path this enemy will follow; 63 | // saving it... 64 | var pathWidth = settings.width; 65 | var pathHeight = settings.height; 66 | 67 | // Creating our parent Enemy class. 68 | this.parent(x, y, settings); 69 | 70 | // X and Y velocities 71 | this.setVelocity(0.12, 0.12); 72 | 73 | // Set start/end position based on that initial area 74 | // size given by Tiled. 75 | if (this.path_type === game.enemy.path.type.HORIZONTAL) { 76 | this.startX = this.pos.x; 77 | this.endX = this.pos.x + pathWidth - settings.spritewidth; 78 | } 79 | else { 80 | this.startY = this.pos.y; 81 | this.endY = this.pos.y + pathHeight - settings.spriteheight; 82 | } 83 | 84 | // Make him start from the right 85 | this.walkLeft = this.walkUp = false; 86 | 87 | this.resetPosition(); 88 | }, 89 | 90 | 91 | /** 92 | * Places the enemy back on it's starting position. 93 | */ 94 | resetPosition : function () { 95 | 96 | if (this.path_type === game.enemy.path.type.HORIZONTAL) { 97 | 98 | // From the left 99 | if (this.path_start === game.enemy.path.path.START) { 100 | 101 | this.pos.x = this.startX; 102 | this.walkLeft = false; 103 | } 104 | // From the right 105 | else { 106 | 107 | this.pos.x = this.endX; 108 | this.walkLeft = true; 109 | } 110 | } 111 | else { 112 | 113 | // From the top 114 | if (this.path_start === game.enemy.path.path.START) { 115 | this.pos.y = this.startY; 116 | this.walkUp = false; 117 | } 118 | 119 | // From the bottom 120 | else { 121 | this.pos.y = this.endY; 122 | this.walkUp = true; 123 | } 124 | } 125 | }, 126 | 127 | /** 128 | * Called by engine when colliding with other object. 129 | * `obj` corresponds to object collided with 130 | */ 131 | onCollision : function(res, obj) { 132 | 133 | // They see me rollin'... 134 | // 135 | // They hatin' 136 | }, 137 | 138 | /** 139 | * Manages enemy movement. 140 | */ 141 | update : function(delta) { 142 | 143 | // Do nothing if not on the screen 144 | if (! this.inViewport) { 145 | return false; 146 | } 147 | 148 | var previousPosition = this.pos.clone(); 149 | 150 | // Making it stay between it's boundaries 151 | if (this.path_type === game.enemy.path.type.HORIZONTAL) { 152 | 153 | if ((this.walkLeft) && 154 | (this.pos.x <= this.startX)) 155 | this.walkLeft = false; 156 | 157 | else if ((! this.walkLeft) && 158 | (this.pos.x >= this.endX)) 159 | this.walkLeft = true; 160 | 161 | // Make it walk 162 | // Note that it's a stiff movement, 163 | // with only two possible speeds. 164 | this.vel.x = ((this.walkLeft) ? 165 | -this.accel.x : 166 | this.accel.x) * me.timer.tick; 167 | } 168 | else { 169 | 170 | if ((this.walkUp) && 171 | (this.pos.y <= this.startY)) 172 | this.walkUp = false; 173 | 174 | else if ((! this.walkUp) && 175 | (this.pos.y >= this.endY)) 176 | this.walkUp = true; 177 | 178 | this.vel.y = ((this.walkUp) ? 179 | -this.accel.y : 180 | this.accel.y) * me.timer.tick; 181 | } 182 | 183 | // MelonJS' internal function to check collisions 184 | // and stuff against the map. 185 | var collision = this.updateMovement(); 186 | 187 | // Just hit the map. 188 | // Let's invert the movement instead of get stuck. 189 | if (collision.y != 0) this.walkUp = !this.walkUp; 190 | if (collision.x != 0) this.walkLeft = !this.walkLeft; 191 | 192 | this.deltaPos = this.deltaPos || {}; 193 | this.deltaPos.x = this.pos.x - previousPosition.x; 194 | this.deltaPos.y = this.pos.y - previousPosition.y; 195 | 196 | // Redraw! 197 | return true; 198 | } 199 | }); 200 | 201 | -------------------------------------------------------------------------------- /js/gui/menu.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A (vertical) menu that can be interacted with 3 | * both the keyboard. 4 | * 5 | * Displays items that can be selected or not. 6 | * It automatically handles positioning, images and 7 | * stuff. 8 | * 9 | * All you need to do is provide item titles and callbacks. 10 | * 11 | * Example: 12 | * 13 | * var menu = new me.Menu(x, y); 14 | * 15 | * // You can add as many as you want 16 | * menu.addItem( 17 | * "title", 18 | * function() { 19 | * console.log("Clicked"); 20 | * } 21 | * ); 22 | */ 23 | 24 | /*global me game*/ 25 | 26 | /** 27 | * A single Menu Item. 28 | * 29 | * @note Don't create standalone Items! 30 | * They're nothing without a menu to be attached to. 31 | * 32 | * Keep scrollin'. 33 | */ 34 | me.MenuItem = me.Renderable.extend({ 35 | 36 | init : function (x, y, label, menu, callback) { 37 | 38 | this.select(false); 39 | 40 | // Need to pre-render so we can measure how much 41 | // space will it occupy on the screen 42 | var size = this.font.measureText( 43 | me.video.getScreenContext(), 44 | label 45 | ); 46 | 47 | this.parent(new me.Vector2d(x, y), 48 | size.width, size.height); 49 | 50 | this.label = label; 51 | this.callback = callback; 52 | 53 | // Our big daddy 54 | this.menu = menu; 55 | 56 | // Make sure we use screen coordinates 57 | this.floating = true; 58 | 59 | // Putting on front of most things 60 | // (related to the menu z order) 61 | this.z = 24; 62 | }, 63 | 64 | /** 65 | * Marks this item as selected (or not). 66 | * 67 | * @note Option is a boolean. 68 | * @note The selected state only changes the way 69 | * this item is drawn. 70 | */ 71 | select : function(option) { 72 | this.selected = option; 73 | 74 | this.font = ((this.selected) ? 75 | game.font_white : 76 | game.font_blue); 77 | }, 78 | 79 | /** 80 | * Toggles the selected state of this item. 81 | */ 82 | toggle : function(option) { 83 | this.select(! this.selected); 84 | }, 85 | 86 | execute : function () { 87 | this.callback(); 88 | }, 89 | 90 | /** 91 | * Always making sure to draw the menu item. 92 | * 93 | * @note Remember, when we return `true` we tell 94 | * melonJS to call `draw()`. 95 | */ 96 | update : function() { 97 | return true; 98 | }, 99 | 100 | draw : function(context) { 101 | 102 | this.font.draw( 103 | context, 104 | this.label, 105 | this.pos.x, 106 | this.pos.y 107 | ); 108 | } 109 | }); 110 | 111 | /** 112 | * The Menu! 113 | * 114 | * Basically a container of items. 115 | * It keeps track of which item is selected 116 | * right now and can activate it at any time. 117 | */ 118 | me.Menu = me.ObjectContainer.extend({ 119 | 120 | init : function(x, y) { 121 | 122 | // Occupying the whole screen (viewport) 123 | this.parent(x, y); 124 | 125 | // The index of the currently selected item 126 | // inside our `children` Array 127 | this.selectedIndex = 0; 128 | 129 | // Not wasting CPU with this 130 | this.autoSort = false; 131 | this.collidable = false; 132 | 133 | // Put at the front of most things 134 | this.z = 25; 135 | }, 136 | 137 | /** 138 | * Creates a new Menu Item. 139 | */ 140 | addItem : function(title, callback, labelOffset) { 141 | 142 | var bottom_margin = 1; 143 | 144 | var item = new me.MenuItem( 145 | this.pos.x, 146 | this.pos.y + 2*game.tile(this.children.length) + (this.children.length * bottom_margin), 147 | title, 148 | this, 149 | callback 150 | ); 151 | 152 | // Setting an offset if specified 153 | // by the user 154 | if (typeof (labelOffset) !== "undefined") 155 | item.labelOffset = labelOffset; 156 | 157 | this.addChild(item); 158 | 159 | if (this.children.length === 1) 160 | this.children[0].select(true); 161 | }, 162 | 163 | /** 164 | * Activates the currently selected item. 165 | */ 166 | activate : function() { 167 | if (this.children.length <= 0) 168 | return; 169 | 170 | this.children[this.selectedIndex].execute(); 171 | }, 172 | 173 | /** 174 | * Highlights the next item. 175 | * 176 | * @note It wraps to the first if it's on the last. 177 | */ 178 | next : function() { 179 | 180 | this.children[this.selectedIndex].select(false); 181 | 182 | this.selectedIndex++; 183 | 184 | if (this.selectedIndex >= this.children.length) 185 | this.selectedIndex = 0; 186 | 187 | // Play a sound? 188 | this.children[this.selectedIndex].select(true); 189 | }, 190 | 191 | /** 192 | * Highlights the previous item. 193 | * 194 | * @note It wraps to the last if it's on the first. 195 | */ 196 | previous : function() { 197 | 198 | this.children[this.selectedIndex].select(false); 199 | this.selectedIndex--; 200 | 201 | if (this.selectedIndex < 0) 202 | this.selectedIndex = this.children.length - 1; 203 | 204 | // Play a sound? 205 | this.children[this.selectedIndex].select(true); 206 | }, 207 | 208 | /** 209 | * Forces the menu to select a specific Item. 210 | * 211 | * @warning It is not an index, it's the Item 212 | * Object itself! 213 | * 214 | * @note This is a costly function, since we need 215 | * to check every element in the items array. 216 | * TODO: Remove this somehow 217 | */ 218 | select : function(item) { 219 | this.children[this.selectedIndex].select(false); 220 | 221 | this.selectedIndex = this.children.indexOf(item); 222 | 223 | this.children[this.selectedIndex].select(true); 224 | } 225 | }); 226 | 227 | -------------------------------------------------------------------------------- /js/entities/platform-movable.js: -------------------------------------------------------------------------------- 1 | /*global game,me*/ 2 | 3 | // Making sure this namespace exists 4 | game.platform = game.platform || {}; 5 | 6 | /** 7 | * A separate namespace for the movable platforms. 8 | * 9 | * It will hold constants and things that control 10 | * all the vanishing platforms. 11 | */ 12 | game.platform.movable = { 13 | 14 | /** 15 | * Defines possible ways they can move. 16 | * 17 | * They can move up-down (vertical) or 18 | * left-right (horizontal). 19 | */ 20 | type : { 21 | HORIZONTAL : "horizontal", 22 | VERTICAL : "vertical" 23 | }, 24 | 25 | /** 26 | * Defines where the platform will start movin'. 27 | * 28 | * If the platform is HORIZONTAL: 29 | * - START: Begin from the left 30 | * - END: Begin from the right 31 | * 32 | * If the platform is VERTICAL: 33 | * - START: Begin from the top 34 | * - END: Begin from the bottom 35 | */ 36 | path : { 37 | START : "start", 38 | END : "end" 39 | } 40 | }; 41 | 42 | /** 43 | * Platform that moves alongside a predetermined path. 44 | * 45 | * The path is defined on Tiled by the entities' width 46 | * and height. Plus, you have to define the following 47 | * properties: 48 | * 49 | * Name: "type" : what kind of movement 50 | * Value: "horizontal" : moves horizontally (along x axis) 51 | * Value: "vertical" : moves vertically (along y axis) 52 | * 53 | * Name: "begin" : from where the movement starts 54 | * Value: "start" : starts from left or top (according to "type") 55 | * Value: "end" : starts from right or bottom (according to "type") 56 | */ 57 | game.platform.movable.entity = game.platform.entity.extend({ 58 | 59 | /** 60 | * Create a new movable platform. 61 | * 62 | * @param settings A hash with options, defined on Tiled. 63 | * 64 | * @note See the class documentation for properties you 65 | * can define on Tiled. 66 | */ 67 | init : function(x, y, settings) { 68 | 69 | // There we specify `width`, which we'll use as the path 70 | // this enemy will follow; saving it... 71 | var pathWidth = settings.width; 72 | var pathHeight = settings.height; 73 | 74 | // Creating the platform... 75 | // It's position (x, y) and size (width, height) will 76 | // be set as the default for all platforms. 77 | this.parent(x, y, settings); 78 | 79 | // Velocities on the X and Y axis 80 | this.setVelocity(0.17, 0.17); 81 | 82 | // What kind of platform is this? 83 | // Falling back to default 84 | this.walkType = settings["type"] || game.platform.movable.type.HORIZONTAL; 85 | 86 | // Where should the platform start from? 87 | // Falling back to default 88 | this.walkStart = settings["begin"] || game.platform.movable.path.START; 89 | 90 | // Set start/end position based on that initial area 91 | // size given by Tiled. 92 | if (this.walkType === game.platform.movable.type.HORIZONTAL) { 93 | this.startX = this.pos.x; 94 | this.endX = this.pos.x + (pathWidth - settings.spritewidth); 95 | } 96 | else { 97 | this.startY = this.pos.y; 98 | this.endY = this.pos.y + (pathHeight - settings.spriteheight); 99 | } 100 | 101 | // These flags are used to determine which 102 | // direction it's moving right now. 103 | // They will get initialized on... 104 | this.walkLeft = this.walkUp = false; 105 | 106 | // ...this function. 107 | // Place it at the beginning, ready to move! 108 | this.resetPosition(); 109 | 110 | this.type = me.game.PLATFORM_MOVABLE_OBJECT; 111 | }, 112 | 113 | /** 114 | * Places the platform back on it's starting position. 115 | */ 116 | resetPosition : function () { 117 | 118 | if (this.walkType === game.platform.movable.type.HORIZONTAL) { 119 | 120 | // From the left 121 | if (this.walkStart === game.platform.movable.path.START) { 122 | 123 | this.pos.x = this.startX; 124 | this.walkLeft = false; 125 | } 126 | // From the right 127 | else { 128 | 129 | this.pos.x = this.endX; 130 | this.walkLeft = true; 131 | } 132 | } 133 | else { 134 | 135 | // From the top 136 | if (this.walkStart === game.platform.movable.path.START) { 137 | this.pos.y = this.startY; 138 | this.walkUp = false; 139 | } 140 | 141 | // From the bottom 142 | else { 143 | this.pos.y = this.endY; 144 | this.walkUp = true; 145 | } 146 | } 147 | }, 148 | 149 | /** 150 | * Manages platform movement. 151 | */ 152 | update : function(delta) { 153 | 154 | // Do nothing if not on the screen 155 | if (! this.inViewport) { 156 | return false; 157 | } 158 | 159 | var previousPosition = this.pos.clone(); 160 | 161 | // Making it stay between it's boundaries 162 | if (this.walkType === game.platform.movable.type.HORIZONTAL) { 163 | 164 | if ((this.walkLeft) && 165 | (this.pos.x <= this.startX)) 166 | this.walkLeft = false; 167 | 168 | else if ((! this.walkLeft) && 169 | (this.pos.x >= this.endX)) 170 | this.walkLeft = true; 171 | 172 | // Make it walk 173 | // Note that it's a stiff movement, 174 | // with only two possible speeds. 175 | this.vel.x = ((this.walkLeft) ? 176 | -this.accel.x : 177 | this.accel.x) * me.timer.tick; 178 | } 179 | else { 180 | 181 | if ((this.walkUp) && 182 | (this.pos.y <= this.startY)) 183 | this.walkUp = false; 184 | 185 | else if ((! this.walkUp) && 186 | (this.pos.y >= this.endY)) 187 | this.walkUp = true; 188 | 189 | this.vel.y = ((this.walkUp) ? 190 | -this.accel.y : 191 | this.accel.y) * me.timer.tick; 192 | } 193 | 194 | // MelonJS' internal function to check collisions 195 | // and stuff against the map. 196 | var collision = this.updateMovement(); 197 | 198 | // Just hit the map. 199 | // Let's invert the movement instead of get stuck. 200 | if (collision.y != 0) this.walkUp = !this.walkUp; 201 | if (collision.x != 0) this.walkLeft = !this.walkLeft; 202 | 203 | this.deltaPos = this.deltaPos || {}; 204 | this.deltaPos.x = this.pos.x - previousPosition.x; 205 | this.deltaPos.y = this.pos.y - previousPosition.y; 206 | 207 | // Redraw! 208 | return true; 209 | }, 210 | 211 | /** 212 | * Called when anything collide with us. 213 | * 214 | * Probably the player, so let's attach ourselves 215 | * to it. 216 | * This way it can keep up with our speed. 217 | */ 218 | onCollision : function(collision, other) { 219 | 220 | // Only vanish if it's the Player 221 | if (other.type === me.game.PLAYER_OBJECT) 222 | 223 | // Only vanish if collided with the head 224 | // or butt - never on the Player's sides. 225 | if (collision.y != 0) 226 | 227 | other.platform = this; 228 | } 229 | }); 230 | 231 | 232 | -------------------------------------------------------------------------------- /js/states/play.js: -------------------------------------------------------------------------------- 1 | /** 2 | * State that will be shown while the game 3 | * is being played. 4 | * 5 | * Note: The game loop is hidden inside melonJS. 6 | * So the whole game logic is specified inside 7 | * each entity. 8 | * Go look the files on `js/entities` 9 | */ 10 | 11 | /*global game,me */ 12 | 13 | game.PlayState = me.ScreenObject.extend({ 14 | 15 | /** 16 | * What to do when starting this state. 17 | */ 18 | onResetEvent : function() { 19 | 20 | // When the game goes out of focus 21 | // (user switched tabs, clicked elsewhere) it 22 | // automatically pauses. 23 | // 24 | // This variable tells melonJS to NOT resume the 25 | // game when the focus is gained back. 26 | // You have to manually press ENTER to resume 27 | // the game. 28 | me.sys.resumeOnFocus = false; 29 | 30 | // Call `this.onLevelLoaded()` every time 31 | // a new level is loaded. 32 | me.game.onLevelLoaded = this.onLevelLoaded.bind(this); 33 | 34 | // Before loading the level, let's place a text 35 | // on the screen saying that we're doing this 36 | game.font_black.draw( 37 | me.video.getScreenContext(), 38 | "Loading level...", 39 | 0, 0 40 | ); 41 | me.levelDirector.loadLevel(game.data.currentLevel); 42 | 43 | // This creates the background that spawns 44 | // random stars, to keep things animated. 45 | // It should be between the background tiles 46 | // and the foreground tiles. 47 | game.enableStars(me.save.stars); 48 | 49 | // The HUD 50 | // (display with meta-information on top of everything) 51 | // Add our HUD to the game world 52 | this.HUD = new game.HUD.Container(); 53 | me.game.world.addChild(this.HUD); 54 | 55 | // Input 56 | // Supporting both arrow keys and WASD 57 | me.input.bindKey(me.input.KEY.LEFT, "left"); 58 | me.input.bindKey(me.input.KEY.A, "left"); 59 | me.input.bindKey(me.input.KEY.RIGHT, "right"); 60 | me.input.bindKey(me.input.KEY.D, "right"); 61 | 62 | // Key to allow the player to walk slowly 63 | me.input.bindKey(me.input.KEY.SHIFT, "walk", false, true); 64 | 65 | // Let's be redundant! 66 | // Lots of keys to invert the gravity 67 | me.input.bindKey(me.input.KEY.UP, "jump", true); 68 | me.input.bindKey(me.input.KEY.W, "jump", true); 69 | me.input.bindKey(me.input.KEY.SPACE, "jump", true); 70 | me.input.bindKey(me.input.KEY.DOWN, "jump", true); 71 | me.input.bindKey(me.input.KEY.S, "jump", true); 72 | me.input.bindKey(me.input.KEY.Z, "jump", true); 73 | me.input.bindKey(me.input.KEY.X, "jump", true); 74 | 75 | // Suicide key (a.k.a. PANIC BUTTON) 76 | me.input.bindKey(me.input.KEY.K, "die", true); 77 | 78 | me.input.bindKey(me.input.KEY.ESC, "pause", true); 79 | me.input.bindKey(me.input.KEY.ENTER, "pause", true); 80 | 81 | // Also creating the thing that will pause the 82 | // game for us (if the user presses "pause") 83 | me.game.world.addChild(new game.pauseHandlerEntity()); 84 | 85 | // To make able to control the game with the mouse 86 | // we must watch for those events (mouse up and down) 87 | // 88 | // Unfortunately we have to keep two different functions 89 | // for this. 90 | // 91 | // But since they're events, we have MULTITOUCH support! 92 | me.input.registerPointerEvent( 93 | 'pointerdown', 94 | me.game.viewport, 95 | this.mouseDown.bind(this) 96 | ); 97 | me.input.registerPointerEvent( 98 | 'pointerup', 99 | me.game.viewport, 100 | this.mouseUp.bind(this) 101 | ); 102 | 103 | // Place the camera on the player 104 | // (but not directly over it, on the map screen) 105 | me.game.viewport.moveTo( 106 | game.player.pos.x / 32, 107 | game.player.pos.y / 32 108 | ); 109 | 110 | // Yay, let's play some sound! 111 | me.audio.stopTrack(); 112 | me.audio.playTrack("area000", me.save.musicVolume); 113 | }, 114 | 115 | /** 116 | * Called when the level is loaded. 117 | * @note Not a melonJS callback! We've attached it 118 | * right up there. 119 | */ 120 | onLevelLoaded : function onLevelLoaded() { 121 | 122 | 123 | }, 124 | 125 | /** 126 | * User started pressing the mouse/finger 127 | * anywhere on the screen. 128 | * @note This is not an automatic callback from 129 | * melonJS! I register this function at 130 | * the end of `init`. 131 | */ 132 | mouseDown : function() { 133 | 134 | this.clickOnGameArea(true); 135 | }, 136 | 137 | /** 138 | * User released the mouse/finger 139 | * anywhere on the screen. 140 | * @note This is not an automatic callback from 141 | * melonJS! I register this function at 142 | * the end of `init`. 143 | */ 144 | mouseUp : function() { 145 | this.clickOnGameArea(false); 146 | }, 147 | 148 | /** 149 | * Reacts to a click/touch the user made on the 150 | * game area. 151 | * The argument tells if the mouse/finger is 152 | * pressed or released. 153 | * 154 | * This is where the magic is! 155 | * We trigger a false key event based on clicks! 156 | * 157 | * - If you click/touch the upper area, character 158 | * jumps. 159 | * - If you click on the lower area left side the 160 | * character walks left, and on the right side 161 | * it walks right. 162 | */ 163 | clickOnGameArea : function (isClickDown) { 164 | 165 | var mouseX = me.input.mouse.pos.x; 166 | var mouseY = me.input.mouse.pos.y; 167 | 168 | // Top Area 169 | if (mouseY < me.game.viewport.height/2) { 170 | me.input.triggerKeyEvent(me.input.KEY.UP, isClickDown); 171 | return; 172 | } 173 | 174 | // Bottom Left Area 175 | if (mouseX < me.game.viewport.width/2) 176 | me.input.triggerKeyEvent(me.input.KEY.LEFT, isClickDown); 177 | 178 | // Bottom Right Area 179 | else 180 | me.input.triggerKeyEvent(me.input.KEY.RIGHT, isClickDown); 181 | }, 182 | 183 | /** 184 | * What to do when leaving this state. 185 | */ 186 | onDestroyEvent : function() { 187 | 188 | // remove the HUD from the game world 189 | me.game.world.removeChild(this.HUD); 190 | 191 | me.input.unbindKey(me.input.KEY.LEFT); 192 | me.input.unbindKey(me.input.KEY.A); 193 | me.input.unbindKey(me.input.KEY.RIGHT); 194 | me.input.unbindKey(me.input.KEY.D); 195 | me.input.unbindKey(me.input.KEY.SHIFT); 196 | 197 | me.input.unbindKey(me.input.KEY.DOWN); 198 | me.input.unbindKey(me.input.KEY.S); 199 | me.input.unbindKey(me.input.KEY.UP); 200 | me.input.unbindKey(me.input.KEY.W); 201 | me.input.unbindKey(me.input.KEY.SPACE); 202 | me.input.unbindKey(me.input.KEY.Z); 203 | me.input.unbindKey(me.input.KEY.X); 204 | 205 | me.input.unbindKey(me.input.KEY.K); 206 | 207 | me.input.unbindKey(me.input.KEY.ESC); 208 | me.input.unbindKey(me.input.KEY.ENTER); 209 | 210 | // Independently of having enabled stars or not 211 | // we should call this when the state finishes. 212 | // Remember to re-enable it on the next state, 213 | // though! 214 | game.enableStars(false); 215 | } 216 | }); 217 | 218 | 219 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WWW 2 | 3 | `WWW` is a low-resolution clone of the [indie game VVVVVV][vvvvvv]. 4 | 5 | ![gif](http://alexdantas.net/stuff/wp-content/uploads/2014/05/www-0.5.3.gif) 6 | 7 | It's an open-source 2D HTML5 platformer, 8 | [made with melonJS][melonjs] and 9 | created for the [2014 Low Resolution GameJam (#lowrezjam 2014)][jam]. 10 | 11 | * [Play the game online (live demo)][play]; 12 | * [Mirror on Newgrounds](http://www.newgrounds.com/portal/view/640265); 13 | * [Mirror on GameJolt](http://gamejolt.com/games/platformer/www/26571/); 14 | * [Mirror on itch.io](http://alexdantas.itch.io/www/); 15 | * [Mirror on Kongregate](http://www.kongregate.com/games/kurebisubarudo/www); 16 | 17 | ## Plot 18 | 19 | Viridian, captain of the D.S.S. SoulEye, is having a nice day when suddenly 20 | the ship's navigational systems goes astray. He and his crew mates are 21 | violently thrown into a huge dimensional vortex and everything fades to black. 22 | 23 | When he awakes, everything around him seems strange. It's as if the world around 24 | him and himself became blurred, square-ish and kinda... pixelated. 25 | 26 | That's when he finds himself on a very familiar situation... 27 | 28 | ## Gameplay 29 | 30 | The game mechanic is [the same as VVVVVV][intro]: you can walk around but 31 | cannot jump. Instead, you can flip gravity and fall upward to the ceiling 32 | (or downward to the floor if you're already on the ceiling). 33 | 34 | When you die (either by touching spikes or enemies), you go back to a 35 | nearby checkpoint. 36 | 37 | ### Controls 38 | 39 | | key | action | 40 | | -------------------------- | ------------- | 41 | | Arrow Keys, WASD | Move | 42 | | Space, z, x | Action | 43 | | Enter, ESC | Pause | 44 | | Shift | Walk slowly | 45 | 46 | ## Instructions 47 | 48 | If you want your own **offline version**, [download the repository][release], 49 | start a web server and open `index.html` on your favorite browser. 50 | 51 | Note that this repository is a **development version** of the game. 52 | It splits the code over several `.js` files. 53 | 54 | You can build a **production version**, that compresses all the 55 | `.js` files into minified versions. 56 | This way it'll be way faster to load the game. 57 | It is the recommended way to host it on your own website. 58 | 59 | To build, be sure you have [node](http://nodejs.org) installed. 60 | On the project directory, run: 61 | 62 | npm install 63 | 64 | And then: 65 | 66 | grunt 67 | 68 | ## Development 69 | 70 | Here's how the code is laid out: 71 | 72 | | directory | contents | 73 | | -------------------- | -------- | 74 | | `index.html` | Entry point for the game; visual elements | 75 | | `data` | All resources; images, audio, fonts, maps... | 76 | | `data/audio` | All things related to sound | 77 | | `data/audio/bgm` | Background music, songs | 78 | | `data/audio/sfx` | Sound effects | 79 | | `data/image` | All images | 80 | | `data/image/font` | Bitmap fonts | 81 | | `data/image/gui` | Backgrounds and borders for game screens | 82 | | `data/image/tile` | Tilesets used on the Tiled maps | 83 | | `data/image/sprite` | Spritesheets or single sprites | 84 | | `data/map` | Tiled maps | 85 | | `js` | Source code for the whole game; main `.js` files | 86 | | `js/entities` | Things that interact with each other (player, enemies...) | 87 | | `js/states` | Game states (screens that can be shown | 88 | | `js/gui` | Components of the user interface (menu, buttons...) | 89 | | `lib` | Libraries used for the game (MelonJS) | 90 | | `lib/plugins` | MelonJS plugins | 91 | | `css` | Stylesheets | 92 | 93 | ## Credits 94 | 95 | This game is a tribute to [Terry Cavanagh's VVVVVV][vvvvvv], one of the best 96 | games I've ever played. It has [an excellent soundtrack, by SoulEye][pppppp]; 97 | I can't stop listening to it on a weekly basis. 98 | 99 | * The _in-game font_ was based on the [3x3 Font for Nerds][font]. 100 | * Thanks to [deviever][deviever] for organizing [the #lowrezjam2014][jam]. 101 | It gave me the motivation necessary to make this game. Also, thanks for the 102 | [Atari Box][atari-box] and [Atari Cartridge][atari-cartridge] arts! 103 | 104 | Also, I'd like to thank the GitHub community for the 105 | [awesome VVVVVV-based projects][github-vvvvvv]. 106 | 107 | ## Tools 108 | 109 | For programming, there's nothing like Emacs; recently installed 110 | [Sr-Speedbar][speedbar] and never looked back. 111 | 112 | I used [MelonJS][melonjs] to make this game. It is a great HTML5 game engine; 113 | I highly encourage people who wish to develop HTML5 games to give it a try. 114 | It has a simple, straight-to-the-point [introduction][melonjs-tutorial] and 115 | a [nice community][melonjs-group]. 116 | 117 | To create the maps I used the [Tiled map editor][tiled]. 118 | 119 | Art assets were made with Photoshop CS5 and GIMP 2.8.10. 120 | 121 | Music was composed with [Guitar Pro 5][gp5] and made chiptune 122 | with [GXSCC 236E][gxscc]. 123 | 124 | ## License 125 | 126 | The whole code is released under the *GPLv3*. 127 | 128 | Check file `LICENSE.md` for details on what you can and 129 | cannot do with it. 130 | 131 | [melonjs]:http://melonjs.org/ 132 | [jam]: http://jams.gamejolt.io/lowrezjam2014 133 | [vvvvvv]: http://thelettervsixtim.es/ 134 | [intro]: http://vvvvvv-wiki.wikispaces.com/Introduction 135 | [play]: http://alexdantas.net/games/www/ 136 | [release]:https://github.com/alexdantas/www/releases 137 | [pppppp]: http://www.souleye.se/pppppp 138 | [github-vvvvvv]: https://github.com/search?q=vvvvvv&type=Repositories&ref=searchresults 139 | [melonjs-tutorial]: http://melonjs.github.io/tutorial/ 140 | [melonjs-group]: https://groups.google.com/forum/#!forum/melonjs 141 | [font]: cargocollective.com/slowercase/3x3-Font-for-Nerds 142 | [deviever]: http://deviever.com/ 143 | [atari-box]: http://deviever.com/atari-box-pack/ 144 | [atari-cartridge]: http://deviever.com/atari-cartridge-photoshop-template/ 145 | [gif]: http://screentogif.codeplex.com/ 146 | [speedbar]: http://www.emacswiki.org/emacs/SrSpeedbar 147 | [gp5]: http://en.wikipedia.org/wiki/Guitar_Pro 148 | [tiled]: http://www.mapeditor.org/ 149 | [gxscc]: http://www.geocities.co.jp/SiliconValley-SanJose/8700/P/GsorigE.htm 150 | 151 | -------------------------------------------------------------------------------- /js/entities/platform-vanishing.js: -------------------------------------------------------------------------------- 1 | // I know this file seems to big to simply implement 2 | // vanishing platforms. 3 | // 4 | // I understand it was too verbose, but some hackish 5 | // things needed to be done in order to make WWW 6 | // behave like VVVVVV 7 | 8 | /*global game,me*/ 9 | 10 | // Making sure this namespace exists 11 | game.platform = game.platform || {}; 12 | 13 | /** 14 | * A separate namespace for the vanishing platforms. 15 | * 16 | * It will hold constants and things that control 17 | * all the vanishing platforms. 18 | * 19 | * It also has "static" methods. 20 | */ 21 | game.platform.vanishing = { 22 | 23 | /** 24 | * Delay (in milliseconds) that it takes to 25 | * a vanishing platform to disappear. 26 | * 27 | * @note It applies after calling `startVanishing`. 28 | */ 29 | timeout : 900, 30 | 31 | /** 32 | * Contains all platforms that already disappeared. 33 | * 34 | * It's necessary to restore all platforms as soon 35 | * as the player dies. 36 | */ 37 | vanished : [], 38 | 39 | /** 40 | * Contains all platforms that are disappearing 41 | * right now. 42 | * 43 | * This is necessary so we can restore them as 44 | * soon as the player dies. 45 | */ 46 | vanishing : [], 47 | 48 | /** 49 | * Makes all the vanishing platforms be shown 50 | * again. 51 | * 52 | * @note On the original VVVVVV, when the player 53 | * dies, all the vanished platforms are 54 | * shown again. 55 | */ 56 | showAll : function () { 57 | 58 | // Oops! Some platforms are still disappearing! 59 | // Let's force them to vanish right now then 60 | for (var j = 0; j < game.platform.vanishing.vanishing.length; j++) { 61 | var current = game.platform.vanishing.vanishing[j]; 62 | 63 | if (current.tween) 64 | current.tween.stop(); 65 | 66 | current.vanishing = false; 67 | current.vanish(); 68 | } 69 | 70 | // And finally show all platforms that vanished 71 | for (var i = 0; i < game.platform.vanishing.vanished.length; i++) 72 | game.platform.vanishing.vanished[i].show(); 73 | 74 | // Since they're all shown right now, 75 | // clear these containers 76 | game.platform.vanishing.vanished = []; 77 | game.platform.vanishing.vanishing = []; 78 | 79 | // As a side note, I saw some arguing on what is 80 | // faster for deleting arrays. 81 | // One could argue about the faster alternative:this is faster: 82 | // array = [] 83 | // Or... 84 | // array.length = 0 85 | // But this page gives a conclusive result: 86 | // http://jsperf.com/array-clearing-performance 87 | } 88 | }; 89 | 90 | /** 91 | * Platform that can disappear. 92 | */ 93 | game.platform.vanishing.entity = game.platform.entity.extend({ 94 | 95 | /** 96 | * Create a new Platform. 97 | * 98 | * @param settings A hash with options, defined on Tiled. 99 | */ 100 | init : function(x, y, settings) { 101 | this.parent(x, y, settings); 102 | 103 | // These will control the internal state 104 | // of the platform 105 | this.vanishing = false; 106 | this.vanished = false; 107 | 108 | // The thing that will animate the 109 | // platform. More info on this below. 110 | this.tween = null; 111 | 112 | this.type = me.game.PLATFORM_VANISHING_OBJECT; 113 | }, 114 | 115 | /** 116 | * Called when anything collide with us. 117 | * 118 | * Probably the player, so let's start vanishing! 119 | */ 120 | onCollision : function(collision, other) { 121 | 122 | // Only vanish if it's the Player 123 | if (other.type === me.game.PLAYER_OBJECT) 124 | 125 | // Only vanish if collided with the head 126 | // or butt - never on the Player's sides. 127 | if (collision.y != 0) 128 | 129 | this.startVanishing(); 130 | }, 131 | 132 | /** 133 | * Makes the platform disappear after a while. 134 | * 135 | * Calling this function triggers the process of 136 | * destroying the platform. 137 | * 138 | * It'll slowly become transparent and then will 139 | * call `vanish()`, effectively removing it from 140 | * the game. 141 | */ 142 | startVanishing : function() { 143 | 144 | if (this.vanished || this.vanishing) 145 | return; 146 | else 147 | this.vanishing = true; 148 | 149 | // Making the platform slowly vanish 150 | // (using a Tween to change opacity from 1.0 to 0.0) 151 | // 152 | // This part is kinda tricky; proceed with care. 153 | // 154 | // Inside this Tween object, we have callbacks 155 | // like `onStart`, `onUpdate` and `onComplete`. 156 | // Inside them, `this` refers to the Tween, NOT to 157 | // the platform! 158 | // 159 | // So when creating the Tween, I'll add a reference 160 | // to the platform. 161 | // This way I can access the platform inside the Tween. 162 | // 163 | this.tween = new me.Tween({ 164 | 165 | // Reference to ourselves inside the Tween 166 | platform : this, 167 | 168 | // The thing that will change with time 169 | // (also known as "transparency") 170 | opacity: this.renderable.getOpacity() 171 | }); 172 | 173 | // Now we configure how the Tween will happen. 174 | this.tween 175 | .to({ opacity: 0 }, game.platform.vanishing.timeout) 176 | 177 | // The way it's going to vanish... 178 | // Ideally it'd appear to disappear quickly 179 | // but leave a decent time gap for the player to react 180 | .easing(me.Tween.Easing.Quartic.Out) 181 | 182 | // Called right when the Tween is about to start 183 | .onStart(function() { 184 | 185 | // Adding the platform to the list of 186 | // platforms that are currently disappearing 187 | game.platform.vanishing.vanishing.push(this.platform); 188 | }) 189 | 190 | // Called on each update of the tween 191 | // (multiple times per sec) 192 | .onUpdate(function() { 193 | 194 | this.platform.renderable.setOpacity(this.opacity); 195 | 196 | }) 197 | 198 | // Same as calling `this.vanish()`, but on another 199 | // program context. 200 | .onComplete(function() { 201 | 202 | this.platform.vanishing = false; 203 | this.platform.vanish(); 204 | 205 | }) 206 | 207 | // Let's do it! 208 | .start(); 209 | }, 210 | 211 | /** 212 | * Removes instantaneously this platform from the game. 213 | * 214 | * @note You shouldn't call this, it'll be done 215 | * by `startVanishing()` anyway. 216 | */ 217 | vanish : function() { 218 | 219 | if (this.vanished || this.vanishing) 220 | return; 221 | 222 | this.vanished = true; 223 | 224 | // Just to be sure. 225 | this.renderable.setOpacity(0); 226 | 227 | // And the player won't even touch it. 228 | this.collidable = false; 229 | 230 | // This adds ourselves to the global list of 231 | // platforms that are vanished. 232 | // 233 | // We do it so we can restore them all just 234 | // by calling `game.platform.vanishing.showAll()` 235 | game.platform.vanishing.vanished.push(this); 236 | }, 237 | 238 | /** 239 | * Makes the platform reappear on the game. 240 | * 241 | * @note Don't worry about calling this when the 242 | * platform is visible or disappearing; it will 243 | * fail silently. 244 | */ 245 | show : function() { 246 | 247 | if (!this.vanished || this.vanishing) 248 | return; 249 | else 250 | this.vanished = false; 251 | 252 | // Now the player will see and collide with it 253 | this.renderable.setOpacity(1); 254 | this.collidable = true; 255 | } 256 | }); 257 | 258 | 259 | 260 | -------------------------------------------------------------------------------- /js/gui/pause-handler.js: -------------------------------------------------------------------------------- 1 | 2 | /*global me,game*/ 3 | 4 | /** 5 | * Watches the pause key, effectively pausing the game 6 | * when the user presses it. 7 | * 8 | * It stops everything and shows a text "PAUSED" with 9 | * a Pause Menu. 10 | * It waits until the user presses the "pause" key again 11 | * or selects "RESUME" from the menu. 12 | * 13 | * @note This file has at least 3 ugly hacks I did to 14 | * make the code work. 15 | * I'm very embarrassed. 16 | * Maybe the shame of publicly exposing them will 17 | * make me fix them quicker. 18 | */ 19 | game.pauseHandlerEntity = me.Renderable.extend({ 20 | 21 | /** 22 | * Initializes the thing that keeps looking for the 23 | * "pause" key. 24 | */ 25 | init : function () { 26 | 27 | // Bleh. 28 | this.parent(new me.Vector2d(5, 0), 29 | me.game.viewport.width, me.game.viewport.height); 30 | 31 | 32 | // This is very important 33 | // 34 | // We're attaching callbacks to know when the game 35 | // loses focus (user clicked elsewhere, changed 36 | // browser tab, changed OS window...) 37 | // 38 | // To do so we MUST remove melonJS's default way 39 | // of handling this. 40 | // 41 | // By default melonJS simply calls `me.state.pause()` 42 | // but since we're showing a Pause Menu and stuff 43 | // we're doing like this: 44 | // 45 | // - When we lose focus, pretend the user has hit the 46 | // "pause" key (on this case, ESC). 47 | // 48 | // Got it? 49 | // First, removing melonJS' handlers. 50 | me.sys.stopOnBlur = false; 51 | me.sys.pauseOnBlur = false; 52 | me.sys.resumeOnFocus = false; 53 | 54 | // Then, attaching our own 55 | // for when losing focus... 56 | window.addEventListener("blur", function () { 57 | 58 | // Remember to change this if you ever decide to 59 | // NOT use ESC as a "pause" key. 60 | me.input.triggerKeyEvent(me.input.KEY.ESC, true); 61 | 62 | }, false); 63 | 64 | 65 | // Aww yeah, now we're talkin' 66 | this.updateWhenPaused = true; 67 | 68 | // Need to draw on top of most things. 69 | this.z = 30; 70 | this.floating = true; 71 | 72 | // This will make sure the menu gets initialized 73 | // at the right time. 74 | this.menu = null; 75 | this.enableMenu(false); 76 | 77 | // Attaching ourselves to the global game namespace. 78 | // I'm not proud of this, but it's necessary so we can 79 | // use it on the `this.handler`. 80 | // Check below. 81 | game.pauseHandler = this; 82 | 83 | // Will keep watching the pause key directly 84 | // (when the user releases the pause key) 85 | this.handler = me.event.subscribe(me.event.KEYDOWN, function (action, keyCode) { 86 | // Only controlling the menu when the game is paused. 87 | // 88 | // Let's grab the user input and control the menu. 89 | // NOTE: HARDCODED KEYS11!!!111 90 | if ((me.state.isPaused()) && 91 | (game.pauseHandler.menu)) { 92 | 93 | if (keyCode === me.input.KEY.DOWN) { 94 | game.pauseHandler.menu.next(); 95 | me.audio.play("menu", false, null, me.save.sfxVolume); 96 | } 97 | else if (keyCode === me.input.KEY.UP) { 98 | game.pauseHandler.menu.previous(); 99 | me.audio.play("menu", false, null, me.save.sfxVolume); 100 | } 101 | else if (keyCode === me.input.KEY.ENTER) { 102 | game.pauseHandler.menu.activate(); 103 | me.audio.play("menu", false, null, me.save.sfxVolume); 104 | 105 | // HACK BUG TODO 106 | // I'm really embarassed to place this here. 107 | // I need this `return` because the "pause" key 108 | // is `me.input.KEY_ENTER`. 109 | // 110 | // So to pause the user presses "ENTER". 111 | // The way it was, if he pressed "ENTER" again it 112 | // would unpause. 113 | // But we need it to control the menu option with 114 | // "ENTER". 115 | // So we'll assign a higher priority for "ENTER" 116 | // to control the menu when paused. 117 | // 118 | // Sorry if it seems confusing. 119 | // Please contact me if you need a better explanation 120 | // Alexandre Dantas 121 | return; 122 | } 123 | } 124 | 125 | // Now, pausing or unpausing the game! 126 | // This is where we enable/disable the Pause Menu. 127 | if (action === "pause") { 128 | 129 | if (me.state.isPaused()) { 130 | me.state.resume(); 131 | me.audio.resumeTrack(); 132 | game.pauseHandler.enableMenu(false); 133 | } 134 | else { 135 | game.pauseHandler.enableMenu(true); 136 | me.state.pause(true); 137 | me.audio.pauseTrack(); 138 | 139 | } 140 | } 141 | 142 | }); 143 | }, 144 | 145 | update : function(dt) { 146 | 147 | // When the game is not paused, do nothing. 148 | // When the game is paused, return `true` so the 149 | // engine can call `draw()`. 150 | return (me.state.isPaused()); 151 | }, 152 | 153 | draw : function(context) { 154 | 155 | // Will only show "PAUSED" if the game 156 | // is paused, duh 157 | if (! me.state.isPaused()) 158 | return; 159 | 160 | game.font_white.draw( 161 | context, 162 | "PAUSED", 163 | this.pos.x, 164 | this.pos.y 165 | ); 166 | 167 | if (this.menu) 168 | this.menu.draw(context, true); 169 | }, 170 | 171 | /** 172 | * Enables/Disables the pause menu. 173 | * It's called once the game is paused to create the menu; 174 | * and once the game gets unpaused, it's called to destroy 175 | * it. 176 | * 177 | * I know it's a waste of resources but I couldn't find a 178 | * way to create a menu that only gets drawn when I ask 179 | * it to. 180 | */ 181 | enableMenu : function(option) { 182 | 183 | if (! option) { 184 | // Let's destroy the menu! 185 | // (but only if it exists) 186 | if (this.menu === null) 187 | return; 188 | 189 | me.game.world.removeChild(this.menu); 190 | this.menu = null; 191 | } 192 | else { 193 | // Creating a sweet sweet pause menu. 194 | // (but only if it doesn't exist) 195 | if (this.menu !== null) 196 | return; 197 | 198 | this.menu = new me.Menu(1, 12); 199 | 200 | // WHAT THE HELL? 201 | // WHY DOESNT THIS APPLY? 202 | //this.menu.floating = true; 203 | 204 | // This way the menu works when paused -- yay! 205 | this.menu.updateWhenPaused = true; 206 | 207 | this.menu.addItem( 208 | "RESUME", 209 | function() { 210 | // Let's simulate the user pressing 211 | // the "pause" key to unpause the game 212 | me.input.triggerKeyEvent(me.input.KEY.ESC, true); 213 | } 214 | ); 215 | this.menu.addItem( 216 | ((me.save.sound)? 217 | "SOUND:Y" : 218 | "SOUND:N"), 219 | function () { 220 | 221 | var newLabel = ""; 222 | 223 | if (me.save.sound) { 224 | newLabel = "SOUND:N"; 225 | me.save.sound = false; 226 | me.audio.disable(); 227 | } 228 | else { 229 | newLabel = "SOUND:Y"; 230 | me.save.sound = true; 231 | me.audio.enable(); 232 | } 233 | 234 | // That's a VERY HACKISH THING TO DO 235 | // I should NEVER have to directly access 236 | // stuff like this! 237 | game.pauseHandler.menu.children[1].label = newLabel; 238 | } 239 | ); 240 | this.menu.addItem( 241 | ((me.save.stars) ? 242 | "STARS:Y" : 243 | "STARS:N"), 244 | function() { 245 | 246 | var newLabel = ""; 247 | 248 | if (me.save.stars) { 249 | newLabel = "STARS:N"; 250 | me.save.stars = false; 251 | 252 | // Dynamically destroying stars 253 | game.enableStars(false); 254 | } 255 | else { 256 | newLabel = "STARS:Y"; 257 | me.save.stars = true; 258 | 259 | // Dynamically creating stars 260 | game.enableStars(true); 261 | } 262 | 263 | // That's a VERY HACKISH THING TO DO 264 | // I should NEVER have to directly access 265 | // stuff like this! 266 | game.pauseHandler.menu.children[2].label = newLabel; 267 | } 268 | ); 269 | 270 | 271 | 272 | // I couldn't add an item to go to the menu because 273 | // it required a lot of hacks and was buggy. 274 | // TODO: implement this later 275 | /* 276 | this.menu.addItem( 277 | "QUIT", 278 | function() { 279 | // This is a clever/hackish thing to do. 280 | // Since I can't change states when paused, I 281 | // simulate this keypress and THEN change the state. 282 | 283 | me.input.triggerKeyEvent(me.input.KEY.ESC, true); 284 | 285 | game.pauseHandler.enableMenu(false); 286 | 287 | // It's very ugly to directly 288 | // access a game state... 289 | me.state.change(me.state.STATE_MAIN_MENU); 290 | } 291 | ); 292 | */ 293 | 294 | 295 | // FINALLY, adding the menu to the world 296 | // (meaning it's update() and draw() functions 297 | // will get called from now on) 298 | me.game.world.addChild(this.menu, 20); 299 | } 300 | } 301 | }); 302 | 303 | -------------------------------------------------------------------------------- /css/normalize.css: -------------------------------------------------------------------------------- 1 | /*! normalize.css v3.0.1 | MIT License | git.io/normalize */ 2 | 3 | /** 4 | * 1. Set default font family to sans-serif. 5 | * 2. Prevent iOS text size adjust after orientation change, without disabling 6 | * user zoom. 7 | */ 8 | 9 | html { 10 | font-family: sans-serif; /* 1 */ 11 | -ms-text-size-adjust: 100%; /* 2 */ 12 | -webkit-text-size-adjust: 100%; /* 2 */ 13 | } 14 | 15 | /** 16 | * Remove default margin. 17 | */ 18 | 19 | body { 20 | margin: 0; 21 | } 22 | 23 | /* HTML5 display definitions 24 | ========================================================================== */ 25 | 26 | /** 27 | * Correct `block` display not defined for any HTML5 element in IE 8/9. 28 | * Correct `block` display not defined for `details` or `summary` in IE 10/11 and Firefox. 29 | * Correct `block` display not defined for `main` in IE 11. 30 | */ 31 | 32 | article, 33 | aside, 34 | details, 35 | figcaption, 36 | figure, 37 | footer, 38 | header, 39 | hgroup, 40 | main, 41 | nav, 42 | section, 43 | summary { 44 | display: block; 45 | } 46 | 47 | /** 48 | * 1. Correct `inline-block` display not defined in IE 8/9. 49 | * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. 50 | */ 51 | 52 | audio, 53 | canvas, 54 | progress, 55 | video { 56 | display: inline-block; /* 1 */ 57 | vertical-align: baseline; /* 2 */ 58 | } 59 | 60 | /** 61 | * Prevent modern browsers from displaying `audio` without controls. 62 | * Remove excess height in iOS 5 devices. 63 | */ 64 | 65 | audio:not([controls]) { 66 | display: none; 67 | height: 0; 68 | } 69 | 70 | /** 71 | * Address `[hidden]` styling not present in IE 8/9/10. 72 | * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22. 73 | */ 74 | 75 | [hidden], 76 | template { 77 | display: none; 78 | } 79 | 80 | /* Links 81 | ========================================================================== */ 82 | 83 | /** 84 | * Remove the gray background color from active links in IE 10. 85 | */ 86 | 87 | a { 88 | background: transparent; 89 | } 90 | 91 | /** 92 | * Improve readability when focused and also mouse hovered in all browsers. 93 | */ 94 | 95 | a:active, 96 | a:hover { 97 | outline: 0; 98 | } 99 | 100 | /* Text-level semantics 101 | ========================================================================== */ 102 | 103 | /** 104 | * Address styling not present in IE 8/9/10/11, Safari, and Chrome. 105 | */ 106 | 107 | abbr[title] { 108 | border-bottom: 1px dotted; 109 | } 110 | 111 | /** 112 | * Address style set to `bolder` in Firefox 4+, Safari, and Chrome. 113 | */ 114 | 115 | b, 116 | strong { 117 | font-weight: bold; 118 | } 119 | 120 | /** 121 | * Address styling not present in Safari and Chrome. 122 | */ 123 | 124 | dfn { 125 | font-style: italic; 126 | } 127 | 128 | /** 129 | * Address variable `h1` font-size and margin within `section` and `article` 130 | * contexts in Firefox 4+, Safari, and Chrome. 131 | */ 132 | 133 | h1 { 134 | font-size: 2em; 135 | margin: 0.67em 0; 136 | } 137 | 138 | /** 139 | * Address styling not present in IE 8/9. 140 | */ 141 | 142 | mark { 143 | background: #ff0; 144 | color: #000; 145 | } 146 | 147 | /** 148 | * Address inconsistent and variable font size in all browsers. 149 | */ 150 | 151 | small { 152 | font-size: 80%; 153 | } 154 | 155 | /** 156 | * Prevent `sub` and `sup` affecting `line-height` in all browsers. 157 | */ 158 | 159 | sub, 160 | sup { 161 | font-size: 75%; 162 | line-height: 0; 163 | position: relative; 164 | vertical-align: baseline; 165 | } 166 | 167 | sup { 168 | top: -0.5em; 169 | } 170 | 171 | sub { 172 | bottom: -0.25em; 173 | } 174 | 175 | /* Embedded content 176 | ========================================================================== */ 177 | 178 | /** 179 | * Remove border when inside `a` element in IE 8/9/10. 180 | */ 181 | 182 | img { 183 | border: 0; 184 | } 185 | 186 | /** 187 | * Correct overflow not hidden in IE 9/10/11. 188 | */ 189 | 190 | svg:not(:root) { 191 | overflow: hidden; 192 | } 193 | 194 | /* Grouping content 195 | ========================================================================== */ 196 | 197 | /** 198 | * Address margin not present in IE 8/9 and Safari. 199 | */ 200 | 201 | figure { 202 | margin: 1em 40px; 203 | } 204 | 205 | /** 206 | * Address differences between Firefox and other browsers. 207 | */ 208 | 209 | hr { 210 | -moz-box-sizing: content-box; 211 | box-sizing: content-box; 212 | height: 0; 213 | } 214 | 215 | /** 216 | * Contain overflow in all browsers. 217 | */ 218 | 219 | pre { 220 | overflow: auto; 221 | } 222 | 223 | /** 224 | * Address odd `em`-unit font size rendering in all browsers. 225 | */ 226 | 227 | code, 228 | kbd, 229 | pre, 230 | samp { 231 | font-family: monospace, monospace; 232 | font-size: 1em; 233 | } 234 | 235 | /* Forms 236 | ========================================================================== */ 237 | 238 | /** 239 | * Known limitation: by default, Chrome and Safari on OS X allow very limited 240 | * styling of `select`, unless a `border` property is set. 241 | */ 242 | 243 | /** 244 | * 1. Correct color not being inherited. 245 | * Known issue: affects color of disabled elements. 246 | * 2. Correct font properties not being inherited. 247 | * 3. Address margins set differently in Firefox 4+, Safari, and Chrome. 248 | */ 249 | 250 | button, 251 | input, 252 | optgroup, 253 | select, 254 | textarea { 255 | color: inherit; /* 1 */ 256 | font: inherit; /* 2 */ 257 | margin: 0; /* 3 */ 258 | } 259 | 260 | /** 261 | * Address `overflow` set to `hidden` in IE 8/9/10/11. 262 | */ 263 | 264 | button { 265 | overflow: visible; 266 | } 267 | 268 | /** 269 | * Address inconsistent `text-transform` inheritance for `button` and `select`. 270 | * All other form control elements do not inherit `text-transform` values. 271 | * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera. 272 | * Correct `select` style inheritance in Firefox. 273 | */ 274 | 275 | button, 276 | select { 277 | text-transform: none; 278 | } 279 | 280 | /** 281 | * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` 282 | * and `video` controls. 283 | * 2. Correct inability to style clickable `input` types in iOS. 284 | * 3. Improve usability and consistency of cursor style between image-type 285 | * `input` and others. 286 | */ 287 | 288 | button, 289 | html input[type="button"], /* 1 */ 290 | input[type="reset"], 291 | input[type="submit"] { 292 | -webkit-appearance: button; /* 2 */ 293 | cursor: pointer; /* 3 */ 294 | } 295 | 296 | /** 297 | * Re-set default cursor for disabled elements. 298 | */ 299 | 300 | button[disabled], 301 | html input[disabled] { 302 | cursor: default; 303 | } 304 | 305 | /** 306 | * Remove inner padding and border in Firefox 4+. 307 | */ 308 | 309 | button::-moz-focus-inner, 310 | input::-moz-focus-inner { 311 | border: 0; 312 | padding: 0; 313 | } 314 | 315 | /** 316 | * Address Firefox 4+ setting `line-height` on `input` using `!important` in 317 | * the UA stylesheet. 318 | */ 319 | 320 | input { 321 | line-height: normal; 322 | } 323 | 324 | /** 325 | * It's recommended that you don't attempt to style these elements. 326 | * Firefox's implementation doesn't respect box-sizing, padding, or width. 327 | * 328 | * 1. Address box sizing set to `content-box` in IE 8/9/10. 329 | * 2. Remove excess padding in IE 8/9/10. 330 | */ 331 | 332 | input[type="checkbox"], 333 | input[type="radio"] { 334 | box-sizing: border-box; /* 1 */ 335 | padding: 0; /* 2 */ 336 | } 337 | 338 | /** 339 | * Fix the cursor style for Chrome's increment/decrement buttons. For certain 340 | * `font-size` values of the `input`, it causes the cursor style of the 341 | * decrement button to change from `default` to `text`. 342 | */ 343 | 344 | input[type="number"]::-webkit-inner-spin-button, 345 | input[type="number"]::-webkit-outer-spin-button { 346 | height: auto; 347 | } 348 | 349 | /** 350 | * 1. Address `appearance` set to `searchfield` in Safari and Chrome. 351 | * 2. Address `box-sizing` set to `border-box` in Safari and Chrome 352 | * (include `-moz` to future-proof). 353 | */ 354 | 355 | input[type="search"] { 356 | -webkit-appearance: textfield; /* 1 */ 357 | -moz-box-sizing: content-box; 358 | -webkit-box-sizing: content-box; /* 2 */ 359 | box-sizing: content-box; 360 | } 361 | 362 | /** 363 | * Remove inner padding and search cancel button in Safari and Chrome on OS X. 364 | * Safari (but not Chrome) clips the cancel button when the search input has 365 | * padding (and `textfield` appearance). 366 | */ 367 | 368 | input[type="search"]::-webkit-search-cancel-button, 369 | input[type="search"]::-webkit-search-decoration { 370 | -webkit-appearance: none; 371 | } 372 | 373 | /** 374 | * Define consistent border, margin, and padding. 375 | */ 376 | 377 | fieldset { 378 | border: 1px solid #c0c0c0; 379 | margin: 0 2px; 380 | padding: 0.35em 0.625em 0.75em; 381 | } 382 | 383 | /** 384 | * 1. Correct `color` not being inherited in IE 8/9/10/11. 385 | * 2. Remove padding so people aren't caught out if they zero out fieldsets. 386 | */ 387 | 388 | legend { 389 | border: 0; /* 1 */ 390 | padding: 0; /* 2 */ 391 | } 392 | 393 | /** 394 | * Remove default vertical scrollbar in IE 8/9/10/11. 395 | */ 396 | 397 | textarea { 398 | overflow: auto; 399 | } 400 | 401 | /** 402 | * Don't inherit the `font-weight` (applied by a rule above). 403 | * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. 404 | */ 405 | 406 | optgroup { 407 | font-weight: bold; 408 | } 409 | 410 | /* Tables 411 | ========================================================================== */ 412 | 413 | /** 414 | * Remove most spacing between table cells. 415 | */ 416 | 417 | table { 418 | border-collapse: collapse; 419 | border-spacing: 0; 420 | } 421 | 422 | td, 423 | th { 424 | padding: 0; 425 | } 426 | -------------------------------------------------------------------------------- /js/entities/player.js: -------------------------------------------------------------------------------- 1 | // Le player 2 | 3 | /*global game,me*/ 4 | 5 | /* Player entity. 6 | * 7 | * The character you control around the game. 8 | */ 9 | game.playerEntity = me.ObjectEntity.extend({ 10 | 11 | // Constructor 12 | init : function(x, y, settings) { 13 | 14 | // Aside from the `settings` passed by Tiled 15 | settings.image = "player-spritesheet"; 16 | 17 | // The collision box will be approximately 1 tile per two 18 | // But the actual sprites are the following: 19 | settings.spritewidth = settings.width = 2; 20 | settings.spriteheight = settings.height = 4; 21 | 22 | // Need to create super-class-specific stuff 23 | this.parent(x, y, settings); 24 | 25 | this.area = "area000"; 26 | 27 | // THIS IS A "BUG" ON MELONJS 28 | // Since the player is 2 pixels large, it's 29 | // collision box actually is 3 pixels large! 30 | // Don't know why but I have to adjust it 31 | // manually here. 32 | var shape = this.getShape(); 33 | shape.resize( 34 | shape.width - 1, 35 | shape.height 36 | ); 37 | 38 | // Normally things outside the screen (viewport) 39 | // are not updated. 40 | // It's not the case of the player. 41 | this.alwaysUpdate = true; 42 | 43 | // Speed when running 44 | this.setVelocity(0.29, 0.39); 45 | 46 | // Speed when walking (holding SHIFT) 47 | this.walkVelocity = new me.Vector2d(0.19, 0.39); 48 | 49 | this.renderable.addAnimation("standing", [0]); 50 | this.renderable.addAnimation("dying", [1]); 51 | 52 | this.renderable.setCurrentAnimation("standing"); 53 | 54 | // Gravity is the key of this game. 55 | // 56 | // @note Independently of this gravity, the player's 57 | // vertical position can't go further than 58 | // what we set up there. 59 | this.gravity = me.sys.gravity; 60 | this.absoluteGravity = Math.abs(this.gravity); 61 | 62 | // Saving our current position so when 63 | // we die we return here. 64 | // (simulating a checkpoint) 65 | this.checkpoint(this.pos.x, this.pos.y+2, game.checkpoint.type.BOTTOM); 66 | 67 | // Movable platform attached to the Player 68 | // 69 | // When the player steps on a movable platform, 70 | // it'll attach to the player through this variable. 71 | // We use it to move the Player alongside the platform 72 | // on `update()`. 73 | this.platform = null; 74 | 75 | // Keeping a global reference so we can acccess 76 | // the player anywhere. 77 | game.player = this; 78 | this.type = me.game.PLAYER_OBJECT; 79 | }, 80 | 81 | /** 82 | * Called every frame to update the Player's internal state. 83 | * 84 | * @note Remember, if we return `true` we tell the engine 85 | * to redraw the player. `false` tells it to avoid 86 | * having all the work of doing that. 87 | */ 88 | 89 | update : function(delta) { 90 | 91 | // Just for safety's sake, let's save the 92 | // current player position. 93 | // If we do move the player, we might use this 94 | // to change it back to where it was. 95 | var previousPos = this.pos.clone(); 96 | 97 | // This makes the Camera center on the player's 98 | // position, making sure it'll move 32 pixels 99 | // at a time. 100 | me.game.viewport.moveTo( 101 | Math.floor(this.pos.x/32) * 32, 102 | Math.floor(this.pos.y/32) * 32 103 | ); 104 | 105 | if (! this.alive) 106 | return false; 107 | 108 | // Player's death animation is happening 109 | if (this.dying) 110 | return true; 111 | 112 | // // Fell into outside the screen 113 | // if (! this.inViewport) { 114 | // this.die(); 115 | // return false; 116 | // } 117 | 118 | // Now we'll handle input! 119 | // 120 | // Invert gravity (only possible when on the floor) 121 | if (me.input.isKeyPressed("jump")) 122 | this.flip(); 123 | 124 | // Let's see if the player will walk slowly or run 125 | this.walking = me.input.keyStatus("walk"); 126 | 127 | // Run (or Walk)! 128 | var xSpeedIncrease = ((this.walking) ? 129 | this.walkVelocity.x : 130 | this.accel.x) * me.timer.tick; 131 | 132 | if (me.input.isKeyPressed("left")) this.vel.x = -xSpeedIncrease; 133 | else if (me.input.isKeyPressed("right")) this.vel.x = xSpeedIncrease; 134 | else this.vel.x = 0; 135 | 136 | // Panic Button aka. Suicide Key aka. Angel of death aka... 137 | if (me.input.isKeyPressed("die")) { 138 | this.die(); 139 | return false; 140 | } 141 | 142 | // Need to call this so we can update 143 | // the movement, animation and stuff 144 | this.parent(delta); 145 | 146 | // Moving Platforms! 147 | // Here we add the player's velocity 148 | // if he's on top of a movable platform RIGHT NOW 149 | if (this.platform) { 150 | this.vel.x += this.platform.vel.x; 151 | this.vel.y += this.platform.vel.y; 152 | 153 | // And now that I've updated the speed, let's 154 | // clear any platforms associated to us. 155 | // If we're still on top of one, it'll attach 156 | // to ourselves again anyway. 157 | this.platform = null; 158 | } 159 | 160 | // Updating the movement and checking for 161 | // collisions with the map 162 | var collision = this.updateMovement(); 163 | 164 | // Here we allow the player to change gravity 165 | // again. 166 | // 167 | // We're going to check if we collided on the Y 168 | // axis. Depending on the current gravity we can 169 | // tell if the player is falling or not. 170 | if (collision.y != 0) { 171 | 172 | // The player's falling up and just hit the ceiling 173 | if ((this.gravity < 0) && (collision.y < 0)) 174 | this.falling = false; 175 | 176 | // The player's falling down and hit the ground 177 | else if ((this.gravity > 0) && (collision.y > 0)) 178 | this.falling = false; 179 | 180 | // NOTE: This is needed, otherwise the collision 181 | // system gets screwed up when the player 182 | // is upside-down. 183 | // That's because although the player is 184 | // drawn with pixels, it's position can be 185 | // between pixels (like, x=1.333335). 186 | // When the player is inverted, it's y 187 | // position used to be very strange, leading 188 | // to awkward collisions. 189 | this.pos.y = Math.floor(this.pos.y); 190 | 191 | } 192 | // Not colliding - means the player can switch 193 | // the gravity 194 | else 195 | this.falling = true; 196 | 197 | // Now checking for collision with 198 | // game objects 199 | collision = me.game.world.collide(this); 200 | 201 | if (collision) { 202 | 203 | if ((collision.obj.type === me.game.SPIKE_OBJECT) || 204 | (collision.obj.type === me.game.ENEMY_OBJECT)) 205 | this.die(); 206 | 207 | else if ((collision.obj.type === me.game.PLATFORM_OBJECT) || 208 | (collision.obj.type === me.game.PLATFORM_VANISHING_OBJECT) || 209 | (collision.obj.type === me.game.PLATFORM_MOVABLE_OBJECT)) { 210 | 211 | // Head (or butt) collision with platform 212 | if (collision.y != 0) { 213 | this.falling = false; 214 | this.vel.y = 0; 215 | 216 | if (this.gravity < 0) 217 | this.pos.y = collision.obj.bottom; 218 | else 219 | this.pos.y = collision.obj.top - this.height; 220 | } 221 | 222 | // Side collision 223 | if (collision.x != 0) { 224 | // What should I do? 225 | } 226 | } 227 | else if (collision.obj.type === me.game.TELEPORTER_OBJECT) { 228 | // game over 229 | me.state.change(me.state.GAME_OVER); 230 | } 231 | 232 | return false; 233 | } 234 | return true; 235 | }, 236 | 237 | /** 238 | * Inverts the player's gravity 239 | */ 240 | flip : function () { 241 | 242 | // Will only flip if we're touching 243 | // the ground 244 | if (this.falling) 245 | return; 246 | 247 | // Simple as that! 248 | this.gravity = -this.gravity; 249 | 250 | // Inverting the player sprite 251 | if (this.gravity < 0) 252 | this.renderable.flipY(true); 253 | else 254 | this.renderable.flipY(false); 255 | 256 | me.audio.play("jump", false, null, me.save.sfxVolume); 257 | }, 258 | 259 | /** 260 | * Starts the player dying animation. 261 | * When it finishes, will actually make the player die 262 | * 263 | * @see #respawn() 264 | */ 265 | die : function() { 266 | 267 | game.data.deaths++; 268 | 269 | // Just a nice quirk -- changing the title 270 | // to the number of times the player died :) 271 | game.changeWindowTitle(game.data.deaths + " : www"); 272 | 273 | // No more updating for Mr. Player! 274 | // (but force the "dying" animation) 275 | this.dying = true; 276 | 277 | this.renderable.setCurrentAnimation("dying"); 278 | 279 | // NOTE: Apparently I can't attach a callback 280 | // to Renderable#flicker()... What the FUCK 281 | this.renderable.flicker(10); 282 | 283 | me.timer.setTimeout( 284 | function() { 285 | game.player.dying = false; 286 | game.player.doRespawn(); 287 | }, 288 | 500 289 | ); 290 | 291 | me.audio.play("death", false, null, me.save.sfxVolume); 292 | 293 | // This is needed so when the player dies we make 294 | // sure it can go through the level again 295 | // (if he made some platforms disappear) 296 | game.platform.vanishing.showAll(); 297 | }, 298 | 299 | /** 300 | * Saves the current position and stuff so when 301 | * we die we return here. 302 | */ 303 | checkpoint : function (x, y, checkpointType) { 304 | 305 | // A little separate name space. 306 | // Just for organizing things 307 | this.respawn = this.respawn || {}; 308 | 309 | // Here we'll store information to reset the player. 310 | // When he dies, it will mirror what's inside here. 311 | 312 | // It's (x,y) position 313 | this.respawn.pos = this.respawn.pos || new me.Vector2d(x, y); 314 | this.respawn.pos.x = x; 315 | this.respawn.pos.y = ((checkpointType === game.checkpoint.type.BOTTOM) ? 316 | y - 2 : 317 | y); 318 | 319 | // Player can die in one map and respawn on another 320 | this.respawn.area = this.area; 321 | 322 | // Checkpoints on the roof or on the ground? 323 | // Makes the player gravity. 324 | this.respawn.gravity = ((checkpointType === game.checkpoint.type.BOTTOM) ? 325 | this.absoluteGravity : 326 | -this.absoluteGravity); 327 | }, 328 | 329 | /** 330 | * Makes the player return to a previously saved 331 | * position. 332 | * 333 | * @note Please don't call this directly... Prefer the 334 | * `die()` animation. 335 | */ 336 | doRespawn : function() { 337 | this.renderable.setCurrentAnimation("standing"); 338 | 339 | // Restore player's original position 340 | this.pos.setV(this.respawn.pos); 341 | 342 | this.falling = false; 343 | this.area = this.respawn.area; 344 | this.gravity = this.respawn.gravity; 345 | 346 | // Inverting the player sprite 347 | // WARNING: Duplicated code! 348 | // See `this.flip()` 349 | if (this.gravity < 0) 350 | this.renderable.flipY(true); 351 | else 352 | this.renderable.flipY(false); 353 | } 354 | }); 355 | 356 | -------------------------------------------------------------------------------- /js/game.js: -------------------------------------------------------------------------------- 1 | /* This is where it all starts. 2 | * 3 | * Initializing melonJS and the "Game Namespace". 4 | */ 5 | 6 | /*global me debugPanel*/ 7 | 8 | var game = { 9 | 10 | /** 11 | * Game version; the same as `package.json`. 12 | */ 13 | version : "0.8.2", 14 | 15 | /** 16 | * Stores information that will be used on current 17 | * game session. 18 | * 19 | * @note This is reset every time the game restarts 20 | * For persistent information saving 21 | * (across page loads, for example) see `me.save` 22 | */ 23 | data : { 24 | // How many times the player has died 25 | deaths : 0, 26 | 27 | // First level to be loaded 28 | currentLevel : "area000" 29 | }, 30 | 31 | /** 32 | * Global tile size. 33 | * Throughout the game, this is the value that 34 | * will be used for the square tiles, width AND height. 35 | */ 36 | tile_size : 2, 37 | 38 | /** 39 | * Returns the pixel coordinates for a specific 40 | * tile. 41 | * 42 | * This is so we can always work with tile sizes 43 | * instead of directly with pixels. 44 | */ 45 | tile : function(n) { 46 | return (n * game.tile_size); 47 | }, 48 | 49 | /** 50 | * Returns the pixel coordinates for half the 51 | * size of a regular tile. 52 | */ 53 | half_tile : function(n) { 54 | return (n * (game.tile_size/2)); 55 | }, 56 | 57 | /** 58 | * This function runs as soon as the page loads. 59 | * 60 | * Meaning when all resources were downloaded from 61 | * the server (GET requests). 62 | * 63 | * At the end, it launches the Loading Screen. 64 | */ 65 | "onload" : function() { 66 | 67 | // Initialize the video, making sure to stretch the canvas 68 | // to fill the available space. 69 | // TODO: See if `double buffering` is any good for performance 70 | if (! me.video.init("screen", 32, 32, true, "auto", true)) { 71 | alert("Your browser does not support HTML5 canvas."); 72 | return; 73 | } 74 | 75 | // Add "#debug" to the URL to enable the debug mode 76 | // - Has a debug Panel on top 77 | // - Several gameplay features are enabled (like secret keys) 78 | // 79 | if (document.location.hash === "#debug") { 80 | window.onReady(function() { 81 | me.plugin.register.defer(this, debugPanel, "debug"); 82 | }); 83 | } 84 | 85 | // Initialize the audio. 86 | me.audio.init("ogg,mp3"); 87 | 88 | // My own custom loading screen! 89 | // 90 | // Will only go to it after loading it's background 91 | // image first. 92 | me.loader.load( 93 | 94 | // I need to full specify the resource here 95 | // because all the resources weren't really loaded yet. 96 | { 97 | name : "loading-bg", 98 | type : "image", 99 | src : "data/image/loading.png" 100 | }, 101 | 102 | // Called when finished loading the resource above 103 | this.goToLoadingScreen.bind(this), 104 | 105 | // Called when an error occurs when loading 106 | function() { 107 | alert("Couldn't load resources!"); 108 | } 109 | ); 110 | }, 111 | 112 | /** 113 | * Changes the current state to the loading screen. 114 | * @note Only call this when you're sure any resources used 115 | * there were loaded (for instance, the background image)! 116 | */ 117 | goToLoadingScreen : function() { 118 | 119 | // For it's implementation, see file `states/loading.js` 120 | me.state.set(me.state.LOADING, new game.CustomLoadingScreen()); 121 | 122 | // Set a callback to run when loading is complete. 123 | me.loader.onload = this.loaded.bind(this); 124 | 125 | // Load the resources. 126 | // (defined on `js/resources.js` 127 | me.loader.preload(game.resources); 128 | 129 | // Initialize melonJS and display a loading screen. 130 | // (pre-defined state) 131 | me.state.change(me.state.LOADING); 132 | }, 133 | 134 | /** 135 | * Run as soon as all the game resources loads 136 | * (past the loading screen). 137 | */ 138 | loaded : function() { 139 | 140 | // I'm changing the global gravity because 141 | // the game is 32x32 -- come on, 9.8 would move 142 | // a thing by 9 pixels! 143 | me.sys.gravity = 0.2; 144 | 145 | // Defining all our game states. 146 | // They're used by `me.state.change()` 147 | // (these are just constants, ignore the right side) 148 | me.state.STATE_MAIN_MENU = me.state.USER + 0; 149 | me.state.STATE_OPTIONS_MENU = me.state.SETTINGS; 150 | me.state.STATE_CREDITS = me.state.CREDITS; 151 | me.state.STATE_GAME_OVER = me.state.GAMEOVER; 152 | me.state.STATE_AREA_SELECT = me.state.USER + 2; 153 | me.state.STATE_PLAY = me.state.PLAY; 154 | me.state.STATE_VICTORY = me.state.USER + 3; 155 | 156 | // Attaching our state constants to actual 157 | // objects. 158 | // Each one has it's file under the `js/screens` directory 159 | me.state.set(me.state.STATE_MAIN_MENU, new game.MainMenuState()); 160 | me.state.set(me.state.STATE_PLAY, new game.PlayState()); 161 | me.state.set(me.state.STATE_CREDITS, new game.CreditsState()); 162 | me.state.set(me.state.GAME_OVER, new game.GameOverState()); 163 | 164 | // Global transition to occur between all states 165 | me.state.transition("fade", "#000000", 250); 166 | 167 | // Add game entities to the entity pool. 168 | // They're defined on the `js/entities` directory 169 | // 170 | // Arguments: 171 | // 1. Object name on Tiled - we'll look for it when 172 | // reading Tiled maps' entities. 173 | // 2. Class name to create (each on it's own file) 174 | // 3. If you plan on creating more than one of those, 175 | // set this as true to speed things up. 176 | // 177 | me.pool.register("player", game.playerEntity); 178 | me.pool.register("spike", game.spikeEntity, true); 179 | me.pool.register("spike-group", game.spikeGroupEntity, true); 180 | me.pool.register("checkpoint", game.checkpointEntity, true); 181 | me.pool.register("enemy", game.enemy.entity, true); 182 | me.pool.register("enemy-path", game.enemy.path.entity, true); 183 | me.pool.register("enemy-bouncy", game.enemy.bouncy.entity, true); 184 | me.pool.register("message", game.messageEntity, true); 185 | me.pool.register("alert", game.alertEntity, true); 186 | me.pool.register("teleporter", game.teleporter.entity, true); 187 | me.pool.register("platform", game.platform.entity, true); 188 | me.pool.register("platform-vanishing", game.platform.vanishing.entity, true); 189 | me.pool.register("platform-movable", game.platform.movable.entity, true); 190 | 191 | // Defining some custom constants to uniquely 192 | // identify some entities on the whole game. 193 | me.game.SPIKE_OBJECT = "spike"; 194 | me.game.CHECKPOINT_OBJECT = "checkpoint"; 195 | me.game.PLATFORM_OBJECT = "platform"; 196 | me.game.PLATFORM_VANISHING_OBJECT = "platform-vanishing"; 197 | me.game.PLATFORM_MOVABLE_OBJECT = "platform-movable"; 198 | 199 | // Global fonts we'll use to draw text 200 | // (see `resources.js`) 201 | game.font_white = new me.BitmapFont("font-white", {x: 4, y:3}); 202 | game.font_black = new me.BitmapFont("font-black", {x: 4, y:3}); 203 | game.font_blue = new me.BitmapFont("font-blue", {x: 4, y:3}); 204 | 205 | // Default settings for the whole game. 206 | // If we already have saved these settings, 207 | // they won't have their default values. 208 | me.save.add({ 209 | // Flag to tell if this is the first time 210 | // the player's running this game. 211 | firstTime : true, 212 | 213 | // Enable/disable all audio 214 | // (music and sound effects) 215 | sound : true, 216 | 217 | musicVolume : 1.0, 218 | sfxVolume : 0.2, 219 | 220 | // If we're going to show the stars 221 | // at the background 222 | stars : true, 223 | 224 | // How many times this user beat 225 | // the game 226 | beatGame : 0 227 | }); 228 | 229 | // If these settings have different values 230 | // than the default it means we saved the 231 | // settings and the user is restarting the game. 232 | if (me.save.firstTime) { 233 | // Do somethin' 234 | } 235 | else { 236 | // Greet the player for returning 237 | // to the game 238 | } 239 | me.save.firstTime = false; 240 | 241 | // Due to the way melonJS is designed, we must 242 | // first play the background music AND THEN 243 | // enable/disable the audio based on the 244 | // settings... 245 | me.audio.playTrack("main-menu", me.save.musicVolume); 246 | 247 | if (! me.save.sound) 248 | me.audio.disable(); 249 | 250 | // Start the game. 251 | me.state.change(me.state.STATE_MAIN_MENU); 252 | }, 253 | 254 | /** 255 | * Small helper that changes the Window title 256 | * (everything inside .. . 257 | */ 258 | changeWindowTitle : function (title) { 259 | 260 | // Since accessing the DOM takes a while, let's 261 | // do it once and keep a global reference to the 262 | // thingy 263 | game.titleElement = game.titleElement || document.getElementsByTagName("title")[0]; 264 | 265 | game.titleElement.innerHTML = title; 266 | }, 267 | 268 | 269 | 270 | 271 | 272 | 273 | // THESE ARE HERE BECAUSE I COULDN'T FIND A BETTER PLACE 274 | // 275 | // TODO: Figure out a best way to put them, since stars 276 | // can be created and deactivated at any state 277 | 278 | 279 | 280 | 281 | /** 282 | * Creates/Destroys the background thing that spawns random 283 | * stars all around. 284 | * 285 | * You can call it multiple times without worrying. 286 | * 287 | * See file `entities/star-background.js`. 288 | * 289 | * @note If you want to have it between states, you MUST 290 | * call `game.enableStars(false)` when at 291 | * `onDestroyEvent` and then `game.enableStars(true)` 292 | * when at `onResetEvent`! 293 | */ 294 | enableStars : function(option) { 295 | 296 | // Avoiding re-initializing stuff. 297 | game.stars = game.stars || null; 298 | 299 | // Do I really need to double check this? 300 | // if (! me.save.stars) { 301 | // option = false; 302 | // } 303 | 304 | if (option) { 305 | 306 | // Will create stars 307 | // 308 | // But of course, won't do anything if they 309 | // already exist. 310 | if (game.stars !== null) 311 | return; 312 | 313 | game.stars = new game.starBackground(); 314 | 315 | // How will this be drawn on top of other stuff. 316 | // 317 | // I had to adjust it so it could be between the 318 | // map's background and the map's tiles. 319 | var z = 2; 320 | 321 | // Adding the particle system 322 | // (and the particles themselves) to the game. 323 | me.game.world.addChild(game.stars, z); 324 | me.game.world.addChild(game.stars.container, z); 325 | 326 | // Finally, command the system to launch constantly 327 | // the particles, like a fountain 328 | game.stars.streamParticles(); 329 | } 330 | else { 331 | 332 | // Will destroy stars 333 | // 334 | // But of course won't do anything if they 335 | // were already destroyed 336 | if (game.stars === null) 337 | return; 338 | 339 | game.stars.stopStream(); 340 | 341 | me.game.world.removeChild(game.stars.container); 342 | me.game.world.removeChild(game.stars); 343 | 344 | game.stars = null; 345 | 346 | } 347 | } 348 | }; 349 | 350 | -------------------------------------------------------------------------------- /lib/plugins/debugPanel.js: -------------------------------------------------------------------------------- 1 | /* 2 | * MelonJS Game Engine 3 | * Copyright (C) 2011 - 2013, Olivier BIOT 4 | * http://www.melonjs.org 5 | * 6 | * a simple debug panel plugin 7 | * usage : me.plugin.register(debugPanel, "debug"); 8 | * 9 | * you can then use me.plugin.debug.show() or me.plugin.debug.hide() 10 | * to show or hide the panel, or press respectively the "S" and "H" keys. 11 | * 12 | * note : 13 | * Heap Memory information is available under Chrome when using 14 | * the "--enable-memory-info" parameter to launch Chrome 15 | */ 16 | 17 | (function($) { 18 | 19 | // ensure that me.debug is defined 20 | me.debug = me.debug || {}; 21 | 22 | /** 23 | * @class 24 | * @public 25 | * @extends me.plugin.Base 26 | * @memberOf me 27 | * @constructor 28 | */ 29 | debugPanel = me.plugin.Base.extend( 30 | /** @scope me.debug.Panel.prototype */ 31 | { 32 | 33 | // Object "Game Unique Identifier" 34 | GUID : null, 35 | 36 | // to hold the debug options 37 | // clickable rect area 38 | area : {}, 39 | 40 | // panel position and size 41 | rect : null, 42 | 43 | // for z ordering 44 | // make it ridiculously high 45 | z : Infinity, 46 | 47 | // visibility flag 48 | visible : false, 49 | 50 | // frame update time in ms 51 | frameUpdateTime : 0, 52 | 53 | // frame draw time in ms 54 | frameDrawTime : 0, 55 | 56 | // minimum melonJS version expected 57 | version : "1.0.0", 58 | 59 | /** @private */ 60 | init : function(showKey, hideKey) { 61 | // call the parent constructor 62 | this.parent(); 63 | 64 | this.rect = new me.Rect(new me.Vector2d(0, 0), me.video.getWidth(), 35); 65 | 66 | // set the object GUID value 67 | this.GUID = "debug-" + me.utils.createGUID(); 68 | 69 | // set the object entity name 70 | this.name = "me.debugPanel"; 71 | 72 | // persistent 73 | this.isPersistent = true; 74 | 75 | // a floating object 76 | this.floating = true; 77 | 78 | // renderable 79 | this.isRenderable = true; 80 | 81 | // always update, even when not visible 82 | this.alwaysUpdate = true; 83 | 84 | // create a default font, with fixed char width 85 | this.font = new me.Font('courier', 10, 'white'); 86 | 87 | // clickable areas 88 | this.area.renderHitBox = new me.Rect(new me.Vector2d(160,5),15,15); 89 | this.area.renderVelocity = new me.Rect(new me.Vector2d(165,18),15,15); 90 | 91 | this.area.renderDirty = new me.Rect(new me.Vector2d(270,5),15,15); 92 | this.area.renderCollisionMap = new me.Rect(new me.Vector2d(270,18),15,15); 93 | 94 | // some internal string/length 95 | this.help_str = "(s)how/(h)ide"; 96 | this.help_str_len = this.font.measureText(me.video.getSystemContext(), this.help_str).width; 97 | this.fps_str_len = this.font.measureText(me.video.getSystemContext(), "00/00 fps").width; 98 | 99 | // enable the FPS counter 100 | me.debug.displayFPS = true; 101 | 102 | // bind the "S" and "H" keys 103 | me.input.bindKey(showKey || me.input.KEY.S, "show", false, false); 104 | me.input.bindKey(hideKey || me.input.KEY.H, "hide", false, false); 105 | 106 | // add some keyboard shortcuts 107 | var self = this; 108 | this.keyHandler = me.event.subscribe(me.event.KEYDOWN, function (action, keyCode, edge) { 109 | if (action === "show") { 110 | self.show(); 111 | } else if (action === "hide") { 112 | self.hide(); 113 | } 114 | }); 115 | 116 | // re-apply panel settings on level changes 117 | this.levelHandler = me.event.subscribe(me.event.LEVEL_LOADED, function () { 118 | var layer = me.game.currentLevel.getLayerByName("collision"); 119 | if (layer) { 120 | layer.setOpacity((me.debug.renderCollisionMap===true)?1:0); 121 | } 122 | }); 123 | 124 | // memory heap sample points 125 | this.samples = []; 126 | 127 | //patch patch patch ! 128 | this.patchSystemFn(); 129 | 130 | // make it visible 131 | this.show(); 132 | }, 133 | 134 | 135 | /** 136 | * patch system fn to draw debug information 137 | */ 138 | patchSystemFn : function() { 139 | 140 | // add a few new debug flag (if not yet defined) 141 | me.debug.renderHitBox = me.debug.renderHitBox || false; 142 | me.debug.renderVelocity = me.debug.renderVelocity || false; 143 | me.debug.renderCollisionMap = me.debug.renderCollisionMap || false; 144 | var _this = this; 145 | // patch timer.js 146 | me.plugin.patch(me.timer, "update", function (time) { 147 | // call the original me.timer.update function 148 | this.parent(time); 149 | 150 | // call the FPS counter 151 | me.timer.countFPS(); 152 | }); 153 | 154 | // patch me.game.update 155 | me.plugin.patch(me.game, 'update', function(time) { 156 | var frameUpdateStartTime = window.performance.now(); 157 | 158 | this.parent(time); 159 | 160 | // calculate the update time 161 | _this.frameUpdateTime = window.performance.now() - frameUpdateStartTime; 162 | }); 163 | 164 | // patch me.game.draw 165 | me.plugin.patch(me.game, 'draw', function() { 166 | var frameDrawStartTime = window.performance.now(); 167 | 168 | this.parent(); 169 | 170 | // calculate the drawing time 171 | _this.frameDrawTime = window.performance.now() - frameDrawStartTime; 172 | }); 173 | 174 | // patch sprite.js 175 | me.plugin.patch(me.SpriteObject, "draw", function (context) { 176 | // call the original me.SpriteObject function 177 | this.parent(context); 178 | 179 | // draw the sprite rectangle 180 | if (me.debug.renderHitBox) { 181 | context.strokeStyle = "green"; 182 | context.strokeRect(this.left, this.top, this.width, this.height); 183 | } 184 | }); 185 | 186 | // patch entities.js 187 | me.plugin.patch(me.ObjectEntity, "draw", function (context) { 188 | // call the original me.game.draw function 189 | this.parent(context); 190 | 191 | // check if debug mode is enabled 192 | if (me.debug.renderHitBox && this.shapes.length) { 193 | 194 | // translate to the object position 195 | var translateX = this.pos.x ; 196 | var translateY = this.pos.y ; 197 | 198 | context.translate(translateX, translateY); 199 | 200 | // draw the original shape 201 | this.getShape().draw(context, "red"); 202 | if (this.getShape().shapeType!=="Rectangle") { 203 | // draw the corresponding bounding box 204 | this.getShape().getBounds().draw(context, "red"); 205 | } 206 | 207 | context.translate(-translateX, -translateY); 208 | 209 | } 210 | 211 | if (me.debug.renderVelocity) { 212 | // draw entity current velocity 213 | var x = ~~(this.pos.x + this.hWidth); 214 | var y = ~~(this.pos.y + this.hHeight); 215 | 216 | context.strokeStyle = "blue"; 217 | context.lineWidth = 1; 218 | context.beginPath(); 219 | context.moveTo(x, y); 220 | context.lineTo( 221 | x + ~~(this.vel.x * this.hWidth), 222 | y + ~~(this.vel.y * this.hHeight) 223 | ); 224 | context.stroke(); 225 | } 226 | }); 227 | }, 228 | 229 | /** 230 | * show the debug panel 231 | */ 232 | show : function() { 233 | if (!this.visible) { 234 | // register a mouse event for the checkboxes 235 | me.input.registerPointerEvent('pointerdown', this.rect, this.onClick.bind(this), true); 236 | // add the debug panel to the game world 237 | me.game.world.addChild(this, Infinity); 238 | // mark it as visible 239 | this.visible = true; 240 | } 241 | }, 242 | 243 | /** 244 | * hide the debug panel 245 | */ 246 | hide : function() { 247 | if (this.visible) { 248 | // release the mouse event for the checkboxes 249 | me.input.releasePointerEvent('pointerdown', this.rect); 250 | // remove the debug panel from the game world 251 | me.game.world.removeChild(this); 252 | // mark it as invisible 253 | this.visible = false; 254 | } 255 | }, 256 | 257 | 258 | /** @private */ 259 | update : function() { 260 | if (me.input.isKeyPressed('show')) { 261 | this.show(); 262 | } 263 | else if (me.input.isKeyPressed('hide')) { 264 | this.hide(); 265 | } 266 | return true; 267 | }, 268 | 269 | /** 270 | * @private 271 | */ 272 | getBounds : function() { 273 | return this.rect; 274 | }, 275 | 276 | /** @private */ 277 | onClick : function(e) { 278 | // check the clickable areas 279 | if (this.area.renderHitBox.containsPoint(e.gameX, e.gameY)) { 280 | me.debug.renderHitBox = !me.debug.renderHitBox; 281 | } 282 | else if (this.area.renderCollisionMap.containsPoint(e.gameX, e.gameY)) { 283 | var layer = me.game.currentLevel.getLayerByName("collision"); 284 | if (layer) { 285 | if (layer.getOpacity() === 0) { 286 | layer.setOpacity(1); 287 | me.debug.renderCollisionMap = true; 288 | } else { 289 | layer.setOpacity(0); 290 | me.debug.renderCollisionMap = false; 291 | } 292 | } 293 | } else if (this.area.renderVelocity.containsPoint(e.gameX, e.gameY)) { 294 | // does nothing for now, since velocity is 295 | // rendered together with hitboxes (is a global debug flag required?) 296 | me.debug.renderVelocity = !me.debug.renderVelocity; 297 | } 298 | // force repaint 299 | me.game.repaint(); 300 | }, 301 | 302 | /** @private */ 303 | drawMemoryGraph : function (context, startX, endX) { 304 | if (window.performance && window.performance.memory) { 305 | var usedHeap = Number.prototype.round(window.performance.memory.usedJSHeapSize/1048576, 2); 306 | var totalHeap = Number.prototype.round(window.performance.memory.totalJSHeapSize/1048576, 2); 307 | 308 | var len = endX - startX; 309 | 310 | // remove the first item 311 | this.samples.shift(); 312 | // add a new sample (25 is the height of the graph) 313 | this.samples[len] = (usedHeap / totalHeap) * 25; 314 | 315 | // draw the graph 316 | for (var x = len;x--;) { 317 | var where = endX - (len - x); 318 | context.beginPath(); 319 | context.strokeStyle = "lightblue"; 320 | context.moveTo(where, 30); 321 | context.lineTo(where, 30 - (this.samples[x] || 0)); 322 | context.stroke(); 323 | } 324 | // display the current value 325 | this.font.draw(context, "Heap : " + usedHeap + '/' + totalHeap + ' MB', startX + 5, 5); 326 | } else { 327 | // Heap Memory information not available 328 | this.font.draw(context, "Heap : ??/?? MB", startX + 5, 5); 329 | } 330 | }, 331 | 332 | /** @private */ 333 | draw : function(context) { 334 | context.save(); 335 | 336 | // draw the panel 337 | context.globalAlpha = 0.5; 338 | context.fillStyle = "black"; 339 | context.fillRect(this.rect.left, this.rect.top, 340 | this.rect.width, this.rect.height); 341 | context.globalAlpha = 1.0; 342 | 343 | // # entities / draw 344 | this.font.draw(context, "#objects : " + me.game.world.children.length, 5, 5); 345 | this.font.draw(context, "#draws : " + me.game.world.drawCount, 5, 18); 346 | 347 | // debug checkboxes 348 | this.font.draw(context, "?hitbox ["+ (me.debug.renderHitBox?"x":" ") +"]", 100, 5); 349 | this.font.draw(context, "?velocity ["+ (me.debug.renderVelocity?"x":" ") +"]", 100, 18); 350 | 351 | this.font.draw(context, "?dirtyRect [ ]", 200, 5); 352 | this.font.draw(context, "?col. layer ["+ (me.debug.renderCollisionMap?"x":" ") +"]", 200, 18); 353 | 354 | // draw the update duration 355 | this.font.draw(context, "Update : " + this.frameUpdateTime.toFixed(2) + " ms", 310, 5); 356 | // draw the draw duration 357 | this.font.draw(context, "Draw : " + (this.frameDrawTime).toFixed(2) + " ms", 310, 18); 358 | 359 | // draw the memory heap usage 360 | this.drawMemoryGraph(context, 425, this.rect.width - this.help_str_len - 10); 361 | 362 | // some help string 363 | this.font.draw(context, this.help_str, this.rect.width - this.help_str_len - 5, 18); 364 | 365 | //fps counter 366 | var fps_str = "" + me.timer.fps + "/" + me.sys.fps + " fps"; 367 | this.font.draw(context, fps_str, this.rect.width - this.fps_str_len - 5, 5); 368 | 369 | context.restore(); 370 | 371 | }, 372 | 373 | /** @private */ 374 | onDestroyEvent : function() { 375 | // hide the panel 376 | this.hide(); 377 | // unbind keys event 378 | me.input.unbindKey(me.input.KEY.S); 379 | me.input.unbindKey(me.input.KEY.H); 380 | me.event.unsubscribe(this.keyHandler); 381 | me.event.unsubscribe(this.levelHandler); 382 | } 383 | 384 | 385 | }); 386 | 387 | /*---------------------------------------------------------*/ 388 | // END END END 389 | /*---------------------------------------------------------*/ 390 | })(window); 391 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 [Free Software Foundation, Inc.](http://fsf.org/) 5 | 6 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 7 | 8 | ## Preamble 9 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 10 | 11 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to 12 | share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 13 | 14 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for 15 | them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 16 | 17 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if 18 | you modify it: responsibilities to respect the freedom of others. 19 | 20 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 21 | 22 | Developers that use the GNU GPL protect your rights with two steps: 23 | 24 | 1. assert copyright on the software, and 25 | 2. offer you this License giving you legal permission to copy, distribute and/or modify it. 26 | 27 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as 28 | changed, so that their problems will not be attributed erroneously to authors of previous versions. 29 | 30 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 31 | 32 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 33 | 34 | The precise terms and conditions for copying, distribution and modification follow. 35 | 36 | ## TERMS AND CONDITIONS 37 | 38 | ### 0. Definitions. 39 | *This License* refers to version 3 of the GNU General Public License. 40 | 41 | *Copyright* also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 42 | 43 | *The Program* refers to any copyrightable work licensed under this License. Each licensee is addressed as *you*. *Licensees* and *recipients* may be individuals or organizations. 44 | 45 | To *modify* a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a *modified version* of the earlier work or a work *based on* the earlier work. 46 | 47 | A *covered work* means either the unmodified Program or a work based on the Program. 48 | 49 | To *propagate* a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 50 | 51 | To *convey* a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 52 | 53 | An interactive user interface displays *Appropriate Legal Notices* to the extent that it includes a convenient and prominently visible feature that 54 | 55 | 1. displays an appropriate copyright notice, and 56 | 2. tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. 57 | 58 | If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 59 | 60 | ### 1. Source Code. 61 | The *source code* for a work means the preferred form of the work for making modifications to it. *Object code* means any non-source form of a work. 62 | 63 | A *Standard Interface* means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 64 | 65 | The *System Libraries* of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A *Major Component*, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 66 | 67 | The *Corresponding Source* for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 68 | 69 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 70 | 71 | The Corresponding Source for a work in source code form is that same work. 72 | 73 | ### 2. Basic Permissions. 74 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 75 | 76 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do 77 | not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of 78 | your copyrighted material outside their relationship with you. 79 | 80 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 81 | 82 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 83 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 84 | 85 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 86 | 87 | ### 4. Conveying Verbatim Copies. 88 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 89 | 90 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 91 | 92 | ### 5. Conveying Modified Source Versions. 93 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 94 | 95 | - a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 96 | - b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to *keep intact all notices*. 97 | - c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 98 | - d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 99 | 100 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an *aggregate* if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 101 | 102 | ### 6. Conveying Non-Source Forms. 103 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 104 | 105 | - a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 106 | - b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either 107 | 1. a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or 108 | 2. access to copy the Corresponding Source from a network server at no charge. 109 | 110 | - c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 111 | - d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 112 | - e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 113 | 114 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 115 | 116 | A *User Product* is either 117 | 118 | 1. a *consumer product*, which means any tangible personal property which is normally used for personal, family, or household purposes, or 119 | 2. anything designed or sold for incorporation into a dwelling. 120 | 121 | In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, *normally used* refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 122 | 123 | *Installation Information* for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 124 | 125 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 126 | 127 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and 128 | protocols for communication across the network. 129 | 130 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 131 | 132 | ### 7. Additional Terms. 133 | *Additional permissions* are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 134 | 135 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 136 | 137 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 138 | 139 | a. Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 140 | b. Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 141 | c. Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 142 | d. Limiting the use for publicity purposes of names of licensors or authors of the material; or 143 | e. Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 144 | f. Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 145 | 146 | All other non-permissive additional terms are considered *further restrictions* within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 147 | 148 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 149 | 150 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 151 | 152 | ### 8. Termination. 153 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 154 | 155 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated 156 | 157 | a. provisionally, unless and until the copyright holder explicitly and finally terminates your license, and 158 | b. permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 159 | 160 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 161 | 162 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 163 | 164 | ### 9. Acceptance Not Required for Having Copies. 165 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 166 | 167 | ### 10. Automatic Licensing of Downstream Recipients. 168 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 169 | 170 | An *entity transaction* is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 171 | 172 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 173 | 174 | ### 11. Patents. 175 | A *contributor* is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's *contributor version*. 176 | 177 | A contributor's *essential patent claims* are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, *control* includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 178 | 179 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 180 | 181 | In the following three paragraphs, a *patent license* is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to 182 | sue for patent infringement). To *grant* such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 183 | 184 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either 185 | 186 | 1. cause the Corresponding Source to be so available, or 187 | 2. arrange to deprive yourself of the benefit of the patent license for this particular work, or 188 | 3. arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. 189 | 190 | *Knowingly relying* means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 191 | 192 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 193 | 194 | A patent license is *discriminatory* if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license 195 | 196 | a. in connection with copies of the covered work conveyed by you (or copies made from those copies), or 197 | b. primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 198 | 199 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 200 | 201 | ### 12. No Surrender of Others' Freedom. 202 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 203 | 204 | ### 13. Use with the GNU Affero General Public License. 205 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 206 | 207 | ### 14. Revised Versions of this License. 208 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 209 | 210 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License *or any later version* applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 211 | 212 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 213 | 214 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 215 | 216 | ### 15. Disclaimer of Warranty. 217 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 218 | 219 | ### 16. Limitation of Liability. 220 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 221 | 222 | ### 17. Interpretation of Sections 15 and 16. 223 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 224 | 225 | ## END OF TERMS AND CONDITIONS 226 | ### How to Apply These Terms to Your New Programs 227 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. 228 | 229 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the *copyright* line and a pointer to where the full notice is found. 230 | 231 | <one line to give the program's name and a brief idea of what it does.> 232 | Copyright (C) <year> <name of author> 233 | 234 | This program is free software: you can redistribute it and/or modify 235 | it under the terms of the GNU General Public License as published by 236 | the Free Software Foundation, either version 3 of the License, or 237 | (at your option) any later version. 238 | 239 | This program is distributed in the hope that it will be useful, 240 | but WITHOUT ANY WARRANTY; without even the implied warranty of 241 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 242 | GNU General Public License for more details. 243 | 244 | You should have received a copy of the GNU General Public License 245 | along with this program. If not, see <http://www.gnu.org/licenses/>. 246 | 247 | Also add information on how to contact you by electronic and paper mail. 248 | 249 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 250 | 251 | <program> Copyright (C) <year> <name of author> 252 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 253 | This is free software, and you are welcome to redistribute it 254 | under certain conditions; type `show c' for details. 255 | 256 | The hypothetical commands `show w` and `show c` should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an *about box*. 257 | 258 | You should also get your employer (if you work as a programmer) or school, if any, to sign a *copyright disclaimer* for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/). 259 | 260 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read [http://www.gnu.org/philosophy/why-not-lgpl.html](http://www.gnu.org/philosophy/why-not-lgpl.html). --------------------------------------------------------------------------------