Final release 1.1.4 examples finished.

This commit is contained in:
photonstorm
2014-02-05 16:54:35 +00:00
parent 02b75b9e23
commit e7a9b96d27
26 changed files with 2338 additions and 936 deletions
+20 -4
View File
@@ -41,6 +41,10 @@
{
"file": "play+music.js",
"title": "play music"
},
{
"file": "protracker.js",
"title": "protracker"
}
],
"basics": [
@@ -142,6 +146,10 @@
"file": "offset+bounding+box.js",
"title": "offset bounding box"
},
{
"file": "one+way+collision.js",
"title": "one way collision"
},
{
"file": "polygon+body.js",
"title": "polygon body"
@@ -281,10 +289,6 @@
{
"file": "tanks.js",
"title": "tanks"
},
{
"file": "wabbits.js",
"title": "wabbits"
}
],
"geometry": [
@@ -322,6 +326,10 @@
"file": "bring+a+group+to+top.js",
"title": "bring a group to top"
},
{
"file": "call+all+animations.js",
"title": "call all animations"
},
{
"file": "call+all.js",
"title": "call all"
@@ -676,6 +684,10 @@
"file": "quadtree+-+ids.js",
"title": "quadtree - ids"
},
{
"file": "ship+trail.js",
"title": "ship trail"
},
{
"file": "shoot+the+pointer.js",
"title": "shoot the pointer"
@@ -792,6 +804,10 @@
}
],
"tilemaps": [
{
"file": "create+from+objects.js",
"title": "create from objects"
},
{
"file": "fill+tiles.js",
"title": "fill tiles"
File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B

+206
View File
@@ -0,0 +1,206 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.script('protracker', '../plugins/ProTracker.js');
game.load.image('vu', 'assets/sprites/vu.png');
game.load.image('logo', 'assets/sprites/soundtracker.png');
game.load.image('bg', 'assets/skies/sky2.png');
game.load.image('vulkaiser', 'assets/pics/vulkaiser_red.png');
game.load.binary('macrocosm', 'assets/audio/protracker/macrocosm.mod', modLoaded, this);
game.load.binary('impulse', 'assets/audio/protracker/act_of_impulse.mod', modLoaded, this);
game.load.binary('enigma', 'assets/audio/protracker/enigma.mod', modLoaded, this);
game.load.binary('elysium', 'assets/audio/protracker/elysium.mod', modLoaded, this);
game.load.binary('stardust', 'assets/audio/protracker/sd-ingame1.mod', modLoaded, this);
game.load.binary('globaltrash', 'assets/audio/protracker/global_trash_3_v2.mod', modLoaded, this);
}
function modLoaded(key, data) {
mods.push(key);
var buffer = new Uint8Array(data);
return buffer;
}
var mods = [];
var current = 0;
var vu1;
var vu2;
var vu3;
var vu4;
var modsample = [];
var module;
var sample1;
var sample2;
var sample3;
var sample4;
var sampleName1;
var sampleName2;
var sampleName3;
var sampleName4;
function create() {
game.add.sprite(0, 0, 'bg');
game.add.sprite(500, 32, 'logo');
game.add.sprite(580, 371, 'vulkaiser');
vu1 = game.add.sprite(400, 200, 'vu');
vu2 = game.add.sprite(400, 250, 'vu');
vu3 = game.add.sprite(400, 300, 'vu');
vu4 = game.add.sprite(400, 350, 'vu');
vu1.width = 0;
vu2.width = 0;
vu3.width = 0;
vu4.width = 0;
module = new Protracker();
module.buffer = game.cache.getBinary('macrocosm');
module.parse();
module.play();
game.input.onDown.add(nextMod, this);
}
function nextMod() {
current++;
if (current > mods.length - 1)
{
current = 0;
}
module.stop();
module.clearsong();
module.buffer = game.cache.getBinary(mods[current]);
module.parse();
module.play();
vu1.width = 0;
vu2.width = 0;
vu3.width = 0;
vu4.width = 0;
}
function update() {
sampleName1 = '';
sampleName2 = '';
sampleName3 = '';
sampleName4 = '';
sample1 = module.channel[0].sample;
sample2 = module.channel[1].sample;
sample3 = module.channel[2].sample;
sample4 = module.channel[3].sample;
/*
module.sample = array of Objects containing:
data (Float32Array)
finetime
length (ms? bytes?)
looplength
loopstart
name
volume
arpeggio: 0
command: 0
data: 0
flags: 0
note: 22
noteon: 1
period: 240
sample: 11
samplepos: 314.3411880952386
samplespeed: 0.335118537414966
semitone: 14
slidespeed: 0
slideto: 214
slidetospeed: 0
vibratodepth: 0
vibratopos: 0
vibratospeed: 0
vibratowave: 0
voiceperiod: 240
volume: 64
*/
if (module.sample[sample1])
{
sampleName1 = module.sample[sample1].name;
}
if (module.sample[sample2])
{
sampleName2 = module.sample[sample2].name;
}
if (module.sample[sample3])
{
sampleName3 = module.sample[sample3].name;
}
if (module.sample[sample4])
{
sampleName4 = module.sample[sample4].name;
}
if (module.vu[0])
{
vu1.width = Math.round(module.vu[0] * 1200);
}
if (module.vu[1])
{
vu2.width = Math.round(module.vu[1] * 1200);
}
if (module.vu[2])
{
vu3.width = Math.round(module.vu[2] * 1200);
}
if (module.vu[3])
{
vu4.width = Math.round(module.vu[3] * 1200);
}
}
function render() {
game.debug.renderText('Sample ' + sample1 + ' : ' + sampleName1, 16, 32);
game.debug.renderText('Sample ' + sample2 + ' : ' + sampleName2, 16, 64);
game.debug.renderText('Sample ' + sample3 + ' : ' + sampleName3, 16, 96);
game.debug.renderText('Sample ' + sample4 + ' : ' + sampleName4, 16, 128);
game.debug.renderText('Position: ' + module.position, 16, 160);
game.debug.renderText('Pattern: ' + module.row, 16, 192);
game.debug.renderText('BPM: ' + module.bpm, 16, 224);
game.debug.renderText('Speed: ' + module.speed, 16, 256);
game.debug.renderText('Name: ' + module.title, 16, 288);
game.debug.renderText('Signature: ' + module.signature, 16, 320);
game.debug.renderText('vu1: ' + module.vu[0], 16, 352);
game.debug.renderText('vu2: ' + module.vu[1], 16, 384);
game.debug.renderText('vu3: ' + module.vu[2], 16, 416);
game.debug.renderText('vu4: ' + module.vu[3], 16, 448);
}
+2 -2
View File
@@ -26,14 +26,14 @@ function create() {
sprite2.name = 'yellow';
sprite2.body.rebound = false;
sprite2.body.velocity.x = -200;
game.add.tween(sprite.scale).to( { x: 3, y: 3 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
}
function update() {
sprite2.body.velocity.x = -200;
game.physics.collide(sprite, sprite2);
}
+58
View File
@@ -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.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
game.load.image('atari', 'assets/sprites/atari130xe.png');
}
var sprite;
var sprite2;
var sprite3;
function create() {
game.stage.backgroundColor = '#124184';
// In this example the little Gameboy sprite can pass through the top/bottom of the Atari sprite
// Because it's set to ignore collisions on its top/bottom faces.
sprite = game.add.sprite(300, 200, 'atari');
sprite.name = 'atari';
sprite.body.collideWorldBounds = true;
sprite.body.checkCollision.up = false;
sprite.body.checkCollision.down = false;
sprite.body.immovable = true;
sprite2 = game.add.sprite(350, 400, 'gameboy', 2);
sprite2.name = 'gameboy';
sprite2.body.collideWorldBounds = true;
sprite2.body.bounce.setTo(1, 1);
sprite3 = game.add.sprite(0, 210, 'gameboy', 4);
sprite3.name = 'gameboy2';
sprite3.body.collideWorldBounds = true;
sprite3.body.bounce.setTo(1, 1);
sprite2.body.velocity.y = -200;
sprite3.body.velocity.x = 200;
}
function update() {
game.physics.collide(sprite, sprite2);
game.physics.collide(sprite, sprite3);
}
function render() {
// game.debug.renderBodyInfo(sprite, 16, 24);
game.debug.renderPhysicsBody(sprite.body);
game.debug.renderPhysicsBody(sprite2.body);
}
+1
View File
@@ -35,6 +35,7 @@ function create() {
// Here we'll create some chillis which the player can pick-up. They are still part of the same Group.
var c = group.create(game.rnd.integerInRange(100, 770), game.rnd.integerInRange(0, 570), 'veggies', 17);
c.name = 'chilli' + i;
c.body.immovable = true;
}
cursors = game.input.keyboard.createCursorKeys();
+155
View File
@@ -0,0 +1,155 @@
<?php
$files = dirToArray(dirname(__FILE__));
$total = 0;
foreach ($files as $key => $value)
{
if (is_array($value) && count($value) > 0)
{
$total += count($value);
}
}
function dirToArray($dir) {
$ignore = array('.', '..', '_site', 'assets', 'states', 'book', 'filters');
$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($section) {
global $files;
$output = "";
if ($section)
{
$tempFiles = $files[$section];
}
else
{
$tempFiles = $files;
}
foreach ($tempFiles as $key => $value)
{
if (is_array($value))
{
$output .= "<optgroup label=\"$key\">";
$output .= printJSLinks($key);
$output .= "</optgroup>";
}
else
{
$value2 = substr($value, 0, -3);
$file = urlencode($value);
$output .= "<option value=\"$section/$file\">$value2</option>";
}
}
return $output;
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>phaser</title>
<script src="_site/js/jquery-2.0.3.min.js" type="text/javascript"></script>
<?php
require('../build/config.php');
?>
<style>
body {
font-family: Arial;
font-size: 14px;
}
input {
font-size: 18px;
}
</style>
</head>
<body>
<div id="phaser-example"></div>
<input type="button" id="start" value="start" />
<input type="button" id="stop" value="stop" style="margin-left: 32px" />
<input type="button" id="step" value="step" style="margin-left: 128px"/>
<h2>Debug</h2>
<select id="filelist">
<?php
echo printJSLinks(false);
?>
</select>
<script type="text/javascript">
$("#filelist").change(function() {
window.location.href = 'debug.php?f=' + $("#filelist").val();
});
var debugSprite = null;
<?php
if (isset($_GET['f']))
{
$src = file_get_contents($_GET['f']);
echo $src;
}
?>
$('#step').click(function(){
console.log('---- STEP', game.stepCount, '-------------------------------');
game.step();
});
$('#start').click(function(){
console.log('---- START DEBUGGING -------------------------------');
game.enableStep();
if (debugSprite)
{
debugSprite.debug = true;
}
});
$('#stop').click(function(){
console.log('---- STOP DEBUGGING -------------------------------');
game.disableStep();
if (debugSprite)
{
debugSprite.debug = false;
}
});
</script>
</body>
</html>
+2 -2
View File
@@ -155,8 +155,8 @@ function update() {
}
// Run collision
game.physics.collide(bullets, aliens, collisionHandler, null, this);
game.physics.collide(enemyBullets, player, enemyHitsPlayer, null, this);
game.physics.overlap(bullets, aliens, collisionHandler, null, this);
game.physics.overlap(enemyBullets, player, enemyHitsPlayer, null, this);
}
+29
View File
@@ -0,0 +1,29 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.spritesheet('coin', 'assets/sprites/coin.png', 32, 32);
}
var coins;
function create() {
// Here we create our coins group
coins = game.add.group();
// Now let's add 50 coins into it
for (var i = 0; i < 50; i++)
{
coins.create(game.world.randomX, game.world.randomY, 'coin', 0);
}
// Now using the power of callAll we can add the same animation to all coins in the group:
coins.callAll('animations.add', 'animations', 'spin', [0, 1, 2, 3, 4, 5], 10, true);
// And play them
coins.callAll('animations.play', 'animations', 'spin');
}
+65
View File
@@ -0,0 +1,65 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('chunk', 'assets/sprites/chunk.png');
game.load.image('arrow', 'assets/sprites/asteroids_ship.png');
}
var sprite;
var bmd;
function create() {
// Click on the left or right of the game to shoot the space ship in that direction
game.stage.backgroundColor = '#124184';
bmd = game.add.bitmapData(800, 600);
bmd.fillStyle('#ffffff');
var bg = game.add.sprite(0, 0, bmd);
bg.body.moves = false;
game.physics.gravity.y = 100;
sprite = game.add.sprite(32, 450, 'arrow');
sprite.anchor.setTo(0.5, 0.5);
sprite.body.collideWorldBounds = true;
sprite.body.bounce.setTo(0.8, 0.8);
sprite.body.linearDamping = 0.1;
game.input.onDown.add(launch, this);
}
function launch() {
if (game.input.x < 400)
{
sprite.body.velocity.setTo(-200, -200);
}
else
{
sprite.body.velocity.setTo(200, -200);
}
}
function update() {
sprite.rotation = sprite.body.angle;
bmd.fillStyle('#ffff00');
bmd.fillRect(sprite.x, sprite.y, 2, 2);
}
function render() {
game.debug.renderBodyInfo(sprite, 16, 24);
}
+104
View File
@@ -0,0 +1,104 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.tilemap('map', 'assets/tilemaps/maps/features_test.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png');
game.load.image('walls_1x2', 'assets/tilemaps/tiles/walls_1x2.png');
game.load.image('tiles2', 'assets/tilemaps/tiles/tiles2.png');
game.load.image('phaser', 'assets/sprites/arrow.png');
game.load.spritesheet('coin', 'assets/sprites/coin.png', 32, 32);
}
var cursors;
var map;
var coins;
var layer;
var sprite;
function create() {
map = game.add.tilemap('map');
map.addTilesetImage('ground_1x1');
map.addTilesetImage('walls_1x2');
map.addTilesetImage('tiles2');
map.setCollisionBetween(1, 12);
layer = map.createLayer('Tile Layer 1');
// layer.debug = true;
layer.resizeWorld();
// Here we create our coins group
coins = game.add.group();
// And now we convert all of the Tiled objects with an ID of 34 into sprites within the coins group
map.createFromObjects('Object Layer 1', 34, 'coin', 0, true, false, coins);
// Add animations to all of the coin sprites
coins.callAll('animations.add', 'animations', 'spin', [0, 1, 2, 3, 4, 5], 10, true);
coins.callAll('animations.play', 'animations', 'spin');
sprite = game.add.sprite(260, 100, 'phaser');
sprite.anchor.setTo(0.5, 0.5);
// This adjusts the collision body size.
sprite.body.setRectangle(16, 16, 25, 15);
// We'll set a lower max angular velocity here to keep it from going totally nuts
sprite.body.maxAngular = 500;
// Apply a drag otherwise the sprite will just spin and never slow down
sprite.body.angularDrag = 50;
game.camera.follow(sprite);
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
game.physics.collide(sprite, layer);
game.physics.overlap(sprite, coins, collectCoin, null, this);
sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
sprite.body.angularVelocity = 0;
if (cursors.left.isDown)
{
sprite.body.angularVelocity = -300;
}
else if (cursors.right.isDown)
{
sprite.body.angularVelocity = 300;
}
if (cursors.up.isDown)
{
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
}
}
function collectCoin(player, coin) {
coin.kill();
}
function render() {
game.debug.renderPhysicsBody(sprite.body);
}
+2 -2
View File
@@ -60,7 +60,7 @@ function update() {
if (cursors.up.isDown)
{
if (p.body.touching.down)
if (p.body.onFloor())
{
p.body.velocity.y = -200;
}
@@ -80,6 +80,6 @@ function update() {
function render() {
game.debug.renderCameraInfo(game.camera, 420, 320);
game.debug.renderSpriteCollision(p, 32, 320);
game.debug.renderPhysicsBody(p.body);
}
+9 -8
View File
@@ -32,17 +32,16 @@ function create() {
layer = map.createLayer('Tile Layer 1');
layer.debug = true;
// layer.debug = true;
layer.resizeWorld();
game.physics.gravity.y = 100;
sprite = game.add.sprite(260, 100, 'phaser');
sprite.anchor.setTo(0.5, 0.5);
sprite.body.setSize(16, 16, 8, 8);
sprite.body.setRectangle(16, 16, 8, 8);
// We'll set a lower max angular velocity here to keep it from going totally nuts
sprite.body.maxAngular = 500;
@@ -50,8 +49,10 @@ function create() {
// Apply a drag otherwise the sprite will just spin and never slow down
sprite.body.angularDrag = 50;
sprite.body.bounce.x = 0.8;
sprite.body.bounce.y = 0.8;
// sprite.body.bounce.x = 0.8;
// sprite.body.bounce.y = 0.8;
debugSprite = sprite;
game.camera.follow(sprite);
@@ -95,7 +96,7 @@ function update() {
function render() {
// game.debug.renderSpriteBody(sprite);
game.debug.renderSpriteBounds(sprite);
// game.debug.renderBodyInfo(sprite, 16, 24);
// game.debug.renderPhysicsBody(sprite.body);
}
+9 -28
View File
@@ -22,42 +22,28 @@ function create() {
game.physics.gravity.y = 100;
// sprite = game.add.sprite(732, 0, 'chunk');
// sprite = game.add.sprite(32, 450, 'chunk');
sprite = game.add.sprite(32, 450, 'arrow');
sprite.anchor.setTo(0.5, 0.5);
sprite.body.collideWorldBounds = true;
// sprite.body.bounce.setTo(0.5, 0.5);
sprite.body.bounce.setTo(0.8, 0.8);
//sprite.body.drag.setTo(0, -20);
// sprite.body.drag.setTo(10, 10);
sprite.body.linearDamping = 0.1;
// sprite.body.sleepMin.setTo(-50, -20);
// sprite.body.sleepMax.setTo(50, 20);
// sprite.body.sleepDuration = 1000;
sprite.body.sleepMin.setTo(-5, -5);
sprite.body.sleepMax.setTo(5, 5);
sprite.body.sleepDuration = 500;
// sprite.body.canSleep = false;
game.input.onDown.add(launch, this);
}
function launch() {
// up and to the right
sprite.body.velocity.setTo(200, -300);
// sprite.body.velocity.setTo(-100, 300);
// sprite.body.gravity.setTo(0, -100);
// sprite.body.gravity.setTo(0, -100);
if (game.input.x < 400)
{
sprite.body.velocity.setTo(-200, -200);
}
else
{
sprite.body.velocity.setTo(200, -200);
}
}
@@ -65,14 +51,9 @@ function update() {
sprite.rotation = sprite.body.angle;
// console.log(sprite.body.velocity.x);
bmd.fillStyle('#ffffff');
bmd.fillStyle('#ffff00');
bmd.fillRect(sprite.x, sprite.y, 2, 2);
// bmd.fillStyle('#ff0000');
// bmd.fillRect(sprite.body.x, sprite.body.y, 2, 2);
}
function render() {
@@ -26,7 +26,7 @@ var wabbitCount = 0;
function create() {
// set global gravity
game.physics.gravity.setTo(0, 4);
game.physics.gravity.y = 200;
game.stage.backgroundColor = '#0072bc';
@@ -72,7 +72,8 @@ function create() {
ball.inputEnabled = true;
ball.body.collideWorldBounds = true;
ball.body.bounce.setTo(0.9, 0.9);
ball.body..friction = 0.2;
ball.body.linearDamping = 0.2;
ball.body.immovable = true;
// Enable input.
ball.input.start(0, true);
@@ -143,13 +144,13 @@ function update() {
wabbitCount = 5 - wabs;
console.log(ball.body.y, ball.body.motionVelocity.y);
// console.log(ball.body.y, ball.body.motionVelocity.y);
}
function render() {
game.debug.renderSpriteCollision(ball, 32, 32);
// game.debug.renderSpriteCollision(ball, 32, 32);
// var graphics = game.add.graphics(0, 0);
// game.context.fillStyle = 'rgba(0,0,255,0.5)';