├── .gitignore ├── CNAME ├── LICENSE.txt ├── README.md ├── img ├── background.png ├── button-pause.png ├── button-start.png ├── candy.png ├── floor.png ├── gameover.png ├── loading-bar.png ├── monster-cover.png ├── monster-idle.png ├── score-bg.png └── title.png ├── index.html └── src ├── Boot.js ├── Game.js ├── MainMenu.js ├── Preloader.js └── phaser-2.0.7.min.js /.gitignore: -------------------------------------------------------------------------------- 1 | # OS generated files # 2 | ###################### 3 | .DS_Store 4 | .DS_Store? 5 | ._* 6 | .Spotlight-V100 7 | .Trashes 8 | ehthumbs.db 9 | Thumbs.db -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | candy-demo.enclavegames.com -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution-NonCommercial 4.0 International Public License 2 | 3 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 4 | 5 | Section 1 – Definitions. 6 | 7 | Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 8 | Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 9 | Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 10 | Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 11 | Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 12 | Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 13 | Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 14 | Licensor means the individual(s) or entity(ies) granting rights under this Public License. 15 | NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. 16 | Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 17 | Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 18 | You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 19 | 20 | Section 2 – Scope. 21 | 22 | License grant. 23 | Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 24 | reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and 25 | produce, reproduce, and Share Adapted Material for NonCommercial purposes only. 26 | Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 27 | Term. The term of this Public License is specified in Section 6(a). 28 | Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 29 | Downstream recipients. 30 | Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 31 | No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 32 | No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 33 | 34 | Other rights. 35 | Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 36 | Patent and trademark rights are not licensed under this Public License. 37 | To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. 38 | 39 | Section 3 – License Conditions. 40 | 41 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 42 | 43 | Attribution. 44 | 45 | If You Share the Licensed Material (including in modified form), You must: 46 | retain the following if it is supplied by the Licensor with the Licensed Material: 47 | identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 48 | a copyright notice; 49 | a notice that refers to this Public License; 50 | a notice that refers to the disclaimer of warranties; 51 | a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 52 | indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 53 | indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 54 | You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 55 | If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 56 | If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License. 57 | 58 | Section 4 – Sui Generis Database Rights. 59 | 60 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 61 | 62 | for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; 63 | if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and 64 | You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 65 | 66 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 67 | 68 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 69 | 70 | Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. 71 | To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. 72 | 73 | The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 74 | 75 | Section 6 – Term and Termination. 76 | 77 | This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 78 | 79 | Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 80 | automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 81 | upon express reinstatement by the Licensor. 82 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 83 | For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 84 | Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 85 | 86 | Section 7 – Other Terms and Conditions. 87 | 88 | The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 89 | Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 90 | 91 | Section 8 – Interpretation. 92 | 93 | For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 94 | To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 95 | No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 96 | Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Monster Wants Candy demo 2 | ======================== 3 | 4 | Monster Wants Candy demo is a simple HTML5 game created with Phaser 2.0.7 and available at: http://candy-demo.enclavegames.com/ 5 | 6 | You can read the detailed tutorial about the demo at Tuts+ Game Development: http://gamedevelopment.tutsplus.com/tutorials/getting-started-with-phaser-building-monster-wants-candy--cms-21723 7 | 8 | ![Monster Wants Candy - screen](https://cms-assets.tutsplus.com/uploads/users/22/posts/21723/image/monster-demo-screens.jpg) 9 | 10 | You can also play the full game at: http://enclavegames.com/games/monster-wants-candy/ 11 | 12 | ## Licensing 13 | 14 | This game demo is licensed under the **Creative Commons Attribution-NonCommercial 4.0 International** (CC BY-NC 4.0). See the [human-readable summary](http://creativecommons.org/licenses/by-nc/4.0/) or [legalcode](http://creativecommons.org/licenses/by-nc/4.0/legalcode) for details. 15 | 16 | Under this license you are permitted to remix/reuse/redistribute my work as long as you credit me ([Andrzej Mazur](http://end3r.com/)) for the original work and don’t use it for commercial purposes. If someone does wish to use it in a commercial context, they should e-mail me at andrzej.mazur@end3r.com to discuss the terms of use. -------------------------------------------------------------------------------- /img/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/background.png -------------------------------------------------------------------------------- /img/button-pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/button-pause.png -------------------------------------------------------------------------------- /img/button-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/button-start.png -------------------------------------------------------------------------------- /img/candy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/candy.png -------------------------------------------------------------------------------- /img/floor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/floor.png -------------------------------------------------------------------------------- /img/gameover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/gameover.png -------------------------------------------------------------------------------- /img/loading-bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/loading-bar.png -------------------------------------------------------------------------------- /img/monster-cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/monster-cover.png -------------------------------------------------------------------------------- /img/monster-idle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/monster-idle.png -------------------------------------------------------------------------------- /img/score-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/score-bg.png -------------------------------------------------------------------------------- /img/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnclaveGames/Monster-Wants-Candy-demo/a6d15680dba0ca34baf51c1d9c2a5245439213e5/img/title.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Monster Wants Candy demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 27 | 28 | -------------------------------------------------------------------------------- /src/Boot.js: -------------------------------------------------------------------------------- 1 | var Candy = {}; 2 | Candy.Boot = function(game){}; 3 | Candy.Boot.prototype = { 4 | preload: function(){ 5 | // preload the loading indicator first before anything else 6 | this.load.image('preloaderBar', 'img/loading-bar.png'); 7 | }, 8 | create: function(){ 9 | // set scale options 10 | this.input.maxPointers = 1; 11 | this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; 12 | this.scale.pageAlignHorizontally = true; 13 | this.scale.pageAlignVertically = true; 14 | this.scale.setScreenSize(true); 15 | // start the Preloader state 16 | this.state.start('Preloader'); 17 | } 18 | }; -------------------------------------------------------------------------------- /src/Game.js: -------------------------------------------------------------------------------- 1 | Candy.Game = function(game){ 2 | // define needed variables for Candy.Game 3 | this._player = null; 4 | this._candyGroup = null; 5 | this._spawnCandyTimer = 0; 6 | this._fontStyle = null; 7 | // define Candy variables to reuse them in Candy.item functions 8 | Candy._scoreText = null; 9 | Candy._score = 0; 10 | Candy._health = 0; 11 | }; 12 | Candy.Game.prototype = { 13 | create: function(){ 14 | // start the physics engine 15 | this.physics.startSystem(Phaser.Physics.ARCADE); 16 | // set the global gravity 17 | this.physics.arcade.gravity.y = 200; 18 | // display images: background, floor and score 19 | this.add.sprite(0, 0, 'background'); 20 | this.add.sprite(-30, Candy.GAME_HEIGHT-160, 'floor'); 21 | this.add.sprite(10, 5, 'score-bg'); 22 | // add pause button 23 | this.add.button(Candy.GAME_WIDTH-96-10, 5, 'button-pause', this.managePause, this); 24 | // create the player 25 | this._player = this.add.sprite(5, 760, 'monster-idle'); 26 | // add player animation 27 | this._player.animations.add('idle', [0,1,2,3,4,5,6,7,8,9,10,11,12], 10, true); 28 | // play the animation 29 | this._player.animations.play('idle'); 30 | // set font style 31 | this._fontStyle = { font: "40px Arial", fill: "#FFCC00", stroke: "#333", strokeThickness: 5, align: "center" }; 32 | // initialize the spawn timer 33 | this._spawnCandyTimer = 0; 34 | // initialize the score text with 0 35 | Candy._scoreText = this.add.text(120, 20, "0", this._fontStyle); 36 | // set health of the player 37 | Candy._health = 10; 38 | // create new group for candy 39 | this._candyGroup = this.add.group(); 40 | // spawn first candy 41 | Candy.item.spawnCandy(this); 42 | }, 43 | managePause: function(){ 44 | // pause the game 45 | this.game.paused = true; 46 | // add proper informational text 47 | var pausedText = this.add.text(100, 250, "Game paused.\nTap anywhere to continue.", this._fontStyle); 48 | // set event listener for the user's click/tap the screen 49 | this.input.onDown.add(function(){ 50 | // remove the pause text 51 | pausedText.destroy(); 52 | // unpause the game 53 | this.game.paused = false; 54 | }, this); 55 | }, 56 | update: function(){ 57 | // update timer every frame 58 | this._spawnCandyTimer += this.time.elapsed; 59 | // if spawn timer reach one second (1000 miliseconds) 60 | if(this._spawnCandyTimer > 1000) { 61 | // reset it 62 | this._spawnCandyTimer = 0; 63 | // and spawn new candy 64 | Candy.item.spawnCandy(this); 65 | } 66 | // loop through all candy on the screen 67 | this._candyGroup.forEach(function(candy){ 68 | // to rotate them accordingly 69 | candy.angle += candy.rotateMe; 70 | }); 71 | // if the health of the player drops to 0, the player dies = game over 72 | if(!Candy._health) { 73 | // show the game over message 74 | this.add.sprite((Candy.GAME_WIDTH-594)/2, (Candy.GAME_HEIGHT-271)/2, 'game-over'); 75 | // pause the game 76 | this.game.paused = true; 77 | } 78 | } 79 | }; 80 | 81 | Candy.item = { 82 | spawnCandy: function(game){ 83 | // calculate drop position (from 0 to game width) on the x axis 84 | var dropPos = Math.floor(Math.random()*Candy.GAME_WIDTH); 85 | // define the offset for every candy 86 | var dropOffset = [-27,-36,-36,-38,-48]; 87 | // randomize candy type 88 | var candyType = Math.floor(Math.random()*5); 89 | // create new candy 90 | var candy = game.add.sprite(dropPos, dropOffset[candyType], 'candy'); 91 | // add new animation frame 92 | candy.animations.add('anim', [candyType], 10, true); 93 | // play the newly created animation 94 | candy.animations.play('anim'); 95 | // enable candy body for physic engine 96 | game.physics.enable(candy, Phaser.Physics.ARCADE); 97 | // enable candy to be clicked/tapped 98 | candy.inputEnabled = true; 99 | // add event listener to click/tap 100 | candy.events.onInputDown.add(this.clickCandy, this); 101 | // be sure that the candy will fire an event when it goes out of the screen 102 | candy.checkWorldBounds = true; 103 | // reset candy when it goes out of screen 104 | candy.events.onOutOfBounds.add(this.removeCandy, this); 105 | // set the anchor (for rotation, position etc) to the middle of the candy 106 | candy.anchor.setTo(0.5, 0.5); 107 | // set the random rotation value 108 | candy.rotateMe = (Math.random()*4)-2; 109 | // add candy to the group 110 | game._candyGroup.add(candy); 111 | }, 112 | clickCandy: function(candy){ 113 | // kill the candy when it's clicked 114 | candy.kill(); 115 | // add points to the score 116 | Candy._score += 1; 117 | // update score text 118 | Candy._scoreText.setText(Candy._score); 119 | }, 120 | removeCandy: function(candy){ 121 | // kill the candy 122 | candy.kill(); 123 | // decrease player's health 124 | Candy._health -= 10; 125 | } 126 | }; -------------------------------------------------------------------------------- /src/MainMenu.js: -------------------------------------------------------------------------------- 1 | Candy.MainMenu = function(game){}; 2 | Candy.MainMenu.prototype = { 3 | create: function(){ 4 | // display images 5 | this.add.sprite(0, 0, 'background'); 6 | this.add.sprite(-130, Candy.GAME_HEIGHT-514, 'monster-cover'); 7 | this.add.sprite((Candy.GAME_WIDTH-395)/2, 60, 'title'); 8 | // add the button that will start the game 9 | this.add.button(Candy.GAME_WIDTH-401-10, Candy.GAME_HEIGHT-143-10, 'button-start', this.startGame, this, 1, 0, 2); 10 | }, 11 | startGame: function() { 12 | // start the Game state 13 | this.state.start('Game'); 14 | } 15 | }; -------------------------------------------------------------------------------- /src/Preloader.js: -------------------------------------------------------------------------------- 1 | Candy.Preloader = function(game){ 2 | // define width and height of the game 3 | Candy.GAME_WIDTH = 640; 4 | Candy.GAME_HEIGHT = 960; 5 | }; 6 | Candy.Preloader.prototype = { 7 | preload: function(){ 8 | // set background color and preload image 9 | this.stage.backgroundColor = '#B4D9E7'; 10 | this.preloadBar = this.add.sprite((Candy.GAME_WIDTH-311)/2, (Candy.GAME_HEIGHT-27)/2, 'preloaderBar'); 11 | this.load.setPreloadSprite(this.preloadBar); 12 | // load images 13 | this.load.image('background', 'img/background.png'); 14 | this.load.image('floor', 'img/floor.png'); 15 | this.load.image('monster-cover', 'img/monster-cover.png'); 16 | this.load.image('title', 'img/title.png'); 17 | this.load.image('game-over', 'img/gameover.png'); 18 | this.load.image('score-bg', 'img/score-bg.png'); 19 | this.load.image('button-pause', 'img/button-pause.png'); 20 | // load spritesheets 21 | this.load.spritesheet('candy', 'img/candy.png', 82, 98); 22 | this.load.spritesheet('monster-idle', 'img/monster-idle.png', 103, 131); 23 | this.load.spritesheet('button-start', 'img/button-start.png', 401, 143); 24 | }, 25 | create: function(){ 26 | // start the MainMenu state 27 | this.state.start('MainMenu'); 28 | } 29 | }; --------------------------------------------------------------------------------