diff --git a/build/build.php b/build/build.php index 416fdb51..82f84bdf 100644 --- a/build/build.php +++ b/build/build.php @@ -8,7 +8,7 @@ $buildLog = "Building version $version \n\n"; $header = ""; - $js = file(dirname(__FILE__) . '/../examples/js.php'); + $js = file(dirname(__FILE__) . '/../examples/phaser-debug-js.php'); $output = ""; for ($i = 0; $i < count($js); $i++) diff --git a/build/phaser.js b/build/phaser.js index 0253f68b..96ca286c 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -9,7 +9,7 @@ * * Phaser - http://www.phaser.io * -* v1.0.7 - Built at: Fri, 18 Oct 2013 01:36:29 +0100 +* v1.0.7 - Built at: Tue, 22 Oct 2013 00:54:52 +0100 * * By Richard Davey http://www.photonstorm.com @photonstorm * diff --git a/examples/animation/animation wraparound.php b/examples/animation/animation wraparound.php deleted file mode 100644 index aef294fe..00000000 --- a/examples/animation/animation wraparound.php +++ /dev/null @@ -1,52 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/animation/change texture on click.js b/examples/animation/change texture on click.js new file mode 100644 index 00000000..5b8487df --- /dev/null +++ b/examples/animation/change texture on click.js @@ -0,0 +1,39 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +function preload() { + + game.load.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json'); + game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18); + +} + +var bot; + +function create() { + + bot = game.add.sprite(200, 200, 'bot'); + + bot.animations.add('run'); + + bot.animations.play('run', 15, true); + + game.input.onDown.addOnce(changeMummy, this); + +} + +function changeMummy() { + + bot.loadTexture('mummy', 0); + + bot.animations.add('walk'); + + bot.animations.play('walk', 30, true); + +} + +function render() { + + game.debug.renderSpriteBounds(bot); + +} diff --git a/examples/animation/change texture.php b/examples/animation/change texture.php deleted file mode 100644 index 67aa9f0a..00000000 --- a/examples/animation/change texture.php +++ /dev/null @@ -1,51 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/animation/from a JSON object.php b/examples/animation/from a JSON object.php deleted file mode 100644 index c42d0643..00000000 --- a/examples/animation/from a JSON object.php +++ /dev/null @@ -1,144 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/animation/from a texturePacker file.php b/examples/animation/from a texturePacker file.php deleted file mode 100644 index 67420bd1..00000000 --- a/examples/animation/from a texturePacker file.php +++ /dev/null @@ -1,38 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/animation/local json object.js b/examples/animation/local json object.js new file mode 100644 index 00000000..59dbf984 --- /dev/null +++ b/examples/animation/local json object.js @@ -0,0 +1,126 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create}); + +function preload() { + + // Texture Atlas Method 2 + // + // In this example we assume that the TexturePacker JSON data is a real json object stored as a var + // (in this case botData) + + game.load.atlas('bot', 'assets/sprites/running_bot.png', null, botData); + +} + +var bot; + +function create() { + + bot = game.add.sprite(game.world.centerX, 300, 'bot'); + + bot.animations.add('run'); + bot.animations.play('run', 10, true); + +} + +var botData = { + "frames": [ + +{ + "filename": "running bot.swf/0000", + "frame": { "x": 34, "y": 128, "w": 56, "h": 60 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 0, "y": 2, "w": 56, "h": 60 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0001", + "frame": { "x": 54, "y": 0, "w": 56, "h": 58 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0002", + "frame": { "x": 54, "y": 58, "w": 56, "h": 58 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0003", + "frame": { "x": 0, "y": 192, "w": 34, "h": 64 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 11, "y": 0, "w": 34, "h": 64 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0004", + "frame": { "x": 0, "y": 64, "w": 54, "h": 64 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 1, "y": 0, "w": 54, "h": 64 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0005", + "frame": { "x": 196, "y": 0, "w": 56, "h": 58 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0006", + "frame": { "x": 0, "y": 0, "w": 54, "h": 64 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 1, "y": 0, "w": 54, "h": 64 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0007", + "frame": { "x": 140, "y": 0, "w": 56, "h": 58 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0008", + "frame": { "x": 34, "y": 188, "w": 50, "h": 60 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 3, "y": 2, "w": 50, "h": 60 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0009", + "frame": { "x": 0, "y": 128, "w": 34, "h": 64 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 11, "y": 0, "w": 34, "h": 64 }, + "sourceSize": { "w": 56, "h": 64 } +}, +{ + "filename": "running bot.swf/0010", + "frame": { "x": 84, "y": 188, "w": 56, "h": 58 }, + "rotated": false, + "trimmed": true, + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } +}], + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "running_bot.png", + "format": "RGBA8888", + "size": { "w": 252, "h": 256 }, + "scale": "0.2", + "smartupdate": "$TexturePacker:SmartUpdate:fb56f261b1eb04e3215824426595f64c$" + } +}; diff --git a/examples/animation/looped animation.js b/examples/animation/looped animation.js new file mode 100644 index 00000000..24a137d1 --- /dev/null +++ b/examples/animation/looped animation.js @@ -0,0 +1,35 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); + +function preload() { + game.load.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json'); +} + +var bot; + +function create() { + + // This sprite is using a texture atlas for all of its animation data + bot = game.add.sprite(200, 200, 'bot'); + + // Here we add a new animation called 'run' + // We haven't specified any frames because it's using every frame in the texture atlas + bot.animations.add('run'); + + // And this starts the animation playing by using its key ("run") + // 15 is the frame rate (15fps) + // true means it will loop when it finishes + bot.animations.play('run', 15, true); + +} + +function update() { + + bot.x -= 2; + + if (bot.x < -bot.width) + { + bot.x = game.world.width; + } + +} diff --git a/examples/animation/multiple anims.js b/examples/animation/multiple anims.js new file mode 100644 index 00000000..316b91b7 --- /dev/null +++ b/examples/animation/multiple anims.js @@ -0,0 +1,20 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); + +function preload() { + game.load.atlas('bot', 'assets/misc/NumberSprite.png', 'assets/misc/NumberSprite.json'); +} + +function create() { + + var bot = game.add.sprite(200, 200, 'bot'); + + bot.animations.add('num1', ['num10000','num10001','num10002','num10003','num10004','num10005'], 24, false, false); + bot.animations.add('num2', ['num20000','num20001','num20002','num20003','num20004','num20005'], 24, false, false); + bot.animations.add('num3', ['num30000','num30001','num30002','num30003','num30004','num30005'], 24, false, false); + + // bot.animations.play('num1', 15, true); + // bot.animations.play('num2', 15, true); + // bot.animations.play('num3', 15, true); + +} diff --git a/examples/animation/multiple anims.php b/examples/animation/multiple anims.php deleted file mode 100644 index 5189cfe3..00000000 --- a/examples/animation/multiple anims.php +++ /dev/null @@ -1,36 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/animation/sprite sheet.js b/examples/animation/sprite sheet.js new file mode 100644 index 00000000..589b2316 --- /dev/null +++ b/examples/animation/sprite sheet.js @@ -0,0 +1,27 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); + +function preload() { + + // 37x45 is the size of each frame + + // There are 18 frames in the PNG - you can leave this value blank if the frames fill up the entire PNG, but in this case there are some + // blank frames at the end, so we tell the loader how many to load + + game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18); +} + +function create() { + + var mummy = game.add.sprite(300, 200, 'mummy'); + + // Here we add a new animation called 'walk' + // Because we didn't give any other parameters it's going to make an animation from all available frames in the 'mummy' sprite sheet + mummy.animations.add('walk'); + + // And this starts the animation playing by using its key ("walk") + // 30 is the frame rate (30fps) + // true means it will loop when it finishes + mummy.animations.play('walk', 20, true); + +} diff --git a/examples/animation/sprite sheet.php b/examples/animation/sprite sheet.php deleted file mode 100644 index 3e491088..00000000 --- a/examples/animation/sprite sheet.php +++ /dev/null @@ -1,39 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/animation/texture packer json hash.js b/examples/animation/texture packer json hash.js new file mode 100644 index 00000000..64c5e456 --- /dev/null +++ b/examples/animation/texture packer json hash.js @@ -0,0 +1,22 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create }); + +function preload() { + game.load.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json'); +} + +function create() { + + // This sprite is using a texture atlas for all of its animation data + var bot = game.add.sprite(200, 200, 'bot'); + + // Here we add a new animation called 'run' + // We haven't specified any frames because it's using every frame in the texture atlas + bot.animations.add('run'); + + // And this starts the animation playing by using its key ("run") + // 15 is the frame rate (15fps) + // true means it will loop when it finishes + bot.animations.play('run', 15, true); + +} diff --git a/examples/html/fonts/HelveticaNeueLTStd-Bd.otf b/examples/assets/html/HelveticaNeueLTStd-Bd.otf similarity index 100% rename from examples/html/fonts/HelveticaNeueLTStd-Bd.otf rename to examples/assets/html/HelveticaNeueLTStd-Bd.otf diff --git a/examples/html/js/application.js b/examples/assets/html/application.js similarity index 100% rename from examples/html/js/application.js rename to examples/assets/html/application.js diff --git a/examples/assets/html/bg-footer.jpg b/examples/assets/html/bg-footer.jpg new file mode 100644 index 00000000..5189cb55 Binary files /dev/null and b/examples/assets/html/bg-footer.jpg differ diff --git a/examples/html/img/controls-label.png b/examples/assets/html/controls-label.png similarity index 100% rename from examples/html/img/controls-label.png rename to examples/assets/html/controls-label.png diff --git a/examples/html/demo.html b/examples/assets/html/demo.html similarity index 100% rename from examples/html/demo.html rename to examples/assets/html/demo.html diff --git a/examples/html/img/down-label.png b/examples/assets/html/down-label.png similarity index 100% rename from examples/html/img/down-label.png rename to examples/assets/html/down-label.png diff --git a/examples/html/img/flixel-logo.png b/examples/assets/html/flixel-logo.png similarity index 100% rename from examples/html/img/flixel-logo.png rename to examples/assets/html/flixel-logo.png diff --git a/examples/html/img/footer-bg.jpg b/examples/assets/html/footer-bg.jpg similarity index 100% rename from examples/html/img/footer-bg.jpg rename to examples/assets/html/footer-bg.jpg diff --git a/examples/assets/html/footer-bg2.jpg b/examples/assets/html/footer-bg2.jpg new file mode 100644 index 00000000..4811c450 Binary files /dev/null and b/examples/assets/html/footer-bg2.jpg differ diff --git a/examples/html/img/forums-icon.png b/examples/assets/html/forums-icon.png similarity index 100% rename from examples/html/img/forums-icon.png rename to examples/assets/html/forums-icon.png diff --git a/examples/html/img/game-controls-bg.jpg b/examples/assets/html/game-controls-bg.jpg similarity index 100% rename from examples/html/img/game-controls-bg.jpg rename to examples/assets/html/game-controls-bg.jpg diff --git a/examples/html/img/github-icon.png b/examples/assets/html/github-icon.png similarity index 100% rename from examples/html/img/github-icon.png rename to examples/assets/html/github-icon.png diff --git a/examples/html/img/gradient-bg.jpg b/examples/assets/html/gradient-bg.jpg similarity index 100% rename from examples/html/img/gradient-bg.jpg rename to examples/assets/html/gradient-bg.jpg diff --git a/examples/html/img/group-item-hover.png b/examples/assets/html/group-item-hover.png similarity index 100% rename from examples/html/img/group-item-hover.png rename to examples/assets/html/group-item-hover.png diff --git a/examples/html/img/group-item.png b/examples/assets/html/group-item.png similarity index 100% rename from examples/html/img/group-item.png rename to examples/assets/html/group-item.png diff --git a/examples/html/img/header-bg.jpg b/examples/assets/html/header-bg.jpg similarity index 100% rename from examples/html/img/header-bg.jpg rename to examples/assets/html/header-bg.jpg diff --git a/examples/assets/html/header-bg2.jpg b/examples/assets/html/header-bg2.jpg new file mode 100644 index 00000000..5dcabec2 Binary files /dev/null and b/examples/assets/html/header-bg2.jpg differ diff --git a/examples/assets/html/inconsolata.woff b/examples/assets/html/inconsolata.woff new file mode 100644 index 00000000..6170a0bf Binary files /dev/null and b/examples/assets/html/inconsolata.woff differ diff --git a/examples/html/index.html b/examples/assets/html/index.html similarity index 100% rename from examples/html/index.html rename to examples/assets/html/index.html diff --git a/examples/html/img/laser1.png b/examples/assets/html/laser1.png similarity index 100% rename from examples/html/img/laser1.png rename to examples/assets/html/laser1.png diff --git a/examples/html/img/laser10.png b/examples/assets/html/laser10.png similarity index 100% rename from examples/html/img/laser10.png rename to examples/assets/html/laser10.png diff --git a/examples/html/img/laser2.png b/examples/assets/html/laser2.png similarity index 100% rename from examples/html/img/laser2.png rename to examples/assets/html/laser2.png diff --git a/examples/html/img/laser3.png b/examples/assets/html/laser3.png similarity index 100% rename from examples/html/img/laser3.png rename to examples/assets/html/laser3.png diff --git a/examples/html/img/laser4.png b/examples/assets/html/laser4.png similarity index 100% rename from examples/html/img/laser4.png rename to examples/assets/html/laser4.png diff --git a/examples/html/img/laser5.png b/examples/assets/html/laser5.png similarity index 100% rename from examples/html/img/laser5.png rename to examples/assets/html/laser5.png diff --git a/examples/html/img/laser6.png b/examples/assets/html/laser6.png similarity index 100% rename from examples/html/img/laser6.png rename to examples/assets/html/laser6.png diff --git a/examples/html/img/laser7.png b/examples/assets/html/laser7.png similarity index 100% rename from examples/html/img/laser7.png rename to examples/assets/html/laser7.png diff --git a/examples/html/img/laser8.png b/examples/assets/html/laser8.png similarity index 100% rename from examples/html/img/laser8.png rename to examples/assets/html/laser8.png diff --git a/examples/html/img/laser9.png b/examples/assets/html/laser9.png similarity index 100% rename from examples/html/img/laser9.png rename to examples/assets/html/laser9.png diff --git a/examples/html/img/left-label.png b/examples/assets/html/left-label.png similarity index 100% rename from examples/html/img/left-label.png rename to examples/assets/html/left-label.png diff --git a/examples/assets/html/lite_footer.jpg b/examples/assets/html/lite_footer.jpg new file mode 100644 index 00000000..51549193 Binary files /dev/null and b/examples/assets/html/lite_footer.jpg differ diff --git a/examples/assets/html/lite_header.jpg b/examples/assets/html/lite_header.jpg new file mode 100644 index 00000000..0aa2e2fc Binary files /dev/null and b/examples/assets/html/lite_header.jpg differ diff --git a/examples/assets/html/lite_header_2.jpg b/examples/assets/html/lite_header_2.jpg new file mode 100644 index 00000000..fa1eb718 Binary files /dev/null and b/examples/assets/html/lite_header_2.jpg differ diff --git a/examples/html/img/mute-button.png b/examples/assets/html/mute-button.png similarity index 100% rename from examples/html/img/mute-button.png rename to examples/assets/html/mute-button.png diff --git a/examples/html/img/nav-icons.png b/examples/assets/html/nav-icons.png similarity index 100% rename from examples/html/img/nav-icons.png rename to examples/assets/html/nav-icons.png diff --git a/examples/html/img/pause-button.png b/examples/assets/html/pause-button.png similarity index 100% rename from examples/html/img/pause-button.png rename to examples/assets/html/pause-button.png diff --git a/examples/html/img/phaser-examples.png b/examples/assets/html/phaser-examples.png similarity index 100% rename from examples/html/img/phaser-examples.png rename to examples/assets/html/phaser-examples.png diff --git a/examples/html/img/phaser-logo.png b/examples/assets/html/phaser-logo.png similarity index 100% rename from examples/html/img/phaser-logo.png rename to examples/assets/html/phaser-logo.png diff --git a/examples/html/img/phaser-version.png b/examples/assets/html/phaser-version.png similarity index 100% rename from examples/html/img/phaser-version.png rename to examples/assets/html/phaser-version.png diff --git a/examples/html/img/photonstorm-logo.png b/examples/assets/html/photonstorm-logo.png similarity index 100% rename from examples/html/img/photonstorm-logo.png rename to examples/assets/html/photonstorm-logo.png diff --git a/examples/html/img/prize-bg.png b/examples/assets/html/prize-bg.png similarity index 100% rename from examples/html/img/prize-bg.png rename to examples/assets/html/prize-bg.png diff --git a/examples/html/img/prize-button.png b/examples/assets/html/prize-button.png similarity index 100% rename from examples/html/img/prize-button.png rename to examples/assets/html/prize-button.png diff --git a/examples/html/img/reset-button.png b/examples/assets/html/reset-button.png similarity index 100% rename from examples/html/img/reset-button.png rename to examples/assets/html/reset-button.png diff --git a/examples/html/img/right-label.png b/examples/assets/html/right-label.png similarity index 100% rename from examples/html/img/right-label.png rename to examples/assets/html/right-label.png diff --git a/examples/html/img/space-label.png b/examples/assets/html/space-label.png similarity index 100% rename from examples/html/img/space-label.png rename to examples/assets/html/space-label.png diff --git a/examples/html/img/twitter-icon.png b/examples/assets/html/twitter-icon.png similarity index 100% rename from examples/html/img/twitter-icon.png rename to examples/assets/html/twitter-icon.png diff --git a/examples/html/img/up-label.png b/examples/assets/html/up-label.png similarity index 100% rename from examples/html/img/up-label.png rename to examples/assets/html/up-label.png diff --git a/examples/html/img/version-button.png b/examples/assets/html/version-button.png similarity index 100% rename from examples/html/img/version-button.png rename to examples/assets/html/version-button.png diff --git a/examples/assets/skies/cavern1.png b/examples/assets/skies/cavern1.png index 9002fae2..15a4ba97 100644 Binary files a/examples/assets/skies/cavern1.png and b/examples/assets/skies/cavern1.png differ diff --git a/examples/assets/skies/cavern2.png b/examples/assets/skies/cavern2.png index c20943de..9b2ecaf1 100644 Binary files a/examples/assets/skies/cavern2.png and b/examples/assets/skies/cavern2.png differ diff --git a/examples/assets/skies/chrome.png b/examples/assets/skies/chrome.png index 414f578e..3d66c32d 100644 Binary files a/examples/assets/skies/chrome.png and b/examples/assets/skies/chrome.png differ diff --git a/examples/assets/skies/fire.png b/examples/assets/skies/fire.png index 759fac2b..8aeab72a 100644 Binary files a/examples/assets/skies/fire.png and b/examples/assets/skies/fire.png differ diff --git a/examples/assets/skies/fog.png b/examples/assets/skies/fog.png index 76c7386c..3108b97e 100644 Binary files a/examples/assets/skies/fog.png and b/examples/assets/skies/fog.png differ diff --git a/examples/assets/skies/sky1.png b/examples/assets/skies/sky1.png index 18a30759..f439c0ca 100644 Binary files a/examples/assets/skies/sky1.png and b/examples/assets/skies/sky1.png differ diff --git a/examples/assets/skies/sky2.png b/examples/assets/skies/sky2.png index 10a85c76..6dd8f580 100644 Binary files a/examples/assets/skies/sky2.png and b/examples/assets/skies/sky2.png differ diff --git a/examples/assets/skies/sky3.png b/examples/assets/skies/sky3.png index 26714faf..e51fdb32 100644 Binary files a/examples/assets/skies/sky3.png and b/examples/assets/skies/sky3.png differ diff --git a/examples/assets/skies/sky4.png b/examples/assets/skies/sky4.png index a2989c3e..5972639f 100644 Binary files a/examples/assets/skies/sky4.png and b/examples/assets/skies/sky4.png differ diff --git a/examples/assets/skies/sky5.png b/examples/assets/skies/sky5.png index 58db4343..70538fe7 100644 Binary files a/examples/assets/skies/sky5.png and b/examples/assets/skies/sky5.png differ diff --git a/examples/assets/skies/space1.png b/examples/assets/skies/space1.png index 9d7643f1..9ad3ec1f 100644 Binary files a/examples/assets/skies/space1.png and b/examples/assets/skies/space1.png differ diff --git a/examples/assets/skies/space2.png b/examples/assets/skies/space2.png index 2198cd4d..a203627a 100644 Binary files a/examples/assets/skies/space2.png and b/examples/assets/skies/space2.png differ diff --git a/examples/assets/skies/sunorbit.png b/examples/assets/skies/sunorbit.png index 8ccc1305..11920576 100644 Binary files a/examples/assets/skies/sunorbit.png and b/examples/assets/skies/sunorbit.png differ diff --git a/examples/assets/skies/sunset.png b/examples/assets/skies/sunset.png index 18f5212b..5ccb7eff 100644 Binary files a/examples/assets/skies/sunset.png and b/examples/assets/skies/sunset.png differ diff --git a/examples/assets/skies/toxic.png b/examples/assets/skies/toxic.png index 8bfb378d..0bba6f5f 100644 Binary files a/examples/assets/skies/toxic.png and b/examples/assets/skies/toxic.png differ diff --git a/examples/assets/skies/underwater1.png b/examples/assets/skies/underwater1.png index c1ee9900..94bbf376 100644 Binary files a/examples/assets/skies/underwater1.png and b/examples/assets/skies/underwater1.png differ diff --git a/examples/assets/skies/underwater2.png b/examples/assets/skies/underwater2.png index 0af1808a..b02373cc 100644 Binary files a/examples/assets/skies/underwater2.png and b/examples/assets/skies/underwater2.png differ diff --git a/examples/assets/skies/underwater3.png b/examples/assets/skies/underwater3.png index d4ff8955..e5197df3 100644 Binary files a/examples/assets/skies/underwater3.png and b/examples/assets/skies/underwater3.png differ diff --git a/examples/assets/skies/wtf.png b/examples/assets/skies/wtf.png index 35159e26..d8559095 100644 Binary files a/examples/assets/skies/wtf.png and b/examples/assets/skies/wtf.png differ diff --git a/examples/audio/loop.js b/examples/audio/loop.js new file mode 100644 index 00000000..18360077 --- /dev/null +++ b/examples/audio/loop.js @@ -0,0 +1,28 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create}); + +function preload() { + + game.load.image('spyro', 'assets/pics/spyro.png'); + + // Firefox doesn't support mp3 files, so use ogg + game.load.audio('squit', ['assets/audio/SoundEffects/squit.mp3', 'assets/audio/SoundEffects/squit.ogg']); + +} + +var s; +var music; + +function create() { + + game.stage.backgroundColor = '#255d3b'; + + + music = game.add.audio('squit',1,true); + + music.play('',0,1,true); + + s = game.add.sprite(game.world.centerX, game.world.centerY, 'spyro'); + s.anchor.setTo(0.5, 0.5); + +} diff --git a/examples/audio/loop.php b/examples/audio/loop.php deleted file mode 100644 index ceda86ee..00000000 --- a/examples/audio/loop.php +++ /dev/null @@ -1,46 +0,0 @@ - - - - - diff --git a/examples/audio/play music.js b/examples/audio/play music.js new file mode 100644 index 00000000..2f471f82 --- /dev/null +++ b/examples/audio/play music.js @@ -0,0 +1,51 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('disk', 'assets/sprites/ra_dont_crack_under_pressure.png'); + + // Firefox doesn't support mp3 files, so use ogg + game.load.audio('boden', ['assets/audio/bodenstaendig_2000_in_rock_4bit.mp3', 'assets/audio/bodenstaendig_2000_in_rock_4bit.ogg']); + +} + +var s; +var music; + +function create() { + + game.stage.backgroundColor = '#182d3b'; + game.input.touch.preventDefault = false; + + music = game.add.audio('boden'); + music.play(); + + s = game.add.sprite(game.world.centerX, game.world.centerY, 'disk'); + s.anchor.setTo(0.5, 0.5); + + game.input.onDown.add(changeVolume, this); + +} + +function changeVolume(pointer) { + + if (pointer.y < 300) + { + music.volume += 0.1; + } + else + { + music.volume -= 0.1; + } + +} + +function update() { + s.rotation += 0.01; +} + +function render() { + game.debug.renderSoundInfo(music, 20, 32); +} + diff --git a/examples/audio/play music.php b/examples/audio/play music.php deleted file mode 100644 index fb851adb..00000000 --- a/examples/audio/play music.php +++ /dev/null @@ -1,66 +0,0 @@ - - - - - diff --git a/examples/build.php b/examples/build.php new file mode 100644 index 00000000..262d7eff --- /dev/null +++ b/examples/build.php @@ -0,0 +1,37 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/examples/buttons/action on click.js b/examples/buttons/action on click.js new file mode 100644 index 00000000..d9746835 --- /dev/null +++ b/examples/buttons/action on click.js @@ -0,0 +1,28 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); + +function preload() { + + game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71); + game.load.image('background','assets/misc/starfield.jpg'); + +} + +var button; +var background; + +function create() { + + game.stage.backgroundColor = '#182d3b'; + + background = game.add.tileSprite(0, 0, 800, 600, 'background'); + + button = game.add.button(game.world.centerX - 95, 400, 'button', actionOnClick, this, 2, 1, 0); + +} + +function actionOnClick () { + + background.visible =! background.visible; + +} diff --git a/examples/buttons/action on click.php b/examples/buttons/action on click.php deleted file mode 100644 index dc1cbbb2..00000000 --- a/examples/buttons/action on click.php +++ /dev/null @@ -1,48 +0,0 @@ - - - - - diff --git a/examples/buttons/changing the frames.js b/examples/buttons/changing the frames.js new file mode 100644 index 00000000..8d2d3777 --- /dev/null +++ b/examples/buttons/changing the frames.js @@ -0,0 +1,32 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); + +function preload() { + + game.load.spritesheet('button', 'assets/buttons/number-buttons-90x90.png', 90,90); + game.load.image('background','assets/misc/starfield.jpg'); + +} + +var button; +var background; + +function create() { + + // Setting the background colour + game.stage.backgroundColor = '#182d3b'; + + // The numbers given in parameters are the indexes of the frames, in this order: over, out, down + button = game.add.button(game.world.centerX, game.world.centerY, 'button', actionOnClick, this, 1, 0, 2); + + // setting the anchor to the center + button.anchor.setTo(0.5, 0.5); + +} + +function actionOnClick () { + + // Manually changing the frames of the button, i.e, how it will look when you play with it + button.setFrames(4, 3, 5); + +} diff --git a/examples/buttons/changing the frames.php b/examples/buttons/changing the frames.php deleted file mode 100644 index 9367f6fe..00000000 --- a/examples/buttons/changing the frames.php +++ /dev/null @@ -1,55 +0,0 @@ - - - - - diff --git a/examples/buttons/rotated buttons.js b/examples/buttons/rotated buttons.js new file mode 100644 index 00000000..ecd842a7 --- /dev/null +++ b/examples/buttons/rotated buttons.js @@ -0,0 +1,36 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create,update : update }); + +function preload() { + + game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71); + game.load.image('background','assets/misc/starfield.jpg'); + +} + +var button; +var background; + +function create() { + + game.stage.backgroundColor = '#cccccc'; + + // The numbers given in parameters are the indexes of the frames, in this order: over, out, down + button = game.add.button(game.world.centerX, game.world.centerY, 'button', actionOnClick, this, 2, 1, 0); + + // Set the anchor of the sprite in the center, otherwise it would rotate around the top-left corner + button.anchor.setTo(0.5, 0.5); + +} + +function actionOnClick () { + + alert("Though I'm turning around, you can still click on me"); + +} + +function update () { + + button.angle += 1; + +} diff --git a/examples/buttons/rotated buttons.php b/examples/buttons/rotated buttons.php deleted file mode 100644 index 10ebf1ed..00000000 --- a/examples/buttons/rotated buttons.php +++ /dev/null @@ -1,47 +0,0 @@ - - - - - diff --git a/examples/camera/basic follow.js b/examples/camera/basic follow.js new file mode 100644 index 00000000..9a225a92 --- /dev/null +++ b/examples/camera/basic follow.js @@ -0,0 +1,60 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +var baddie; +var keys = Phaser.Keyboard; + +function preload() { + + game.load.image('background','assets/misc/starfield.jpg'); + game.load.image('ufo','assets/sprites/ufo.png'); + game.load.image('baddie','assets/sprites/space-baddie.png'); + +} + +function create() { + + game.add.tileSprite(0, 0, 2000, 2000, 'background'); + + game.world.setBounds(0, 0, 1400,1400); + + for (var i = 0; i < 10; i++) + { + game.add.sprite(game.world.randomX, game.world.randomY, 'ufo'); + } + + baddie = game.add.sprite(150, 320, 'baddie'); + + game.camera.follow(baddie); + +} + +function update() { + + baddie.body.velocity.setTo(0, 0); + + if (game.input.keyboard.isDown(keys.LEFT) && !game.input.keyboard.isDown(keys.RIGHT)) + { + baddie.body.velocity.x = -155; + } + else if (game.input.keyboard.isDown(keys.RIGHT) && !game.input.keyboard.isDown(keys.LEFT)) + { + baddie.body.velocity.x = 155; + } + else if (game.input.keyboard.isDown(keys.UP) && !game.input.keyboard.isDown(keys.DOWN)) + { + baddie.angle = 90; + baddie.body.velocity.y = -155; + } + else if (game.input.keyboard.isDown(keys.DOWN) && !game.input.keyboard.isDown(keys.UP)) + { + baddie.angle = 90; + baddie.body.velocity.y = 155; + } +} + +function render() { + + game.debug.renderCameraInfo(game.camera, 32, 32); + +} diff --git a/examples/camera/basic follow.php b/examples/camera/basic follow.php deleted file mode 100644 index 501494ab..00000000 --- a/examples/camera/basic follow.php +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - diff --git a/examples/camera/camera cull.js b/examples/camera/camera cull.js new file mode 100644 index 00000000..6060ada2 --- /dev/null +++ b/examples/camera/camera cull.js @@ -0,0 +1,48 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + game.load.image('disk', 'assets/sprites/ra_dont_crack_under_pressure.png'); +} + +var s; + +function create() { + + game.stage.backgroundColor = '#182d3b'; + + s = game.add.sprite(game.world.centerX, game.world.centerY, 'disk'); + s.anchor.setTo(0.5, 0.5); + +} + +function update() { + + s.rotation += 0.01; + + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) + { + s.x -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) + { + s.x += 4; + } + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) + { + s.y -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) + { + s.y += 4; + } + +} + +function render() { + + game.debug.renderSpriteCorners(s, true, true); + game.debug.renderSpriteInfo(s, 20, 32); + +} diff --git a/examples/camera/camera cull.php b/examples/camera/camera cull.php deleted file mode 100644 index 32196a6a..00000000 --- a/examples/camera/camera cull.php +++ /dev/null @@ -1,64 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/camera/follow styles.js b/examples/camera/follow styles.js new file mode 100644 index 00000000..339dc1e0 --- /dev/null +++ b/examples/camera/follow styles.js @@ -0,0 +1,109 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +var ufo; +var Keys = Phaser.Keyboard; +var speed = 4; +var style = 'default'; + +function preload() { + + game.load.image('ground', 'assets/tests/ground-2x.png'); + game.load.image('river', 'assets/tests/river-2x.png'); + game.load.image('sky', 'assets/tests/sky-2x.png'); + game.load.image('cloud0', 'assets/tests/cloud-big-2x.png'); + game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png'); + game.load.image('cloud2', 'assets/tests/cloud-small-2x.png'); + game.load.image('ufo','assets/sprites/ufo.png'); + game.load.image('baddie','assets/sprites/space-baddie.png'); + game.load.spritesheet('button', 'assets/buttons/follow-style-button.png', 224, 70); + +} + +function create() { + + // Make the world larger than the actual canvas + game.world.setBounds(0, 0, 1400, 1400); + + for (var i=0; i < 10; i++) + { + game.add.sprite(game.world.randomX, game.world.randomY, 'baddie'); + } + + // Background images + game.add.tileSprite(0, 0, 1400, 600, 'sky'); + game.add.sprite(0, 360, 'ground'); + game.add.sprite(0, 400, 'river'); + game.add.sprite(200, 120, 'cloud0'); + game.add.sprite(-60, 120, 'cloud1'); + game.add.sprite(900, 170, 'cloud2'); + + // ufo sprite + ufo = game.add.sprite(300, 240, 'ufo'); + + //registration point + ufo.anchor.setTo(0.5, 0.5); + + game.camera.follow(ufo); + + // follow style switch buttons + btn0 = game.add.button(6, 40, 'button', lockonFollow,this, 0, 0, 0); + btn1 = game.add.button(6, 120, 'button', platformerFollow,this, 1, 1, 1); + btn2 = game.add.button(6, 200, 'button', topdownFollow,this, 2, 2, 2); + btn3 = game.add.button(6, 280, 'button', topdownTightFollow,this, 3, 3, 3); + +} + +function lockonFollow() { + game.camera.follow(ufo, Phaser.Camera.FOLLOW_LOCKON); + style = 'STYLE_LOCKON'; +} + +function platformerFollow() { + game.camera.follow(ufo, Phaser.Camera.FOLLOW_PLATFORMER); + style = 'STYLE_PLATFORMER'; +} + +function topdownFollow() { + game.camera.follow(ufo, Phaser.Camera.FOLLOW_TOPDOWN); + style = 'STYLE_TOPDOWN'; +} + +function topdownTightFollow() { + game.camera.follow(ufo, Phaser.Camera.FOLLOW_TOPDOWN_TIGHT); + style = 'STYLE_TOPDOWN_TIGHT'; +} + +function update() { + + if (game.input.keyboard.isDown(Keys.LEFT)) + { + ufo.x -= speed; + ufo.angle = -15; + } + else if (game.input.keyboard.isDown(Keys.RIGHT)) + { + ufo.x += speed; + ufo.angle = 15; + } + else if (game.input.keyboard.isDown(Keys.UP)) + { + ufo.y -= speed; + } + else if (game.input.keyboard.isDown(Keys.DOWN)) + { + ufo.y += speed; + } + else + { + ufo.angle = 0; + } + +} + +function render () { + + game.debug.renderText('Click buttons to switch follow styles', 32, 32); + game.debug.renderText('Current style: ' + style, 32, 64); + +} diff --git a/examples/camera/follow styles.php b/examples/camera/follow styles.php deleted file mode 100644 index 148eec18..00000000 --- a/examples/camera/follow styles.php +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - diff --git a/examples/camera/moving the camera.js b/examples/camera/moving the camera.js new file mode 100644 index 00000000..7bbf28ba --- /dev/null +++ b/examples/camera/moving the camera.js @@ -0,0 +1,52 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); + +function preload() { + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); +} + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + // Make our game world 2000x2000 pixels in size (the default is to match the game size) + game.world.setBounds(0,0,2000, 2000); + + for (var i = 0; i < 50; i++) + { + var s = game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom'); + } + + for (var i = 0; i < 50; i++) + { + game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom'); + } + + for (var i = 0; i < 50; i++) + { + var s = game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom'); + } + +} + +function update() { + + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) + { + game.camera.x -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) + { + game.camera.x += 4; + } + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) + { + game.camera.y -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) + { + game.camera.y += 4; + } + +} diff --git a/examples/camera/moving the camera.php b/examples/camera/moving the camera.php deleted file mode 100644 index 3b6e93c5..00000000 --- a/examples/camera/moving the camera.php +++ /dev/null @@ -1,68 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/camera/world sprite.js b/examples/camera/world sprite.js new file mode 100644 index 00000000..13936f22 --- /dev/null +++ b/examples/camera/world sprite.js @@ -0,0 +1,54 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update,render : render }); + +function preload() { + + game.world.setBounds(0, 0, 1920, 1200); + + game.load.image('backdrop', 'assets/pics/remember-me.jpg'); + game.load.image('card', 'assets/sprites/mana_card.png'); + +} + +var card; +var Keys = Phaser.Keyboard; + +function create() { + + game.add.sprite(0, 0, 'backdrop'); + + card = game.add.sprite(200, 200, 'card'); + + card.body.velocity.x = 50; + card.scale.setTo(2, 2); + +} + +function update() { + + if (game.input.keyboard.isDown(Keys.LEFT)) + { + card.x -= 4; + } + else if (game.input.keyboard.isDown(Keys.RIGHT)) + { + card.x += 4; + } + + if (game.input.keyboard.isDown(Keys.UP)) + { + card.y -= 4; + } + else if (game.input.keyboard.isDown(Keys.DOWN)) + { + card.y += 4; + } + +} + +function render() { + + game.debug.renderCameraInfo(game.camera, 32, 32); + game.debug.renderSpriteInfo(card, 32, 200); + +} diff --git a/examples/camera/world sprite.php b/examples/camera/world sprite.php deleted file mode 100644 index 9a0dca40..00000000 --- a/examples/camera/world sprite.php +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - diff --git a/examples/collision/bounding box.js b/examples/collision/bounding box.js new file mode 100644 index 00000000..760e6ce0 --- /dev/null +++ b/examples/collision/bounding box.js @@ -0,0 +1,55 @@ +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('atari', 'assets/sprites/atari130xe.png'); + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); + +} + +var sprite1; +var sprite2; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + sprite1 = game.add.sprite(50, 200, 'atari'); + sprite1.name = 'atari'; + sprite1.body.velocity.x = 100; + + // This adjusts the collision body size. + // 100x100 is the new width/height. + // See the offset bounding box for another example. + sprite1.body.setSize(100, 100, 0, 0); + + sprite2 = game.add.sprite(700, 220, 'mushroom'); + sprite2.name = 'mushroom'; + sprite2.body.velocity.x = -100; + +} + +function update() { + + // object1, object2, collideCallback, processCallback, callbackContext + game.physics.collide(sprite1, sprite2, collisionHandler, null, this); + +} + +function collisionHandler (obj1, obj2) { + + game.stage.backgroundColor = '#992d2d'; + + console.log(obj1.name + ' collided with ' + obj2.name); + +} + +function render() { + + game.debug.renderSpriteInfo(sprite1, 32, 32); + game.debug.renderSpriteCollision(sprite1, 32, 400); + + game.debug.renderSpriteBody(sprite1); + game.debug.renderSpriteBody(sprite2); + +} diff --git a/examples/collision/bounding box.php b/examples/collision/bounding box.php deleted file mode 100644 index 9dc6eb82..00000000 --- a/examples/collision/bounding box.php +++ /dev/null @@ -1,71 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/collision/group vs group.js b/examples/collision/group vs group.js new file mode 100644 index 00000000..75754867 --- /dev/null +++ b/examples/collision/group vs group.js @@ -0,0 +1,98 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); + +function preload() { + + game.load.image('phaser', 'assets/sprites/phaser-dude.png'); + game.load.image('bullet', 'assets/misc/bullet0.png'); + game.load.spritesheet('veggies', 'assets/sprites/fruitnveg32wh37.png', 32, 32); + +} + +var sprite; +var bullets; +var veggies; +var bulletTime = 0; + +var bullet; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + // This will check Group vs. Group collision (bullets vs. veggies!) + + veggies = game.add.group(); + + for (var i = 0; i < 50; i++) + { + var c = veggies.create(game.world.randomX, Math.random() * 500, 'veggies', game.rnd.integerInRange(0, 36)); + c.name = 'veg' + i; + c.body.immovable = true; + } + + bullets = game.add.group(); + + for (var i = 0; i < 10; i++) + { + var b = bullets.create(0, 0, 'bullet'); + b.name = 'bullet' + i; + b.exists = false; + b.visible = false; + b.events.onOutOfBounds.add(resetBullet, this); + } + + sprite = game.add.sprite(400, 550, 'phaser'); + +} + +function update() { + + sprite.body.velocity.x = 0; + sprite.body.velocity.y = 0; + + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) + { + sprite.body.velocity.x = -200; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) + { + sprite.body.velocity.x = 200; + } + + if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) + { + fireBullet(); + } + + game.physics.collide(bullets, veggies, collisionHandler, null, this); + +} + +function fireBullet () { + + if (game.time.now > bulletTime) + { + bullet = bullets.getFirstExists(false); + + if (bullet) + { + bullet.reset(sprite.x + 6, sprite.y - 8); + bullet.body.velocity.y = -300; + bulletTime = game.time.now + 250; + } + } + +} + +// Called if the bullet goes out of the screen +function resetBullet (bullet) { + bullet.kill(); +} + +function collisionHandler (bullet, veg) { + + bullet.kill(); + veg.kill(); + +} diff --git a/examples/collision/group vs group.php b/examples/collision/group vs group.php deleted file mode 100644 index d8a03298..00000000 --- a/examples/collision/group vs group.php +++ /dev/null @@ -1,114 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/collision/larger bounding box.js b/examples/collision/larger bounding box.js new file mode 100644 index 00000000..3bde58aa --- /dev/null +++ b/examples/collision/larger bounding box.js @@ -0,0 +1,51 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('atari', 'assets/sprites/atari130xe.png'); + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); + +} + +var sprite1; +var sprite2; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + sprite1 = game.add.sprite(50, 200, 'atari'); + sprite1.name = 'atari'; + sprite1.body.velocity.x = 100; + + // In this example the new collision box is much larger than the original sprite + sprite1.body.setSize(400, 50, -100, 20); + + sprite2 = game.add.sprite(700, 220, 'mushroom'); + sprite2.name = 'mushroom'; + sprite2.body.velocity.x = -100; + +} + +function update() { + + // object1, object2, collideCallback, processCallback, callbackContext + game.physics.collide(sprite1, sprite2, collisionHandler, null, this); + +} + +function collisionHandler (obj1, obj2) { + + game.stage.backgroundColor = '#992d2d'; + + console.log(obj1.name + ' collided with ' + obj2.name); + +} + +function render() { + + game.debug.renderRectangle(sprite1.body); + game.debug.renderRectangle(sprite2.body); + +} diff --git a/examples/collision/larger bounding box.php b/examples/collision/larger bounding box.php deleted file mode 100644 index 0c61384d..00000000 --- a/examples/collision/larger bounding box.php +++ /dev/null @@ -1,66 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/collision/offset bounding box.js b/examples/collision/offset bounding box.js new file mode 100644 index 00000000..4ae4b1d7 --- /dev/null +++ b/examples/collision/offset bounding box.js @@ -0,0 +1,54 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('atari', 'assets/sprites/atari130xe.png'); + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); + +} + +var sprite1; +var sprite2; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + sprite1 = game.add.sprite(50, 200, 'atari'); + sprite1.name = 'atari'; + sprite1.body.velocity.x = 100; + + // This adjusts the collision body size. + // 100x50 is the new width/height. + // 50, 25 is the X and Y offset of the newly sized box. + // In this case the box is 50px in and 25px down. + sprite1.body.setSize(100, 50, 50, 25); + + sprite2 = game.add.sprite(700, 220, 'mushroom'); + sprite2.name = 'mushroom'; + sprite2.body.velocity.x = -100; + +} + +function update() { + + // object1, object2, collideCallback, processCallback, callbackContext + game.physics.collide(sprite1, sprite2, collisionHandler, null, this); + +} + +function collisionHandler (obj1, obj2) { + + game.stage.backgroundColor = '#992d2d'; + + console.log(obj1.name + ' collided with ' + obj2.name); + +} + +function render() { + + game.debug.renderRectangle(sprite1.body); + game.debug.renderRectangle(sprite2.body); + +} diff --git a/examples/collision/offset bounding box.php b/examples/collision/offset bounding box.php deleted file mode 100644 index 87a98e85..00000000 --- a/examples/collision/offset bounding box.php +++ /dev/null @@ -1,69 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/collision/sprite tiles.js b/examples/collision/sprite tiles.js new file mode 100644 index 00000000..f2fd2d34 --- /dev/null +++ b/examples/collision/sprite tiles.js @@ -0,0 +1,69 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.spritesheet('tiles', 'assets/tiles/platformer_tiles.png', 16, 16); + game.load.image('carrot', 'assets/sprites/carrot.png'); + +} + +var tiles; +var sprite; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + tiles = game.add.group(); + + for (var x = 0; x < 40; x++) + { + var tile = tiles.create(100 + (x * 16), 300, 'tiles', 4); + tile.body.immovable = true; + } + + sprite = game.add.sprite(300, 150, 'carrot'); + sprite.name = 'mushroom'; + sprite.body.collideWorldBounds = true; + sprite.body.velocity.x = 40; + sprite.body.velocity.y = 120; + sprite.body.bounce.setTo(1, 1); + + game.input.onDown.add(carryOn, this); + +} + +function carryOn() { + + game.paused = false; + +} + +function update() { + + // object1, object2, collideCallback, processCallback, callbackContext + game.physics.collide(sprite, tiles, collisionHandler, null, this); + +} + +function collisionHandler (s, t) { + + t.alpha = 0.5; + + console.log('---------------------------------------------'); + console.log(t.body); + + game.paused = true; + +} + +function render() { + + // game.debug.renderSpriteInfo(sprite1, 32, 32); + // game.debug.renderSpriteCollision(sprite1, 32, 400); + + game.debug.renderSpriteBody(sprite); + // game.debug.renderSpriteBody(sprite2); + +} diff --git a/examples/collision/sprite tiles.php b/examples/collision/sprite tiles.php deleted file mode 100644 index fc39a409..00000000 --- a/examples/collision/sprite tiles.php +++ /dev/null @@ -1,84 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/collision/sprite vs group.js b/examples/collision/sprite vs group.js new file mode 100644 index 00000000..781e10fd --- /dev/null +++ b/examples/collision/sprite vs group.js @@ -0,0 +1,87 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('phaser', 'assets/sprites/phaser-dude.png'); + game.load.spritesheet('veggies', 'assets/sprites/fruitnveg32wh37.png', 32, 32); + +} + +var sprite; +var group; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + // This will check Sprite vs. Group collision + + sprite = game.add.sprite(32, 200, 'phaser'); + sprite.name = 'phaser-dude'; + + group = game.add.group(); + + for (var i = 0; i < 50; i++) + { + var c = group.create(100 + Math.random() * 700, game.world.randomY, 'veggies', game.rnd.integerInRange(0, 36)); + c.name = 'veg' + i; + c.body.immovable = true; + } + + for (var i = 0; i < 20; i++) + { + // Here we'll create some chillis which the player can pick-up. They are still part of the same Group. + var c = group.create(100 + Math.random() * 700, game.world.randomY, 'veggies', 17); + c.name = 'chilli' + i; + c.body.immovable = true; + } + +} + +function update() { + + sprite.body.velocity.x = 0; + sprite.body.velocity.y = 0; + + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) + { + sprite.body.velocity.x = -200; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) + { + sprite.body.velocity.x = 200; + } + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) + { + sprite.body.velocity.y = -200; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) + { + sprite.body.velocity.y = 200; + } + + game.physics.collide(sprite, group, collisionHandler, null, this); + +} + +function collisionHandler (obj1, obj2) { + + // If the player collides with the chillis then they get eaten :) + // The chilli frame ID is 17 + + console.log('Hit', obj2.name); + + if (obj2.frame == 17) + { + obj2.kill(); + } + +} + +function render () { + + game.debug.renderQuadTree(game.physics.quadTree); + +} diff --git a/examples/collision/sprite vs group.php b/examples/collision/sprite vs group.php deleted file mode 100644 index a8153b41..00000000 --- a/examples/collision/sprite vs group.php +++ /dev/null @@ -1,103 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/collision/sprite vs sprite custom.js b/examples/collision/sprite vs sprite custom.js new file mode 100644 index 00000000..a05f225c --- /dev/null +++ b/examples/collision/sprite vs sprite custom.js @@ -0,0 +1,78 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('atari', 'assets/sprites/atari130xe.png'); + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); + +} + +var sprite1; +var sprite2; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + // This will check Sprite vs. Sprite collision using a custom process callback + + sprite1 = game.add.sprite(0, 200, 'atari'); + sprite1.name = 'atari'; + // We'll use a random velocity here so we can test it in our processHandler + sprite1.body.velocity.x = 50 + Math.random() * 100; + // This tells phaser to not use the built-in body separation, instead you should handle it in your process callback (see below) + sprite1.body.customSeparateX = true; + + sprite2 = game.add.sprite(750, 220, 'mushroom'); + sprite2.name = 'mushroom'; + // We'll use a random velocity here so we can test it in our processHandler + sprite2.body.velocity.x = -(50 + Math.random() * 100); + // This tells phaser to not use the built-in body separation, instead you should handle it in your process callback (see below) + sprite2.body.customSeparateX = true; + +} + +function update() { + + game.physics.collide(sprite1, sprite2, collisionHandler, processHandler, this); + +} + +function processHandler (obj1, obj2) { + + // This function can perform your own additional checks on the 2 objects that collided. + // For example you could test for velocity, health, etc. + // If you want the collision to be deemed successful this function must return true. + // In which case the collisionHandler will be called, otherwise it won't. + + // Note: the objects will have already been separated by this point unless you have set + // their customSeparateX/Y flags to true. If you do that it's up to you to handle separation. + + // Whichever one is going fastest wins, the other dies :) + if (obj1.body.velocity.x > Math.abs(obj2.body.velocity.x)) + { + obj2.kill(); + obj1.body.velocity.x = 0; + } + else + { + obj1.kill(); + obj2.body.velocity.x = 0; + } + + return true; + +} + +function collisionHandler (obj1, obj2) { + + game.stage.backgroundColor = '#992d2d'; + + console.log(obj1.name + ' collided with ' + obj2.name); + +} + +function render() { +} + diff --git a/examples/collision/sprite vs sprite custom.php b/examples/collision/sprite vs sprite custom.php deleted file mode 100644 index bbf5c44f..00000000 --- a/examples/collision/sprite vs sprite custom.php +++ /dev/null @@ -1,92 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/collision/sprite vs sprite.js b/examples/collision/sprite vs sprite.js new file mode 100644 index 00000000..b344e94e --- /dev/null +++ b/examples/collision/sprite vs sprite.js @@ -0,0 +1,43 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); + +function preload() { + + game.load.image('atari', 'assets/sprites/atari130xe.png'); + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); + +} + +var sprite1; +var sprite2; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + // This will check Sprite vs. Sprite collision + + sprite1 = game.add.sprite(50, 200, 'atari'); + sprite1.name = 'atari'; + sprite1.body.velocity.x = 100; + + sprite2 = game.add.sprite(700, 220, 'mushroom'); + sprite2.name = 'mushroom'; + sprite2.body.velocity.x = -100; + +} + +function update() { + + // object1, object2, collideCallback, processCallback, callbackContext + game.physics.collide(sprite1, sprite2, collisionHandler, null, this); + +} + +function collisionHandler (obj1, obj2) { + + game.stage.backgroundColor = '#992d2d'; + + console.log(obj1.name + ' collided with ' + obj2.name); + +} diff --git a/examples/collision/sprite vs sprite.php b/examples/collision/sprite vs sprite.php deleted file mode 100644 index 02f289a7..00000000 --- a/examples/collision/sprite vs sprite.php +++ /dev/null @@ -1,61 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/collision/transform.js b/examples/collision/transform.js new file mode 100644 index 00000000..4188d132 --- /dev/null +++ b/examples/collision/transform.js @@ -0,0 +1,117 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('atari', 'assets/sprites/atari130xe.png'); + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); + game.load.image('flectrum', 'assets/sprites/flectrum.png'); + +} + +var testGroup; +var sprite1; +var sprite2; +var sprite3; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + game.world.setBounds(-1000, -1000, 2000, 2000); + + testGroup = game.add.group(); + + test2(); + +} + +function test1 () { + + // Test 1 - 2 sprites in world space (seems to work fine with local transform?) + sprite1 = game.add.sprite(-600, 200, 'atari'); + sprite1.name = 'atari'; + // sprite1.body.setSize(100, 100, 0, 0); + + sprite2 = game.add.sprite(-100, 220, 'mushroom'); + sprite2.name = 'mushroom'; + + game.camera.focusOn(sprite1); + game.camera.x += 300; + + game.input.onDown.add(go1, this); + +} + +function test2 () { + + // 1 sprite in world space (seems to work fine with local transform?) and 1 in a group + + sprite1 = testGroup.create(0, -150, 'atari'); + sprite1.name = 'atari'; + sprite1.body.immovable = true; + // sprite1.body.setSize(100, 100, 0, 0); + + sprite2 = game.add.sprite(-100, 150, 'mushroom'); + sprite2.name = 'mushroom'; + + sprite3 = game.add.sprite(-200, 150, 'flectrum'); + sprite3.name = 'tall'; + + testGroup.x = -600; + testGroup.y = 200; + + game.camera.focusOn(sprite2); + game.camera.x -= 300; + + game.input.onDown.add(go2, this); + +} + +function go1 () { + + sprite1.body.velocity.x = 100; + sprite2.body.velocity.x = -100; + +} + +function go2 () { + + sprite2.body.velocity.x = -100; + +} + +function update () { + + game.physics.collide(sprite1, sprite2, collisionHandler, null, this); + + // sprite3.angle += 0.5; + +} + +function collisionHandler (obj1, obj2) { + + game.stage.backgroundColor = '#992d2d'; + + console.log(obj1.name + ' collided with ' + obj2.name); + +} + +function render() { + + // game.debug.renderSpriteInfo(sprite1, 32, 32); + // game.debug.renderSpriteCollision(sprite1, 32, 400); + + game.debug.renderSpriteCoords(sprite1, 32, 32); + game.debug.renderSpriteCoords(sprite2, 300, 32); + + game.debug.renderCameraInfo(game.camera, 32, 500); + + game.debug.renderSpriteBody(sprite1); + game.debug.renderSpriteBody(sprite2); + game.debug.renderSpriteBody(sprite3); + + game.debug.renderGroupInfo(testGroup, 500, 500); + game.debug.renderPixel(testGroup.x, testGroup.y, 'rgb(255,255,0)'); + +} diff --git a/examples/collision/transform.php b/examples/collision/transform.php deleted file mode 100644 index b33b677c..00000000 --- a/examples/collision/transform.php +++ /dev/null @@ -1,131 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/collision/vertical collision.js b/examples/collision/vertical collision.js new file mode 100644 index 00000000..1d3279ab --- /dev/null +++ b/examples/collision/vertical collision.js @@ -0,0 +1,58 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('atari', 'assets/sprites/atari130xe.png'); + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); + +} + +var sprite1; +var sprite2; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + sprite1 = game.add.sprite(300, 50, 'atari'); + sprite1.name = 'atari'; + sprite1.body.velocity.y = 100; + + // This adjusts the collision body size. + // 100x100 is the new width/height. + // See the offset bounding box for another example. + sprite1.body.setSize(220, 50, 0, 0); + + sprite2 = game.add.sprite(400, 500, 'mushroom'); + sprite2.name = 'mushroom'; + sprite2.body.immovable = true; + // sprite2.body.velocity.x = -100; + +} + +function update() { + + // object1, object2, collideCallback, processCallback, callbackContext + game.physics.collide(sprite1, sprite2, collisionHandler, null, this); + +} + +function collisionHandler (obj1, obj2) { + + game.stage.backgroundColor = '#992d2d'; + + console.log(obj1.name + ' collided with ' + obj2.name); + +} + +function render() { + + game.debug.renderSpriteInfo(sprite1, 32, 32); + game.debug.renderSpriteCollision(sprite1, 32, 400); + + game.debug.renderSpriteBody(sprite1); + game.debug.renderSpriteBody(sprite2); + +} + diff --git a/examples/collision/vertical collision.php b/examples/collision/vertical collision.php deleted file mode 100644 index 7f0681aa..00000000 --- a/examples/collision/vertical collision.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/display/fullscreen.js b/examples/display/fullscreen.js new file mode 100644 index 00000000..5f38a7fa --- /dev/null +++ b/examples/display/fullscreen.js @@ -0,0 +1,40 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('atari1', 'assets/sprites/atari130xe.png'); + +} + +function create() { + + var sprite = game.add.sprite(0, 0, 'atari1'); + + game.stage.backgroundColor = '#e3ed49'; + + game.input.onDown.add(gofull, this); + +} + +function gofull() { + + game.stage.scale.startFullScreen(); + +} + +function update() { + + if (document.getElementsByTagName('body')[0].scrollTop > 1000) + { + game.stage.backgroundColor = '#87ff55'; + window.scrollTo(0, 0); + } + +} + +function render () { + + game.debug.renderText('Tap to go fullscreen', 32, 150); + +} diff --git a/examples/display/fullscreen.php b/examples/display/fullscreen.php deleted file mode 100644 index 29f593dd..00000000 --- a/examples/display/fullscreen.php +++ /dev/null @@ -1,55 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/display/graphics.js b/examples/display/graphics.js new file mode 100644 index 00000000..0332560f --- /dev/null +++ b/examples/display/graphics.js @@ -0,0 +1,47 @@ +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { create: create }); + +function create() { + + var graphics = game.add.graphics(0, 0); + + // set a fill and line style + graphics.beginFill(0xFF3300); + graphics.lineStyle(10, 0xffd900, 1); + + // draw a shape + graphics.moveTo(0,50); + graphics.lineTo(250, 50); + graphics.lineTo(100, 100); + graphics.lineTo(250, 220); + graphics.lineTo(50, 220); + graphics.lineTo(0, 50); + graphics.endFill(); + + // set a fill and line style again + graphics.lineStyle(10, 0xFF0000, 0.8); + graphics.beginFill(0xFF700B, 1); + + // draw a second shape + graphics.moveTo(210,300); + graphics.lineTo(450,320); + graphics.lineTo(570,350); + graphics.lineTo(580,20); + graphics.lineTo(330,120); + graphics.lineTo(410,200); + graphics.lineTo(210,300); + graphics.endFill(); + + // draw a rectangle + graphics.lineStyle(2, 0x0000FF, 1); + graphics.drawRect(50, 250, 100, 100); + + // draw a circle + graphics.lineStyle(0); + graphics.beginFill(0xFFFF0B, 0.5); + graphics.drawCircle(470, 200,100); + + graphics.lineStyle(20, 0x33FF00); + graphics.moveTo(30,30); + graphics.lineTo(600, 300); + +} diff --git a/examples/display/graphics.php b/examples/display/graphics.php deleted file mode 100644 index 530fa88d..00000000 --- a/examples/display/graphics.php +++ /dev/null @@ -1,65 +0,0 @@ - - - - - diff --git a/examples/display/linkedList.php b/examples/display/linkedList.php deleted file mode 100644 index 61b18360..00000000 --- a/examples/display/linkedList.php +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - diff --git a/examples/display/render crisp.js b/examples/display/render crisp.js new file mode 100644 index 00000000..16f56fc0 --- /dev/null +++ b/examples/display/render crisp.js @@ -0,0 +1,32 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create }); + +function preload() { + + game.load.image('boss', 'assets/misc/boss1.png'); + game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71); + +} + +var boss; +var button; + +function create() { + + // For browsers that support it, this keeps our pixel art looking crisp + // This only works when you use Phaser.CANVAS as the renderer + Phaser.Canvas.setSmoothingEnabled(game.context, false); + + boss = game.add.sprite(game.world.centerX, game.world.centerY, 'boss'); + boss.anchor.setTo(0.5, 0.5); + + // Zoom in each time we press the button + button = game.add.button(32, 32, 'button', clickedIt, this, 2, 1, 0); +} + +function clickedIt() { + + boss.scale.x += 0.5; + boss.scale.y += 0.5; + +} diff --git a/examples/display/render crisp.php b/examples/display/render crisp.php deleted file mode 100644 index 9f46bc32..00000000 --- a/examples/display/render crisp.php +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - diff --git a/examples/examples.json b/examples/examples.json new file mode 100644 index 00000000..d9f0e44b --- /dev/null +++ b/examples/examples.json @@ -0,0 +1,188 @@ +{ +"animation": [ + { "file": "change+texture+on+click.js", "title": "change texture on click" }, + { "file": "local+json+object.js", "title": "local json object" }, + { "file": "looped+animation.js", "title": "looped animation" }, + { "file": "multiple+anims.js", "title": "multiple anims" }, + { "file": "sprite+sheet.js", "title": "sprite sheet" }, + { "file": "texture+packer+json+hash.js", "title": "texture packer json hash" } +], +"audio": [ + { "file": "loop.js", "title": "loop" }, + { "file": "play+music.js", "title": "play music" } +], +"buttons": [ + { "file": "action+on+click.js", "title": "action on click" }, + { "file": "changing+the+frames.js", "title": "changing the frames" }, + { "file": "rotated+buttons.js", "title": "rotated buttons" } +], +"camera": [ + { "file": "basic+follow.js", "title": "basic follow" }, + { "file": "camera+cull.js", "title": "camera cull" }, + { "file": "follow+styles.js", "title": "follow styles" }, + { "file": "moving+the+camera.js", "title": "moving the camera" }, + { "file": "world+sprite.js", "title": "world sprite" } +], +"collision": [ + { "file": "bounding+box.js", "title": "bounding box" }, + { "file": "group+vs+group.js", "title": "group vs group" }, + { "file": "larger+bounding+box.js", "title": "larger bounding box" }, + { "file": "offset+bounding+box.js", "title": "offset bounding box" }, + { "file": "sprite+tiles.js", "title": "sprite tiles" }, + { "file": "sprite+vs+group.js", "title": "sprite vs group" }, + { "file": "sprite+vs+sprite+custom.js", "title": "sprite vs sprite custom" }, + { "file": "sprite+vs+sprite.js", "title": "sprite vs sprite" }, + { "file": "transform.js", "title": "transform" }, + { "file": "vertical+collision.js", "title": "vertical collision" } +], +"display": [ + { "file": "fullscreen.js", "title": "fullscreen" }, + { "file": "graphics.js", "title": "graphics" }, + { "file": "render+crisp.js", "title": "render crisp" } +], +"games": [ + { "file": "breakout.js", "title": "breakout" }, + { "file": "invaders.js", "title": "invaders" }, + { "file": "starstruck.js", "title": "starstruck" }, + { "file": "tanks.js", "title": "tanks" } +], +"geometry": [ + { "file": "circle.js", "title": "circle" }, + { "file": "line.js", "title": "line" }, + { "file": "playing+with+points.js", "title": "playing with points" }, + { "file": "rectangle.js", "title": "rectangle" }, + { "file": "rotate+point.js", "title": "rotate point" } +], +"groups": [ + { "file": "add+a+sprite+to+group.js", "title": "add a sprite to group" }, + { "file": "bring+a+child+to+top.js", "title": "bring a child to top" }, + { "file": "bring+a+group+to+top.js", "title": "bring a group to top" }, + { "file": "call+all.js", "title": "call all" }, + { "file": "create+group.js", "title": "create group" }, + { "file": "create+sprite+in+a+group.js", "title": "create sprite in a group" }, + { "file": "display+order.js", "title": "display order" }, + { "file": "for+each.js", "title": "for each" }, + { "file": "get+first.js", "title": "get first" }, + { "file": "group+as+layer.js", "title": "group as layer" }, + { "file": "group+transform+-+rotate.js", "title": "group transform - rotate" }, + { "file": "group+transform+-+tween.js", "title": "group transform - tween" }, + { "file": "group+transform.js", "title": "group transform" }, + { "file": "recyling.js", "title": "recyling" }, + { "file": "remove.js", "title": "remove" }, + { "file": "replace.js", "title": "replace" }, + { "file": "set+All.js", "title": "set All" }, + { "file": "sub+groups+-+group+length.js", "title": "sub groups - group length" }, + { "file": "swap+children+in+a+group.js", "title": "swap children in a group" } +], +"input": [ + { "file": "cursor+key+movement.js", "title": "cursor key movement" }, + { "file": "drag+several+sprites.js", "title": "drag several sprites" }, + { "file": "drag.js", "title": "drag" }, + { "file": "drop+limitation.js", "title": "drop limitation" }, + { "file": "follow+mouse.js", "title": "follow mouse" }, + { "file": "game+scale.js", "title": "game scale" }, + { "file": "key.js", "title": "key" }, + { "file": "keyboard+hotkeys.js", "title": "keyboard hotkeys" }, + { "file": "keyboard+justpressed.js", "title": "keyboard justpressed" }, + { "file": "keyboard.js", "title": "keyboard" }, + { "file": "motion+lock+-+horizontal.js", "title": "motion lock - horizontal" }, + { "file": "motion+lock+-+vertical.js", "title": "motion lock - vertical" }, + { "file": "multi+touch.js", "title": "multi touch" }, + { "file": "override+default+controls.js", "title": "override default controls" }, + { "file": "pixel+perfect+click+detection.js", "title": "pixel perfect click detection" }, + { "file": "pixelpick+-+scrolling+effect.js", "title": "pixelpick - scrolling effect" }, + { "file": "pixelpick+-+spritesheet.js", "title": "pixelpick - spritesheet" }, + { "file": "snap+on+drag.js", "title": "snap on drag" } +], +"loader": [ + { "file": "pick+images+from+cache.js", "title": "pick images from cache" } +], +"misc": [ + { "file": "net.js", "title": "net" }, + { "file": "random+generators.js", "title": "random generators" }, + { "file": "repeatable+random+numbers.js", "title": "repeatable random numbers" } +], +"particles": [ + { "file": "click+burst.js", "title": "click burst" }, + { "file": "collision.js", "title": "collision" }, + { "file": "diamond+burst.js", "title": "diamond burst" }, + { "file": "no+rotation.js", "title": "no rotation" }, + { "file": "random+sprite.js", "title": "random sprite" }, + { "file": "when+particles+collide.js", "title": "when particles collide" }, + { "file": "zero+gravity.js", "title": "zero gravity" } +], +"physics": [ + { "file": "accelerate+to+pointer.js", "title": "accelerate to pointer" }, + { "file": "angle+between.js", "title": "angle between" }, + { "file": "angle+to+pointer.js", "title": "angle to pointer" }, + { "file": "angular+acceleration.js", "title": "angular acceleration" }, + { "file": "angular+velocity.js", "title": "angular velocity" }, + { "file": "mass+velocity+test.js", "title": "mass velocity test" }, + { "file": "move+towards+object.js", "title": "move towards object" }, + { "file": "multi+angle+to+pointer.js", "title": "multi angle to pointer" }, + { "file": "quadtree+-+collision+infos.js", "title": "quadtree - collision infos" }, + { "file": "quadtree+-+ids.js", "title": "quadtree - ids" }, + { "file": "shoot+the+pointer.js", "title": "shoot the pointer" }, + { "file": "sprite+bounds.js", "title": "sprite bounds" } +], +"sprites": [ + { "file": "add+a+sprite.js", "title": "add a sprite" }, + { "file": "add+several+sprites.js", "title": "add several sprites" }, + { "file": "collide+world+bounds.js", "title": "collide world bounds" }, + { "file": "destroy.js", "title": "destroy" }, + { "file": "dynamic+crop.js", "title": "dynamic crop" }, + { "file": "extending+sprite+object+demo+2.js", "title": "extending sprite object demo 2" }, + { "file": "extending+sprite+object.js", "title": "extending sprite object" }, + { "file": "horizontal+crop.js", "title": "horizontal crop" }, + { "file": "move+a+sprite.js", "title": "move a sprite" }, + { "file": "out+of+bounds.js", "title": "out of bounds" }, + { "file": "scale+a+sprite.js", "title": "scale a sprite" }, + { "file": "shared+sprite+textures.js", "title": "shared sprite textures" }, + { "file": "sprite+rotation.js", "title": "sprite rotation" }, + { "file": "spritesheet.js", "title": "spritesheet" }, + { "file": "vertical+crop.js", "title": "vertical crop" } +], +"text": [ + { "file": "bitmap+fonts.js", "title": "bitmap fonts" }, + { "file": "hello+arial.js", "title": "hello arial" }, + { "file": "kern+of+duty.js", "title": "kern of duty" }, + { "file": "remove+text.js", "title": "remove text" }, + { "file": "text+stroke.js", "title": "text stroke" } +], +"tile sprites": [ + { "file": "animated+tiling+sprite.js", "title": "animated tiling sprite" }, + { "file": "tiling+sprite.js", "title": "tiling sprite" } +], +"tilemaps": [ + { "file": "Sci-Fly.js", "title": "Sci-Fly" }, + { "file": "fill+tiles.js", "title": "fill tiles" }, + { "file": "mapcollide.js", "title": "mapcollide" }, + { "file": "mario.js", "title": "mario" }, + { "file": "mariotogether.js", "title": "mariotogether" }, + { "file": "paint+tiles.js", "title": "paint tiles" }, + { "file": "randomise+tiles.js", "title": "randomise tiles" }, + { "file": "replace+tiles.js", "title": "replace tiles" }, + { "file": "supermario.js", "title": "supermario" }, + { "file": "supermario2.js", "title": "supermario2" }, + { "file": "swap+tiles.js", "title": "swap tiles" }, + { "file": "wip1.js", "title": "wip1" }, + { "file": "wip2.js", "title": "wip2" }, + { "file": "wip3.js", "title": "wip3" }, + { "file": "wip4.js", "title": "wip4" } +], +"tweens": [ + { "file": "bounce.js", "title": "bounce" }, + { "file": "bubbles.js", "title": "bubbles" }, + { "file": "chained+tweens.js", "title": "chained tweens" }, + { "file": "combined+tweens.js", "title": "combined tweens" }, + { "file": "easing+spritesheets.js", "title": "easing spritesheets" }, + { "file": "easing.js", "title": "easing" }, + { "file": "fading+in+a+sprite.js", "title": "fading in a sprite" }, + { "file": "pause+tween.js", "title": "pause tween" }, + { "file": "tween+several+properties.js", "title": "tween several properties" } +], +"world": [ + { "file": "fixed+to+camera.js", "title": "fixed to camera" }, + { "file": "move+around+world.js", "title": "move around world" } +] +} \ No newline at end of file diff --git a/examples/foot.php b/examples/foot.php deleted file mode 100644 index 576f8502..00000000 --- a/examples/foot.php +++ /dev/null @@ -1,14 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/funcs.php b/examples/funcs.php new file mode 100644 index 00000000..b06f3946 --- /dev/null +++ b/examples/funcs.php @@ -0,0 +1,95 @@ + $value) + { + if (is_array($value) && count($value) > 0) + { + $total += count($value); + } + } + + function getFile() { + + global $files, $dir, $filename, $title, $code; + + if (isset($_GET['d']) && isset($_GET['f'])) + { + $dir = urldecode($_GET['d']); + $filename = urldecode($_GET['d']) . '/' . urldecode($_GET['f']); + $title = urldecode($_GET['t']); + + if (file_exists($filename)) + { + $code = file_get_contents($filename); + $files = dirToArray($dir); + } + } + + } + + function dirToArray($dir) { + + $ignore = array('.', '..', 'html', 'assets', 'states'); + $result = array(); + $root = scandir($dir); + $dirs = array_diff($root, $ignore); + + foreach ($dirs as $key => $value) + { + if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) + { + $result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value); + } + else + { + if (substr($value, -3) == '.js') + { + $result[] = $value; + } + } + } + + return $result; + } + + function printJSLinks($dir, $files, $target) { + + $output = ""; + + foreach ($files as $key => $value) + { + $value2 = substr($value, 0, -3); + $dir = urlencode($dir); + $file = urlencode($value); + $title = urlencode($value2); + + if ($target == 'viewer') + { + $output .= " $value2
\n"; + } + else if ($target == 'json') + { + $output .= " { \"file\": \"$file\", \"title\": \"$value2\" },\n"; + } + else + { + $output .= "
  • $value2
  • \n"; + } + } + + if ($target == 'json') + { + $output = rtrim($output); + $output = substr($output, 0, -1); + $output .= "\n"; + } + + return $output; + + } + +?> \ No newline at end of file diff --git a/examples/games/breakout.js b/examples/games/breakout.js new file mode 100644 index 00000000..981681f7 --- /dev/null +++ b/examples/games/breakout.js @@ -0,0 +1,195 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); + +function preload() { + + game.load.atlas('breakout', 'assets/games/breakout/breakout.png', 'assets/games/breakout/breakout.json'); + game.load.image('starfield', 'assets/misc/starfield.jpg'); + +} + +var ball; +var paddle; +var bricks; + +var ballOnPaddle = true; + +var lives = 3; +var score = 0; + +var scoreText; +var livesText; +var introText; + +var s; + +function create() { + + // We do this so the ball can still rebound with the world bounds, but it will look like it has gone off the bottom of the screen + game.world.height = 620; + + s = game.add.tileSprite(0, 0, 800, 600, 'starfield'); + + var brick; + bricks = game.add.group(); + + for (var y = 0; y < 4; y++) + { + for (var x = 0; x < 15; x++) + { + brick = bricks.create(120 + (x * 36), 100 + (y * 52), 'breakout', 'brick_' + (y+1) + '_1.png'); + brick.body.bounce.setTo(1, 1); + brick.body.immovable = true; + } + } + + paddle = game.add.sprite(game.world.centerX, 500, 'breakout', 'paddle_big.png'); + paddle.anchor.setTo(0.5, 0.5); + paddle.body.collideWorldBounds = true; + paddle.body.bounce.setTo(1, 1); + paddle.body.immovable = true; + + ball = game.add.sprite(game.world.centerX, paddle.y - 16, 'breakout', 'ball_1.png'); + ball.anchor.setTo(0.5, 0.5); + ball.body.collideWorldBounds = true; + ball.body.bounce.setTo(1, 1); + ball.animations.add('spin', [ 'ball_1.png', 'ball_2.png', 'ball_3.png', 'ball_4.png', 'ball_5.png' ], 50, true, false); + + scoreText = game.add.text(32, 550, 'score: 0', { font: "20px Arial", fill: "#ffffff", align: "left" }); + livesText = game.add.text(680, 550, 'lives: 3', { font: "20px Arial", fill: "#ffffff", align: "left" }); + introText = game.add.text(game.world.centerX, 400, '- click to start -', { font: "40px Arial", fill: "#ffffff", align: "center" }); + introText.anchor.setTo(0.5, 0.5); + + game.input.onDown.add(releaseBall, this); + +} + +function update () { + + // Fun, but a little sea-sick inducing :) Uncomment if you like! + // s.tilePosition.x += (game.input.speed.x / 2); + + paddle.x = game.input.x; + + if (paddle.x < 24) + { + paddle.x = 24; + } + else if (paddle.x > game.width - 24) + { + paddle.x = game.width - 24; + } + + if (ballOnPaddle) + { + ball.x = paddle.x; + } + else + { + game.physics.collide(ball, paddle, ballHitPaddle, null, this); + game.physics.collide(ball, bricks, ballHitBrick, null, this); + } + + // Out? + if (ball.y > 600 && ballOnPaddle == false) + { + ballLost(); + } + +} + +function releaseBall () { + + if (ballOnPaddle) + { + ballOnPaddle = false; + ball.body.velocity.y = -300; + ball.body.velocity.x = -75; + ball.animations.play('spin'); + introText.visible = false; + } + +} + +function ballLost () { + + lives--; + + if (lives == 0) + { + gameOver(); + } + else + { + livesText.content = 'lives: ' + lives; + ballOnPaddle = true; + ball.body.velocity.setTo(0, 0); + ball.x = paddle.x + 16; + ball.y = paddle.y - 16; + ball.animations.stop(); + } + +} + +function gameOver () { + + ball.body.velocity.setTo(0, 0); + + introText.content = "Game Over!"; + introText.visible = true; + +} + +function ballHitBrick (_ball, _brick) { + + _brick.kill(); + + score += 10; + + scoreText.content = 'score: ' + score; + + // Are they any bricks left? + if (bricks.countLiving() == 0) + { + // New level starts + score += 1000; + scoreText.content = 'score: ' + score; + introText = '- Next Level -'; + + // Let's move the ball back to the paddle + ballOnPaddle = true; + ball.body.velocity.setTo(0, 0); + ball.x = paddle.x + 16; + ball.y = paddle.y - 16; + ball.animations.stop(); + + // And bring the bricks back from the dead :) + bricks.callAll('revive', this); + } + +} + +function ballHitPaddle (_ball, _paddle) { + + var diff = 0; + + if (_ball.x < _paddle.x) + { + // Ball is on the left-hand side of the paddle + diff = _paddle.x - _ball.x; + _ball.body.velocity.x = (-10 * diff); + } + else if (_ball.x > _paddle.x) + { + // Ball is on the right-hand side of the paddle + diff = _ball.x -_paddle.x; + _ball.body.velocity.x = (10 * diff); + } + else + { + // Ball is perfectly in the middle + // Add a little random X to stop it bouncing straight up! + _ball.body.velocity.x = 2 + Math.random() * 8; + } + +} diff --git a/examples/games/breakout.php b/examples/games/breakout.php deleted file mode 100644 index b2b294cb..00000000 --- a/examples/games/breakout.php +++ /dev/null @@ -1,211 +0,0 @@ - - - - - diff --git a/examples/games/invaders.js b/examples/games/invaders.js new file mode 100644 index 00000000..82434b86 --- /dev/null +++ b/examples/games/invaders.js @@ -0,0 +1,119 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('phaser', 'assets/sprites/phaser-dude.png'); + game.load.image('bullet', 'assets/misc/bullet0.png'); + game.load.image('alien', 'assets/sprites/space-baddie.png'); + game.load.image('ship', 'assets/sprites/shmup-ship.png'); + +} + +var player; +var aliens; +var bullets; +var bulletTime = 0; + +function create() { + + player = game.add.sprite(400, 500, 'ship'); + player.anchor.setTo(0.5, 0.5); + + aliens = game.add.group(null, 'aliens'); + + for (var y = 0; y < 4; y++) + { + for (var x = 0; x < 10; x++) + { + aliens.create(x * 48, y * 50, 'alien'); + } + } + + aliens.x = 100; + aliens.y = 50; + + bullets = game.add.group(null, 'bullets'); + + for (var i = 0; i < 10; i++) + { + var b = bullets.create(0, 0, 'bullet'); + b.name = 'bullet' + i; + b.exists = false; + b.visible = false; + b.anchor.setTo(0.5, 1); + b.events.onOutOfBounds.add(resetBullet, this); + } + + var tween = game.add.tween(aliens).to({x: 200}, 3000, Phaser.Easing.Linear.None, true, 0, 1000, true); + tween.onComplete.add(descend, this); + +} + + +function descend() { + aliens.y += 10; +} + +function update() { + + player.body.velocity.x = 0; + player.body.velocity.y = 0; + + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) + { + player.body.velocity.x = -200; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) + { + player.body.velocity.x = 200; + } + + if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) + { + fireBullet(); + } + + game.physics.collide(bullets, aliens, collisionHandler, null, this); + +} + +function fireBullet () { + + if (game.time.now > bulletTime) + { + bullet = bullets.getFirstExists(false); + + if (bullet) + { + bullet.reset(player.x, player.y - 8); + bullet.body.velocity.y = -300; + bulletTime = game.time.now + 250; + } + } + +} + +// Called if the bullet goes out of the screen +function resetBullet (bullet) { + bullet.kill(); +} + +function collisionHandler (bullet, alien) { + + bullet.kill(); + alien.kill(); + +} + +function render () { + + // aliens.forEach(renderBounds, this); + + game.debug.renderQuadTree(game.physics.quadTree); + +} + +function renderBounds(s) { + game.debug.renderSpriteBounds(s, 'rgba(0,0,255,0.4)', true); +} diff --git a/examples/games/invaders.php b/examples/games/invaders.php deleted file mode 100644 index 05e671d2..00000000 --- a/examples/games/invaders.php +++ /dev/null @@ -1,134 +0,0 @@ - - - - - diff --git a/examples/games/starstruck.js b/examples/games/starstruck.js new file mode 100644 index 00000000..300f2768 --- /dev/null +++ b/examples/games/starstruck.js @@ -0,0 +1,139 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.tilemap('level1', 'assets/games/starstruck/level1.json', null, Phaser.Tilemap.TILED_JSON); + game.load.tileset('tiles', 'assets/games/starstruck/tiles-1.png', 16, 16); + game.load.spritesheet('dude', 'assets/games/starstruck/dude.png', 32, 48); + game.load.spritesheet('droid', 'assets/games/starstruck/droid.png', 32, 32); + game.load.image('starSmall', 'assets/games/starstruck/star.png'); + game.load.image('starBig', 'assets/games/starstruck/star2.png'); + game.load.image('background', 'assets/games/starstruck/background2.png'); + +} + +var map; +var tileset; +var layer; +var player; +var facing = 'left'; +var jumpTimer = 0; +var bg; + +function create() { + + game.stage.backgroundColor = '#000000'; + + bg = game.add.tileSprite(0, 0, 800, 600, 'background'); + bg.fixedToCamera = true; + + map = new Phaser.Tilemap(game, 'level1'); + + tileset = game.cache.getTileset('tiles'); + + tileset.setCollisionRange(0, tileset.total - 1, true, true, true, true); + + tileset.setCollisionRange(12, 17, false, false, false, false); + tileset.setCollisionRange(46, 51, false, false, false, false); + + layer = new Phaser.TilemapLayer(game, 0, 0, 800, 600, tileset, map, 0); + layer.resizeWorld(); + + game.world.add(layer.sprite); + + player = game.add.sprite(32, 32, 'dude'); + player.body.bounce.y = 0.2; + player.body.collideWorldBounds = true; + player.body.gravity.y = 6; + player.body.setSize(16, 32, 8, 16); + + player.animations.add('left', [0, 1, 2, 3], 10, true); + player.animations.add('turn', [4], 20, true); + player.animations.add('right', [5, 6, 7, 8], 10, true); + + game.camera.follow(player); + +} + +function update() { + + layer.update(); + + // getTiles: function (x, y, width, height, collides, layer) { + overlap = layer.getTiles(player.body.x, player.body.y, player.body.width, player.body.height, true); + + if (overlap.length > 1) + { + for (var i = 1; i < overlap.length; i++) + { + game.physics.separateTile(player.body, overlap[i]); + } + } + + // game.physics.collide(player, map); + + player.body.velocity.x = 0; + // player.body.velocity.y = 0; + // player.body.acceleration.y = 500; + + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) + { + player.body.velocity.x = -150; + + if (facing != 'left') + { + player.animations.play('left'); + facing = 'left'; + } + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) + { + player.body.velocity.x = 150; + + if (facing != 'right') + { + player.animations.play('right'); + facing = 'right'; + } + } + else + { + if (facing != 'idle') + { + player.animations.stop(); + + if (facing == 'left') + { + player.frame = 0; + } + else + { + player.frame = 5; + } + + facing = 'idle'; + } + } + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP) || game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) + { + if (player.body.touching.down && game.time.now > jumpTimer) + { + player.body.velocity.y = -250; + jumpTimer = game.time.now + 750; + } + } + +} + +function render() { + + layer.render(); + + // game.debug.renderSpriteBody(player); + + // game.debug.renderSpriteInfo(player, 32, 32); + // game.debug.renderSpriteCollision(player, 32, 320); + +} diff --git a/examples/games/starstruck.php b/examples/games/starstruck.php deleted file mode 100644 index 6d5b85f4..00000000 --- a/examples/games/starstruck.php +++ /dev/null @@ -1,151 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/games/tanks.js b/examples/games/tanks.js new file mode 100644 index 00000000..010c58a3 --- /dev/null +++ b/examples/games/tanks.js @@ -0,0 +1,298 @@ + +EnemyTank = function (index, game, player, bullets) { + + var x = game.world.randomX; + var y = game.world.randomY; + + this.game = game; + this.health = 3; + this.player = player; + this.bullets = bullets; + this.fireRate = 1000; + this.nextFire = 0; + this.alive = true; + + this.shadow = game.add.sprite(x, y, 'enemy', 'shadow'); + this.tank = game.add.sprite(x, y, 'enemy', 'tank1'); + this.turret = game.add.sprite(x, y, 'enemy', 'turret'); + + this.shadow.anchor.setTo(0.5, 0.5); + this.tank.anchor.setTo(0.5, 0.5); + this.turret.anchor.setTo(0.3, 0.5); + + this.tank.name = index.toString(); + this.tank.body.immovable = true; + this.tank.body.collideWorldBounds = true; + this.tank.body.bounce.setTo(1, 1); + + this.tank.angle = game.rnd.angle(); + + game.physics.velocityFromRotation(this.tank.rotation, 100, this.tank.body.velocity); + +}; + +EnemyTank.prototype.damage = function() { + + this.health -= 1; + + if (this.health <= 0) + { + this.alive = false; + + this.shadow.kill(); + this.tank.kill(); + this.turret.kill(); + + return true; + } + + return false; + +} + +EnemyTank.prototype.update = function() { + + this.shadow.x = this.tank.x; + this.shadow.y = this.tank.y; + this.shadow.rotation = this.tank.rotation; + + this.turret.x = this.tank.x; + this.turret.y = this.tank.y; + this.turret.rotation = this.game.physics.angleBetween(this.tank, this.player); + + if (this.game.physics.distanceBetween(this.tank, this.player) < 300) + { + if (this.game.time.now > this.nextFire && this.bullets.countDead() > 0) + { + this.nextFire = this.game.time.now + this.fireRate; + + var bullet = this.bullets.getFirstDead(); + + bullet.reset(this.turret.x, this.turret.y); + + bullet.rotation = this.game.physics.moveToObject(bullet, this.player, 500); + } + } + +}; + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); +// var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload () { + + game.load.atlas('tank', 'assets/games/tanks/tanks.png', 'assets/games/tanks/tanks.json'); + game.load.atlas('enemy', 'assets/games/tanks/enemy-tanks.png', 'assets/games/tanks/tanks.json'); + game.load.image('logo', 'assets/games/tanks/logo.png'); + game.load.image('bullet', 'assets/games/tanks/bullet.png'); + game.load.image('earth', 'assets/games/tanks/scorched_earth.png'); + game.load.spritesheet('kaboom', 'assets/games/tanks/explosion.png', 64, 64, 23); + +} + +var land; + +var shadow; +var tank; +var turret; + +var enemies; +var enemyBullets; +var explosions; + +var logo; + +var currentSpeed = 0; +var cursors; + +var bullets; +var fireRate = 100; +var nextFire = 0; + +function create () { + + // Resize our game world to be a 2000 x 2000 square + game.world.setBounds(-1000, -1000, 2000, 2000); + + // Our tiled scrolling background + land = game.add.tileSprite(0, 0, 800, 600, 'earth'); + land.fixedToCamera = true; + + // The base of our tank + tank = game.add.sprite(0, 0, 'tank', 'tank1'); + tank.anchor.setTo(0.5, 0.5); + tank.animations.add('move', ['tank1', 'tank2', 'tank3', 'tank4', 'tank5', 'tank6'], 20, true); + // tank.play('move'); + + // This will force it to decelerate and limit its speed + tank.body.drag.setTo(200, 200); + tank.body.maxVelocity.setTo(400, 400); + tank.body.collideWorldBounds = true; + + // Finally the turret that we place on-top of the tank body + turret = game.add.sprite(0, 0, 'tank', 'turret'); + turret.anchor.setTo(0.3, 0.5); + + // The enemies bullet group + enemyBullets = game.add.group(); + enemyBullets.createMultiple(100, 'bullet'); + enemyBullets.setAll('anchor.x', 0.5); + enemyBullets.setAll('anchor.y', 0.5); + enemyBullets.setAll('outOfBoundsKill', true); + + // Create some baddies to waste :) + enemies = []; + + for (var i = 0; i < 20; i++) + { + enemies.push(new EnemyTank(i, game, tank, enemyBullets)); + } + + // A shadow below our tank + shadow = game.add.sprite(0, 0, 'tank', 'shadow'); + shadow.anchor.setTo(0.5, 0.5); + + // Our bullet group + bullets = game.add.group(); + bullets.createMultiple(30, 'bullet'); + bullets.setAll('anchor.x', 0.5); + bullets.setAll('anchor.y', 0.5); + bullets.setAll('outOfBoundsKill', true); + + // Explosion pool + explosions = game.add.group(); + + for (var i = 0; i < 10; i++) + { + var explosionAnimation = explosions.create(0, 0, 'kaboom', [0], false); + explosionAnimation.anchor.setTo(0.5, 0.5); + explosionAnimation.animations.add('kaboom'); + } + + tank.bringToTop(); + turret.bringToTop(); + + logo = game.add.sprite(0, 200, 'logo'); + logo.fixedToCamera = true; + + game.input.onDown.add(removeLogo, this); + + game.camera.follow(tank); + game.camera.deadzone = new Phaser.Rectangle(150, 150, 500, 300); + game.camera.focusOnXY(0, 0); + + cursors = game.input.keyboard.createCursorKeys(); + +} + +function removeLogo () { + + game.input.onDown.remove(removeLogo, this); + logo.kill(); + +} + +function update () { + + game.physics.collide(enemyBullets, tank, bulletHitPlayer, null, this); + + for (var i = 0; i < enemies.length; i++) + { + if (enemies[i].alive) + { + enemies[i].update(); + game.physics.collide(tank, enemies[i].tank); + game.physics.collide(bullets, enemies[i].tank, bulletHitEnemy, null, this); + } + } + + if (cursors.left.isDown) + { + tank.angle -= 4; + } + else if (cursors.right.isDown) + { + tank.angle += 4; + } + + if (cursors.up.isDown) + { + // The speed we'll travel at + currentSpeed = 300; + } + else + { + if (currentSpeed > 0) + { + currentSpeed -= 4; + } + } + + if (currentSpeed > 0) + { + game.physics.velocityFromRotation(tank.rotation, currentSpeed, tank.body.velocity); + } + + land.tilePosition.x = -game.camera.x; + land.tilePosition.y = -game.camera.y; + + // Position all the parts and align rotations + shadow.x = tank.x; + shadow.y = tank.y; + shadow.rotation = tank.rotation; + + turret.x = tank.x; + turret.y = tank.y; + + turret.rotation = game.physics.angleToPointer(turret); + + if (game.input.activePointer.isDown) + { + // Boom! + fire(); + } + +} + +function bulletHitPlayer (tank, bullet) { + + bullet.kill(); + +} + +function bulletHitEnemy (tank, bullet) { + + bullet.kill(); + + var destroyed = enemies[tank.name].damage(); + + if (destroyed) + { + var explosionAnimation = explosions.getFirstDead(); + explosionAnimation.reset(tank.x, tank.y); + explosionAnimation.play('kaboom', 30, false, true); + } + +} + +function fire () { + + if (game.time.now > nextFire && bullets.countDead() > 0) + { + nextFire = game.time.now + fireRate; + + var bullet = bullets.getFirstDead(); + + bullet.reset(turret.x, turret.y); + + bullet.rotation = game.physics.moveToPointer(bullet, 1000); + } + +} + +function render () { + + // game.debug.renderText('Active Bullets: ' + bullets.countLiving() + ' / ' + bullets.total, 32, 32); + +} + diff --git a/examples/games/tanks.php b/examples/games/tanks.php deleted file mode 100644 index 0e8655c0..00000000 --- a/examples/games/tanks.php +++ /dev/null @@ -1,325 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/geometry/circle.js b/examples/geometry/circle.js new file mode 100644 index 00000000..45972def --- /dev/null +++ b/examples/geometry/circle.js @@ -0,0 +1,19 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create, render: render }); + +var circle; +var floor; + +function create() { + + circle = new Phaser.Circle(game.world.centerX, 100,64); + +} + +function render () { + + game.debug.renderCircle(circle,'#cfffff'); + game.debug.renderText('Diameter : '+circle.diameter,50,200); + game.debug.renderText('Circumference : '+circle.circumference(),50,230); + +} diff --git a/examples/geometry/circle.php b/examples/geometry/circle.php deleted file mode 100644 index 3672d01f..00000000 --- a/examples/geometry/circle.php +++ /dev/null @@ -1,32 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/geometry/line.js b/examples/geometry/line.js new file mode 100644 index 00000000..61b3f502 --- /dev/null +++ b/examples/geometry/line.js @@ -0,0 +1,17 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { create: create }); + +function create() { + + var graphics = game.add.graphics(50,50); + + // set a fill and line style + graphics.beginFill(0xFF0000); + graphics.lineStyle(10, 0xFF0000, 1); + + // draw a shape + graphics.moveTo(50,50); + graphics.lineTo(250, 50); + graphics.endFill(); + +} diff --git a/examples/geometry/line.php b/examples/geometry/line.php deleted file mode 100644 index edfd6474..00000000 --- a/examples/geometry/line.php +++ /dev/null @@ -1,32 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/geometry/playing with points.js b/examples/geometry/playing with points.js new file mode 100644 index 00000000..7b930218 --- /dev/null +++ b/examples/geometry/playing with points.js @@ -0,0 +1,57 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', {create: create, update: update, render: render }); + +var p1; +var p2; +var p3; +var p4; + +var d2 = 0; +var d3 = 0; +var d4 = 0; + +function create() { + + p1 = new Phaser.Point(game.world.centerX, game.world.centerY); + p2 = new Phaser.Point(p1.x - 50, p1.y - 50); + p3 = new Phaser.Point(p2.x - 50, p2.y - 50); + p4 = new Phaser.Point(p3.x - 50, p3.y - 50); + +} + +function update() { + + p2.rotate(p1.x, p1.y, game.math.wrapAngle(d2), true, 150); + p3.rotate(p2.x, p2.y, game.math.wrapAngle(d3), true, 50); + p4.rotate(p3.x, p3.y, game.math.wrapAngle(d4), true, 100); + + d2 += 1; + d3 += 4; + d4 += 6; + +} + +function render() { + + game.context.strokeStyle = 'rgb(0,255,255)'; + game.context.beginPath(); + game.context.moveTo(p1.x, p1.y); + game.context.lineTo(p2.x, p2.y); + game.context.lineTo(p3.x, p3.y); + game.context.lineTo(p4.x, p4.y); + game.context.stroke(); + game.context.closePath(); + + game.context.fillStyle = 'rgb(255,255,0)'; + game.context.fillRect(p1.x, p1.y, 4, 4); + + game.context.fillStyle = 'rgb(255,0,0)'; + game.context.fillRect(p2.x, p2.y, 4, 4); + + game.context.fillStyle = 'rgb(0,255,0)'; + game.context.fillRect(p3.x, p3.y, 4, 4); + + game.context.fillStyle = 'rgb(255,0,255)'; + game.context.fillRect(p4.x, p4.y, 4, 4); + +} diff --git a/examples/geometry/playing with points.php b/examples/geometry/playing with points.php deleted file mode 100644 index c1e008c7..00000000 --- a/examples/geometry/playing with points.php +++ /dev/null @@ -1,70 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/geometry/rectangle.js b/examples/geometry/rectangle.js new file mode 100644 index 00000000..71af3359 --- /dev/null +++ b/examples/geometry/rectangle.js @@ -0,0 +1,16 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create, render: render }); + +var floor; + +function create() { + + floor = new Phaser.Rectangle(0, 550, 800, 50); + +} + +function render () { + + game.debug.renderRectangle(floor,'#0fffff'); + +} diff --git a/examples/geometry/rectangle.php b/examples/geometry/rectangle.php deleted file mode 100644 index c1d9211c..00000000 --- a/examples/geometry/rectangle.php +++ /dev/null @@ -1,30 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/geometry/rotate point.js b/examples/geometry/rotate point.js new file mode 100644 index 00000000..99b2ec01 --- /dev/null +++ b/examples/geometry/rotate point.js @@ -0,0 +1,31 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', {create: create, update: update, render: render }); + +var p1; +var p2; +var d = 0; + +function create() { + + p1 = new Phaser.Point(200, 300); + p2 = new Phaser.Point(300, 300); + +} + +function update() { + + p1.rotate(p2.x, p2.y, game.math.wrapAngle(d), true); + + d++; + +} + +function render() { + + game.context.fillStyle = 'rgb(255,255,0)'; + game.context.fillRect(p1.x, p1.y, 4, 4); + + game.context.fillStyle = 'rgb(255,0,0)'; + game.context.fillRect(p2.x, p2.y, 4, 4); + +} diff --git a/examples/geometry/rotate point.php b/examples/geometry/rotate point.php deleted file mode 100644 index 25905f26..00000000 --- a/examples/geometry/rotate point.php +++ /dev/null @@ -1,47 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/groups/add a sprite to group.js b/examples/groups/add a sprite to group.js new file mode 100644 index 00000000..09f9d257 --- /dev/null +++ b/examples/groups/add a sprite to group.js @@ -0,0 +1,34 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create }); + +var friendAndFoe; +var enemies; + +function preload() { + + game.load.image('ufo', 'assets/sprites/ufo.png'); + game.load.image('baddie', 'assets/sprites/space-baddie.png'); + +} + +function create() { + + // Here we create 2 new groups + friendAndFoe = game.add.group(); + enemies = game.add.group(); + + for (var i = 0; i < 16; i++) + { + // This creates a new Phaser.Sprite instance within the group + // It will be randomly placed within the world and use the 'baddie' image to display + enemies.create(360 + Math.random() * 200, 120 + Math.random() * 200, 'baddie'); + } + + // You can also add existing sprites to a group. + // Here we'll create a local sprite called 'ufo' + var ufo = game.add.sprite(200, 240, 'ufo'); + + // And then add it to the group + friendAndFoe.add(ufo); + +} diff --git a/examples/groups/add a sprite to group.php b/examples/groups/add a sprite to group.php deleted file mode 100644 index b224864a..00000000 --- a/examples/groups/add a sprite to group.php +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - diff --git a/examples/groups/bring a child to top.js b/examples/groups/bring a child to top.js new file mode 100644 index 00000000..07a2f82a --- /dev/null +++ b/examples/groups/bring a child to top.js @@ -0,0 +1,34 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +function preload() { + game.load.spritesheet('button', 'assets/buttons/number-buttons.png', 160, 160); +} + +var container; + +function create() { + + container = game.add.group(); + + // Add buttons to container. + container.add(game.add.button(200, 100, 'button', bringMeToTop, this, 0, 0, 0)); + container.add(game.add.button(300, 100, 'button', bringMeToTop, this, 1, 1, 1)); + container.add(game.add.button(100, 200, 'button', bringMeToTop, this, 2, 2, 2)); + container.add(game.add.button(400, 200, 'button', bringMeToTop, this, 3, 3, 3)); + container.add(game.add.button(300, 300, 'button', bringMeToTop, this, 4, 4, 4)); + container.add(game.add.button(200, 300, 'button', bringMeToTop, this, 5, 5, 5)); + +} + +function render() { + + game.debug.renderText('Tap or click button to bring it to the top.', 32, 32); + +} + +function bringMeToTop(btn) { + + container.bringToTop(btn); + +} diff --git a/examples/groups/bring a child to top.php b/examples/groups/bring a child to top.php deleted file mode 100644 index 8c0d043a..00000000 --- a/examples/groups/bring a child to top.php +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - diff --git a/examples/groups/bring a group to top.js b/examples/groups/bring a group to top.js new file mode 100644 index 00000000..2a67bf2b --- /dev/null +++ b/examples/groups/bring a group to top.js @@ -0,0 +1,83 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('beast', 'assets/pics/shadow_of_the_beast2_karamoon.png'); + game.load.image('snot', 'assets/pics/nslide_snot.png'); + game.load.image('atari1', 'assets/sprites/atari130xe.png'); + game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png'); + game.load.image('coke', 'assets/sprites/cokecan.png'); + game.load.image('disk', 'assets/sprites/oz_pov_melting_disk.png'); + +} + +var group1; +var group2; +var coke; +var disk; + +function create() { + + // Create a background image + game.add.sprite(0, 0, 'beast'); + + // Create a Group that will sit above the background image + group1 = game.add.group(); + + // Create a Group that will sit above Group 1 + group2 = game.add.group(); + + // Now let's create some random sprites and enable them all for drag and 'bring to top' + for (var i = 0; i < 10; i++) + { + + var tempSprite = game.add.sprite(game.stage.randomX, game.stage.randomY, 'atari1'); + + tempSprite.name = 'atari' + i; + tempSprite.input.start(i, true); + tempSprite.input.enableDrag(false, true); + + group1.add(tempSprite); + + // Sonics + + var tempSprite=game.add.sprite(game.stage.randomX, game.stage.randomY, 'sonic'); + + tempSprite.name = 'sonic' + i; + tempSprite.input.start(10 + i, true); + tempSprite.input.enableDrag(false, true); + + group2.add(tempSprite); + } + + // Add 2 control sprites into each group - these cannot be dragged but should be bought to the top each time + coke = group1.create(100, 100, 'coke'); + disk = group2.create(400, 300, 'disk'); + + // Create a foreground image - everything should appear behind this, even when dragged + var snot = game.add.sprite(game.world.centerX, game.world.height, 'snot'); + snot.anchor.setTo(0.5, 1); + + // You can click and drag any sprite but Sonic sprites should always appear above the Atari sprites + // and both types of sprite should only ever appear above the background and behind the + +} + +function update() { + + if (game.input.keyboard.justReleased(Phaser.Keyboard.ONE)) + { + coke.bringToTop(); + } + + if (game.input.keyboard.justReleased(Phaser.Keyboard.TWO)) + { + disk.bringToTop(); + } + +} + +function render() { + game.debug.renderInputInfo(32, 32); +} diff --git a/examples/groups/bring a group to top.php b/examples/groups/bring a group to top.php deleted file mode 100644 index 5a8324aa..00000000 --- a/examples/groups/bring a group to top.php +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - diff --git a/examples/groups/call all.js b/examples/groups/call all.js new file mode 100644 index 00000000..ac7d1418 --- /dev/null +++ b/examples/groups/call all.js @@ -0,0 +1,52 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +function preload() { + + game.load.spritesheet('item', 'assets/buttons/number-buttons-90x90.png', 90, 90); + game.load.image('reviveBtn', 'assets/buttons/revive-button.png'); + +} + +function create() { + + // Add some items. + var item; + + for (var i = 0; i < 3; i++) + { + // Give the items a different alpha increase speed. + item = game.add.sprite(290, 98 * (i + 1), 'item', i); + + // Enable input. + item.input.start(0, true); + item.events.onInputUp.add(kill); + + // An item besides the left one. + item = game.add.sprite(388, 98 * (i + 1), 'item', i + 3); + item.input.start(0, true); + item.events.onInputUp.add(kill); + } + + // Add a button to revive all the items. + game.add.button(270, 400, 'reviveBtn', reviveAll, this, 0, 0, 0); + +} + +function kill(item) { + + item.kill(); + +} + +function reviveAll() { + + game.world.callAll('revive'); + +} + +function render() { + + game.debug.renderText('Tap or click an item to kill it, and press the revive button to revive them all.', 160, 500); + +} diff --git a/examples/groups/call all.php b/examples/groups/call all.php deleted file mode 100644 index a876b5f4..00000000 --- a/examples/groups/call all.php +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - diff --git a/examples/groups/create group.js b/examples/groups/create group.js new file mode 100644 index 00000000..81af43d2 --- /dev/null +++ b/examples/groups/create group.js @@ -0,0 +1,36 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create}); + + function preload() { + + game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png'); + +} + +var firstGroup; + +function create() { + + // Here we'll create a new Group + firstGroup = game.add.group(); + + // And add some sprites to it + for (var i = 0; i < 10; i++) + { + // Create a new sprite at a random screen location + var newSprite = new Phaser.Sprite(game, game.stage.randomX, game.stage.randomY, 'sonic'); + + // This set-ups a listener for the event, view your console.log output to see the result + newSprite.events.onAddedToGroup.add(logGroupAdd); + + // Add the sprite to the Group + firstGroup.add(newSprite); + } + +} + +function logGroupAdd(sprite, group) { + + console.log('Sprite added to Group', group.ID, 'at z-index:', group.getIndex(sprite)); + +} diff --git a/examples/groups/create group.php b/examples/groups/create group.php deleted file mode 100644 index e0c68a91..00000000 --- a/examples/groups/create group.php +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - diff --git a/examples/groups/create sprite in a group.js b/examples/groups/create sprite in a group.js new file mode 100644 index 00000000..4b6689f4 --- /dev/null +++ b/examples/groups/create sprite in a group.js @@ -0,0 +1,45 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +function preload() { + + game.load.image('ufo', 'assets/sprites/ufo.png'); + game.load.image('baddie', 'assets/sprites/space-baddie.png'); + +} + +var friendAndFoe; +var enemies; + +function create() { + + // Create some local groups for later use. + friendAndFoe = game.add.group(); + enemies = game.add.group(); + + // You can directly create a sprite and add it to a group + // using just one line. + friendAndFoe.create(200, 240, 'ufo'); + + // Create some enemies. + for (var i = 0; i < 8; i++) + { + createBaddie(); + } + + // Tap to create new baddie sprites. + game.input.onTap.add(createBaddie, this); + +} + +function createBaddie() { + + enemies.create(360 + Math.random() * 200, 120 + Math.random() * 200,'baddie'); + +} + +function render() { + + game.debug.renderText('Tap screen or click to create new baddies.', 16, 24); + +} diff --git a/examples/groups/create sprite in a group.php b/examples/groups/create sprite in a group.php deleted file mode 100644 index 16ccdf0c..00000000 --- a/examples/groups/create sprite in a group.php +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - diff --git a/examples/groups/display order.js b/examples/groups/display order.js new file mode 100644 index 00000000..f9ae1c13 --- /dev/null +++ b/examples/groups/display order.js @@ -0,0 +1,43 @@ +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); + +function preload() { + + game.load.image('atari1', 'assets/sprites/atari130xe.png'); + game.load.image('atari2', 'assets/sprites/atari800xl.png'); + game.load.image('card', 'assets/sprites/mana_card.png'); + +} + +var items; +var card; + +function create() { + + items = game.add.group(); + + // Items are rendered in the depth order in which they are added to the Group + items.create(64, 100, 'atari1'); + card = items.create(240, 80, 'card'); + items.create(280, 100, 'atari2'); + + game.input.onTap.addOnce(removeCard, this);// obviously the event can be fired only once + +} + +function removeCard() { + + // Now let's kill the card sprite + card.kill(); + + game.input.onTap.addOnce(replaceCard, this); + +} + +function replaceCard() { + + // And bring it back to life again - I assume it will render in the same place as before? + var bob = items.getFirstDead(); + + bob.revive(); + +} diff --git a/examples/groups/display order.php b/examples/groups/display order.php deleted file mode 100644 index 25d7e5a1..00000000 --- a/examples/groups/display order.php +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - diff --git a/examples/groups/for each.js b/examples/groups/for each.js new file mode 100644 index 00000000..705422d3 --- /dev/null +++ b/examples/groups/for each.js @@ -0,0 +1,43 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +var baseAlphaIncSpeed= 0.006; + +function preload() { + game.load.spritesheet('item', 'assets/buttons/number-buttons-90x90.png', 90, 90); +} + +function create() { + + for (var i = 0; i < 3; i++) + { + // Note: alphaIncSpeed is a new property we're adding to Phaser.Sprite, not a pre-existing one + game.add.sprite(290, 98 * (i + 1), 'item', i).alphaIncSpeed = baseAlphaIncSpeed * (i + 1); + game.add.sprite(388, 98 * (i + 1), 'item', i + 3).alphaIncSpeed = baseAlphaIncSpeed * (i + 4); + } + +} + +function update() { + + // Animating alpha property of each item using forEach() method. + game.world.forEach(function(item) { + + // Update alpha first. + item.alpha -= item.alphaIncSpeed; + + // Check for switch between increasing and descreasing. + if (item.alpha < 0.001 || item.alpha > 0.999) + { + item.alphaIncSpeed *= -1; + } + + }); + +} + +function render() { + + game.debug.renderText('Alpha of items is always changing.', 280, 480); + +} diff --git a/examples/groups/for each.php b/examples/groups/for each.php deleted file mode 100644 index 502b2e20..00000000 --- a/examples/groups/for each.php +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - diff --git a/examples/groups/get first.js b/examples/groups/get first.js new file mode 100644 index 00000000..e6ea77ba --- /dev/null +++ b/examples/groups/get first.js @@ -0,0 +1,60 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.spritesheet('item', 'assets/buttons/number-buttons-90x90.png', 90, 90); + game.load.image('reviveBtn', 'assets/buttons/revive-button.png'); + +} + +var timer; +var cycle; + +function create() { + + // Add some items. + var item; + + for (var i = 0; i < 3; i++) + { + // Give the items a different alpha increase speed. + item = game.add.sprite(290, 98 * (i + 1), 'item', i); + + // An item beside the left one. + item = game.add.sprite(388, 98 * (i + 1), 'item', i + 3); + } + + // Set a timer so we can perform an action after a delay. + timer = 0; + cycle = 1000; + +} + +function update() { + + if (game.time.now > timer) + { + // Update timer. + timer = game.time.now +cycle; + + // Get the first alive item and kill it. + var item = game.world.getFirstAlive(); + + if (item) + { + item.kill(); + } + + } + +} + +function render() { + + game.debug.renderText('One item will be killed each second.', 280, 420); + + // Get living and dead number of a group. + game.debug.renderText('Living: ' + game.world.countLiving() + ', Dead: ' + game.world.countDead(), 330, 440); + +} diff --git a/examples/groups/get first.php b/examples/groups/get first.php deleted file mode 100644 index 4948e755..00000000 --- a/examples/groups/get first.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - diff --git a/examples/groups/group as layer.js b/examples/groups/group as layer.js new file mode 100644 index 00000000..c88581c2 --- /dev/null +++ b/examples/groups/group as layer.js @@ -0,0 +1,73 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +function preload() { + + game.world.setBounds(0,0,1280, 800); + + game.load.image('ground', 'assets/tests/ground-2x.png'); + game.load.image('river', 'assets/tests/river-2x.png'); + game.load.image('sky', 'assets/tests/sky-2x.png'); + game.load.image('cloud0', 'assets/tests/cloud-big-2x.png'); + game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png'); + game.load.image('cloud2', 'assets/tests/cloud-small-2x.png'); + + game.load.spritesheet('ufo', 'assets/sprites/ufo.png', 24, 21); + +} + +function create() { + + // Create the sky layer, behind everything and donot move. + var skyLayer = game.add.group(); + skyLayer.z = 0; + // Create the cloud layer, only beyond the sky. + var cloudLayer = game.add.group(); + cloudLayer.z = 1; + // Create the ground, behind the river and beyond clouds. + var groundLayer = game.add.group(); + groundLayer.z = 2; + // Create the sprite layer. This should behind the river, + // and beyond the ground, cloud and sky layer. + var spriteLayer = game.add.group(); + spriteLayer.z = 3; + // Create the river layer, beyond everything. + var riverLayer = game.add.group(); + riverLayer.z = 4; + + // Add sky background to skyLayer. + var sky = new Phaser.Sprite(game, 0, 0, 'sky'); + skyLayer.add(sky); + + // Add clouds to cloudLayer. + var cloud0 = new Phaser.Sprite(game, 200, 120, 'cloud0'); + var cloud1 = new Phaser.Sprite(game, -60, 120, 'cloud1'); + var cloud2 = new Phaser.Sprite(game, 900, 170, 'cloud2'); + cloudLayer.add(cloud0); + cloudLayer.add(cloud1); + cloudLayer.add(cloud2); + + // Add ground sprite to groundLayer. + var ground = new Phaser.Sprite(game, 0, 360, 'ground'); + groundLayer.add(ground); + + // Add river to riverLayer. + var river = new Phaser.Sprite(game, 0, 400, 'river'); + riverLayer.add(river); + + // Add sprites to spriteLayer. + var ufo = new Phaser.Sprite(game, 360, 240, 'ufo'); + ufo.anchor.setTo(0.5, 0.5); + spriteLayer.add(ufo); + +} + +function render() { + + game.debug.renderText('sky layer: z = 0', 16, 20); + game.debug.renderText('cloud layer: z = 1', 16, 36); + game.debug.renderText('ground layer: z = 2', 16, 52); + game.debug.renderText('sprite layer: z = 3', 16, 68); + game.debug.renderText('river layer: z = 4', 16, 84); + +} diff --git a/examples/groups/group as layer.php b/examples/groups/group as layer.php deleted file mode 100644 index ac433a8d..00000000 --- a/examples/groups/group as layer.php +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - diff --git a/examples/groups/group transform - rotate.js b/examples/groups/group transform - rotate.js new file mode 100644 index 00000000..e310ee5c --- /dev/null +++ b/examples/groups/group transform - rotate.js @@ -0,0 +1,50 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +var robot; +var eye; +var body; +var leftArm; +var rightArm; +var leftLeg; +var rightLeg; + +function preload() { + + game.load.image('eye', 'assets/sprites/robot/eye.png'); + game.load.image('body', 'assets/sprites/robot/body.png'); + game.load.image('arm-l', 'assets/sprites/robot/arm-l.png'); + game.load.image('arm-r', 'assets/sprites/robot/arm-r.png'); + game.load.image('leg-l', 'assets/sprites/robot/leg-l.png'); + game.load.image('leg-r', 'assets/sprites/robot/leg-r.png'); + +} + +function create() { + + // Use groups of sprites to create a big robot. + // Robot itself, you can subclass group class in a real game. + robot = game.add.group(); + + // Robot components. + leftArm = robot.create(90, 175, 'arm-l'); + rightArm = robot.create(549, 175, 'arm-r'); + leftLeg = robot.create(270, 325, 'leg-l'); + rightLeg = robot.create(410, 325, 'leg-r'); + body = robot.create(219, 32, 'body'); + eye = robot.create(335, 173,'eye'); + +} + +function update() { + + // Change parent's rotation to change all the childs. + robot.angle += 2; + +} + +function render() { + + game.debug.renderText('The robot is a group and every component is a sprite.', 240, 580); + +} diff --git a/examples/groups/group transform - rotate.php b/examples/groups/group transform - rotate.php deleted file mode 100644 index bbccd179..00000000 --- a/examples/groups/group transform - rotate.php +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - diff --git a/examples/groups/group transform - tween.js b/examples/groups/group transform - tween.js new file mode 100644 index 00000000..7b37db20 --- /dev/null +++ b/examples/groups/group transform - tween.js @@ -0,0 +1,46 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +var robot; +var eye; +var body; +var leftArm; +var rightArm; +var leftLeg; +var rightLeg; + +function preload() { + + game.load.image('eye', 'assets/sprites/robot/eye.png'); + game.load.image('body', 'assets/sprites/robot/body.png'); + game.load.image('arm-l', 'assets/sprites/robot/arm-l.png'); + game.load.image('arm-r', 'assets/sprites/robot/arm-r.png'); + game.load.image('leg-l', 'assets/sprites/robot/leg-l.png'); + game.load.image('leg-r', 'assets/sprites/robot/leg-r.png'); + +} + +function create() { + + // Use groups of sprites to create a big robot. + // Robot itself, you can subclass group class in a real game. + robot = game.add.group(); + + // Robot components. + leftArm = robot.create(90, 175, 'arm-l'); + rightArm = robot.create(549, 175, 'arm-r'); + leftLeg = robot.create(270, 325, 'leg-l'); + rightLeg = robot.create(410, 325, 'leg-r'); + body = robot.create(219, 32, 'body'); + eye = robot.create(335, 173,'eye'); + + // Tween the robot's size, so all the components also scaled. + game.add.tween(robot._container.scale).to( {x: 1.2, y: 1.2}, 1000, Phaser.Easing.Back.InOut, true, 0, false).yoyo(true); + +} + +function render() { + + game.debug.renderText('The robot is a group and every component is a sprite.', 240, 580); + +} diff --git a/examples/groups/group transform - tween.php b/examples/groups/group transform - tween.php deleted file mode 100644 index 6321e5ba..00000000 --- a/examples/groups/group transform - tween.php +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - diff --git a/examples/groups/group transform.js b/examples/groups/group transform.js new file mode 100644 index 00000000..07c3cec4 --- /dev/null +++ b/examples/groups/group transform.js @@ -0,0 +1,65 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +var robot; +var eye; +var body; +var leftArm; +var rightArm; +var leftLeg; +var rightLeg; + +function preload() { + + game.load.image('eye', 'assets/sprites/robot/eye.png'); + game.load.image('body', 'assets/sprites/robot/body.png'); + game.load.image('arm-l', 'assets/sprites/robot/arm-l.png'); + game.load.image('arm-r', 'assets/sprites/robot/arm-r.png'); + game.load.image('leg-l', 'assets/sprites/robot/leg-l.png'); + game.load.image('leg-r', 'assets/sprites/robot/leg-r.png'); + +} + +function create() { + + // Use groups of sprites to create a big robot. + // Robot itself, you can subclass group class in a real game. + robot = game.add.group(); + + // Robot components. + leftArm = robot.create(90, 175, 'arm-l'); + rightArm = robot.create(549, 175, 'arm-r'); + leftLeg = robot.create(270, 325, 'leg-l'); + rightLeg = robot.create(410, 325, 'leg-r'); + body = robot.create(219, 32, 'body'); + eye = robot.create(335, 173,'eye'); + + leftArm.input.start(0, false, true); + leftArm.input.enableDrag(); + rightArm.input.start(0, false, true); + rightArm.input.enableDrag(); + leftLeg.input.start(0, false, true); + leftLeg.input.enableDrag(); + rightLeg.input.start(0, false, true); + rightLeg.input.enableDrag(); + body.input.start(0, false, true); + body.input.enableDrag(); + eye.input.start(0, false, true); + eye.input.enableDrag(); + +} + +function render() { + + game.debug.renderSpriteInfo(leftArm, 32, 30); + game.debug.renderSpriteInfo(rightArm, 32, 180); + game.debug.renderSpriteInfo(leftLeg, 32, 325); + game.debug.renderSpriteInfo(rightLeg, 32, 470); + game.debug.renderSpriteInfo(rightLeg, 450, 30); + game.debug.renderSpriteInfo(rightLeg, 450, 180); + + game.debug.renderText('The robot is a group and every component is a sprite.', 240, 580); + game.debug.renderText('Drag each part to re-position them. ', 288, 592); + +} + diff --git a/examples/groups/group transform.php b/examples/groups/group transform.php deleted file mode 100644 index 8dec4ec6..00000000 --- a/examples/groups/group transform.php +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - diff --git a/examples/groups/recyling.js b/examples/groups/recyling.js new file mode 100644 index 00000000..4374543b --- /dev/null +++ b/examples/groups/recyling.js @@ -0,0 +1,62 @@ +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +var enemies; + +function preload() { + + game.load.image('baddie', 'assets/sprites/space-baddie.png'); + game.load.spritesheet('button', 'assets/buttons/baddie-buttons.png', 224, 70); + +} + +function create() { + + // Create a enemies group to store the baddies + enemies = game.add.group(); + + // Create some enemies. + for (var i = 0; i < 8; i++) + { + // Since the getFirstExists() which we'll use for recycling + // cannot allocate new objects, create them manually here. + enemies.create(360 + Math.random() * 200, 120 + Math.random() * 200, 'baddie'); + } + + // Create buttons to create and kill baddies. + game.add.button(16, 50, 'button', createBaddie,this, 0, 0, 0); + game.add.button(16, 130, 'button', killBaddie,this, 1, 1, 1); + +} + +function killBaddie() { + + var baddie = enemies.getFirstAlive(); + + if (baddie) + { + baddie.kill(); + } + +} + +function createBaddie() { + + // Recycle using getFirstExists(false) + // Notice that this method will not create new objects if there's no one + // available, and it won't change size of this group. + var enemy = enemies.getFirstExists(false); + + if (enemy) + { + enemy.revive(); + } + +} + +function render() { + + game.debug.renderText('Recycle baddies from a group using getFirstExists.', 16, 24); + game.debug.renderText('Notice that you cannot add more than 8 baddies since we only create 8 instance.', 16, 36); + game.debug.renderText('Living baddies: ' + (enemies.countLiving()), 340, 420); + +} diff --git a/examples/groups/recyling.php b/examples/groups/recyling.php deleted file mode 100644 index 4447503c..00000000 --- a/examples/groups/recyling.php +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - diff --git a/examples/groups/remove.js b/examples/groups/remove.js new file mode 100644 index 00000000..85ed08dd --- /dev/null +++ b/examples/groups/remove.js @@ -0,0 +1,64 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +var items; + +function preload() { + + game.load.spritesheet('item', 'assets/buttons/number-buttons-90x90.png', 90, 90); + game.load.image('rect', 'assets/tests/200x100corners.png'); +} + +function create() { + + // Create item container group. + items = game.add.group(); + + // Add some items and add them to the container group, + // then you can drag and drop them to remove. + var item; + + for (var i = 0; i < 6; i++) + { + // Directly create sprites from the group. + item = items.create(90, 90 * i, 'item', i); + // Enable input detection, then it's possible be dragged. + item.input.start(0,true); + // Make this item draggable. + item.input.enableDrag(); + // Then we make it snap to 90x90 grids. + item.input.enableSnap(90, 90, false, true); + // Add a handler to remove it using different options when dropped. + item.events.onDragStop.add(dropHandler); + } + + // Create a rectangle drop it at this rectangle to + // remove it from origin group normally or + // cut it from the group's array entirely. + var rect = game.add.sprite(390, 0, 'rect'); + rect.scale.setTo(2.0, 3.0); + +} + +function render() { + + game.debug.renderText('Size of group: ' + items.length, 100, 560); + game.debug.renderText('Drop here to cut items from groups entirely.', 390, 24); + +} + +function dropHandler(item, pointer) { + + if (item.x < 90) + { + item.x = 90; + } + else if (item.x > 400) + { + // So it is dropped in one rectangle. + // Remove it from group normally, so the group's size does not change. + items.remove(item); + console.log("Group length : "+items.length); + } + +} diff --git a/examples/groups/remove.php b/examples/groups/remove.php deleted file mode 100644 index afd9ce2e..00000000 --- a/examples/groups/remove.php +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - diff --git a/examples/groups/replace.js b/examples/groups/replace.js new file mode 100644 index 00000000..8fac9595 --- /dev/null +++ b/examples/groups/replace.js @@ -0,0 +1,76 @@ +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +// Left and right group. +var left +var right; + +// The first selected item. +var selected = null; + +function preload() { + game.load.spritesheet('item', 'assets/buttons/number-buttons-90x90.png', 90, 90); +} + +function create() { + + left = game.add.group(); + right = game.add.group(); + + // Add some items to left side, and set a onDragStop listener + // to limit its location when dropped. + var item; + + for (var i = 0; i < 3; i++) + { + // Directly create sprites from the left group. + item = left.create(290, 98 * (i + 1), 'item', i); + // Enable input. + item.input.start(0, false, true); + item.events.onInputUp.add(select); + // Add another to the right group. + item = right.create(388, 98 * (i + 1), 'item', i + 3); + // Enable input. + item.input.start(0,true); + item.events.onInputUp.add(select); + } +} + +function select(item, pointer) { + + // If there's no one selected, mark it as selected. + if (!selected) + { + selected = item; + selected.alpha = 0.5; + } + else + { + // Items from different group selected, replace with each other; + // Something like a swap action, maybe better done with + // group.swap() method. + if (selected.group !== item.group) + { + // Move the later selected to the first selected item's position. + item.x = selected.x; + item.y = selected.y; + // Replace first selected with the second one. + selected.group.replace(selected, item); + } + else + { + selected.alpha = 1; + } + + // After checking, now clear the helper var. + selected = null; + } + +} + +function render() { + + game.debug.renderText('Left Group', 300, 80); + game.debug.renderText('Right Group', 400, 80); + game.debug.renderText('Click an item and one from another group to replace it.', 240, 480); + +} diff --git a/examples/groups/replace.php b/examples/groups/replace.php deleted file mode 100644 index 6866d331..00000000 --- a/examples/groups/replace.php +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - diff --git a/examples/groups/set All.js b/examples/groups/set All.js new file mode 100644 index 00000000..bafcc3a7 --- /dev/null +++ b/examples/groups/set All.js @@ -0,0 +1,35 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +var baseIncSpeed= 0.006; + +function preload() { + game.load.spritesheet('item', 'assets/buttons/number-buttons-90x90.png', 90, 90); +} + +function create() { + + // Add some items. + for (var i = 0; i < 3; i++) + { + // Give the items a different alpha increase speed. + game.add.sprite(290, 98 * (i + 1), 'item', i).alphaIncSpeed = baseIncSpeed * (i + 1); + game.add.sprite(388, 98 * (i + 1), 'item', i + 3).alphaIncSpeed = baseIncSpeed * (i + 4); + } + + game.input.onTap.add(resetAlpha,this); + +} + +function resetAlpha() { + + // Set "alpha" value of all the childs. + game.world.setAll('alpha', Math.random()); + +} + +function render() { + + game.debug.renderText('Tap or click to set random alpha of all the items.', 240, 480); + +} diff --git a/examples/groups/set All.php b/examples/groups/set All.php deleted file mode 100644 index 6f0058f8..00000000 --- a/examples/groups/set All.php +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - diff --git a/examples/groups/sub groups - group length.js b/examples/groups/sub groups - group length.js new file mode 100644 index 00000000..0311b95d --- /dev/null +++ b/examples/groups/sub groups - group length.js @@ -0,0 +1,72 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +// Groups for storing friends and enemies, may use for collision later. +var friendAndFoe; +var enemies; + +// Groups for teaming up stuff. +var normalBaddies; +var purpleBaddies; + +function preload() { + + game.load.image('ufo', 'assets/sprites/ufo.png'); + game.load.image('baddie', 'assets/sprites/space-baddie.png'); + game.load.image('purple-baddie', 'assets/sprites/space-baddie-purple.png'); + +} + +function create() { + + // Create some local groups for later use. + friendAndFoe = game.add.group(); + enemies = game.add.group(); + normalBaddies = game.add.group(); + purpleBaddies = game.add.group(); + + // Add both teams to enemies group, using the Pixi container otherwise it's impossible + enemies.add(normalBaddies._container); + enemies.add(purpleBaddies._container); + + + // Create a ufo as a friend sprite. + friendAndFoe.create(200, 240, 'ufo'); + + // Create some enemies. + for (var i = 0; i < 16; i++) + { + createBaddie(); + } + + // Tap to create new baddie sprites. + game.input.onTap.add(createBaddie, this); + +} + +function createBaddie() { + + var baddie; + + // Of course, the baddies created will belong to their respective groups + if (Math.random() > 0.5) + { + baddie = purpleBaddies.create(360 + Math.random() * 200, 120 + Math.random() * 200, 'purple-baddie'); + } + else + { + baddie = normalBaddies.create(360 + Math.random() * 200, 120 + Math.random() * 200, 'baddie'); + } + +} + +function render() { + + game.debug.renderStyle = '#fff'; + game.debug.renderText('Tap screen or click to create new baddies.', 16, 24); + game.debug.renderText('enemies: ' + enemies.length + ' (actually ' + enemies.length + ' groups)', 16, 48); + game.debug.renderText('normal baddies: ' + normalBaddies.length, 16, 60); + game.debug.renderText('purple baddies: ' + purpleBaddies.length, 16, 72); + game.debug.renderText('friends: ' + friendAndFoe.length, 16, 96); + +} diff --git a/examples/groups/sub groups - group length.php b/examples/groups/sub groups - group length.php deleted file mode 100644 index 717d7018..00000000 --- a/examples/groups/sub groups - group length.php +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - diff --git a/examples/groups/swap children in a group.js b/examples/groups/swap children in a group.js new file mode 100644 index 00000000..115c359e --- /dev/null +++ b/examples/groups/swap children in a group.js @@ -0,0 +1,35 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +function preload() { + + game.load.image('atari1', 'assets/sprites/atari130xe.png'); + game.load.image('atari2', 'assets/sprites/atari800xl.png'); + +} + +var atari1; +var atari2; + +function create() { + + // Items are rendered in the depth order in which they are added to the Group + atari1 = game.add.sprite(100, 100, 'atari1'); + atari2 = game.add.sprite(250, 90, 'atari2'); + + game.input.onTap.add(swapSprites, this); + +} + +function swapSprites() { + + //The 2 Sprites are in the global world Group (World class extends the Group class), but this will work for any Group: + game.world.swap(atari1, atari2); + +} + +function render () { + + game.debug.renderText('Tap screen to swap the children and therefore swap their indexes.', 10, 280); + +} diff --git a/examples/groups/swap children in a group.php b/examples/groups/swap children in a group.php deleted file mode 100644 index e2ce0adf..00000000 --- a/examples/groups/swap children in a group.php +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - diff --git a/examples/head.php b/examples/head.php deleted file mode 100644 index b401c577..00000000 --- a/examples/head.php +++ /dev/null @@ -1,21 +0,0 @@ - - - - - phaser - <?php echo $title?> - - '; - } - - if (isset($css)) - { - echo " "; - } - ?> - - diff --git a/examples/head_live.php b/examples/head_live.php deleted file mode 100644 index 86b20af8..00000000 --- a/examples/head_live.php +++ /dev/null @@ -1,8 +0,0 @@ - - - - - phaser - <?php echo $title?> - - - diff --git a/examples/html/img/screenshot.jpg b/examples/html/img/screenshot.jpg deleted file mode 100644 index da010c1d..00000000 Binary files a/examples/html/img/screenshot.jpg and /dev/null differ diff --git a/examples/index.php b/examples/index.php index c75b50b2..4c15fd2a 100644 --- a/examples/index.php +++ b/examples/index.php @@ -1,63 +1,19 @@ $value) - { - if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) - { - $result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value); - } - else - { - if (substr($value, -4) == '.php') - { - $result[] = $value; - } - } - } - - return $result; - } - - function printJSLinks($dir, $files) { - - foreach ($files as $key => $value) - { - $value2 = substr($value, 0, -4); - echo "
  • $value2
  • \n"; - } - - } - - $files = dirToArray(dirname(__FILE__)); - $total = 0; - - foreach ($files as $key => $value) - { - if (is_array($value) && count($value) > 0) - { - $total += count($value); - } - } + require('funcs.php'); ?> - - + +
    - Phaser Version: 1.0.6 - Update to 1.1 + Phaser Version: 1.1 +
    @@ -113,7 +69,7 @@