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
-1
View File
@@ -147,7 +147,6 @@ New Examples:
* Input - Touch Joystick example showing how to use the clay.io virtual game controller (thanks gabehollombe)
* Games - Matching Pairs by Patrick OReilly.
* Games - Simon Says by Patrick OReilly.
* Games - Wabbits by Patrick OReilly.
* Tweens - Example showing how to use the tween events, onStart, onLoop and onComplete.
* Display - Pixi Render Texture. A Phaser conversion of the Pixi.js Render Texture example.
* Input - 5 new examples showing how to use the Gamepad API (thanks Karl Macklin)
+3
View File
@@ -1,4 +1,7 @@
<?php
// NOTE: This script is deprecated. The build process is managed by grunt now.
// Keeping this file here for those that I know use it, but if you're trying to build fresh, use grunt.
date_default_timezone_set('Europe/London');
// Get the version number
+82 -82
View File
@@ -1,12 +1,12 @@
<?php
// All JS files in build order.
// Much easier for debugging re: line numbers
if (!isset($path))
{
$path = '..';
}
// All JS files in build order.
// Much easier for debugging re: line numbers
if (!isset($path))
{
$path = '..';
}
echo <<<EOL
echo <<<EOL
<script src="$path/src/Intro.js"></script>
<script src="$path/src/pixi/Pixi.js"></script>
@@ -55,97 +55,97 @@
<script src="$path/src/pixi/utils/EventTarget.js"></script>
<script src="$path/src/pixi/utils/Polyk.js"></script>
<script src="$path/src/core/Camera.js"></script>
<script src="$path/src/core/State.js"></script>
<script src="$path/src/core/StateManager.js"></script>
<script src="$path/src/core/LinkedList.js"></script>
<script src="$path/src/core/Signal.js"></script>
<script src="$path/src/core/SignalBinding.js"></script>
<script src="$path/src/core/Filter.js"></script>
<script src="$path/src/core/Plugin.js"></script>
<script src="$path/src/core/PluginManager.js"></script>
<script src="$path/src/core/Stage.js"></script>
<script src="$path/src/core/Group.js"></script>
<script src="$path/src/core/World.js"></script>
<script src="$path/src/core/Game.js"></script>
<script src="$path/src/core/Camera.js"></script>
<script src="$path/src/core/State.js"></script>
<script src="$path/src/core/StateManager.js"></script>
<script src="$path/src/core/LinkedList.js"></script>
<script src="$path/src/core/Signal.js"></script>
<script src="$path/src/core/SignalBinding.js"></script>
<script src="$path/src/core/Filter.js"></script>
<script src="$path/src/core/Plugin.js"></script>
<script src="$path/src/core/PluginManager.js"></script>
<script src="$path/src/core/Stage.js"></script>
<script src="$path/src/core/Group.js"></script>
<script src="$path/src/core/World.js"></script>
<script src="$path/src/core/Game.js"></script>
<script src="$path/src/input/Input.js"></script>
<script src="$path/src/input/Key.js"></script>
<script src="$path/src/input/Keyboard.js"></script>
<script src="$path/src/input/Mouse.js"></script>
<script src="$path/src/input/MSPointer.js"></script>
<script src="$path/src/input/Pointer.js"></script>
<script src="$path/src/input/Touch.js"></script>
<script src="$path/src/input/Gamepad.js"></script>
<script src="$path/src/input/Input.js"></script>
<script src="$path/src/input/Key.js"></script>
<script src="$path/src/input/Keyboard.js"></script>
<script src="$path/src/input/Mouse.js"></script>
<script src="$path/src/input/MSPointer.js"></script>
<script src="$path/src/input/Pointer.js"></script>
<script src="$path/src/input/Touch.js"></script>
<script src="$path/src/input/Gamepad.js"></script>
<script src="$path/src/input/SinglePad.js"></script>
<script src="$path/src/input/GamepadButton.js"></script>
<script src="$path/src/input/InputHandler.js"></script>
<script src="$path/src/input/InputHandler.js"></script>
<script src="$path/src/gameobjects/Events.js"></script>
<script src="$path/src/gameobjects/GameObjectFactory.js"></script>
<script src="$path/src/gameobjects/BitmapData.js"></script>
<script src="$path/src/gameobjects/Sprite.js"></script>
<script src="$path/src/gameobjects/TileSprite.js"></script>
<script src="$path/src/gameobjects/Text.js"></script>
<script src="$path/src/gameobjects/BitmapText.js"></script>
<script src="$path/src/gameobjects/Button.js"></script>
<script src="$path/src/gameobjects/Graphics.js"></script>
<script src="$path/src/gameobjects/RenderTexture.js"></script>
<script src="$path/src/gameobjects/Events.js"></script>
<script src="$path/src/gameobjects/GameObjectFactory.js"></script>
<script src="$path/src/gameobjects/BitmapData.js"></script>
<script src="$path/src/gameobjects/Sprite.js"></script>
<script src="$path/src/gameobjects/TileSprite.js"></script>
<script src="$path/src/gameobjects/Text.js"></script>
<script src="$path/src/gameobjects/BitmapText.js"></script>
<script src="$path/src/gameobjects/Button.js"></script>
<script src="$path/src/gameobjects/Graphics.js"></script>
<script src="$path/src/gameobjects/RenderTexture.js"></script>
<script src="$path/src/system/Canvas.js"></script>
<script src="$path/src/system/StageScaleMode.js"></script>
<script src="$path/src/system/Device.js"></script>
<script src="$path/src/system/RequestAnimationFrame.js"></script>
<script src="$path/src/system/Canvas.js"></script>
<script src="$path/src/system/StageScaleMode.js"></script>
<script src="$path/src/system/Device.js"></script>
<script src="$path/src/system/RequestAnimationFrame.js"></script>
<script src="$path/src/math/RandomDataGenerator.js"></script>
<script src="$path/src/math/Math.js"></script>
<script src="$path/src/math/QuadTree.js"></script>
<script src="$path/src/math/RandomDataGenerator.js"></script>
<script src="$path/src/math/Math.js"></script>
<script src="$path/src/math/QuadTree.js"></script>
<script src="$path/src/geom/Circle.js"></script>
<script src="$path/src/geom/Point.js"></script>
<script src="$path/src/geom/Rectangle.js"></script>
<script src="$path/src/geom/Line.js"></script>
<script src="$path/src/geom/Circle.js"></script>
<script src="$path/src/geom/Point.js"></script>
<script src="$path/src/geom/Rectangle.js"></script>
<script src="$path/src/geom/Line.js"></script>
<script src="$path/src/net/Net.js"></script>
<script src="$path/src/net/Net.js"></script>
<script src="$path/src/tween/TweenManager.js"></script>
<script src="$path/src/tween/Tween.js"></script>
<script src="$path/src/tween/Easing.js"></script>
<script src="$path/src/tween/TweenManager.js"></script>
<script src="$path/src/tween/Tween.js"></script>
<script src="$path/src/tween/Easing.js"></script>
<script src="$path/src/time/Time.js"></script>
<script src="$path/src/time/Timer.js"></script>
<script src="$path/src/time/TimerEvent.js"></script>
<script src="$path/src/time/Time.js"></script>
<script src="$path/src/time/Timer.js"></script>
<script src="$path/src/time/TimerEvent.js"></script>
<script src="$path/src/animation/AnimationManager.js"></script>
<script src="$path/src/animation/Animation.js"></script>
<script src="$path/src/animation/Frame.js"></script>
<script src="$path/src/animation/FrameData.js"></script>
<script src="$path/src/animation/AnimationParser.js"></script>
<script src="$path/src/animation/AnimationManager.js"></script>
<script src="$path/src/animation/Animation.js"></script>
<script src="$path/src/animation/Frame.js"></script>
<script src="$path/src/animation/FrameData.js"></script>
<script src="$path/src/animation/AnimationParser.js"></script>
<script src="$path/src/loader/Cache.js"></script>
<script src="$path/src/loader/Loader.js"></script>
<script src="$path/src/loader/LoaderParser.js"></script>
<script src="$path/src/loader/Cache.js"></script>
<script src="$path/src/loader/Loader.js"></script>
<script src="$path/src/loader/LoaderParser.js"></script>
<script src="$path/src/sound/Sound.js"></script>
<script src="$path/src/sound/SoundManager.js"></script>
<script src="$path/src/sound/Sound.js"></script>
<script src="$path/src/sound/SoundManager.js"></script>
<script src="$path/src/utils/Debug.js"></script>
<script src="$path/src/utils/Color.js"></script>
<script src="$path/src/utils/Debug.js"></script>
<script src="$path/src/utils/Color.js"></script>
<script src="$path/src/physics/arcade/SAT.js"></script>
<script src="$path/src/physics/arcade/ArcadePhysics.js"></script>
<script src="$path/src/physics/arcade/Body.js"></script>
<script src="$path/src/physics/arcade/SAT.js"></script>
<script src="$path/src/physics/arcade/ArcadePhysics.js"></script>
<script src="$path/src/physics/arcade/Body.js"></script>
<script src="$path/src/particles/Particles.js"></script>
<script src="$path/src/particles/arcade/ArcadeParticles.js"></script>
<script src="$path/src/particles/arcade/Emitter.js"></script>
<script src="$path/src/particles/Particles.js"></script>
<script src="$path/src/particles/arcade/ArcadeParticles.js"></script>
<script src="$path/src/particles/arcade/Emitter.js"></script>
<script src="$path/src/tilemap/Tile.js"></script>
<script src="$path/src/tilemap/Tilemap.js"></script>
<script src="$path/src/tilemap/TilemapLayer.js"></script>
<script src="$path/src/tilemap/TilemapParser.js"></script>
<script src="$path/src/tilemap/Tileset.js"></script>
<script src="$path/src/PixiPatch.js"></script>
<script src="$path/src/tilemap/Tile.js"></script>
<script src="$path/src/tilemap/Tilemap.js"></script>
<script src="$path/src/tilemap/TilemapLayer.js"></script>
<script src="$path/src/tilemap/TilemapParser.js"></script>
<script src="$path/src/tilemap/Tileset.js"></script>
<script src="$path/src/PixiPatch.js"></script>
EOL;
?>
+630 -782
View File
File diff suppressed because it is too large Load Diff
+9 -9
View File
File diff suppressed because one or more lines are too long
+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)';
+913
View File
@@ -0,0 +1,913 @@
/*
amiga protracker module player for web audio api
(c) 2012-2013 firehawk/tda (firehawk@haxor.fi)
originally hacked together in a weekend, so please excuse
me for the spaghetti code. :)
AMIGAAAAAAAAH!!
kinda sorta changelog:
(apr 2013)
- changed the logic for pattern break/jump. mod.pattern_skank now
plays correctly.
(feb 2013)
- fixed NaN samples with mod.fractured and mod.multicolour (thanks Aegis!)
(jan 2013)
- fixed vibrato amplitude (was half of what it should be, apparently)
- fixed to work on safari again (thanks Matt Diamond @ stackoverflow.com)
(dec 2012)
- replaced effect switch-statement with jumptables
- fixed clicks (bad loops, empty samples)
- fixed playback bug with sample-only rows
- added amiga 500 lowpass filters (not 100% authentic, though)
- added compressor to output
- latest safari has broken web audio so chrome-only for now
(aug 2012)
- first version written from scratch
todo:
- safari on ipad is broken again, it seems
- fix more playback bugs
* mod.black_queen (pattern loop has glitches)
- properly test EEx delay pattern
- implement the rest of the effects
- optimize for more speed!! SPEEEED!!
* switch to fixed point sample pointers, Math.floor() is _slow_ on iOS
*/
// constructor for protracker player object
function Protracker()
{
var i, t;
this.initialize();
this.clearsong();
this.url="";
this.loading=false;
this.ready=false;
this.playing=false;
this.buffer=0;
this.mixerNode=0;
this.paused=false;
this.repeat=false;
this.separation=true;
this.palclock=true;
this.autostart=false;
this.onReady=function(){};
this.onPlay=function(){};
this.onStop=function(){};
// paula period values
this.baseperiodtable=new Array(
856,808,762,720,678,640,604,570,538,508,480,453,
428,404,381,360,339,320,302,285,269,254,240,226,
214,202,190,180,170,160,151,143,135,127,120,113);
// finetune multipliers
this.finetunetable=new Array();
for(t=0;t<16;t++) this.finetunetable[t]=Math.pow(2, (t-8)/12/8);
// calc tables for vibrato waveforms
this.vibratotable=new Array();
for(t=0;t<4;t++) {
this.vibratotable[t]=new Array();
for(i=0;i<64;i++) {
switch(t) {
case 0:
this.vibratotable[t][i]=127*Math.sin(Math.PI*2*(i/64));
break;
case 1:
this.vibratotable[t][i]=127-4*i;
break;
case 2:
this.vibratotable[t][i]=(i<32)?127:-127;
break;
case 3:
this.vibratotable[t][i]=(1-2*Math.random())*127;
break;
}
}
}
// effect jumptables
this.effects_t0 = new Array(
this.effect_t0_0, this.effect_t0_1, this.effect_t0_2, this.effect_t0_3, this.effect_t0_4, this.effect_t0_5, this.effect_t0_6, this.effect_t0_7,
this.effect_t0_8, this.effect_t0_9, this.effect_t0_a, this.effect_t0_b, this.effect_t0_c, this.effect_t0_d, this.effect_t0_e, this.effect_t0_f);
this.effects_t0_e = new Array(
this.effect_t0_e0, this.effect_t0_e1, this.effect_t0_e2, this.effect_t0_e3, this.effect_t0_e4, this.effect_t0_e5, this.effect_t0_e6, this.effect_t0_e7,
this.effect_t0_e8, this.effect_t0_e9, this.effect_t0_ea, this.effect_t0_eb, this.effect_t0_ec, this.effect_t0_ed, this.effect_t0_ee, this.effect_t0_ef);
this.effects_t1 = new Array(
this.effect_t1_0, this.effect_t1_1, this.effect_t1_2, this.effect_t1_3, this.effect_t1_4, this.effect_t1_5, this.effect_t1_6, this.effect_t1_7,
this.effect_t1_8, this.effect_t1_9, this.effect_t1_a, this.effect_t1_b, this.effect_t1_c, this.effect_t1_d, this.effect_t1_e, this.effect_t1_f);
this.effects_t1_e = new Array(
this.effect_t1_e0, this.effect_t1_e1, this.effect_t1_e2, this.effect_t1_e3, this.effect_t1_e4, this.effect_t1_e5, this.effect_t1_e6, this.effect_t1_e7,
this.effect_t1_e8, this.effect_t1_e9, this.effect_t1_ea, this.effect_t1_eb, this.effect_t1_ec, this.effect_t1_ed, this.effect_t1_ee, this.effect_t1_ef);
this.context = null;
this.samplerate=44100;
this.bufferlen=2048;
}
// create the web audio context
Protracker.prototype.createContext = function()
{
this.context = new webkitAudioContext();
this.samplerate=this.context.sampleRate;
this.bufferlen=(this.samplerate > 44100) ? 4096 : 2048;
// fixed filter at 6kHz
this.filterNode=this.context.createBiquadFilter();
this.filterNode.frequency.value=6000
// "LED filter" at 3.5kHz - off by default
this.lowpassNode=this.context.createBiquadFilter();
this.lowpassNode.frequency.value=28867;
// mixer
this.mixerNode=this.context.createJavaScriptNode(this.bufferlen, 1, 2);
this.mixerNode.module=this;
this.mixerNode.onaudioprocess=Protracker.prototype.mix;
// compressor for a bit of volume boost
this.compressorNode=this.context.createDynamicsCompressor();
// patch up some cables :)
this.mixerNode.connect(this.filterNode);
this.filterNode.connect(this.lowpassNode);
this.lowpassNode.connect(this.compressorNode);
this.compressorNode.connect(this.context.destination);
}
// play loaded and parsed module with webaudio context
Protracker.prototype.play = function()
{
if (this.context==null) this.createContext();
if (!this.ready) return false;
if (this.paused) {
this.paused=false;
return true;
}
this.paused=false;
this.initialize();
this.flags=1+2;
this.playing=true;
this.onPlay();
return true;
}
// pause playback
Protracker.prototype.pause = function()
{
if (!this.paused) {
this.paused=true;
} else {
this.paused=false;
}
}
// stop playback and release webaudio node
Protracker.prototype.stop = function()
{
this.playing=false;
this.onStop();
}
// jump positions forward/back
Protracker.prototype.jump = function(step)
{
this.tick=0;
this.row=0;
this.position+=step;
this.flags=1+2;
if (this.position<0) this.position=0;
if (this.position >= this.songlen) this.stop();
}
// set whether module repeats after songlen
Protracker.prototype.setrepeat = function(rep)
{
this.repeat=rep;
}
// set stereo separation mode (false=paula, true=betterpaula)
Protracker.prototype.setseparation = function(sep)
{
this.separation=sep;
}
// set amiga video standard (false=NTSC, true=PAL)
Protracker.prototype.setamigatype = function(clock)
{
this.palclock=clock;
}
// set autostart to play immediately after loading
Protracker.prototype.setautostart = function(st)
{
this.autostart=st;
}
// clear song data
Protracker.prototype.clearsong = function()
{
this.title="";
this.signature="";
this.songlen=1;
this.repeatpos=0;
this.patterntable=new ArrayBuffer(128);
for(i=0;i<128;i++) this.patterntable[i]=0;
this.channels=4;
this.sample=new Array();
this.samples=31;
for(i=0;i<31;i++) {
this.sample[i]=new Object();
this.sample[i].name="";
this.sample[i].length=0;
this.sample[i].finetune=0;
this.sample[i].volume=64;
this.sample[i].loopstart=0;
this.sample[i].looplength=0;
this.sample[i].data=0;
}
this.patterns=0;
this.pattern=new Array();
this.note=new Array();
this.looprow=0;
this.loopstart=0;
this.loopcount=0;
this.patterndelay=0;
this.patternwait=0;
}
// initialize all player variables
Protracker.prototype.initialize = function()
{
this.tick=0;
this.position=0;
this.row=0;
this.offset=0;
this.flags=0;
this.speed=6;
this.bpm=125;
this.breakrow=0;
this.patternjump=0;
this.patterndelay=0;
this.patternwait=0;
this.channel=new Array();
for(i=0;i<this.channels;i++) {
this.channel[i]=new Object();
this.channel[i].sample=0;
this.channel[i].period=214;
this.channel[i].voiceperiod=214;
this.channel[i].note=24;
this.channel[i].volume=64;
this.channel[i].command=0;
this.channel[i].data=0;
this.channel[i].samplepos=0;
this.channel[i].samplespeed=0;
this.channel[i].flags=0;
this.channel[i].noteon=0;
this.channel[i].slidespeed=0;
this.channel[i].slideto=214;
this.channel[i].slidetospeed=0;
this.channel[i].arpeggio=0;
this.channel[i].semitone=12;
this.channel[i].vibratospeed=0
this.channel[i].vibratodepth=0
this.channel[i].vibratopos=0;
this.channel[i].vibratowave=0;
}
this.vu=new Array();
}
// load module from url into local buffer
Protracker.prototype.load = function(url)
{
this.url=url;
this.clearsong();
var request = new XMLHttpRequest();
request.open("GET", this.url, true);
request.responseType = "arraybuffer";
this.request = request;
this.loading=true;
var asset = this;
request.onload = function() {
asset.buffer=new Uint8Array(request.response);
asset.parse();
if (asset.autostart) asset.play();
}
request.send();
}
// parse the module from local buffer
Protracker.prototype.parse = function()
{
var i,j,c;
if (!this.buffer) return false;
for(i=0;i<4;i++) this.signature+=String.fromCharCode(this.buffer[1080+i]);
switch (this.signature) {
case "M.K.":
case "M!K!":
case "4CHN":
case "FLT4":
break;
case "6CHN":
this.channels=6;
break;
case "8CHN":
case "FLT8":
this.channels=8;
break;
case "28CH":
this.channels=28;
break;
default:
return false;
}
this.vu=new Array();
for(i=0;i<this.channels;i++) this.vu[i]=0.0;
i=0;
while(this.buffer[i] && i<20)
this.title=this.title+String.fromCharCode(this.buffer[i++]);
for(i=0;i<this.samples;i++) {
var st=20+i*30;
j=0;
while(this.buffer[st+j] && j<22) {
this.sample[i].name+=
((this.buffer[st+j]>0x1f) && (this.buffer[st+j]<0x7f)) ?
(String.fromCharCode(this.buffer[st+j])) :
(" ");
j++;
}
this.sample[i].length=2*(this.buffer[st+22]*256 + this.buffer[st+23]);
this.sample[i].finetune=this.buffer[st+24];
if (this.sample[i].finetune > 7) this.sample[i].finetune=this.sample[i].finetune-16;
this.sample[i].volume=this.buffer[st+25];
this.sample[i].loopstart=2*(this.buffer[st+26]*256 + this.buffer[st+27]);
this.sample[i].looplength=2*(this.buffer[st+28]*256 + this.buffer[st+29]);
if (this.sample[i].looplength==2) this.sample[i].looplength=0;
if (this.sample[i].loopstart>this.sample[i].length) {
this.sample[i].loopstart=0;
this.sample[i].looplength=0;
}
}
this.songlen=this.buffer[950];
if (this.buffer[951] != 127) this.repeatpos=this.buffer[951];
for(i=0;i<128;i++) {
this.patterntable[i]=this.buffer[952+i];
if (this.patterntable[i] > this.patterns) this.patterns=this.patterntable[i];
}
this.patterns+=1;
var patlen=4*64*this.channels;
this.pattern=new Array();
this.note=new Array();
for(i=0;i<this.patterns;i++) {
this.pattern[i]=new Uint8Array(patlen);
this.note[i]=new Uint8Array(this.channels*64);
for(j=0;j<patlen;j++) this.pattern[i][j]=this.buffer[1084+i*patlen+j];
for(j=0;j<64;j++) for(c=0;c<this.channels;c++) {
this.note[i][j*this.channels+c]=0;
var n=(this.pattern[i][j*4*this.channels+c*4]&0x0f)<<8 | this.pattern[i][j*4*this.channels+c*4+1];
for(var np=0; np<this.baseperiodtable.length; np++)
if (n==this.baseperiodtable[np]) this.note[i][j*this.channels+c]=np;
}
}
var sst=1084+this.patterns*patlen;
for(i=0;i<this.samples;i++) {
this.sample[i].data=new Float32Array(this.sample[i].length);
for(j=0;j<this.sample[i].length;j++) {
var q=this.buffer[sst+j];
if (q<128) {
q=q/128.0;
} else {
q=((q-128)/128.0)-1.0;
}
this.sample[i].data[j]=q;
}
sst+=this.sample[i].length;
}
this.ready=true;
this.loading=false;
this.buffer=0;
if (this.context) this.lowpassNode.frequency.value=28867;
this.onReady();
return true;
}
// advance player
Protracker.prototype.advance=function(mod) {
var spd=(((mod.samplerate*60)/mod.bpm)/4)/6;
// advance player
if (mod.offset>spd) { mod.tick++; mod.offset=0; mod.flags|=1; }
if (mod.tick>=mod.speed) {
if (mod.patterndelay) { // delay pattern
if (mod.tick < ((mod.patternwait+1)*mod.speed)) {
mod.patternwait++;
} else {
mod.row++; mod.tick=0; mod.flags|=2; mod.patterndelay=0;
}
}
else {
if (mod.flags&(16+32+64)) {
if (mod.flags&64) { // loop pattern?
mod.row=mod.looprow;
mod.flags&=0xa1;
mod.flags|=2;
}
else {
if (mod.flags&16) { // pattern jump/break?
//console.log("break to pattern " + mod.patternjump + " row "+mod.breakrow);
mod.position=mod.patternjump;
mod.row=mod.breakrow;
mod.patternjump=0;
mod.breakrow=0;
mod.flags&=0xe1;
mod.flags|=2;
}
}
mod.tick=0;
} else {
mod.row++; mod.tick=0; mod.flags|=2;
}
}
}
if (mod.row>=64) { mod.position++; mod.row=0; mod.flags|=4; }
if (mod.position>=mod.songlen) {
if (mod.repeat) {
mod.position=0;
} else {
mod.stop();
}
return;
}
}
// mix an audio buffer with data
Protracker.prototype.mix = function(ape) {
var f;
var p, pp, n, nn;
var mod=ape.srcElement.module;
outp=new Array();
var bufs=new Array(ape.outputBuffer.getChannelData(0), ape.outputBuffer.getChannelData(1));
var buflen=ape.outputBuffer.length;
for(var s=0;s<buflen;s++)
{
outp[0]=0.0;
outp[1]=0.0;
if (!mod.paused && mod.playing)
{
mod.advance(mod);
var och=0;
for(var ch=0;ch<mod.channels;ch++)
{
// calculate playback position
p=mod.patterntable[mod.position];
pp=mod.row*4*mod.channels + ch*4;
if (mod.flags&2) { // new row
modrow = mod.row; // here
mod.channel[ch].command=mod.pattern[p][pp+2]&0x0f;
mod.channel[ch].data=mod.pattern[p][pp+3];
if (!(mod.channel[ch].command==0x0e && (mod.channel[ch].data&0xf0)==0xd0)) {
n=(mod.pattern[p][pp]&0x0f)<<8 | mod.pattern[p][pp+1];
if (n) {
// noteon, except if command=3 (porta to note)
if ((mod.channel[ch].command != 0x03) && (mod.channel[ch].command != 0x05)) {
mod.channel[ch].period=n;
mod.channel[ch].samplepos=0;
if (mod.channel[ch].vibratowave>3) mod.channel[ch].vibratopos=0;
mod.channel[ch].flags|=3; // recalc speed
mod.channel[ch].noteon=1;
} else {
mod.channel[ch].slideto=n;
}
}
nn=mod.pattern[p][pp+0]&0xf0 | mod.pattern[p][pp+2]>>4;
if (nn) {
mod.channel[ch].sample=nn-1;
mod.channel[ch].volume=mod.sample[nn-1].volume;
if (!n && (mod.channel[ch].samplepos > mod.sample[nn-1].length)) mod.channel[ch].samplepos=0;
}
}
}
mod.channel[ch].voiceperiod=mod.channel[ch].period;
if (mod.channel[ch].samplepos==0) modsample[ch]=mod.channel[ch].sample;
// kill empty samples
if (!mod.sample[mod.channel[ch].sample].length) mod.channel[ch].noteon=0;
// effects
if (mod.flags&1) {
if (!mod.tick) {
// process only on tick 0
mod.effects_t0[mod.channel[ch].command](mod, ch);
} else {
mod.effects_t1[mod.channel[ch].command](mod, ch);
}
}
// recalc note number from period
if (mod.channel[ch].flags&2) {
for(var np=0; np<mod.baseperiodtable.length; np++)
if (mod.baseperiodtable[np]>=mod.channel[ch].period) mod.channel[ch].note=np;
mod.channel[ch].semitone=7;
if (mod.channel[ch].period>=120)
mod.channel[ch].semitone=mod.baseperiodtable[mod.channel[ch].note]-mod.baseperiodtable[mod.channel[ch].note+1];
}
// recalc sample speed and apply finetune
if ((mod.channel[ch].flags&1 || mod.flags&2) && mod.channel[ch].voiceperiod)
mod.channel[ch].samplespeed=
(mod.palclock ? 7093789.2 : 7159090.5)/(mod.channel[ch].voiceperiod*2) * mod.finetunetable[mod.sample[mod.channel[ch].sample].finetune+8] / mod.samplerate;
// advance vibrato on each new tick
if (mod.flags&1) {
mod.channel[ch].vibratopos+=mod.channel[ch].vibratospeed;
mod.channel[ch].vibratopos&=0x3f;
}
// mix channel to output
och=och^(ch&1);
f=0.0;
if (mod.channel[ch].noteon) {
if (mod.sample[mod.channel[ch].sample].length > mod.channel[ch].samplepos)
f=(1.0/mod.channels) *
(mod.sample[mod.channel[ch].sample].data[Math.floor(mod.channel[ch].samplepos)]*mod.channel[ch].volume)/64.0;
outp[och]+=f;
mod.channel[ch].samplepos+=mod.channel[ch].samplespeed;
}
if (s==0) mod.vu[ch]=Math.abs(f);
// loop or end samples
if (mod.channel[ch].noteon) {
if (mod.sample[mod.channel[ch].sample].loopstart || mod.sample[mod.channel[ch].sample].looplength) {
if (mod.channel[ch].samplepos >= (mod.sample[mod.channel[ch].sample].loopstart+mod.sample[mod.channel[ch].sample].looplength)) {
mod.channel[ch].samplepos=mod.sample[mod.channel[ch].sample].loopstart;
}
} else {
if (mod.channel[ch].samplepos >= mod.sample[mod.channel[ch].sample].length) {
mod.channel[ch].noteon=0;
}
}
}
// clear channel flags
mod.channel[ch].flags=0;
}
mod.offset++;
mod.flags&=0x70;
}
// a more headphone-friendly stereo separation (aka. betterpaula)
if (mod.separation) {
t=outp[0];
outp[0]=outp[0]*0.6 + outp[1]*0.4;
outp[1]=outp[1]*0.6 + t*0.4;
}
bufs[0][s]=outp[0];
bufs[1][s]=outp[1];
}
}
//
// tick 0 effect functions
//
Protracker.prototype.effect_t0_0=function(mod, ch) { // 0 arpeggio
mod.channel[ch].arpeggio=mod.channel[ch].data;
}
Protracker.prototype.effect_t0_1=function(mod, ch) { // 1 slide up
if (mod.channel[ch].data) mod.channel[ch].slidespeed=mod.channel[ch].data;
}
Protracker.prototype.effect_t0_2=function(mod, ch) { // 2 slide down
if (mod.channel[ch].data) mod.channel[ch].slidespeed=mod.channel[ch].data;
}
Protracker.prototype.effect_t0_3=function(mod, ch) { // 3 slide to note
if (mod.channel[ch].data) mod.channel[ch].slidetospeed=mod.channel[ch].data;
}
Protracker.prototype.effect_t0_4=function(mod, ch) { // 4 vibrato
if (mod.channel[ch].data&0x0f && mod.channel[ch].data&0xf0) {
mod.channel[ch].vibratodepth=(mod.channel[ch].data&0x0f);
mod.channel[ch].vibratospeed=(mod.channel[ch].data&0xf0)>>4;
}
mod.channel[ch].voiceperiod+=
(mod.channel[ch].vibratodepth/32)*mod.channel[ch].semitone*(mod.vibratotable[mod.channel[ch].vibratowave&3][mod.channel[ch].vibratopos]/127);
mod.channel[ch].flags|=1;
}
Protracker.prototype.effect_t0_5=function(mod, ch) { // 5
}
Protracker.prototype.effect_t0_6=function(mod, ch) { // 6
}
Protracker.prototype.effect_t0_7=function(mod, ch) { // 7
}
Protracker.prototype.effect_t0_8=function(mod, ch) { // 8
}
Protracker.prototype.effect_t0_9=function(mod, ch) { // 9 set sample offset
mod.channel[ch].samplepos=mod.channel[ch].data*256;
}
Protracker.prototype.effect_t0_a=function(mod, ch) { // a
}
Protracker.prototype.effect_t0_b=function(mod, ch) { // b pattern jump
mod.breakrow=0;
mod.patternjump=mod.channel[ch].data;
mod.flags|=16;
}
Protracker.prototype.effect_t0_c=function(mod, ch) { // c set volume
mod.channel[ch].volume=mod.channel[ch].data;
}
Protracker.prototype.effect_t0_d=function(mod, ch) { // d pattern break
mod.breakrow=((mod.channel[ch].data&0xf0)>>4)*10 + (mod.channel[ch].data&0x0f);
if (!(mod.flags&16)) mod.patternjump=mod.position+1;
mod.flags|=16;
}
Protracker.prototype.effect_t0_e=function(mod, ch) { // e
var i=(mod.channel[ch].data&0xf0)>>4;
mod.effects_t0_e[i](mod, ch);
}
Protracker.prototype.effect_t0_f=function(mod, ch) { // f set speed
if (mod.channel[ch].data > 32) {
mod.bpm=mod.channel[ch].data;
} else {
if (mod.channel[ch].data) mod.speed=mod.channel[ch].data;
}
}
//
// tick 0 effect e functions
//
Protracker.prototype.effect_t0_e0=function(mod, ch) { // e0 filter on/off
if (mod.channel[ch].data&0x0f) {
mod.lowpassNode.frequency.value=4280; //3500;
} else {
mod.lowpassNode.frequency.value=28867;
}
}
Protracker.prototype.effect_t0_e1=function(mod, ch) { // e1 fine slide up
mod.channel[ch].period-=mod.channel[ch].data&0x0f;
if (mod.channel[ch].period < 113) mod.channel[ch].period=113;
}
Protracker.prototype.effect_t0_e2=function(mod, ch) { // e2 fine slide down
mod.channel[ch].period+=mod.channel[ch].data&0x0f;
if (mod.channel[ch].period > 856) mod.channel[ch].period=856;
mod.channel[ch].flags|=1;
}
Protracker.prototype.effect_t0_e3=function(mod, ch) { // e3 set glissando
}
Protracker.prototype.effect_t0_e4=function(mod, ch) { // e4 set vibrato waveform
mod.channel[ch].vibratowave=mod.channel[ch].data&0x07;
}
Protracker.prototype.effect_t0_e5=function(mod, ch) { // e5 set finetune
}
Protracker.prototype.effect_t0_e6=function(mod, ch) { // e6 loop pattern
if (mod.channel[ch].data&0x0f) {
if (mod.loopcount) {
mod.loopcount--;
} else {
mod.loopcount=mod.channel[ch].data&0x0f;
}
if (mod.loopcount) mod.flags|=64;
} else {
mod.looprow=mod.row;
}
}
Protracker.prototype.effect_t0_e7=function(mod, ch) { // e7
}
Protracker.prototype.effect_t0_e8=function(mod, ch) { // e8
}
Protracker.prototype.effect_t0_e9=function(mod, ch) { // e9
}
Protracker.prototype.effect_t0_ea=function(mod, ch) { // ea fine volslide up
mod.channel[ch].volume+=mod.channel[ch].data&0x0f;
if (mod.channel[ch].volume > 64) mod.channel[ch].volume=64;
}
Protracker.prototype.effect_t0_eb=function(mod, ch) { // eb fine volslide down
mod.channel[ch].volume-=mod.channel[ch].data&0x0f;
if (mod.channel[ch].volume < 0) mod.channel[ch].volume=0;
}
Protracker.prototype.effect_t0_ec=function(mod, ch) { // ec
}
Protracker.prototype.effect_t0_ed=function(mod, ch) { // ed delay sample
if (mod.tick==(mod.channel[ch].data&0x0f)) {
// start note
var p=mod.patterntable[mod.position];
var pp=mod.row*4*mod.channels + ch*4;
n=(mod.pattern[p][pp]&0x0f)<<8 | mod.pattern[p][pp+1];
if (n) {
mod.channel[ch].period=n;
mod.channel[ch].voiceperiod=mod.channel[ch].period;
mod.channel[ch].samplepos=0;
if (mod.channel[ch].vibratowave>3) mod.channel[ch].vibratopos=0;
mod.channel[ch].flags|=3; // recalc speed
mod.channel[ch].noteon=1;
}
n=mod.pattern[p][pp+0]&0xf0 | mod.pattern[p][pp+2]>>4;
if (n) {
mod.channel[ch].sample=n-1;
mod.channel[ch].volume=mod.sample[n-1].volume;
}
}
}
Protracker.prototype.effect_t0_ee=function(mod, ch) { // ee delay pattern
mod.patterndelay=mod.channel[ch].data&0x0f;
mod.patternwait=0;
}
Protracker.prototype.effect_t0_ef=function(mod, ch) { // ef
}
//
// tick 1+ effect functions
//
Protracker.prototype.effect_t1_0=function(mod, ch) { // 0 arpeggio
if (mod.channel[ch].data) {
var apn=mod.channel[ch].note;
if ((mod.tick%3)==1) apn+=mod.channel[ch].arpeggio>>4;
if ((mod.tick%3)==2) apn+=mod.channel[ch].arpeggio&0x0f;
if (apn>=0 && apn <= mod.baseperiodtable.length)
mod.channel[ch].voiceperiod = mod.baseperiodtable[apn];
mod.channel[ch].flags|=1;
}
}
Protracker.prototype.effect_t1_1=function(mod, ch) { // 1 slide up
mod.channel[ch].period-=mod.channel[ch].slidespeed;
if (mod.channel[ch].period<113) mod.channel[ch].period=113;
mod.channel[ch].flags|=3; // recalc speed
}
Protracker.prototype.effect_t1_2=function(mod, ch) { // 2 slide down
mod.channel[ch].period+=mod.channel[ch].slidespeed;
if (mod.channel[ch].period>856) mod.channel[ch].period=856;
mod.channel[ch].flags|=3; // recalc speed
}
Protracker.prototype.effect_t1_3=function(mod, ch) { // 3 slide to note
if (mod.channel[ch].period < mod.channel[ch].slideto) {
mod.channel[ch].period+=mod.channel[ch].slidetospeed;
if (mod.channel[ch].period > mod.channel[ch].slideto)
mod.channel[ch].period=mod.channel[ch].slideto;
}
if (mod.channel[ch].period > mod.channel[ch].slideto) {
mod.channel[ch].period-=mod.channel[ch].slidetospeed;
if (mod.channel[ch].period<mod.channel[ch].slideto)
mod.channel[ch].period=mod.channel[ch].slideto;
}
mod.channel[ch].flags|=3; // recalc speed
}
Protracker.prototype.effect_t1_4=function(mod, ch) { // 4 vibrato
mod.channel[ch].voiceperiod+=
(mod.channel[ch].vibratodepth/16)*mod.channel[ch].semitone*(mod.vibratotable[mod.channel[ch].vibratowave&3][mod.channel[ch].vibratopos]/127);
mod.channel[ch].flags|=1;
}
Protracker.prototype.effect_t1_5=function(mod, ch) { // 5 volslide + slide to note
mod.effect_t1_3(mod, ch); // slide to note
mod.effect_t1_a(mod, ch); // volslide
}
Protracker.prototype.effect_t1_6=function(mod, ch) { // 6 volslide + vibrato
mod.effect_t1_4(mod, ch); // vibrato
mod.effect_t1_a(mod, ch); // volslide
}
Protracker.prototype.effect_t1_7=function(mod, ch) { // 7
}
Protracker.prototype.effect_t1_8=function(mod, ch) { // 8
}
Protracker.prototype.effect_t1_9=function(mod, ch) { // 9 set sample offset
}
Protracker.prototype.effect_t1_a=function(mod, ch) { // a volume slide
if (!(mod.channel[ch].data&0x0f)) {
// y is zero, slide up
mod.channel[ch].volume+=(mod.channel[ch].data>>4);
if (mod.channel[ch].volume>64) mod.channel[ch].volume=64;
}
if (!(mod.channel[ch].data&0xf0)) {
// x is zero, slide down
mod.channel[ch].volume-=(mod.channel[ch].data&0x0f);
if (mod.channel[ch].volume<0) mod.channel[ch].volume=0;
}
}
Protracker.prototype.effect_t1_b=function(mod, ch) { // b pattern jump
}
Protracker.prototype.effect_t1_c=function(mod, ch) { // c set volume
}
Protracker.prototype.effect_t1_d=function(mod, ch) { // d pattern break
}
Protracker.prototype.effect_t1_e=function(mod, ch) { // e
var i=(mod.channel[ch].data&0xf0)>>4;
mod.effects_t1_e[i](mod, ch);
}
Protracker.prototype.effect_t1_f=function(mod, ch) { // f
}
//
// tick 1+ effect e functions
//
Protracker.prototype.effect_t1_e0=function(mod, ch) { // e0
}
Protracker.prototype.effect_t1_e1=function(mod, ch) { // e1
}
Protracker.prototype.effect_t1_e2=function(mod, ch) { // e2
}
Protracker.prototype.effect_t1_e3=function(mod, ch) { // e3
}
Protracker.prototype.effect_t1_e4=function(mod, ch) { // e4
}
Protracker.prototype.effect_t1_e5=function(mod, ch) { // e5
}
Protracker.prototype.effect_t1_e6=function(mod, ch) { // e6
}
Protracker.prototype.effect_t1_e7=function(mod, ch) { // e7
}
Protracker.prototype.effect_t1_e8=function(mod, ch) { // e8
}
Protracker.prototype.effect_t1_e9=function(mod, ch) { // e9 retrig sample
if (mod.tick%(mod.channel[ch].data&0x0f)==0)
mod.channel[ch].samplepos=0;
}
Protracker.prototype.effect_t1_ea=function(mod, ch) { // ea
}
Protracker.prototype.effect_t1_eb=function(mod, ch) { // eb
}
Protracker.prototype.effect_t1_ec=function(mod, ch) { // ec cut sample
if (mod.tick==(mod.channel[ch].data&0x0f))
mod.channel[ch].volume=0;
}
Protracker.prototype.effect_t1_ed=function(mod, ch) { // ed delay sample
mod.effect_t0_ed(mod, ch);
}
Protracker.prototype.effect_t1_ee=function(mod, ch) { // ee
}
Protracker.prototype.effect_t1_ef=function(mod, ch) { // ef
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

+2 -2
View File
@@ -266,7 +266,7 @@ Phaser.AnimationManager.prototype = {
*
* @method Phaser.AnimationManager#getAnimation
* @param {string} name - The name of the animation to be returned, e.g. "fire".
* @return {Phaser.Animation|boolean} The Animation instance, if found, otherwise false.
* @return {Phaser.Animation} The Animation instance, if found, otherwise null.
*/
getAnimation: function (name) {
@@ -278,7 +278,7 @@ Phaser.AnimationManager.prototype = {
}
}
return false;
return null;
},
+2
View File
@@ -1056,6 +1056,8 @@ Phaser.Physics.Arcade.prototype = {
body.blocked.down = true;
}
body.reboundCheck(body.overlapX, body.overlapY, true);
return true;
},
+29 -10
View File
@@ -919,11 +919,11 @@ Phaser.Physics.Arcade.Body.prototype = {
if (response.overlapN.x)
{
// Which is smaller? Left or Right?
if (this._distances[0] < this._distances[1] && (body.checkCollision.right || this.checkCollision.left))
if (this._distances[0] < this._distances[1])
{
hasSeparated = this.hitLeft(body, response);
}
else if (this._distances[1] < this._distances[0] && (body.checkCollision.left || this.checkCollision.right))
else if (this._distances[1] < this._distances[0])
{
hasSeparated = this.hitRight(body, response);
}
@@ -931,11 +931,11 @@ Phaser.Physics.Arcade.Body.prototype = {
else if (response.overlapN.y)
{
// Which is smaller? Top or Bottom?
if (this._distances[2] < this._distances[3] && (body.checkCollision.down || this.checkCollision.up))
if (this._distances[2] < this._distances[3])
{
hasSeparated = this.hitTop(body, response);
}
else if (this._distances[3] < this._distances[2] && (body.checkCollision.up || this.checkCollision.down))
else if (this._distances[3] < this._distances[2])
{
hasSeparated = this.hitBottom(body, response);
}
@@ -949,10 +949,10 @@ Phaser.Physics.Arcade.Body.prototype = {
else
{
// They can only contact like this if at least one of their sides is open, otherwise it's a separation
if (!this.checkCollision.up || !this.checkCollision.down || !this.checkCollision.left || !this.checkCollision.right || !body.checkCollision.up || !body.checkCollision.down || !body.checkCollision.left || !body.checkCollision.right)
{
// if (!this.checkCollision.up || !this.checkCollision.down || !this.checkCollision.left || !this.checkCollision.right || !body.checkCollision.up || !body.checkCollision.down || !body.checkCollision.left || !body.checkCollision.right)
// {
this.addContact(body);
}
// }
}
return hasSeparated;
@@ -973,6 +973,11 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
hitLeft: function (body, response) {
if (!this.checkCollision.left || !body.checkCollision.right)
{
return false;
}
if (this.collideCallback && !this.collideCallback.call(this.collideCallbackContext, Phaser.LEFT, this, body, response))
{
return;
@@ -1015,6 +1020,11 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
hitRight: function (body, response) {
if (!this.checkCollision.right || !body.checkCollision.left)
{
return false;
}
if (this.collideCallback && !this.collideCallback.call(this.collideCallbackContext, Phaser.RIGHT, this, body))
{
return;
@@ -1057,6 +1067,11 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
hitTop: function (body, response) {
if (!this.checkCollision.up || !body.checkCollision.down)
{
return false;
}
if (this.collideCallback && !this.collideCallback.call(this.collideCallbackContext, Phaser.UP, this, body))
{
return false;
@@ -1101,6 +1116,11 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
hitBottom: function (body, response) {
if (!this.checkCollision.down || !body.checkCollision.up)
{
return false;
}
if (this.collideCallback && !this.collideCallback.call(this.collideCallbackContext, Phaser.DOWN, this, body))
{
return false;
@@ -1188,10 +1208,10 @@ Phaser.Physics.Arcade.Body.prototype = {
if (this.moves)
{
this.reboundCheck(true, true, true);
this.game.physics.checkBounds(this);
this.reboundCheck(true, true, true);
this._dx = this.deltaX();
this._dy = this.deltaY();
@@ -1228,7 +1248,6 @@ Phaser.Physics.Arcade.Body.prototype = {
{
this.updateScale();
}
}
},