Skip to content

Commit 7cae283

Browse files
committed
Add typescript source for the 46 tests added last time.
1 parent 04106b1 commit 7cae283

49 files changed

Lines changed: 2485 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Tests/cameras/basic follow.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/// <reference path="../../Phaser/Game.ts" />
2+
(function () {
3+
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
4+
5+
var ufo: Phaser.Sprite;
6+
var speed: Number = 4;
7+
8+
function init() {
9+
game.world.setSize(1280, 600, true);
10+
game.load.image('ground', 'assets/tests/ground-2x.png');
11+
game.load.image('river', 'assets/tests/river-2x.png');
12+
game.load.image('sky', 'assets/tests/sky-2x.png');
13+
game.load.image('cloud0', 'assets/tests/cloud-big-2x.png');
14+
game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png');
15+
game.load.image('cloud2', 'assets/tests/cloud-small-2x.png');
16+
17+
game.load.spritesheet('ufo', 'assets/sprites/ufo.png', 24, 21);
18+
19+
game.load.start();
20+
}
21+
function create() {
22+
// background images
23+
game.add.sprite(0, 0, 'sky')
24+
.transform.scrollFactor.setTo(0, 0);
25+
game.add.sprite(0, 360, 'ground')
26+
.transform.scrollFactor.setTo(0.5, 0.5);
27+
game.add.sprite(0, 400, 'river')
28+
.transform.scrollFactor.setTo(1.3, 1.3);
29+
game.add.sprite(200, 120, 'cloud0')
30+
.transform.scrollFactor.setTo(0.3, 0.3);
31+
game.add.sprite(-60, 120, 'cloud1')
32+
.transform.scrollFactor.setTo(0.5, 0.3);
33+
game.add.sprite(900, 170, 'cloud2')
34+
.transform.scrollFactor.setTo(0.7, 0.3);
35+
36+
// ufo spirte
37+
ufo = game.add.sprite(320, 240, 'ufo');
38+
ufo.animations.add('fly', null, 30, false);
39+
ufo.animations.play('fly');
40+
ufo.transform.origin.setTo(0.5, 0.5);
41+
42+
// make camera follows ufo
43+
game.camera.follow(ufo);
44+
}
45+
function update() {
46+
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
47+
ufo.x -= speed;
48+
ufo.rotation = -15;
49+
}
50+
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
51+
ufo.x += speed;
52+
ufo.rotation = 15;
53+
}
54+
else {
55+
ufo.rotation = 0;
56+
}
57+
if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
58+
ufo.y -= speed;
59+
}
60+
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
61+
ufo.y += speed;
62+
}
63+
}
64+
})();

Tests/cameras/camera fx 1.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// <reference path="../../Phaser/Game.ts" />
2+
(function () {
3+
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
4+
5+
var btn1: Phaser.Button,
6+
btn2: Phaser.Button,
7+
btn3: Phaser.Button;
8+
var fx;
9+
10+
function init() {
11+
game.world.setSize(800, 600, true);
12+
game.load.image('blue', 'assets/tests/blue-circle.png');
13+
game.load.image('yellow', 'assets/tests/yellow-circle.png');
14+
game.load.image('magenta', 'assets/tests/magenta-circle.png');
15+
16+
game.load.start();
17+
}
18+
function create() {
19+
btn1 = game.add.button(114, 34, 'blue', simpleFade, this);
20+
btn2 = game.add.button(426, 86, 'yellow', forceFade, this);
21+
btn3 = game.add.button(221, 318, 'magenta', fadeWithCallback, this);
22+
23+
fx = game.camera.fx.add(Phaser.FX.Camera.Fade);
24+
}
25+
function render() {
26+
Phaser.DebugUtils.context.fillStyle = '#fff';
27+
Phaser.DebugUtils.context.fillText('Press to fade.', 114 + 90, 34 + 130);
28+
Phaser.DebugUtils.context.fillText('Force to fade every time you press it.', 426 + 20, 86 + 130);
29+
Phaser.DebugUtils.context.fillText('Popup a window when fade finished.', 221 + 30, 318 + 130);
30+
}
31+
function simpleFade() {
32+
// Simply fade to black in 0.5 seconds.
33+
fx.start(0x330033, 0.5);
34+
}
35+
function forceFade() {
36+
// Force restart fade effect each time you pressed the button.
37+
fx.start(0x003333, 0.5, null, true);
38+
}
39+
function fadeWithCallback() {
40+
// Popup a alert window when fade finished.
41+
fx.start(0x333300, 0.5, function() {
42+
alert('Fade finished!');
43+
});
44+
}
45+
})();

Tests/cameras/camera fx 2.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/// <reference path="../../Phaser/Game.ts" />
2+
(function () {
3+
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
4+
5+
var btn1: Phaser.Button,
6+
btn2: Phaser.Button,
7+
btn3: Phaser.Button;
8+
var fx;
9+
10+
function init() {
11+
game.world.setSize(800, 600, true);
12+
game.load.image('blue', 'assets/tests/blue-circle.png');
13+
game.load.image('yellow', 'assets/tests/yellow-circle.png');
14+
game.load.image('magenta', 'assets/tests/magenta-circle.png');
15+
16+
game.load.start();
17+
}
18+
function create() {
19+
btn1 = game.add.button(114, 34, 'blue', simpleFlash, this);
20+
btn2 = game.add.button(426, 86, 'yellow', forceFlash, this);
21+
btn3 = game.add.button(221, 318, 'magenta', flashWithCallback, this);
22+
23+
// Usage of flash fx is the same as fade.
24+
fx = game.camera.fx.add(Phaser.FX.Camera.Flash);
25+
}
26+
function render() {
27+
Phaser.DebugUtils.context.fillStyle = '#fff';
28+
Phaser.DebugUtils.context.fillText('Press to flash.', 114 + 90, 34 + 130);
29+
Phaser.DebugUtils.context.fillText('Force to flash every time you press it.', 426 + 20, 86 + 130);
30+
Phaser.DebugUtils.context.fillText('Popup a window when flash finished.', 221 + 30, 318 + 130);
31+
}
32+
function simpleFlash() {
33+
// Simply flash to black in 0.5 seconds.
34+
fx.start(0x330033, 0.5);
35+
}
36+
function forceFlash() {
37+
// Force restart flash effect each time you pressed the button.
38+
fx.start(0x003333, 0.5, null, true);
39+
}
40+
function flashWithCallback() {
41+
// Popup a alert window when flash finished.
42+
fx.start(0x333300, 0.5, function() {
43+
alert('Flash finished!');
44+
});
45+
}
46+
})();

Tests/cameras/camera fx 3.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/// <reference path="../../Phaser/Game.ts" />
2+
(function () {
3+
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
4+
5+
var btn1: Phaser.Button,
6+
btn2: Phaser.Button,
7+
btn3: Phaser.Button;
8+
var fx;
9+
10+
function init() {
11+
game.world.setSize(800, 600, true);
12+
game.load.image('blue', 'assets/tests/blue-circle.png');
13+
game.load.image('yellow', 'assets/tests/yellow-circle.png');
14+
game.load.image('magenta', 'assets/tests/magenta-circle.png');
15+
16+
game.load.start();
17+
}
18+
function create() {
19+
btn1 = game.add.button(114, 34, 'blue', simpleShake, this);
20+
btn2 = game.add.button(426, 86, 'yellow', forceShake, this);
21+
btn3 = game.add.button(221, 318, 'magenta', shakeWithCallback, this);
22+
23+
// Usage of shake fx is the same as fade and flash.
24+
fx = game.camera.fx.add(Phaser.FX.Camera.Shake);
25+
}
26+
function render() {
27+
Phaser.DebugUtils.context.fillStyle = '#fff';
28+
Phaser.DebugUtils.context.fillText('Press to shake.', 114 + 90, 34 + 130);
29+
Phaser.DebugUtils.context.fillText('Force to shake every time you press it.', 426 + 20, 86 + 130);
30+
Phaser.DebugUtils.context.fillText('Popup a window when shake finished.', 221 + 30, 318 + 130);
31+
}
32+
function simpleShake() {
33+
// Simply shake to black in 0.5 seconds.
34+
fx.start(0x330033, 0.5);
35+
}
36+
function forceShake() {
37+
// Force restart shake effect each time you pressed the button.
38+
fx.start(0x003333, 0.5, null, true);
39+
}
40+
function shakeWithCallback() {
41+
// Popup a alert window when shake finished.
42+
fx.start(0x333300, 0.5, function() {
43+
alert('Shake finished!');
44+
});
45+
}
46+
})();

Tests/cameras/camera scale.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/// <reference path="../../Phaser/Game.ts" />
2+
(function () {
3+
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
4+
5+
var zombieCamera: Phaser.Camera;
6+
7+
var zombie: Phaser.Sprite;
8+
var walkSpeed: Number = 2,
9+
direction: Number = 1;
10+
11+
function init() {
12+
game.world.setSize(1280, 600, true);
13+
game.load.image('ground', 'assets/tests/ground-2x.png');
14+
game.load.image('river', 'assets/tests/river-2x.png');
15+
game.load.image('sky', 'assets/tests/sky-2x.png');
16+
17+
game.load.spritesheet('zombie', 'assets/sprites/metalslug_monster39x40.png', 39, 40);
18+
19+
game.load.start();
20+
}
21+
function create() {
22+
// Add background images.
23+
game.add.sprite(0, 0, 'sky');
24+
game.add.sprite(0, 360, 'ground');
25+
game.add.sprite(0, 400, 'river');
26+
27+
// Create zombie spirte
28+
zombie = game.add.sprite(480, 336, 'zombie');
29+
zombie.animations.add('walk', null, 30, true);
30+
zombie.animations.play('walk');
31+
32+
// Create a small camera which looks at the zombie.
33+
// Use the same settings as the default camera.
34+
zombieCamera = game.add.camera(0, 0, 800, 600);
35+
// Use x and y properties to set the target area.
36+
zombieCamera.x = 420;
37+
zombieCamera.y = 240;
38+
// Resize the camera so that it will only look at 200x200 area.
39+
zombieCamera.setSize(200, 200);
40+
// Scale the camera to 2.0, now its target will be 100x100.
41+
zombieCamera.transform.scale.setTo(2.0, 2.0);
42+
// Use setPosition() method to set where the camera rendered
43+
// on the screen.
44+
zombieCamera.setPosition(0, 0);
45+
}
46+
function update() {
47+
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
48+
zombieCamera.x -= 2;
49+
}
50+
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
51+
zombieCamera.x += 2;
52+
}
53+
if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
54+
zombieCamera.y -= 2;
55+
}
56+
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
57+
zombieCamera.y += 2;
58+
}
59+
// zombie wandering update
60+
zombie.x += walkSpeed * direction;
61+
if (zombie.x > 540 || zombie.x < 440) {
62+
// Change walk direction.
63+
direction *= -1;
64+
// Flip zombie's animation.
65+
zombie.texture.flippedX = !zombie.texture.flippedX;
66+
}
67+
}
68+
function render() {
69+
game.camera.renderDebugInfo(32, 32);
70+
zombieCamera.renderDebugInfo(32, 128);
71+
}
72+
})();

Tests/cameras/camera texture.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="../../Phaser/Game.ts" />
2+
(function () {
3+
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
4+
5+
function init() {
6+
game.world.setSize(800, 600, true);
7+
game.load.image('background', 'assets/misc/water_texture.jpg');
8+
9+
game.load.start();
10+
}
11+
function create() {
12+
game.camera.texture.loadImage('background', false);
13+
}
14+
function render() {
15+
Phaser.DebugUtils.context.fillStyle = 'rgb(255, 255, 255)';
16+
Phaser.DebugUtils.context.fillText('Draw background image using camera.texture property.',
17+
196, 320);
18+
}
19+
})();

0 commit comments

Comments
 (0)