mirror of
https://github.com/wassname/phaser.git
synced 2026-08-17 11:23:42 +08:00
Preparing new tests
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('balls', 'assets/sprites/balls.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var scroller;
|
||||
function create() {
|
||||
// The source image (balls.png) is only 102x17 in size, but we want it to create a scroll the size of the whole game window.
|
||||
// We can take advantage of the way a ScrollZone can create a seamless pattern for us automatically.
|
||||
// If you create a ScrollRegion larger than the source texture, it'll create a DynamicTexture and perform a pattern fill on it and use that
|
||||
// for rendering.
|
||||
// We've rounded the height up to 612 because in order to have a seamless pattern it needs to be a multiple of 17 (the height of the source image)
|
||||
scroller = myGame.add.scrollZone('balls', 0, 0, 800, 612);
|
||||
// Some sin/cos data for the movement
|
||||
myGame.math.sinCosGenerator(256, 4, 4, 2);
|
||||
}
|
||||
function update() {
|
||||
// Cycle through the wave data and apply it to the scroll speed (causes the circular wave motion)
|
||||
scroller.currentRegion.scrollSpeed.x = myGame.math.shiftSinTable();
|
||||
scroller.currentRegion.scrollSpeed.y = myGame.math.shiftCosTable();
|
||||
}
|
||||
})();
|
||||
@@ -1,41 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('balls', 'assets/sprites/balls.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scroller: Phaser.ScrollZone;
|
||||
|
||||
function create() {
|
||||
|
||||
// The source image (balls.png) is only 102x17 in size, but we want it to create a scroll the size of the whole game window.
|
||||
// We can take advantage of the way a ScrollZone can create a seamless pattern for us automatically.
|
||||
// If you create a ScrollRegion larger than the source texture, it'll create a DynamicTexture and perform a pattern fill on it and use that
|
||||
// for rendering.
|
||||
|
||||
// We've rounded the height up to 612 because in order to have a seamless pattern it needs to be a multiple of 17 (the height of the source image)
|
||||
scroller = myGame.add.scrollZone('balls', 0, 0, 800, 612);
|
||||
|
||||
// Some sin/cos data for the movement
|
||||
myGame.math.sinCosGenerator(256, 4, 4, 2);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
// Cycle through the wave data and apply it to the scroll speed (causes the circular wave motion)
|
||||
scroller.currentRegion.scrollSpeed.x = myGame.math.shiftSinTable();
|
||||
scroller.currentRegion.scrollSpeed.y = myGame.math.shiftCosTable();
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -1,95 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
myGame.loader.addImageFile('jet', 'assets/sprites/particle1.png');
|
||||
myGame.loader.addImageFile('bullet', 'assets/misc/bullet1.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var scroller;
|
||||
var emitter;
|
||||
var ship;
|
||||
var bullets;
|
||||
var speed = 0;
|
||||
var fireRate = 0;
|
||||
var shipMotion;
|
||||
function create() {
|
||||
scroller = myGame.add.scrollZone('starfield', 0, 0, 1024, 1024);
|
||||
emitter = myGame.add.emitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, false, 0);
|
||||
emitter.setRotation(0, 0);
|
||||
// Looks like a smoke trail!
|
||||
//emitter.globalCompositeOperation = 'xor';
|
||||
// Looks way cool :)
|
||||
emitter.globalCompositeOperation = 'lighter';
|
||||
bullets = myGame.add.group(50);
|
||||
// Create our bullet pool
|
||||
for(var i = 0; i < 50; i++) {
|
||||
var tempBullet = new Phaser.Sprite(myGame, myGame.stage.centerX, myGame.stage.centerY, 'bullet');
|
||||
tempBullet.exists = false;
|
||||
tempBullet.rotationOffset = 90;
|
||||
tempBullet.setBounds(-100, -100, 900, 700);
|
||||
tempBullet.outOfBoundsAction = Phaser.GameObject.OUT_OF_BOUNDS_KILL;
|
||||
bullets.add(tempBullet);
|
||||
}
|
||||
ship = myGame.add.sprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.rotationOffset = 90;
|
||||
myGame.input.onDown.add(test, this);
|
||||
}
|
||||
function test(event) {
|
||||
myGame.stage.scale.startFullScreen();
|
||||
}
|
||||
function update() {
|
||||
ship.angularVelocity = 0;
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
ship.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
ship.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
speed += 0.1;
|
||||
if(speed > 10) {
|
||||
speed = 10;
|
||||
}
|
||||
} else {
|
||||
speed -= 0.1;
|
||||
if(speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
shipMotion = myGame.motion.velocityFromAngle(ship.angle, speed);
|
||||
scroller.setSpeed(shipMotion.x, shipMotion.y);
|
||||
// emit particles
|
||||
if(speed > 2) {
|
||||
// We use the opposite of the motion because the jets emit out the back of the ship
|
||||
// The 20 and 30 values just keep them nice and fast
|
||||
emitter.setXSpeed(-(shipMotion.x * 20), -(shipMotion.x * 30));
|
||||
emitter.setYSpeed(-(shipMotion.y * 20), -(shipMotion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) {
|
||||
fire();
|
||||
}
|
||||
}
|
||||
function recycleBullet(bullet) {
|
||||
if(bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640) {
|
||||
bullet.exists = false;
|
||||
}
|
||||
}
|
||||
function fire() {
|
||||
if(myGame.time.now > fireRate) {
|
||||
var b = bullets.getFirstAvailable();
|
||||
b.x = ship.x;
|
||||
b.y = ship.y - 26;
|
||||
var bulletMotion = myGame.motion.velocityFromAngle(ship.angle, 400);
|
||||
b.revive();
|
||||
b.angle = ship.angle;
|
||||
b.velocity.setTo(bulletMotion.x, bulletMotion.y);
|
||||
fireRate = myGame.time.now + 100;
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -1,151 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
myGame.loader.addImageFile('jet', 'assets/sprites/particle1.png');
|
||||
myGame.loader.addImageFile('bullet', 'assets/misc/bullet1.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scroller: Phaser.ScrollZone;
|
||||
var emitter: Phaser.Emitter;
|
||||
var ship: Phaser.Sprite;
|
||||
var bullets: Phaser.Group;
|
||||
|
||||
var speed: number = 0;
|
||||
var fireRate: number = 0;
|
||||
var shipMotion: Phaser.Point;
|
||||
|
||||
function create() {
|
||||
|
||||
scroller = myGame.add.scrollZone('starfield', 0, 0, 1024, 1024);
|
||||
|
||||
emitter = myGame.add.emitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, false, 0);
|
||||
emitter.setRotation(0, 0);
|
||||
|
||||
// Looks like a smoke trail!
|
||||
//emitter.globalCompositeOperation = 'xor';
|
||||
|
||||
// Looks way cool :)
|
||||
emitter.globalCompositeOperation = 'lighter';
|
||||
|
||||
bullets = myGame.add.group(50);
|
||||
|
||||
// Create our bullet pool
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var tempBullet = new Phaser.Sprite(myGame, myGame.stage.centerX, myGame.stage.centerY, 'bullet');
|
||||
tempBullet.exists = false;
|
||||
tempBullet.rotationOffset = 90;
|
||||
tempBullet.setBounds(-100, -100, 900, 700);
|
||||
tempBullet.outOfBoundsAction = Phaser.GameObject.OUT_OF_BOUNDS_KILL;
|
||||
bullets.add(tempBullet);
|
||||
}
|
||||
|
||||
ship = myGame.add.sprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
|
||||
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.rotationOffset = 90;
|
||||
|
||||
myGame.input.onDown.add(test, this);
|
||||
|
||||
}
|
||||
|
||||
function test(event) {
|
||||
|
||||
myGame.stage.scale.startFullScreen();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
ship.angularVelocity = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
ship.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
ship.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
speed += 0.1;
|
||||
|
||||
if (speed > 10)
|
||||
{
|
||||
speed = 10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
speed -= 0.1;
|
||||
|
||||
if (speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
shipMotion = myGame.motion.velocityFromAngle(ship.angle, speed);
|
||||
|
||||
scroller.setSpeed(shipMotion.x, shipMotion.y);
|
||||
|
||||
// emit particles
|
||||
if (speed > 2)
|
||||
{
|
||||
// We use the opposite of the motion because the jets emit out the back of the ship
|
||||
// The 20 and 30 values just keep them nice and fast
|
||||
emitter.setXSpeed(-(shipMotion.x * 20), -(shipMotion.x * 30));
|
||||
emitter.setYSpeed(-(shipMotion.y * 20), -(shipMotion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
|
||||
{
|
||||
fire();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function recycleBullet(bullet:Phaser.Sprite) {
|
||||
|
||||
if (bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640)
|
||||
{
|
||||
bullet.exists = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function fire() {
|
||||
|
||||
if (myGame.time.now > fireRate)
|
||||
{
|
||||
var b:Phaser.Sprite = bullets.getFirstAvailable();
|
||||
|
||||
b.x = ship.x;
|
||||
b.y = ship.y - 26;
|
||||
|
||||
var bulletMotion = myGame.motion.velocityFromAngle(ship.angle, 400);
|
||||
|
||||
b.revive();
|
||||
b.angle = ship.angle;
|
||||
b.velocity.setTo(bulletMotion.x, bulletMotion.y);
|
||||
|
||||
fireRate = myGame.time.now + 100;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -1,31 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('starray', 'assets/pics/auto_scroll_landscape.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
function create() {
|
||||
var zone = myGame.add.scrollZone('starray');
|
||||
// Hide the default region (the full image)
|
||||
zone.currentRegion.visible = false;
|
||||
var y = 0;
|
||||
var speed = 16;
|
||||
// The image consists of 10px high scrolling layers, this creates them quickly (top = fastest, getting slower as we move down)
|
||||
for(var z = 0; z < 32; z++) {
|
||||
zone.addRegion(0, y, 640, 10, speed);
|
||||
if(z <= 15) {
|
||||
speed -= 1;
|
||||
} else {
|
||||
speed += 1;
|
||||
}
|
||||
if(z == 15) {
|
||||
y = 240;
|
||||
speed += 1;
|
||||
} else {
|
||||
y += 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -1,53 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('starray', 'assets/pics/auto_scroll_landscape.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
var zone: Phaser.ScrollZone = myGame.add.scrollZone('starray');
|
||||
|
||||
// Hide the default region (the full image)
|
||||
zone.currentRegion.visible = false;
|
||||
|
||||
var y:number = 0;
|
||||
var speed:number = 16;
|
||||
|
||||
// The image consists of 10px high scrolling layers, this creates them quickly (top = fastest, getting slower as we move down)
|
||||
for (var z:number = 0; z < 32; z++)
|
||||
{
|
||||
zone.addRegion(0, y, 640, 10, speed);
|
||||
|
||||
if (z <= 15)
|
||||
{
|
||||
speed -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
speed += 1;
|
||||
}
|
||||
|
||||
if (z == 15)
|
||||
{
|
||||
y = 240;
|
||||
speed += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
y += 10;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -1,22 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('angelDawn', 'assets/pics/game14_angel_dawn.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var scroller;
|
||||
function create() {
|
||||
// This creates our ScrollZone centered in the middle of the stage.
|
||||
scroller = myGame.add.scrollZone('angelDawn', myGame.stage.centerX - 320, 100);
|
||||
// By default we won't scroll the full image, but we will create 3 ScrollRegions within it:
|
||||
// This creates a ScrollRegion which can be thought of as a rectangle within the ScrollZone that can be scrolled
|
||||
// independantly - this one scrolls the image of the spacemans head
|
||||
scroller.addRegion(32, 32, 352, 240, 0, 2);
|
||||
// The head in the top right
|
||||
scroller.addRegion(480, 30, 96, 96, 4, 0);
|
||||
// The small piece of text
|
||||
scroller.addRegion(466, 160, 122, 14, 0, -0.5);
|
||||
}
|
||||
})();
|
||||
@@ -1,37 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('angelDawn', 'assets/pics/game14_angel_dawn.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scroller: Phaser.ScrollZone;
|
||||
|
||||
function create() {
|
||||
|
||||
// This creates our ScrollZone centered in the middle of the stage.
|
||||
scroller = myGame.add.scrollZone('angelDawn', myGame.stage.centerX - 320, 100);
|
||||
|
||||
// By default we won't scroll the full image, but we will create 3 ScrollRegions within it:
|
||||
|
||||
// This creates a ScrollRegion which can be thought of as a rectangle within the ScrollZone that can be scrolled
|
||||
// independantly - this one scrolls the image of the spacemans head
|
||||
scroller.addRegion(32, 32, 352, 240, 0, 2);
|
||||
|
||||
// The head in the top right
|
||||
scroller.addRegion(480, 30, 96, 96, 4, 0);
|
||||
|
||||
// The small piece of text
|
||||
scroller.addRegion(466, 160, 122, 14, 0, -0.5);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -1,18 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('dragonsun', 'assets/pics/cougar_dragonsun.png');
|
||||
myGame.loader.addImageFile('overlay', 'assets/pics/scrollframe.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var scroller;
|
||||
function create() {
|
||||
// This creates our ScrollZone. It is positioned at x32 y32 (world coodinates)
|
||||
// and is a size of 352x240 (which matches the window in our overlay image)
|
||||
scroller = myGame.add.scrollZone('dragonsun', 32, 32, 352, 240);
|
||||
scroller.setSpeed(2, 2);
|
||||
myGame.add.sprite(0, 0, 'overlay');
|
||||
}
|
||||
})();
|
||||
@@ -1,31 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('dragonsun', 'assets/pics/cougar_dragonsun.png');
|
||||
myGame.loader.addImageFile('overlay', 'assets/pics/scrollframe.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scroller: Phaser.ScrollZone;
|
||||
|
||||
function create() {
|
||||
|
||||
// This creates our ScrollZone. It is positioned at x32 y32 (world coodinates)
|
||||
// and is a size of 352x240 (which matches the window in our overlay image)
|
||||
scroller = myGame.add.scrollZone('dragonsun', 32, 32, 352, 240);
|
||||
|
||||
scroller.setSpeed(2, 2);
|
||||
|
||||
myGame.add.sprite(0, 0, 'overlay');
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -1,16 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('crystal', 'assets/pics/jim_sachs_time_crystal.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
function create() {
|
||||
// This creates our ScrollZone. It is positioned at x0 y0 (world coodinates) by default and uses
|
||||
// the 'crystal' image from the cache.
|
||||
// The default is for the scroll zone to create 1 new scrolling region the size of the whole image you gave it.
|
||||
// For this example we'll keep that, but look at the other tests to see reasons why you may not want to.
|
||||
myGame.add.scrollZone('crystal').setSpeed(4, 2);
|
||||
}
|
||||
})();
|
||||
@@ -1,28 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('crystal', 'assets/pics/jim_sachs_time_crystal.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
// This creates our ScrollZone. It is positioned at x0 y0 (world coodinates) by default and uses
|
||||
// the 'crystal' image from the cache.
|
||||
|
||||
// The default is for the scroll zone to create 1 new scrolling region the size of the whole image you gave it.
|
||||
// For this example we'll keep that, but look at the other tests to see reasons why you may not want to.
|
||||
|
||||
myGame.add.scrollZone('crystal').setSpeed(4, 2);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user