Skip to content

Commit 254bf67

Browse files
committed
Working on creating a test project in typescript using the Template JS and Breakout game. More to come
1 parent f71b8d4 commit 254bf67

19 files changed

Lines changed: 40232 additions & 0 deletions
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var __extends = this.__extends || function (d, b) {
2+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3+
function __() { this.constructor = d; }
4+
__.prototype = b.prototype;
5+
d.prototype = new __();
6+
};
7+
/// <reference path="phaser.d.ts" />
8+
var BasicGame;
9+
(function (BasicGame) {
10+
var Boot = (function (_super) {
11+
__extends(Boot, _super);
12+
function Boot() {
13+
_super.apply(this, arguments);
14+
}
15+
Boot.prototype.preload = function () {
16+
this.load.image("preloaderBackground", "assets/preloader_background.gif", false);
17+
this.load.image("preloaderBar", "assets/preloadr_bar.png", false);
18+
};
19+
Boot.prototype.create = function () {
20+
this.game.input.maxPointers = 1;
21+
22+
if (this.game.device.desktop) {
23+
this.game.stage.scale.pageAlignHorizontally = true;
24+
} else {
25+
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
26+
this.game.stage.scale.minWidth = 480;
27+
this.game.stage.scale.minHeight = 260;
28+
this.game.stage.scale.maxWidth = 1024;
29+
this.game.stage.scale.maxHeight = 768;
30+
this.game.stage.scale.forceLandscape = true;
31+
this.game.stage.scale.pageAlignHorizontally = true;
32+
this.game.stage.scale.setScreenSize(true);
33+
}
34+
35+
this.game.state.start("Preloader");
36+
};
37+
return Boot;
38+
})(Phaser.State);
39+
BasicGame.Boot = Boot;
40+
})(BasicGame || (BasicGame = {}));
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference path="phaser.d.ts" />
2+
module BasicGame
3+
{
4+
export class Boot extends Phaser.State{
5+
preload() {
6+
this.load.image("preloaderBackground","assets/preloader_background.gif",false);
7+
this.load.image("preloaderBar","assets/preloadr_bar.png",false);
8+
}
9+
create() {
10+
this.game.input.maxPointers = 1;
11+
//this.game.stage. disableVisibilityChange is missing
12+
13+
if( this.game.device.desktop )
14+
{
15+
this.game.stage.scale.pageAlignHorizontally = true;
16+
}
17+
else
18+
{
19+
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
20+
this.game.stage.scale.minWidth = 480;
21+
this.game.stage.scale.minHeight = 260;
22+
this.game.stage.scale.maxWidth = 1024;
23+
this.game.stage.scale.maxHeight = 768;
24+
this.game.stage.scale.forceLandscape = true;
25+
this.game.stage.scale.pageAlignHorizontally = true;
26+
this.game.stage.scale.setScreenSize( true );
27+
}
28+
29+
this.game.state.start("Preloader");
30+
}
31+
}
32+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="phaser.d.ts" />
2+
/// <reference path="Boot.ts" />
3+
/// <reference path="Preloader.ts" />
4+
/// <reference path="MainMenu.ts" />
5+
window.onload = function () {
6+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer', null, false, false);
7+
8+
game.state.add("Boot", BasicGame.Boot, false);
9+
game.state.add("Preloader", BasicGame.Preloader, false);
10+
game.state.add("MainMenu", BasicGame.MainMenu, false);
11+
12+
game.state.start("Boot");
13+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="phaser.d.ts" />
2+
/// <reference path="Boot.ts" />
3+
/// <reference path="Preloader.ts" />
4+
/// <reference path="MainMenu.ts" />
5+
6+
window.onload = function() {
7+
var game:Phaser.Game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer', null, false, false);
8+
9+
game.state.add("Boot", BasicGame.Boot, false);
10+
game.state.add("Preloader", BasicGame.Preloader, false);
11+
game.state.add("MainMenu", BasicGame.MainMenu, false );
12+
13+
game.state.start("Boot");
14+
}
15+
16+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference path="phaser.d.ts" />
2+
var __extends = this.__extends || function (d, b) {
3+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4+
function __() { this.constructor = d; }
5+
__.prototype = b.prototype;
6+
d.prototype = new __();
7+
};
8+
var BasicGame;
9+
(function (BasicGame) {
10+
var MainMenu = (function (_super) {
11+
__extends(MainMenu, _super);
12+
function MainMenu() {
13+
_super.apply(this, arguments);
14+
}
15+
MainMenu.prototype.create = function () {
16+
this.music = this.add.audio("titleMusic", 1, false);
17+
this.music.play("titleMusic", 0);
18+
19+
this.add.sprite(0, 0, "titlepage");
20+
21+
this.playButton = this.add.button(200, 300, "playButton", this.startGame, 1, 1, 1);
22+
};
23+
24+
MainMenu.prototype.startGame = function () {
25+
this.music.stop();
26+
alert("START THE GAME!");
27+
};
28+
return MainMenu;
29+
})(Phaser.State);
30+
BasicGame.MainMenu = MainMenu;
31+
})(BasicGame || (BasicGame = {}));
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path="phaser.d.ts" />
2+
3+
module BasicGame
4+
{
5+
export class MainMenu extends Phaser.State
6+
{
7+
music:Phaser.Sound;
8+
playButton:Phaser.Button;
9+
10+
create():void {
11+
12+
this.music = this.add.audio("titleMusic",1,false);
13+
this.music.play("titleMusic",0);
14+
15+
this.add.sprite(0,0,"titlepage");
16+
17+
this.playButton = this.add.button(200,300,"playButton", this.startGame, 1, 1, 1);
18+
}
19+
20+
startGame():void {
21+
this.music.stop();
22+
alert("START THE GAME!");
23+
}
24+
}
25+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var __extends = this.__extends || function (d, b) {
2+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3+
function __() { this.constructor = d; }
4+
__.prototype = b.prototype;
5+
d.prototype = new __();
6+
};
7+
/// <reference path="phaser.d.ts" />
8+
var BasicGame;
9+
(function (BasicGame) {
10+
var Preloader = (function (_super) {
11+
__extends(Preloader, _super);
12+
function Preloader() {
13+
_super.apply(this, arguments);
14+
this.background = null;
15+
this.preloadBar = null;
16+
this.ready = false;
17+
}
18+
Preloader.prototype.preload = function () {
19+
this.background = this.add.sprite(0.0, 0.0, "preloaderBackground");
20+
this.preloadBar = this.add.sprite(300, 400, "preloaderBar");
21+
22+
this.load.setPreloadSprite(this.preloadBar, 0);
23+
24+
this.load.image("titlepage", "assets/title.jpg", false);
25+
this.load.image("playButton", "assets/play_button.png", false);
26+
this.load.audio("titleMusic", ["assets/main_menu.mp3", "assets/main_menu.ogg"], false);
27+
28+
this.load.atlas("breakout", "assets/breakout.png", "assets/breakout.json");
29+
this.load.image("starfield", "assets/starfield.jpg", false);
30+
};
31+
32+
Preloader.prototype.create = function () {
33+
this.preloadBar.cropEnabled = false;
34+
};
35+
36+
Preloader.prototype.update = function () {
37+
if (this.cache.isSoundDecoded("titleMusic") && this.ready == false) {
38+
this.ready = true;
39+
this.game.state.start("MainMenu");
40+
}
41+
};
42+
return Preloader;
43+
})(Phaser.State);
44+
BasicGame.Preloader = Preloader;
45+
})(BasicGame || (BasicGame = {}));
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/// <reference path="phaser.d.ts" />
2+
module BasicGame
3+
{
4+
export class Preloader extends Phaser.State {
5+
background:Phaser.Sprite = null;
6+
preloadBar:Phaser.Sprite = null;
7+
ready:boolean = false;
8+
9+
preload():void {
10+
this.background = this.add.sprite(0.0,0.0,"preloaderBackground");
11+
this.preloadBar = this.add.sprite(300,400,"preloaderBar");
12+
13+
this.load.setPreloadSprite( this.preloadBar, 0 );
14+
15+
this.load.image("titlepage","assets/title.jpg",false);
16+
this.load.image("playButton","assets/play_button.png",false);
17+
this.load.audio("titleMusic",["assets/main_menu.mp3","assets/main_menu.ogg"],false);
18+
19+
this.load.atlas("breakout","assets/breakout.png","assets/breakout.json");
20+
this.load.image("starfield","assets/starfield.jpg",false);
21+
}
22+
23+
create():void {
24+
this.preloadBar.cropEnabled = false;
25+
}
26+
27+
update():void {
28+
if( this.cache.isSoundDecoded("titleMusic") && this.ready == false )
29+
{
30+
this.ready = true;
31+
this.game.state.start("MainMenu");
32+
}
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)