Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
- Phaser from Bower
- Basic game (game and preloader states)
  • Loading branch information
cloakedninjas committed Dec 8, 2015
0 parents commit 7856f49
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
.tscache
src/scripts/.baseDir.ts
node_modules
bower_components
public
28 changes: 28 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "phaser-typescript-boilerplate",
"version": "1.0.0",
"homepage": "https://github.com/cloakedninjas/phaser-typescript-boilerplate",
"authors": [
"cloakedninjas <[email protected]>"
],
"description": "Boilerplate for Phaser using Typescript",
"moduleType": [
"amd"
],
"keywords": [
"phaser",
"typescript",
"boilerplate"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"phaser": "~2.4.4"
}
}
65 changes: 65 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module.exports = function (grunt) {
grunt.initConfig({
ts: {
dev: {
src: ['src/scripts/**/*.ts'],
dest: 'public/js',
options: {
module: 'amd', //or commonjs
target: 'es5', //or es3
sourceMap: false,
declaration: false
}
}
},

copy: {
dev: {
files: [
{
expand: true,
cwd: 'src',
src: [
'assets/**'
],
dest: 'public/'
},
{
src: 'src/index.html',
dest: 'public/index.html'
},
{
src: 'bower_components/phaser/build/custom/phaser-no-physics.js',
dest: 'public/vendor/phaser/phaser.js'
}
]
}
},

clean: {
dev: ['public/**/*']
},

watch: {
scripts: {
files: ['src/**/*'],
tasks: ['dev'],
options: {
spawn: false,
debounceDelay: 250
}
}
}
});

grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('dev', [
'clean:dev',
'ts:dev',
'copy:dev'
]);
};
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "phaser-typescript-boilerplate",
"version": "1.0.0",
"description": "Boilerplate for Phaser using Typescript",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/cloakedninjas/phaser-typescript-boilerplate.git"
},
"author": "cloakedninjas",
"license": "MIT",
"bugs": {
"url": "https://github.com/cloakedninjas/phaser-typescript-boilerplate/issues"
},
"homepage": "https://github.com/cloakedninjas/phaser-typescript-boilerplate#readme",
"dependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-ts": "^5.2.0"
}
}
Binary file added src/assets/images/phaser-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui">
<title>Phaser Boilerplate</title>

<style>
html, body {
margin: 0;
}
</style>
</head>
<body>

<script src="vendor/phaser/phaser.js"></script>

<script src="js/state/preloader.js"></script>
<script src="js/state/game.js"></script>

<script src="js/entity/preload-bar.js"></script>

<script src="js/game.js"></script>

<script type="text/javascript">
window.addEventListener("load", function () {
window.game = new Game();
});
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions src/refs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference path="../bower_components/phaser/typescript/phaser.comments.d.ts" />
/// <reference path="../bower_components/phaser/typescript/pixi.comments.d.ts" />
14 changes: 14 additions & 0 deletions src/scripts/entity/preload-bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Namespace.Entity {
export class PreloadBar {
game:Game;

constructor(game) {
this.game = game;
}

setFillPercent(percent:number) {

}

}
}
21 changes: 21 additions & 0 deletions src/scripts/game.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference path="../refs.d.ts" />

module Namespace {
export class Game extends Phaser.Game {

constructor() {
super({
width: window.innerWidth,
height: window.innerHeight,
renderer: Phaser.AUTO
});

this.state.add('preloader', State.Preloader, true);
this.state.add('game', State.Game);
}
}
}

// export Game to window
var Game = Namespace.Game;

9 changes: 9 additions & 0 deletions src/scripts/state/game.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Namespace.State {
export class Game extends Phaser.State {
create() {
var img = this.add.sprite(this.game.world.centerX, this.game.world.centerY, 'phaser-logo');
img.anchor.x = 0.5;
img.anchor.y = 0.5;
}
}
}
23 changes: 23 additions & 0 deletions src/scripts/state/preloader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Namespace.State {
export class Preloader extends Phaser.State {
loadingBar:Entity.PreloadBar;

preload() {
this.loadingBar = new Entity.PreloadBar(this.game);
this.load.image('phaser-logo', 'assets/images/phaser-logo.png');
}

create() {
var tween = this.game.add.tween(this.loadingBar).to({alpha: 0}, 1000, Phaser.Easing.Linear.None, true);
tween.onComplete.add(this.startGame, this);
}

startGame() {
this.game.state.start('game', true);
}

loadUpdate() {
this.loadingBar.setFillPercent(this.load.progress);
}
}
}

0 comments on commit 7856f49

Please sign in to comment.