mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 07:01:20 +00:00
Merge pull request #204 from gltovar/dev
Update typescript definition file
This commit is contained in:
commit
3249aa2673
22 changed files with 40601 additions and 21 deletions
48
build/phaser.d.ts
vendored
48
build/phaser.d.ts
vendored
|
@ -62,7 +62,7 @@ declare module Phaser {
|
|||
world: Phaser.World;
|
||||
particles: Phaser.Particles;
|
||||
physics: Phaser.Physics.Arcade;
|
||||
load();
|
||||
load: Phaser.Loader;
|
||||
preload();
|
||||
create();
|
||||
render();
|
||||
|
@ -87,9 +87,9 @@ declare module Phaser {
|
|||
onPausedCallback(): void;
|
||||
onShutDownCallback(): void;
|
||||
boot(): void;
|
||||
add(key: string, state: Phaser.State, autoStart: boolean): void;
|
||||
add(key: string, state: typeof Phaser.State, autoStart?: boolean): void;
|
||||
remove(key: string): void;
|
||||
start(key: string, clearWorld: boolean, clearCache: boolean): void;
|
||||
start(key: string, clearWorld?: boolean, clearCache?: boolean): void;
|
||||
dummy(): void;
|
||||
checkState(key: string): boolean;
|
||||
link(key: string): void;
|
||||
|
@ -120,10 +120,10 @@ declare module Phaser {
|
|||
memorize: boolean;
|
||||
active: boolean;
|
||||
validateListener(listener: Function, fnName: string): void;
|
||||
has(listener: Function, context?: Object): boolean;
|
||||
add(listener: Function, listenerContext?: Object, priority?: number): Phaser.SignalBinding;
|
||||
addOnce(listener: Function, listenerContext?: Object, priority?: number): Phaser.SignalBinding;
|
||||
remove(listener: Function, context?: Object): Function;
|
||||
has(listener: Function, context?: any): boolean;
|
||||
add(listener: Function, listenerContext?: any, priority?: number): Phaser.SignalBinding;
|
||||
addOnce(listener: Function, listenerContext?: any, priority?: number): Phaser.SignalBinding;
|
||||
remove(listener: Function, context?: any): Function;
|
||||
removeAll(): void;
|
||||
getNumListeners(): number;
|
||||
halt(): void;
|
||||
|
@ -185,6 +185,7 @@ declare module Phaser {
|
|||
scale: Phaser.StageScaleMode;
|
||||
aspectRatio: number;
|
||||
backgroundColor: string;
|
||||
disableVisibilityChange: boolean;
|
||||
boot(): void;
|
||||
visibilityChange(event: Event): void;
|
||||
}
|
||||
|
@ -205,7 +206,7 @@ declare module Phaser {
|
|||
add(child: any): any;
|
||||
addAt(child: any, index: number): any;
|
||||
getAt(index: number): any;
|
||||
create(x: number, y: number, key: string, frame: string, exists: boolean): any;
|
||||
create(x: number, y: number, key: string, frame: string, exists?: boolean): any;
|
||||
swap(child1: any, child2: any): boolean;
|
||||
bringToTop(child: any): any;
|
||||
getIndex(child: any): number;
|
||||
|
@ -216,7 +217,7 @@ declare module Phaser {
|
|||
multiplyAll(key: string, value: number, checkAlive: boolean, checkVisible: boolean, operation: number): void;
|
||||
divideAll(key: string, value: number, checkAlive: boolean, checkVisible: boolean, operation: number): void;
|
||||
callAllExists(callback: Function, callbackContext: Object, existsValue: boolean): void;
|
||||
callAll(callback: Function, callbackContext: Object): void;
|
||||
callAll(callback: string, callbackContext?: Object): void;
|
||||
forEach(callback: Function, callbackContext: Object, checkExists: boolean): void;
|
||||
forEachAlive(callback: Function, callbackContext: Object): void;
|
||||
forEachDead(callback: Function, callbackContext: Object): void;
|
||||
|
@ -253,7 +254,7 @@ declare module Phaser {
|
|||
}
|
||||
|
||||
class Game {
|
||||
constructor(width: number, height: number, renderer: number, parent: string, state: object, transparent: boolean, antialias: boolean);
|
||||
constructor(width: number, height: number, renderer: number, parent: string, state: Object, transparent: boolean, antialias: boolean);
|
||||
id: number;
|
||||
width: number;
|
||||
height: number;
|
||||
|
@ -343,10 +344,10 @@ declare module Phaser {
|
|||
touch: Phaser.Touch;
|
||||
mspointer: Phaser.MSPointer;
|
||||
interactiveItems: Phaser.LinkedList;
|
||||
onDown(): void;
|
||||
onUp(): void;
|
||||
onTap(): void;
|
||||
onHold(): void;
|
||||
onDown: Phaser.Signal;
|
||||
onUp: Phaser.Signal;
|
||||
onTap: Phaser.Signal;
|
||||
onHold: Phaser.Signal;
|
||||
boot(): void;
|
||||
update(): void;
|
||||
reset(hard?: boolean);
|
||||
|
@ -655,14 +656,14 @@ declare module Phaser {
|
|||
game: Phaser.Game;
|
||||
world: Phaser.World;
|
||||
existing(object: any): boolean;
|
||||
sprite(x: number, y: number, key?: string, frame?: number): Phaser.Sprite;
|
||||
sprite(x: number, y: number, key?: string, frame?: any): Phaser.Sprite;
|
||||
child(parent: any, x: number, y: number, key?: string, frame?: number): Phaser.Sprite;
|
||||
tween(obj: Object): Phaser.Tween;
|
||||
group(parent: any, name: string): Phaser.Group;
|
||||
audio(key: string, volume: number, loop: boolean): Phaser.Sound;
|
||||
group(parent?: any, name?: string): Phaser.Group;
|
||||
audio(key: string, volume?: number, loop?: boolean): Phaser.Sound;
|
||||
tileSprite(x: number, y: number, width: number, height: number, key?: string, frame?: number): Phaser.TileSprite;
|
||||
text(x: number, y: number, text: string, style: string): Phaser.Text;
|
||||
button(x: number, y: number, key: string, callback: Function, callbackContext: Object, overFrame?: number, outFrame?: number, downFrame?: number): Phaser.Button;
|
||||
text(x: number, y: number, text: string, style: any): Phaser.Text;
|
||||
button(x: number, y: number, key: string, callback: Function, callbackContext: Object, overFrame?: any, outFrame?: any, downFrame?: any): Phaser.Button;
|
||||
graphics(x: number, y: number): Phaser.Graphics;
|
||||
emitter(x: number, y: number, maxParticles: number): Phaser.Particles.Arcade.Emitter;
|
||||
bitmapText(x: number, y: number, text: string, style: string): Phaser.BitmapText;
|
||||
|
@ -709,6 +710,7 @@ declare module Phaser {
|
|||
frameName: string;
|
||||
inCamera: boolean;
|
||||
crop: boolean;
|
||||
cropEnabled: boolean;
|
||||
inputEnabled: boolean;
|
||||
preUpdate(): void;
|
||||
postUpdate(): void;
|
||||
|
@ -736,12 +738,14 @@ declare module Phaser {
|
|||
exists: boolean;
|
||||
alive: boolean;
|
||||
group: Phaser.Group;
|
||||
content: string;
|
||||
name: string;
|
||||
game: Phaser.Game;
|
||||
type: number;
|
||||
text: string;
|
||||
angle: number;
|
||||
style: string;
|
||||
visible: boolean;
|
||||
position: Phaser.Point;
|
||||
anchor: Phaser.Point;
|
||||
scale: Phaser.Point;
|
||||
|
@ -804,6 +808,8 @@ declare module Phaser {
|
|||
pageAlignVeritcally: boolean;
|
||||
minWidth: number;
|
||||
maxWidth: number;
|
||||
minHeight: number;
|
||||
maxHeight: number;
|
||||
width: number;
|
||||
height: number;
|
||||
maxIterations: number;
|
||||
|
@ -1380,7 +1386,7 @@ declare module Phaser {
|
|||
onFileError: Phaser.Signal;
|
||||
onLoadStart: Phaser.Signal;
|
||||
onLoadComplete: Phaser.Signal;
|
||||
setPreloadSprite(sprite: Phaser.Sprite, direction: number): void;
|
||||
setPreloadSprite(sprite: Phaser.Sprite, direction?: number): void;
|
||||
checkKeyExists(key: string): boolean;
|
||||
reset(): void;
|
||||
addToFileList(type: string, key: string, url: string, properties: Array): void;
|
||||
|
@ -1451,7 +1457,7 @@ declare module Phaser {
|
|||
addMarker(name: string, start: number, stop: number, volume?: number, loop?: boolean): void;
|
||||
removeMarker(name: string): void;
|
||||
update(): void;
|
||||
play(marker: string, position: number, volume?: number, loop?: boolean): Phaser.Sound;
|
||||
play(marker?: string, position?: number, volume?: number, loop?: boolean): Phaser.Sound;
|
||||
restart(marker: string, position: number, volume?: number, loop?: boolean): void;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
|
|
41
wip/TS Tests/template_breakout/Boot.js
Normal file
41
wip/TS Tests/template_breakout/Boot.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="phaser.d.ts" />
|
||||
var BasicGame;
|
||||
(function (BasicGame) {
|
||||
var Boot = (function (_super) {
|
||||
__extends(Boot, _super);
|
||||
function Boot() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
Boot.prototype.preload = function () {
|
||||
this.load.image("preloaderBackground", "assets/preloader_background.gif");
|
||||
this.load.image("preloaderBar", "assets/preloadr_bar.png");
|
||||
};
|
||||
Boot.prototype.create = function () {
|
||||
this.game.input.maxPointers = 1;
|
||||
this.game.stage.disableVisibilityChange = true;
|
||||
|
||||
if (this.game.device.desktop) {
|
||||
this.game.stage.scale.pageAlignHorizontally = true;
|
||||
} else {
|
||||
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
|
||||
this.game.stage.scale.minWidth = 480;
|
||||
this.game.stage.scale.minHeight = 260;
|
||||
this.game.stage.scale.maxWidth = 1024;
|
||||
this.game.stage.scale.maxHeight = 768;
|
||||
this.game.stage.scale.forceLandscape = true;
|
||||
this.game.stage.scale.pageAlignHorizontally = true;
|
||||
this.game.stage.scale.setScreenSize(true);
|
||||
}
|
||||
|
||||
this.game.state.start("Preloader");
|
||||
};
|
||||
return Boot;
|
||||
})(Phaser.State);
|
||||
BasicGame.Boot = Boot;
|
||||
})(BasicGame || (BasicGame = {}));
|
32
wip/TS Tests/template_breakout/Boot.ts
Normal file
32
wip/TS Tests/template_breakout/Boot.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
/// <reference path="phaser.d.ts" />
|
||||
module BasicGame
|
||||
{
|
||||
export class Boot extends Phaser.State{
|
||||
preload() {
|
||||
this.load.image("preloaderBackground","assets/preloader_background.gif");
|
||||
this.load.image("preloaderBar","assets/preloadr_bar.png");
|
||||
}
|
||||
create() {
|
||||
this.game.input.maxPointers = 1;
|
||||
this.game.stage.disableVisibilityChange = true;
|
||||
|
||||
if( this.game.device.desktop )
|
||||
{
|
||||
this.game.stage.scale.pageAlignHorizontally = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
|
||||
this.game.stage.scale.minWidth = 480;
|
||||
this.game.stage.scale.minHeight = 260;
|
||||
this.game.stage.scale.maxWidth = 1024;
|
||||
this.game.stage.scale.maxHeight = 768;
|
||||
this.game.stage.scale.forceLandscape = true;
|
||||
this.game.stage.scale.pageAlignHorizontally = true;
|
||||
this.game.stage.scale.setScreenSize( true );
|
||||
}
|
||||
|
||||
this.game.state.start("Preloader");
|
||||
}
|
||||
}
|
||||
}
|
151
wip/TS Tests/template_breakout/GameState.js
Normal file
151
wip/TS Tests/template_breakout/GameState.js
Normal file
|
@ -0,0 +1,151 @@
|
|||
/// <reference path="phaser.d.ts" />
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var BasicGame;
|
||||
(function (BasicGame) {
|
||||
var GameState = (function (_super) {
|
||||
__extends(GameState, _super);
|
||||
function GameState() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
GameState.prototype.create = function () {
|
||||
this.game.world.height = 620;
|
||||
|
||||
this._ballOnPaddle = true;
|
||||
this._score = 0;
|
||||
this._lives = 3;
|
||||
|
||||
this._s = this.game.add.tileSprite(0, 0, 800, 600, "starfield");
|
||||
|
||||
var brick;
|
||||
this._bricks = this.game.add.group();
|
||||
|
||||
for (var y = 0; y < 4; y++) {
|
||||
for (var x = 0; x < 15; x++) {
|
||||
brick = this._bricks.create(120 + (x * 36), 100 + (y * 52), "breakout", "brick_" + (y + 1) + "_1.png");
|
||||
brick.body.bounce.setTo(1, 1);
|
||||
brick.body.immovable = true;
|
||||
}
|
||||
}
|
||||
|
||||
this._paddle = this.game.add.sprite(this.game.world.centerX, 500, "breakout", "paddle_big.png");
|
||||
this._paddle.anchor.setTo(0.5, 0.5);
|
||||
this._paddle.body.collideWorldBounds = true;
|
||||
this._paddle.body.bounce.setTo(1, 1);
|
||||
this._paddle.body.immovable = true;
|
||||
|
||||
this._ball = this.game.add.sprite(this.game.world.centerX, this._paddle.y - 16, "breakout", 'ball_1.png');
|
||||
this._ball.anchor.setTo(0.5, 0.5);
|
||||
this._ball.body.collideWorldBounds = true;
|
||||
|
||||
this._ball.body.bounce.setTo(1, 1);
|
||||
this._ball.animations.add("spin", ["ball_1.png", "ball_2.png", "ball_3.png", "ball_4.png", "ball_5.png"], 50, true, false);
|
||||
|
||||
this._scoreText = this.game.add.text(32, 550, "score: 0", { font: "20px Arial", fill: "#ffffff", align: "left" });
|
||||
this._livesText = this.game.add.text(680, 550, "lives: 3", { font: "20px Arial", fill: "#ffffff", align: "left" });
|
||||
this._introText = this.game.add.text(this.game.world.centerX, 400, "- click to start -", { font: "40px Arial", fill: "#ffffff", align: "center" });
|
||||
this._introText.anchor.setTo(0.5, 0.5);
|
||||
|
||||
this.game.input.onDown.add(this.releaseBall, this);
|
||||
|
||||
this._ballOnPaddle = true;
|
||||
};
|
||||
|
||||
GameState.prototype.update = function () {
|
||||
this._paddle.x = this.game.input.x;
|
||||
|
||||
if (this._paddle.x < 24) {
|
||||
this._paddle.x = 24;
|
||||
} else if (this._paddle.x > this.game.width - 24) {
|
||||
this._paddle.x = this.game.width - 24;
|
||||
}
|
||||
|
||||
if (this._ballOnPaddle) {
|
||||
this._ball.x = this._paddle.x;
|
||||
} else {
|
||||
this.game.physics.collide(this._ball, this._paddle, this.ballHitPaddle, null, this);
|
||||
this.game.physics.collide(this._ball, this._bricks, this.ballHitBrick, null, this);
|
||||
}
|
||||
|
||||
if (this._ball.y > 600 && this._ballOnPaddle == false) {
|
||||
this.ballLost();
|
||||
}
|
||||
};
|
||||
|
||||
GameState.prototype.quitGame = function (p_pointer) {
|
||||
this.game.state.start("MainMenu");
|
||||
};
|
||||
|
||||
GameState.prototype.releaseBall = function () {
|
||||
if (this._ballOnPaddle) {
|
||||
this._ballOnPaddle = false;
|
||||
this._ball.body.velocity.y = -300;
|
||||
this._ball.body.velocity.x = -75;
|
||||
this._ball.animations.play("spin");
|
||||
this._introText.visible = false;
|
||||
}
|
||||
};
|
||||
|
||||
GameState.prototype.ballLost = function () {
|
||||
this._lives--;
|
||||
|
||||
if (this._lives == 0) {
|
||||
this.gameOver();
|
||||
} else {
|
||||
this._livesText.content = "lives: " + this._lives;
|
||||
this._ballOnPaddle = true;
|
||||
this._ball.body.velocity.setTo(0, 0);
|
||||
this._ball.x = this._paddle.x + 16;
|
||||
this._ball.y = this._paddle.y - 16;
|
||||
this._ball.animations.stop();
|
||||
}
|
||||
};
|
||||
|
||||
GameState.prototype.gameOver = function () {
|
||||
this._ball.body.velocity.setTo(0, 0);
|
||||
|
||||
this.quitGame();
|
||||
};
|
||||
|
||||
GameState.prototype.ballHitBrick = function (p_ball, p_brick) {
|
||||
p_brick.kill();
|
||||
|
||||
this._score += 10;
|
||||
this._scoreText.content = "score: " + this._score;
|
||||
|
||||
if (this._bricks.countLiving() == 0) {
|
||||
this._score += 1000;
|
||||
this._scoreText.content = "score: " + this._score;
|
||||
this._introText.content = "- Next Level -";
|
||||
|
||||
this._ballOnPaddle = true;
|
||||
this._ball.body.velocity.setTo(0, 0);
|
||||
this._ball.x = this._paddle.x + 16;
|
||||
this._ball.y = this._paddle.y - 16;
|
||||
this._ball.animations.stop();
|
||||
|
||||
this._bricks.callAll('revive');
|
||||
}
|
||||
};
|
||||
|
||||
GameState.prototype.ballHitPaddle = function (p_ball, p_paddle) {
|
||||
var l_diff = 0;
|
||||
|
||||
if (p_ball.x < p_paddle.x) {
|
||||
l_diff = p_paddle.x - p_ball.x;
|
||||
p_ball.body.velocity.x = (-10 * l_diff);
|
||||
} else if (p_ball.x > p_paddle.x) {
|
||||
l_diff = p_ball.x - p_paddle.x;
|
||||
p_ball.body.velocity.x = (10 * l_diff);
|
||||
} else {
|
||||
p_ball.body.velocity.x = 2 + Math.random() * 8;
|
||||
}
|
||||
};
|
||||
return GameState;
|
||||
})(Phaser.State);
|
||||
BasicGame.GameState = GameState;
|
||||
})(BasicGame || (BasicGame = {}));
|
184
wip/TS Tests/template_breakout/GameState.ts
Normal file
184
wip/TS Tests/template_breakout/GameState.ts
Normal file
|
@ -0,0 +1,184 @@
|
|||
/// <reference path="phaser.d.ts" />
|
||||
|
||||
module BasicGame
|
||||
{
|
||||
export class GameState extends Phaser.State {
|
||||
private _ball:Phaser.Sprite;
|
||||
private _paddle:Phaser.Sprite;
|
||||
private _bricks:Phaser.Group;
|
||||
|
||||
private _ballOnPaddle:boolean;
|
||||
|
||||
private _lives:number;
|
||||
private _score:number;
|
||||
|
||||
private _scoreText:Phaser.Text;
|
||||
private _livesText:Phaser.Text;
|
||||
private _introText:Phaser.Text;
|
||||
|
||||
private _s:Phaser.TileSprite;
|
||||
|
||||
create():void {
|
||||
this.game.world.height = 620;
|
||||
|
||||
this._ballOnPaddle = true;
|
||||
this._score = 0;
|
||||
this._lives = 3;
|
||||
|
||||
this._s = this.game.add.tileSprite(0,0,800,600,"starfield");
|
||||
|
||||
var brick:Phaser.Sprite;
|
||||
this._bricks = this.game.add.group();
|
||||
|
||||
for( var y=0; y < 4; y++ )
|
||||
{
|
||||
for( var x=0; x < 15; x++)
|
||||
{
|
||||
brick = this._bricks.create(120 + ( x * 36 ), 100 + ( y * 52 ),"breakout","brick_" + ( y+1 ) + "_1.png");
|
||||
brick.body.bounce.setTo(1, 1);
|
||||
brick.body.immovable = true;
|
||||
}
|
||||
}
|
||||
|
||||
this._paddle = this.game.add.sprite( this.game.world.centerX, 500, "breakout", "paddle_big.png");
|
||||
this._paddle.anchor.setTo(0.5,0.5);
|
||||
this._paddle.body.collideWorldBounds = true;
|
||||
this._paddle.body.bounce.setTo(1,1);
|
||||
this._paddle.body.immovable = true;
|
||||
|
||||
this._ball = this.game.add.sprite( this.game.world.centerX, this._paddle.y - 16, "breakout",'ball_1.png');
|
||||
this._ball.anchor.setTo(0.5,0.5);
|
||||
this._ball.body.collideWorldBounds = true;
|
||||
|
||||
this._ball.body.bounce.setTo(1,1);
|
||||
this._ball.animations.add("spin", ["ball_1.png", "ball_2.png", "ball_3.png", "ball_4.png", "ball_5.png" ], 50, true, false);
|
||||
|
||||
this._scoreText = this.game.add.text(32, 550, "score: 0", {font: "20px Arial", fill: "#ffffff", align: "left" });
|
||||
this._livesText = this.game.add.text(680, 550, "lives: 3", {font: "20px Arial", fill: "#ffffff", align: "left" });
|
||||
this._introText = this.game.add.text(this.game.world.centerX, 400, "- click to start -", {font: "40px Arial", fill: "#ffffff", align: "center" });
|
||||
this._introText.anchor.setTo(0.5,0.5);
|
||||
|
||||
this.game.input.onDown.add( this.releaseBall, this );
|
||||
|
||||
this._ballOnPaddle = true;
|
||||
|
||||
}
|
||||
|
||||
update():void
|
||||
{
|
||||
this._paddle.x = this.game.input.x;
|
||||
|
||||
if( this._paddle.x < 24 )
|
||||
{
|
||||
this._paddle.x = 24;
|
||||
}
|
||||
else if( this._paddle.x > this.game.width - 24 )
|
||||
{
|
||||
this._paddle.x = this.game.width - 24;
|
||||
}
|
||||
|
||||
if( this._ballOnPaddle )
|
||||
{
|
||||
this._ball.x = this._paddle.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.game.physics.collide( this._ball, this._paddle, this.ballHitPaddle, null, this );
|
||||
this.game.physics.collide( this._ball, this._bricks, this.ballHitBrick, null, this );
|
||||
}
|
||||
|
||||
if( this._ball.y > 600 && this._ballOnPaddle == false )
|
||||
{
|
||||
this.ballLost();
|
||||
}
|
||||
}
|
||||
|
||||
private quitGame( p_pointer?:any ):void
|
||||
{
|
||||
this.game.state.start("MainMenu");
|
||||
}
|
||||
|
||||
private releaseBall():void
|
||||
{
|
||||
if( this._ballOnPaddle )
|
||||
{
|
||||
this._ballOnPaddle = false;
|
||||
this._ball.body.velocity.y = -300;
|
||||
this._ball.body.velocity.x = -75;
|
||||
this._ball.animations.play("spin");
|
||||
this._introText.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private ballLost():void
|
||||
{
|
||||
this._lives--;
|
||||
|
||||
if( this._lives == 0)
|
||||
{
|
||||
this.gameOver();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._livesText.content = "lives: " + this._lives;
|
||||
this._ballOnPaddle = true;
|
||||
this._ball.body.velocity.setTo(0,0);
|
||||
this._ball.x = this._paddle.x + 16;
|
||||
this._ball.y = this._paddle.y - 16;
|
||||
this._ball.animations.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private gameOver():void
|
||||
{
|
||||
this._ball.body.velocity.setTo(0,0);
|
||||
|
||||
this.quitGame();
|
||||
}
|
||||
|
||||
private ballHitBrick( p_ball:Phaser.Sprite, p_brick:Phaser.Sprite ):void
|
||||
{
|
||||
p_brick.kill();
|
||||
|
||||
this._score += 10;
|
||||
this._scoreText.content = "score: " + this._score;
|
||||
|
||||
if( this._bricks.countLiving() == 0 )
|
||||
{
|
||||
this._score += 1000;
|
||||
this._scoreText.content = "score: " + this._score;
|
||||
this._introText.content = "- Next Level -";
|
||||
|
||||
this._ballOnPaddle = true;
|
||||
this._ball.body.velocity.setTo(0,0);
|
||||
this._ball.x = this._paddle.x + 16;
|
||||
this._ball.y = this._paddle.y - 16;
|
||||
this._ball.animations.stop();
|
||||
|
||||
this._bricks.callAll('revive');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private ballHitPaddle( p_ball:Phaser.Sprite, p_paddle:Phaser.Sprite ):void
|
||||
{
|
||||
var l_diff:number = 0;
|
||||
|
||||
if( p_ball.x < p_paddle.x )
|
||||
{
|
||||
l_diff = p_paddle.x - p_ball.x;
|
||||
p_ball.body.velocity.x = (-10 * l_diff);
|
||||
}
|
||||
else if( p_ball.x > p_paddle.x )
|
||||
{
|
||||
l_diff = p_ball.x - p_paddle.x;
|
||||
p_ball.body.velocity.x = (10 * l_diff);
|
||||
}
|
||||
else
|
||||
{
|
||||
p_ball.body.velocity.x = 2 + Math.random() * 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
15
wip/TS Tests/template_breakout/Main.js
Normal file
15
wip/TS Tests/template_breakout/Main.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/// <reference path="phaser.d.ts" />
|
||||
/// <reference path="Boot.ts" />
|
||||
/// <reference path="Preloader.ts" />
|
||||
/// <reference path="MainMenu.ts" />
|
||||
/// <reference path="GameState.ts" />
|
||||
window.onload = function () {
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer', null, false, false);
|
||||
|
||||
game.state.add("Boot", BasicGame.Boot);
|
||||
game.state.add("Preloader", BasicGame.Preloader);
|
||||
game.state.add("MainMenu", BasicGame.MainMenu);
|
||||
game.state.add("GameState", BasicGame.GameState);
|
||||
|
||||
game.state.start("Boot");
|
||||
};
|
18
wip/TS Tests/template_breakout/Main.ts
Normal file
18
wip/TS Tests/template_breakout/Main.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
/// <reference path="phaser.d.ts" />
|
||||
/// <reference path="Boot.ts" />
|
||||
/// <reference path="Preloader.ts" />
|
||||
/// <reference path="MainMenu.ts" />
|
||||
/// <reference path="GameState.ts" />
|
||||
|
||||
window.onload = function() {
|
||||
var game:Phaser.Game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer', null, false, false);
|
||||
|
||||
game.state.add("Boot", BasicGame.Boot);
|
||||
game.state.add("Preloader", BasicGame.Preloader);
|
||||
game.state.add("MainMenu", BasicGame.MainMenu);
|
||||
game.state.add("GameState", BasicGame.GameState );
|
||||
|
||||
game.state.start("Boot");
|
||||
}
|
||||
|
||||
|
31
wip/TS Tests/template_breakout/MainMenu.js
Normal file
31
wip/TS Tests/template_breakout/MainMenu.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
/// <reference path="phaser.d.ts" />
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var BasicGame;
|
||||
(function (BasicGame) {
|
||||
var MainMenu = (function (_super) {
|
||||
__extends(MainMenu, _super);
|
||||
function MainMenu() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
MainMenu.prototype.create = function () {
|
||||
this.music = this.add.audio("titleMusic");
|
||||
this.music.play();
|
||||
|
||||
this.add.sprite(0, 0, "titlepage");
|
||||
|
||||
this.playButton = this.add.button(200, 300, "playButton", this.startGame, this);
|
||||
};
|
||||
|
||||
MainMenu.prototype.startGame = function () {
|
||||
this.music.stop();
|
||||
this.game.state.start("GameState");
|
||||
};
|
||||
return MainMenu;
|
||||
})(Phaser.State);
|
||||
BasicGame.MainMenu = MainMenu;
|
||||
})(BasicGame || (BasicGame = {}));
|
24
wip/TS Tests/template_breakout/MainMenu.ts
Normal file
24
wip/TS Tests/template_breakout/MainMenu.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
/// <reference path="phaser.d.ts" />
|
||||
|
||||
module BasicGame
|
||||
{
|
||||
export class MainMenu extends Phaser.State{
|
||||
music:Phaser.Sound;
|
||||
playButton:Phaser.Button;
|
||||
|
||||
create():void {
|
||||
|
||||
this.music = this.add.audio("titleMusic");
|
||||
this.music.play();
|
||||
|
||||
this.add.sprite(0,0,"titlepage");
|
||||
|
||||
this.playButton = this.add.button(200,300,"playButton", this.startGame, this);
|
||||
}
|
||||
|
||||
startGame():void {
|
||||
this.music.stop();
|
||||
this.game.state.start("GameState");
|
||||
}
|
||||
}
|
||||
}
|
45
wip/TS Tests/template_breakout/Preloader.js
Normal file
45
wip/TS Tests/template_breakout/Preloader.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="phaser.d.ts" />
|
||||
var BasicGame;
|
||||
(function (BasicGame) {
|
||||
var Preloader = (function (_super) {
|
||||
__extends(Preloader, _super);
|
||||
function Preloader() {
|
||||
_super.apply(this, arguments);
|
||||
this.background = null;
|
||||
this.preloadBar = null;
|
||||
this.ready = false;
|
||||
}
|
||||
Preloader.prototype.preload = function () {
|
||||
this.background = this.add.sprite(0.0, 0.0, "preloaderBackground");
|
||||
this.preloadBar = this.add.sprite(300, 400, "preloaderBar");
|
||||
|
||||
this.load.setPreloadSprite(this.preloadBar);
|
||||
|
||||
this.load.image("titlepage", "assets/title.gif");
|
||||
this.load.image("playButton", "assets/play_button.png");
|
||||
this.load.audio("titleMusic", ["assets/main_menu.mp3", "assets/main_menu.ogg"]);
|
||||
|
||||
this.load.atlas("breakout", "assets/breakout.png", "assets/breakout.json");
|
||||
this.load.image("starfield", "assets/starfield.jpg");
|
||||
};
|
||||
|
||||
Preloader.prototype.create = function () {
|
||||
this.preloadBar.cropEnabled = false;
|
||||
};
|
||||
|
||||
Preloader.prototype.update = function () {
|
||||
if (this.cache.isSoundDecoded("titleMusic") && this.ready == false) {
|
||||
this.ready = true;
|
||||
this.game.state.start("MainMenu");
|
||||
}
|
||||
};
|
||||
return Preloader;
|
||||
})(Phaser.State);
|
||||
BasicGame.Preloader = Preloader;
|
||||
})(BasicGame || (BasicGame = {}));
|
35
wip/TS Tests/template_breakout/Preloader.ts
Normal file
35
wip/TS Tests/template_breakout/Preloader.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
/// <reference path="phaser.d.ts" />
|
||||
module BasicGame
|
||||
{
|
||||
export class Preloader extends Phaser.State {
|
||||
background:Phaser.Sprite = null;
|
||||
preloadBar:Phaser.Sprite = null;
|
||||
ready:boolean = false;
|
||||
|
||||
preload():void {
|
||||
this.background = this.add.sprite(0.0,0.0,"preloaderBackground");
|
||||
this.preloadBar = this.add.sprite(300,400,"preloaderBar");
|
||||
|
||||
this.load.setPreloadSprite( this.preloadBar );
|
||||
|
||||
this.load.image("titlepage","assets/title.gif");
|
||||
this.load.image("playButton","assets/play_button.png");
|
||||
this.load.audio("titleMusic",["assets/main_menu.mp3","assets/main_menu.ogg"]);
|
||||
|
||||
this.load.atlas("breakout","assets/breakout.png","assets/breakout.json");
|
||||
this.load.image("starfield","assets/starfield.jpg");
|
||||
}
|
||||
|
||||
create():void {
|
||||
this.preloadBar.cropEnabled = false;
|
||||
}
|
||||
|
||||
update():void {
|
||||
if( this.cache.isSoundDecoded("titleMusic") && this.ready == false )
|
||||
{
|
||||
this.ready = true;
|
||||
this.game.state.start("MainMenu");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
236
wip/TS Tests/template_breakout/assets/breakout.json
Normal file
236
wip/TS Tests/template_breakout/assets/breakout.json
Normal file
|
@ -0,0 +1,236 @@
|
|||
{"frames": [
|
||||
|
||||
{
|
||||
"filename": "ball_1.png",
|
||||
"frame": {"x":218,"y":38,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "ball_2.png",
|
||||
"frame": {"x":218,"y":20,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "ball_3.png",
|
||||
"frame": {"x":218,"y":2,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "ball_4.png",
|
||||
"frame": {"x":200,"y":38,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "ball_5.png",
|
||||
"frame": {"x":200,"y":20,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_1_1.png",
|
||||
"frame": {"x":98,"y":21,"w":32,"h":17},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":17},
|
||||
"sourceSize": {"w":32,"h":17}
|
||||
},
|
||||
{
|
||||
"filename": "brick_1_2.png",
|
||||
"frame": {"x":98,"y":2,"w":32,"h":17},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":17},
|
||||
"sourceSize": {"w":32,"h":17}
|
||||
},
|
||||
{
|
||||
"filename": "brick_1_3.png",
|
||||
"frame": {"x":270,"y":17,"w":30,"h":13},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":1,"w":30,"h":13},
|
||||
"sourceSize": {"w":32,"h":17}
|
||||
},
|
||||
{
|
||||
"filename": "brick_1_4.png",
|
||||
"frame": {"x":54,"y":52,"w":24,"h":9},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":4,"w":24,"h":9},
|
||||
"sourceSize": {"w":32,"h":17}
|
||||
},
|
||||
{
|
||||
"filename": "brick_2_1.png",
|
||||
"frame": {"x":236,"y":19,"w":32,"h":15},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":15},
|
||||
"sourceSize": {"w":32,"h":15}
|
||||
},
|
||||
{
|
||||
"filename": "brick_2_2.png",
|
||||
"frame": {"x":236,"y":2,"w":32,"h":15},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":15},
|
||||
"sourceSize": {"w":32,"h":15}
|
||||
},
|
||||
{
|
||||
"filename": "brick_2_3.png",
|
||||
"frame": {"x":270,"y":2,"w":30,"h":13},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":0,"w":30,"h":13},
|
||||
"sourceSize": {"w":32,"h":15}
|
||||
},
|
||||
{
|
||||
"filename": "brick_2_4.png",
|
||||
"frame": {"x":236,"y":50,"w":24,"h":11},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":3,"w":24,"h":11},
|
||||
"sourceSize": {"w":32,"h":15}
|
||||
},
|
||||
{
|
||||
"filename": "brick_3_1.png",
|
||||
"frame": {"x":166,"y":20,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_3_2.png",
|
||||
"frame": {"x":166,"y":2,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_3_3.png",
|
||||
"frame": {"x":236,"y":36,"w":30,"h":12},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":2,"w":30,"h":12},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_3_4.png",
|
||||
"frame": {"x":28,"y":52,"w":24,"h":10},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":3,"w":24,"h":10},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "one.png",
|
||||
"frame": {"x":66,"y":2,"w":30,"h":48},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":16,"w":30,"h":48},
|
||||
"sourceSize": {"w":32,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "paddle_big.png",
|
||||
"frame": {"x":98,"y":40,"w":48,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":48,"h":16},
|
||||
"sourceSize": {"w":48,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "paddle_small.png",
|
||||
"frame": {"x":148,"y":38,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "power_down.png",
|
||||
"frame": {"x":200,"y":2,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "power_up.png",
|
||||
"frame": {"x":182,"y":38,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_4_1.png",
|
||||
"frame": {"x":132,"y":20,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_4_2.png",
|
||||
"frame": {"x":132,"y":2,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_4_3.png",
|
||||
"frame": {"x":270,"y":32,"w":30,"h":12},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":2,"w":30,"h":12},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_4_4.png",
|
||||
"frame": {"x":2,"y":52,"w":24,"h":10},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":3,"w":24,"h":10},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "three.png",
|
||||
"frame": {"x":34,"y":2,"w":30,"h":48},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":0,"w":30,"h":48},
|
||||
"sourceSize": {"w":32,"h":48}
|
||||
},
|
||||
{
|
||||
"filename": "two.png",
|
||||
"frame": {"x":2,"y":2,"w":30,"h":48},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":16,"w":30,"h":48},
|
||||
"sourceSize": {"w":32,"h":64}
|
||||
}],
|
||||
"meta": {
|
||||
"app": "http://www.texturepacker.com",
|
||||
"version": "1.0",
|
||||
"image": "breakout.png",
|
||||
"format": "RGBA8888",
|
||||
"size": {"w":302,"h":64},
|
||||
"scale": "1",
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:c510ff2f709e8d175b059cd1cbe64773$"
|
||||
}
|
||||
}
|
BIN
wip/TS Tests/template_breakout/assets/breakout.png
Normal file
BIN
wip/TS Tests/template_breakout/assets/breakout.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
BIN
wip/TS Tests/template_breakout/assets/main_menu.mp3
Normal file
BIN
wip/TS Tests/template_breakout/assets/main_menu.mp3
Normal file
Binary file not shown.
BIN
wip/TS Tests/template_breakout/assets/main_menu.ogg
Normal file
BIN
wip/TS Tests/template_breakout/assets/main_menu.ogg
Normal file
Binary file not shown.
BIN
wip/TS Tests/template_breakout/assets/play_button.png
Normal file
BIN
wip/TS Tests/template_breakout/assets/play_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.5 KiB |
BIN
wip/TS Tests/template_breakout/assets/preloader_background.gif
Normal file
BIN
wip/TS Tests/template_breakout/assets/preloader_background.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
wip/TS Tests/template_breakout/assets/preloadr_bar.png
Normal file
BIN
wip/TS Tests/template_breakout/assets/preloadr_bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
BIN
wip/TS Tests/template_breakout/assets/starfield.jpg
Normal file
BIN
wip/TS Tests/template_breakout/assets/starfield.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 128 KiB |
BIN
wip/TS Tests/template_breakout/assets/title.gif
Normal file
BIN
wip/TS Tests/template_breakout/assets/title.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
1824
wip/TS Tests/template_breakout/phaser.d.ts
vendored
Normal file
1824
wip/TS Tests/template_breakout/phaser.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load diff
37938
wip/TS Tests/template_breakout/phaser.js
Normal file
37938
wip/TS Tests/template_breakout/phaser.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue