a basic state project that leads to breakout

This commit is contained in:
Louis Tovar 2013-11-15 13:50:41 -08:00
parent 0dab85c853
commit 04ebae7a9f
9 changed files with 57 additions and 50 deletions

View file

@ -13,11 +13,12 @@ var BasicGame;
_super.apply(this, arguments); _super.apply(this, arguments);
} }
Boot.prototype.preload = function () { Boot.prototype.preload = function () {
this.load.image("preloaderBackground", "assets/preloader_background.gif", false); this.load.image("preloaderBackground", "assets/preloader_background.gif");
this.load.image("preloaderBar", "assets/preloadr_bar.png", false); this.load.image("preloaderBar", "assets/preloadr_bar.png");
}; };
Boot.prototype.create = function () { Boot.prototype.create = function () {
this.game.input.maxPointers = 1; this.game.input.maxPointers = 1;
this.game.stage.disableVisibilityChange = true;
if (this.game.device.desktop) { if (this.game.device.desktop) {
this.game.stage.scale.pageAlignHorizontally = true; this.game.stage.scale.pageAlignHorizontally = true;

View file

@ -3,12 +3,12 @@ module BasicGame
{ {
export class Boot extends Phaser.State{ export class Boot extends Phaser.State{
preload() { preload() {
this.load.image("preloaderBackground","assets/preloader_background.gif",false); this.load.image("preloaderBackground","assets/preloader_background.gif");
this.load.image("preloaderBar","assets/preloadr_bar.png",false); this.load.image("preloaderBar","assets/preloadr_bar.png");
} }
create() { create() {
this.game.input.maxPointers = 1; this.game.input.maxPointers = 1;
//this.game.stage. disableVisibilityChange is missing this.game.stage.disableVisibilityChange = true;
if( this.game.device.desktop ) if( this.game.device.desktop )
{ {

View file

@ -2,12 +2,14 @@
/// <reference path="Boot.ts" /> /// <reference path="Boot.ts" />
/// <reference path="Preloader.ts" /> /// <reference path="Preloader.ts" />
/// <reference path="MainMenu.ts" /> /// <reference path="MainMenu.ts" />
/// <reference path="GameState.ts" />
window.onload = function () { window.onload = function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer', null, false, false); var game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer', null, false, false);
game.state.add("Boot", BasicGame.Boot, false); game.state.add("Boot", BasicGame.Boot);
game.state.add("Preloader", BasicGame.Preloader, false); game.state.add("Preloader", BasicGame.Preloader);
game.state.add("MainMenu", BasicGame.MainMenu, false); game.state.add("MainMenu", BasicGame.MainMenu);
game.state.add("GameState", BasicGame.GameState);
game.state.start("Boot"); game.state.start("Boot");
}; };

View file

@ -2,13 +2,15 @@
/// <reference path="Boot.ts" /> /// <reference path="Boot.ts" />
/// <reference path="Preloader.ts" /> /// <reference path="Preloader.ts" />
/// <reference path="MainMenu.ts" /> /// <reference path="MainMenu.ts" />
/// <reference path="GameState.ts" />
window.onload = function() { window.onload = function() {
var game:Phaser.Game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer', null, false, false); var game:Phaser.Game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer', null, false, false);
game.state.add("Boot", BasicGame.Boot, false); game.state.add("Boot", BasicGame.Boot);
game.state.add("Preloader", BasicGame.Preloader, false); game.state.add("Preloader", BasicGame.Preloader);
game.state.add("MainMenu", BasicGame.MainMenu, false ); game.state.add("MainMenu", BasicGame.MainMenu);
game.state.add("GameState", BasicGame.GameState );
game.state.start("Boot"); game.state.start("Boot");
} }

View file

@ -13,17 +13,17 @@ var BasicGame;
_super.apply(this, arguments); _super.apply(this, arguments);
} }
MainMenu.prototype.create = function () { MainMenu.prototype.create = function () {
this.music = this.add.audio("titleMusic", 1, false); this.music = this.add.audio("titleMusic");
this.music.play("titleMusic", 0); this.music.play();
this.add.sprite(0, 0, "titlepage"); this.add.sprite(0, 0, "titlepage");
this.playButton = this.add.button(200, 300, "playButton", this.startGame, 1, 1, 1); this.playButton = this.add.button(200, 300, "playButton", this.startGame, this);
}; };
MainMenu.prototype.startGame = function () { MainMenu.prototype.startGame = function () {
this.music.stop(); this.music.stop();
alert("START THE GAME!"); this.game.state.start("GameState");
}; };
return MainMenu; return MainMenu;
})(Phaser.State); })(Phaser.State);

View file

@ -2,24 +2,23 @@
module BasicGame module BasicGame
{ {
export class MainMenu extends Phaser.State export class MainMenu extends Phaser.State{
{
music:Phaser.Sound; music:Phaser.Sound;
playButton:Phaser.Button; playButton:Phaser.Button;
create():void { create():void {
this.music = this.add.audio("titleMusic",1,false); this.music = this.add.audio("titleMusic");
this.music.play("titleMusic",0); this.music.play();
this.add.sprite(0,0,"titlepage"); this.add.sprite(0,0,"titlepage");
this.playButton = this.add.button(200,300,"playButton", this.startGame, 1, 1, 1); this.playButton = this.add.button(200,300,"playButton", this.startGame, this);
} }
startGame():void { startGame():void {
this.music.stop(); this.music.stop();
alert("START THE GAME!"); this.game.state.start("GameState");
} }
} }
} }

View file

@ -19,14 +19,14 @@ var BasicGame;
this.background = this.add.sprite(0.0, 0.0, "preloaderBackground"); this.background = this.add.sprite(0.0, 0.0, "preloaderBackground");
this.preloadBar = this.add.sprite(300, 400, "preloaderBar"); this.preloadBar = this.add.sprite(300, 400, "preloaderBar");
this.load.setPreloadSprite(this.preloadBar, 0); this.load.setPreloadSprite(this.preloadBar);
this.load.image("titlepage", "assets/title.jpg", false); this.load.image("titlepage", "assets/title.gif");
this.load.image("playButton", "assets/play_button.png", false); this.load.image("playButton", "assets/play_button.png");
this.load.audio("titleMusic", ["assets/main_menu.mp3", "assets/main_menu.ogg"], false); this.load.audio("titleMusic", ["assets/main_menu.mp3", "assets/main_menu.ogg"]);
this.load.atlas("breakout", "assets/breakout.png", "assets/breakout.json"); this.load.atlas("breakout", "assets/breakout.png", "assets/breakout.json");
this.load.image("starfield", "assets/starfield.jpg", false); this.load.image("starfield", "assets/starfield.jpg");
}; };
Preloader.prototype.create = function () { Preloader.prototype.create = function () {

View file

@ -10,14 +10,14 @@ module BasicGame
this.background = this.add.sprite(0.0,0.0,"preloaderBackground"); this.background = this.add.sprite(0.0,0.0,"preloaderBackground");
this.preloadBar = this.add.sprite(300,400,"preloaderBar"); this.preloadBar = this.add.sprite(300,400,"preloaderBar");
this.load.setPreloadSprite( this.preloadBar, 0 ); this.load.setPreloadSprite( this.preloadBar );
this.load.image("titlepage","assets/title.jpg",false); this.load.image("titlepage","assets/title.gif");
this.load.image("playButton","assets/play_button.png",false); this.load.image("playButton","assets/play_button.png");
this.load.audio("titleMusic",["assets/main_menu.mp3","assets/main_menu.ogg"],false); this.load.audio("titleMusic",["assets/main_menu.mp3","assets/main_menu.ogg"]);
this.load.atlas("breakout","assets/breakout.png","assets/breakout.json"); this.load.atlas("breakout","assets/breakout.png","assets/breakout.json");
this.load.image("starfield","assets/starfield.jpg",false); this.load.image("starfield","assets/starfield.jpg");
} }
create():void { create():void {

View file

@ -87,7 +87,7 @@ declare module Phaser {
onPausedCallback(): void; onPausedCallback(): void;
onShutDownCallback(): void; onShutDownCallback(): void;
boot(): void; boot(): void;
add(key: string, state: typeof Phaser.State, autoStart: boolean): void; add(key: string, state: typeof Phaser.State, autoStart?: boolean): void;
remove(key: string): void; remove(key: string): void;
start(key: string, clearWorld?: boolean, clearCache?: boolean): void; start(key: string, clearWorld?: boolean, clearCache?: boolean): void;
dummy(): void; dummy(): void;
@ -120,10 +120,10 @@ declare module Phaser {
memorize: boolean; memorize: boolean;
active: boolean; active: boolean;
validateListener(listener: Function, fnName: string): void; validateListener(listener: Function, fnName: string): void;
has(listener: Function, context?: Object): boolean; has(listener: Function, context?: any): boolean;
add(listener: Function, listenerContext?: Object, priority?: number): Phaser.SignalBinding; add(listener: Function, listenerContext?: any, priority?: number): Phaser.SignalBinding;
addOnce(listener: Function, listenerContext?: Object, priority?: number): Phaser.SignalBinding; addOnce(listener: Function, listenerContext?: any, priority?: number): Phaser.SignalBinding;
remove(listener: Function, context?: Object): Function; remove(listener: Function, context?: any): Function;
removeAll(): void; removeAll(): void;
getNumListeners(): number; getNumListeners(): number;
halt(): void; halt(): void;
@ -185,6 +185,7 @@ declare module Phaser {
scale: Phaser.StageScaleMode; scale: Phaser.StageScaleMode;
aspectRatio: number; aspectRatio: number;
backgroundColor: string; backgroundColor: string;
disableVisibilityChange: boolean;
boot(): void; boot(): void;
visibilityChange(event: Event): void; visibilityChange(event: Event): void;
} }
@ -205,7 +206,7 @@ declare module Phaser {
add(child: any): any; add(child: any): any;
addAt(child: any, index: number): any; addAt(child: any, index: number): any;
getAt(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; swap(child1: any, child2: any): boolean;
bringToTop(child: any): any; bringToTop(child: any): any;
getIndex(child: any): number; getIndex(child: any): number;
@ -216,7 +217,7 @@ declare module Phaser {
multiplyAll(key: string, value: number, checkAlive: boolean, checkVisible: boolean, operation: number): void; multiplyAll(key: string, value: number, checkAlive: boolean, checkVisible: boolean, operation: number): void;
divideAll(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; 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; forEach(callback: Function, callbackContext: Object, checkExists: boolean): void;
forEachAlive(callback: Function, callbackContext: Object): void; forEachAlive(callback: Function, callbackContext: Object): void;
forEachDead(callback: Function, callbackContext: Object): void; forEachDead(callback: Function, callbackContext: Object): void;
@ -343,10 +344,10 @@ declare module Phaser {
touch: Phaser.Touch; touch: Phaser.Touch;
mspointer: Phaser.MSPointer; mspointer: Phaser.MSPointer;
interactiveItems: Phaser.LinkedList; interactiveItems: Phaser.LinkedList;
onDown(): void; onDown: Phaser.Signal;
onUp(): void; onUp: Phaser.Signal;
onTap(): void; onTap: Phaser.Signal;
onHold(): void; onHold: Phaser.Signal;
boot(): void; boot(): void;
update(): void; update(): void;
reset(hard?: boolean); reset(hard?: boolean);
@ -655,14 +656,14 @@ declare module Phaser {
game: Phaser.Game; game: Phaser.Game;
world: Phaser.World; world: Phaser.World;
existing(object: any): boolean; 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; child(parent: any, x: number, y: number, key?: string, frame?: number): Phaser.Sprite;
tween(obj: Object): Phaser.Tween; tween(obj: Object): Phaser.Tween;
group(parent: any, name: string): Phaser.Group; group(parent?: any, name?: string): Phaser.Group;
audio(key: string, volume: number, loop: boolean): Phaser.Sound; audio(key: string, volume?: number, loop?: boolean): Phaser.Sound;
tileSprite(x: number, y: number, width: number, height: number, key?: string, frame?: number): Phaser.TileSprite; 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; text(x: number, y: number, text: string, style: any): Phaser.Text;
button(x: number, y: number, key: string, callback: Function, callbackContext: Object, overFrame?: number, outFrame?: number, downFrame?: number): Phaser.Button; 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; graphics(x: number, y: number): Phaser.Graphics;
emitter(x: number, y: number, maxParticles: number): Phaser.Particles.Arcade.Emitter; emitter(x: number, y: number, maxParticles: number): Phaser.Particles.Arcade.Emitter;
bitmapText(x: number, y: number, text: string, style: string): Phaser.BitmapText; bitmapText(x: number, y: number, text: string, style: string): Phaser.BitmapText;
@ -737,12 +738,14 @@ declare module Phaser {
exists: boolean; exists: boolean;
alive: boolean; alive: boolean;
group: Phaser.Group; group: Phaser.Group;
content: string;
name: string; name: string;
game: Phaser.Game; game: Phaser.Game;
type: number; type: number;
text: string; text: string;
angle: number; angle: number;
style: string; style: string;
visible: boolean;
position: Phaser.Point; position: Phaser.Point;
anchor: Phaser.Point; anchor: Phaser.Point;
scale: Phaser.Point; scale: Phaser.Point;
@ -755,7 +758,7 @@ declare module Phaser {
} }
class Button { class Button {
constructor(game: Phaser.Game, x: number, y: number, key: string, callback: typeof Function, overFrame: number, outFrame: number, downFrame: number); constructor(game: Phaser.Game, x: number, y: number, key: string, callback: Function, overFrame: number, outFrame: number, downFrame: number);
input: Phaser.InputHandler; input: Phaser.InputHandler;
onInputUp: Phaser.Signal; onInputUp: Phaser.Signal;
onInputDown: Phaser.Signal; onInputDown: Phaser.Signal;
@ -1383,7 +1386,7 @@ declare module Phaser {
onFileError: Phaser.Signal; onFileError: Phaser.Signal;
onLoadStart: Phaser.Signal; onLoadStart: Phaser.Signal;
onLoadComplete: Phaser.Signal; onLoadComplete: Phaser.Signal;
setPreloadSprite(sprite: Phaser.Sprite, direction: number): void; setPreloadSprite(sprite: Phaser.Sprite, direction?: number): void;
checkKeyExists(key: string): boolean; checkKeyExists(key: string): boolean;
reset(): void; reset(): void;
addToFileList(type: string, key: string, url: string, properties: Array): void; addToFileList(type: string, key: string, url: string, properties: Array): void;
@ -1454,7 +1457,7 @@ declare module Phaser {
addMarker(name: string, start: number, stop: number, volume?: number, loop?: boolean): void; addMarker(name: string, start: number, stop: number, volume?: number, loop?: boolean): void;
removeMarker(name: string): void; removeMarker(name: string): void;
update(): 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; restart(marker: string, position: number, volume?: number, loop?: boolean): void;
pause(): void; pause(): void;
resume(): void; resume(): void;