Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: seanhess/uarbg2
base: 2c51af30cd
...
head fork: seanhess/uarbg2
compare: b026c0b8ce
  • 10 commits
  • 42 files changed
  • 0 commit comments
  • 1 contributor
Showing with 890 additions and 685 deletions.
  1. +4 −0 .bowerrc
  2. +2 −3 .gitignore
  3. +2 −0  .vimrc
  4. +6 −0 Makefile
  5. +9 −0 README.md
  6. +0 −21 app.js
  7. +2 −5 component.json
  8. +2 −2 package.json
  9. +20 −0 public/app.ts
  10. +0 −1  public/components
  11. +23 −12 public/controllers/{GameCtrl.js → GameCtrl.ts}
  12. +101 −0 public/controllers/Identify.ts
  13. +0 −76 public/controllers/IdentifyCtrl.js
  14. +1 −0  public/controllers/{PaymentCtrl.js → PaymentCtrl.ts}
  15. +2 −0  public/def/angular.d.ts
  16. +1 −0  public/def/jquery.d.ts
  17. +1 −0  public/def/underscore.d.ts
  18. +0 −24 public/directives/keys.js
  19. +28 −0 public/directives/keys.ts
  20. +0 −75 public/directives/sprite.js
  21. +77 −0 public/directives/sprite.ts
  22. +0 −15 public/filters/position.js
  23. +9 −0 public/filters/position.ts
  24. +11 −20 public/index.html
  25. +0 −13 public/main.js
  26. 0  public/modules.js
  27. +6 −0 public/modules.ts
  28. +1 −1  public/partials/game.html
  29. +0 −3  public/services/AppVersion.js
  30. +7 −0 public/services/AppVersion.ts
  31. +0 −98 public/services/Board.js
  32. +125 −0 public/services/Board.ts
  33. +0 −26 public/services/CurrentPlayer.js
  34. +39 −0 public/services/CurrentPlayer.ts
  35. +0 −32 public/services/FB.js
  36. +76 −0 public/services/FB.ts
  37. +5 −4 public/services/{Missiles.js → Missiles.ts}
  38. +0 −229 public/services/Players.js
  39. +285 −0 public/services/Players.ts
  40. +24 −24 public/services/{SoundEffects.js → SoundEffects.ts}
  41. +0 −1  server.js
  42. +21 −0 server.js
View
4 .bowerrc
@@ -0,0 +1,4 @@
+{
+ "directory" : "public/components",
+ "json" : "component.json"
+}
View
5 .gitignore
@@ -14,6 +14,5 @@ results
node_modules
npm-debug.log
-components/
-
-public/AngularJS
+public/components/
+*.js
View
2  .vimrc
@@ -0,0 +1,2 @@
+" Use 'make' to build instead of the default
+au filetype typescript setlocal makeprg=make
View
6 Makefile
@@ -0,0 +1,6 @@
+all: build-ts
+
+build-ts:
+ tsc --out public/main.js public/app.ts
+
+
View
9 README.md
@@ -12,6 +12,15 @@ Install
* node_modules/.bin/coffee app.coffee
+Compiling
+---------
+
+This should compile EVERYTHING, since app includes the controllers, and the controllers import the services
+
+ tsc --module amd public/app.ts
+
+You still need to add everything to public/main.js to get it to load
+
Todo
----
View
21 app.js
@@ -1,21 +0,0 @@
-var PORT = process.env.PORT || 3000
-var express = require('express')
-var stylus = require('stylus')
-var nib = require('nib')
-
-app = express()
-
-app.configure(function() {
- app.use(stylus.middleware({
- src: 'public',
- compile: function(str, path) {
- return stylus(str).use(nib()).import('nib').set('filename', path)
- }
- }))
- app.use(express.static(__dirname + '/public'))
- app.use('/components', express.static(__dirname + '/components'))
-})
-
-app.listen(PORT, function() {
- return console.log("RUNNING " + PORT)
-})
View
7 component.json
@@ -4,10 +4,7 @@
"main": "./path/to/main.css",
"directory": "public/components",
"dependencies": {
- "jquery": "git://github.com/components/jquery.git#1.8.1",
- "requirejs": "git://github.com/jrburke/requirejs#2.0.6",
- "underscore": "git://github.com/documentcloud/underscore.git#1.4.2",
- "angular": "git://github.com/angular/bower-angular.git",
- "fjs": "git://github.com/seanhess/fjs#0.5.2"
+ "fjs": "0.5.2",
+ "DefinitelyTyped": "latest"
}
}
View
4 package.json
@@ -2,7 +2,7 @@
"name": "uarbg2",
"version": "0.0.0",
"description": "uarbg2",
- "main": "app.js",
+ "main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
@@ -21,4 +21,4 @@
"stylus": "0.30.1",
"nib": "0.8.2"
}
-}
+v
View
20 public/app.ts
@@ -0,0 +1,20 @@
+///<reference path="def/jquery.d.ts"/>
+///<reference path="def/angular.d.ts"/>
+///<reference path="def/underscore.d.ts"/>
+
+// Require stuff (modules.js must be first! to initialize modules)
+///<reference path="modules.ts"/>
+///<reference path="controllers/Identify.ts"/>
+///<reference path="controllers/GameCtrl.ts"/>
+///<reference path="controllers/PaymentCtrl.ts"/>
+
+// sometimes you're going to want to reference controllers dynamically.
+// so register them
+
+var app = angular.module('app', ['controllers'], function ($routeProvider: ng.IRouteProviderProvider) {
+ $routeProvider.when('/game/:gameId', {templateUrl: 'partials/game.html', controller: "GameCtrl"})
+ $routeProvider.when('/paid', {templateUrl: 'partials/paid.html', controller: "PaymentCtrl"})
+ $routeProvider.when('/identify', {templateUrl: 'partials/identify.html', controller: "IdentifyCtrl"})
+
+ $routeProvider.otherwise({redirectTo: '/identify'})
+})
View
1  public/components
View
35 public/controllers/GameCtrl.js → public/controllers/GameCtrl.ts
@@ -1,5 +1,19 @@
+///<reference path="../def/angular.d.ts"/>
-function GameCtrl($scope, Players, Missiles, $routeParams, CurrentPlayer, $location, Board, SoundEffects, AppVersion) {
+///<reference path="../services/Missiles"/>
+///<reference path="../services/Players"/>
+///<reference path="../services/CurrentPlayer"/>
+///<reference path="../services/Board"/>
+///<reference path="../services/SoundEffects"/>
+///<reference path="../services/AppVersion"/>
+
+///<reference path="../filters/position.ts"/>
+///<reference path="../directives/keys.ts"/>
+///<reference path="../directives/sprite.ts"/>
+
+angular.module('controllers')
+
+.controller('GameCtrl', function ($scope, Players:IPlayerService, Missiles, $routeParams, CurrentPlayer, $location, Board, SoundEffects, AppVersion) {
$scope.version = AppVersion
$scope.gameId = $routeParams.gameId
@@ -19,13 +33,14 @@ function GameCtrl($scope, Players, Missiles, $routeParams, CurrentPlayer, $locat
//return
//}
- var players = new Players($scope.gameId, $routeParams.debugPlayerName)
+ var players = Players.connect($scope.gameId)
+ Players.join(players, CurrentPlayer.player)
$scope.players = players
var missiles = new Missiles($scope.gameId,players)
+ missiles.listen()
$scope.missiles = missiles
-
$scope.latestAlert = "Welcome to Your Underwater Adventure"
$scope.$on("kill", function(e, player) {
@@ -39,7 +54,7 @@ function GameCtrl($scope, Players, Missiles, $routeParams, CurrentPlayer, $locat
// AUDIO
- SoundEffects.music()
+ //SoundEffects.music()
$scope.test = function() {
//SoundEffects.rocket()
@@ -90,7 +105,7 @@ function GameCtrl($scope, Players, Missiles, $routeParams, CurrentPlayer, $locat
setTimeout(function(){
$scope.$apply(function() {
players.current.walking = false;
- players.move(players.current);
+ Players.move(players, players.current);
});
}, 500);
@@ -99,7 +114,7 @@ function GameCtrl($scope, Players, Missiles, $routeParams, CurrentPlayer, $locat
players.move(players.current);*/
var collision = false;
- players.alivePlayers().forEach(function(val,key){
+ Players.alivePlayers(players.all).forEach(function(val,key){
if (val.name != players.current.name && val.status != "dead") {
if (location.axis == "x") {
if (val.x == location.location && val.y == players.current.y) collision = true;
@@ -112,15 +127,11 @@ function GameCtrl($scope, Players, Missiles, $routeParams, CurrentPlayer, $locat
if (!collision) {
players.current[location.axis] = location.location;
players.current.facing = location.facing;
- players.move(players.current);
+ Players.move(players, players.current);
} else {
// we can play a collision sound here!
}
}
}
}
-
- players.join(CurrentPlayer.player)
- players.listen()
- missiles.listen()
-}
+})
View
101 public/controllers/Identify.ts
@@ -0,0 +1,101 @@
+///<reference path="../def/angular.d.ts"/>
+
+///<reference path="../services/Players"/>
+///<reference path="../services/CurrentPlayer"/>
+
+console.log("Register: IdentifyCtrl")
+
+interface IdentifyScope extends ng.IScope {
+ intro:string;
+ error:string;
+
+ version:any;
+ player:any;
+ gameId:string;
+ players:IPlayerState;
+ avatars:string [];
+ freeAvatars:string [];
+
+ avatarIsFree(name:string): bool;
+ avatarIsAvailable(name:string): bool;
+ avatarIsLocked(name:string): bool;
+ join(): void;
+ selectAvatar(name: string): void;
+ isPlayerAvatar(name:string): bool;
+}
+
+angular.module('controllers').controller('IdentifyCtrl', function($scope: IdentifyScope, $location: any, Players:IPlayerService, CurrentPlayer: any, AppVersion: string) {
+
+ // HACKY way to do the transition
+ $scope.intro = "intro"
+
+ // hacky way to do this. cssTransitionEnd would be better
+ setTimeout(function() {
+ $scope.$apply(function() {
+ $scope.intro = "show"
+ })
+ }, 1200)
+
+ $scope.version = AppVersion
+
+ // see if they have a preferred name and gameId
+ $scope.player = CurrentPlayer.loadPreferences()
+ $scope.gameId = $scope.player.gameId || "global"
+
+ // [ ] detect which game to join ("global")
+ var players = Players.connect($scope.gameId)
+ $scope.players = players
+
+ // available avatars
+ $scope.avatars = ['player2', 'player5', 'player3','player1', 'player4', 'player6']
+ $scope.freeAvatars = ['player1','player2']
+ $scope.avatarIsFree = function (avatarName) {
+ return ($scope.freeAvatars.indexOf(avatarName) != -1);
+ }
+
+ $scope.avatarIsAvailable = function (avatarName) {
+ return (players.isPaid || $scope.freeAvatars.indexOf(avatarName) != -1);
+ }
+
+ $scope.avatarIsLocked = function (avatarName) {
+ return ($scope.avatarIsAvailable(avatarName) != true);
+ }
+
+ // [ ] Pick a name and avatar
+ // set a service with the currently selected player. the name and avatar, etc
+ // must be set by the time you get to game
+
+ // If game doesn't have a current player, then go back to the identify/matchmaking screen!
+
+ $scope.join = function() {
+ if (!$scope.player || !$scope.player.avatar || !$scope.player.name) {
+ $scope.error = "Please select a valid name and an avatar"
+ return
+ }
+
+ if (Players.playerByName(players.all, $scope.player.name)) {
+ $scope.error = '"' + $scope.player.name + '" is already taken'
+ return
+ }
+
+ CurrentPlayer.player = $scope.player
+ CurrentPlayer.savePreferences(CurrentPlayer.player, $scope.gameId)
+ $location.path("/game/" + $scope.gameId)
+ }
+
+ $scope.selectAvatar = function(name) {
+ if ($scope.avatarIsAvailable(name)) {
+ $scope.player = $scope.player || {}
+ $scope.player.avatar = name
+ } else {
+ window.location.href = "https://spb.io/s/osgtq3F3kS";
+ }
+ }
+
+ $scope.isPlayerAvatar = function(name) {
+ return ($scope.player && $scope.player.avatar == name)
+ }
+
+})
+
+
View
76 public/controllers/IdentifyCtrl.js
@@ -1,76 +0,0 @@
-
-// https://seanhess.firebaseio.com/
-
-function IdentifyCtrl($scope, Players, CurrentPlayer, $location, AppVersion) {
-
- // HACKY way to do the transition
- $scope.intro = "intro"
-
- // hacky way to do this. cssTransitionEnd would be better
- setTimeout(function() {
- $scope.$apply(function() {
- $scope.intro = "show"
- })
- }, 1200)
-
- $scope.version = AppVersion
-
- // see if they have a preferred name and gameId
- $scope.player = CurrentPlayer.loadPreferences()
- $scope.gameId = $scope.player.gameId || "global"
-
- // [ ] detect which game to join ("global")
- var players = new Players($scope.gameId)
- $scope.players = players
-
- // available avatars
- $scope.avatars = ['player2', 'player5', 'player3','player1', 'player4', 'player6']
- $scope.freeAvatars = ['player1','player2']
- $scope.avatarIsFree = function (avatarName) {
- return ($scope.freeAvatars.indexOf(avatarName) != -1);
- }
- $scope.avatarIsAvailable = function (avatarName) {
- return (players.isPaid || $scope.freeAvatars.indexOf(avatarName) != -1);
- }
-
- $scope.avatarIsLocked = function (avatarName) {
- return ($scope.avatarIsAvailable(avatarName) != true);
- }
-
- // [ ] Pick a name and avatar
- // set a service with the currently selected player. the name and avatar, etc
- // must be set by the time you get to game
-
- // If game doesn't have a current player, then go back to the identify/matchmaking screen!
-
- $scope.join = function() {
- if (!$scope.player || !$scope.player.avatar || !$scope.player.name) {
- $scope.error = "Please select a valid name and an avatar"
- return
- }
-
- if (players.playerByName($scope.player.name)) {
- $scope.error = '"' + $scope.player.name + '" is already taken'
- return
- }
-
- CurrentPlayer.player = $scope.player
- CurrentPlayer.savePreferences(CurrentPlayer.player, $scope.gameId)
- $location.path("/game/" + $scope.gameId)
- }
-
- $scope.selectAvatar = function(name) {
- if ($scope.avatarIsAvailable(name)) {
- $scope.player = $scope.player || {}
- $scope.player.avatar = name
- } else {
- window.location = "https://spb.io/s/osgtq3F3kS";
- }
- }
-
- $scope.isPlayerAvatar = function(name) {
- return ($scope.player && $scope.player.avatar == name)
- }
-
- players.listen()
-}
View
1  public/controllers/PaymentCtrl.js → public/controllers/PaymentCtrl.ts
@@ -1,3 +1,4 @@
+///<reference path="../def/angular.d.ts"/>
function PaymentCtrl($scope, $routeParams, $location) {
if ($routeParams.unpaid) {
View
2  public/def/angular.d.ts
@@ -0,0 +1,2 @@
+///<reference path="../jquery.d.ts"/>
+///<reference path="../components/DefinitelyTyped/Definitions/angular-1.0.d.ts"/>
View
1  public/def/jquery.d.ts
@@ -0,0 +1 @@
+///<reference path="../components/DefinitelyTyped/Definitions/jquery-1.8.d.ts"/>
View
1  public/def/underscore.d.ts
@@ -0,0 +1 @@
+///<reference path="../components/DefinitelyTyped/Definitions/underscore-1.4.d.ts"/>
View
24 public/directives/keys.js
@@ -1,24 +0,0 @@
-angular.module('directives')
- .directive('keypress', function($parse) {
- return function(scope, element, attrs) {
- // element is a jquery element
-
- // focus the div
- element.attr('tabindex', 0)
-
- var onPress = $parse(attrs.keypress)
- var isPressed = false
-
- element.keydown(function(e) {
- if (isPressed) return
- isPressed = true
- scope.$apply(function() {
- onPress(scope, {e:e})
- })
- });
-
- element.keyup(function(e) {
- isPressed = false
- })
- }
- })
View
28 public/directives/keys.ts
@@ -0,0 +1,28 @@
+///<reference path="../def/angular.d.ts"/>
+///<reference path="../def/jquery.d.ts"/>
+
+angular.module('directives')
+
+.directive('keypress', function($parse) {
+ return function(scope:ng.IScope, element:JQuery, attrs) {
+ // element is a jquery element
+
+ // focus the div
+ element.attr('tabindex', 0)
+
+ var onPress = $parse(attrs.keypress)
+ var isPressed = false
+
+ element.keydown(function(e) {
+ if (isPressed) return
+ isPressed = true
+ scope.$apply(function() {
+ onPress(scope, {e:e})
+ })
+ });
+
+ element.keyup(function(e) {
+ isPressed = false
+ })
+ }
+})
View
75 public/directives/sprite.js
@@ -1,75 +0,0 @@
-angular.module('directives')
- .directive('sprite', function($parse) {
- return function(scope, element, attrs) {
- // element is the player div
- // attrs.sprite is "player1"
-
- var isWalking;
-
- function setFacing(facing) {
- var facing = (typeof facing == 'undefined') ? "down" : facing;
-
- if(facing == "up") {
- element.css('backgroundPositionY', '-100px');
- }
-
- if(facing == "right") {
- element.css('backgroundPositionY', '-50px');
- }
-
- if(facing == "down") {
- element.css('backgroundPositionY', '-150px');
- }
-
- if(facing == "left") {
- element.css('backgroundPositionY', '0px');
- }
- }
-
- function walking() {
- var i = 0;
- var animateWalk = function() {
- return setTimeout(function(){
- setSprite(++i % 3);
- if(isWalking) {
- animateWalk();
- }
- }, 70);
- }
-
- return animateWalk();
- }
-
- function setSprite(sprite) {
- if(sprite == 0) {
- element.css('backgroundPositionX', '0');
- }
-
- if(sprite == 1) {
- element.css('backgroundPositionX', '-50px');
- }
-
- if(sprite == 2) {
- element.css('backgroundPositionX', '-100px');
- }
- }
-
- scope.$watch(attrs.sprite, function(val) {
- setSprite(val, scope.player.facing);
- })
-
- scope.$watch(attrs.spriteFacing, function(val) {
- setFacing(val);
- })
-
- scope.$watch(attrs.spriteWalking, function(val) {
- if(val) {
- isWalking = true;
- walking();
- } else {
- isWalking = false;
- }
- })
-
- }
- })
View
77 public/directives/sprite.ts
@@ -0,0 +1,77 @@
+///<reference path="../def/angular.d.ts"/>
+
+angular.module('directives')
+
+.directive('sprite', function($parse) {
+ return function(scope:ng.IScope, element:JQuery, attrs) {
+ // element is the player div
+ // attrs.sprite is "player1"
+
+ var isWalking;
+
+ function setFacing(facing) {
+ var facing = (typeof facing == 'undefined') ? "down" : facing;
+
+ if(facing == "up") {
+ element.css('backgroundPositionY', '-100px');
+ }
+
+ if(facing == "right") {
+ element.css('backgroundPositionY', '-50px');
+ }
+
+ if(facing == "down") {
+ element.css('backgroundPositionY', '-150px');
+ }
+
+ if(facing == "left") {
+ element.css('backgroundPositionY', '0px');
+ }
+ }
+
+ function walking() {
+ var i = 0;
+ var animateWalk = function() {
+ return setTimeout(function(){
+ setSprite(++i % 3);
+ if(isWalking) {
+ animateWalk();
+ }
+ }, 70);
+ }
+
+ return animateWalk();
+ }
+
+ function setSprite(sprite) {
+ if(sprite == 0) {
+ element.css('backgroundPositionX', '0');
+ }
+
+ if(sprite == 1) {
+ element.css('backgroundPositionX', '-50px');
+ }
+
+ if(sprite == 2) {
+ element.css('backgroundPositionX', '-100px');
+ }
+ }
+
+ scope.$watch(attrs.sprite, function(val) {
+ setSprite(val);
+ })
+
+ scope.$watch(attrs.spriteFacing, function(val) {
+ setFacing(val);
+ })
+
+ scope.$watch(attrs.spriteWalking, function(val) {
+ if(val) {
+ isWalking = true;
+ walking();
+ } else {
+ isWalking = false;
+ }
+ })
+ }
+})
View
15 public/filters/position.js
@@ -1,15 +0,0 @@
-
-
-angular.module("filters")
- .filter("position", function(Board) {
- return function(object) {
- return {left: object.x * Board.unit + "px", top: object.y * Board.unit + "px"}
- }
- })
-
-angular.module("filters")
- .filter("tauntposition", function(Board) {
- return function(object) {
- return {left: (object.x+1) * Board.unit + "px", top: object.y * Board.unit + "px"}
- }
- })
View
9 public/filters/position.ts
@@ -0,0 +1,9 @@
+///<reference path="../def/angular.d.ts"/>
+
+angular.module('filters')
+
+.filter("position", function(Board:IBoard) {
+ return function(object:IPoint) {
+ return {left: object.x * Board.UNIT + "px", top: object.y * Board.UNIT + "px"}
+ }
+})
View
31 public/index.html
@@ -1,30 +1,21 @@
<!doctype html>
-<html lang="en" ng-app="uarbg2">
+<html lang="en" ng-app="app">
<head>
<meta charset="utf-8">
<title>Underwater Adventure Rocket Bazooka Guys II</title>
<link rel="stylesheet" href="css/main.css"/>
</head>
<body>
- <div ng-view></div>
- <script src="https://static.firebase.com/v0/firebase.js"></script>
- <script src="components/underscore/underscore-min.js"></script>
- <script src="components/jquery/jquery.js"></script>
- <script src="components/AngularJS/angular.js"></script>
+ <div ng-view></div>
+
+ <!-- Libraries: TODO switch to AMD once typescript is less stupid -->
+ <script src="https://static.firebase.com/v0/firebase.js"></script>
+ <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script>
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
+ <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
+
+ <!-- Application Code -->
+ <script src="main.js"></script>
- <script src="main.js"></script>
- <script src="controllers/IdentifyCtrl.js"></script>
- <script src="controllers/GameCtrl.js"></script>
- <script src="controllers/PaymentCtrl.js"></script>
- <script src="services/Board.js"></script>
- <script src="services/Players.js"></script>
- <script src="services/Missiles.js"></script>
- <script src="services/FB.js"></script>
- <script src="services/CurrentPlayer.js"></script>
- <script src="services/SoundEffects.js"></script>
- <script src="services/AppVersion.js"></script>
- <script src="directives/keys.js"></script>
- <script src="directives/sprite.js"></script>
- <script src="filters/position.js"></script>
</body>
</html>
View
13 public/main.js
@@ -1,13 +0,0 @@
-angular.module('services', [])
-angular.module('directives', [])
-angular.module('filters', [])
-
-angular.module('uarbg2', ['services', 'directives', 'filters'], function ($routeProvider) {
- $routeProvider.when('/game/:gameId', {templateUrl: 'partials/game.html', controller: GameCtrl})
- $routeProvider.when('/identify', {templateUrl: 'partials/identify.html', controller: IdentifyCtrl})
- $routeProvider.when('/paid', {templateUrl: 'partials/paid.html', controller: PaymentCtrl})
- $routeProvider.otherwise({redirectTo: '/identify'})
-})
-
-//var myDataReference = new Firebase('https://seanhess.firebaseio.com/');
-//myDataReference.set('I am now writing data into Firebase!');
View
0  public/modules.js
No changes.
View
6 public/modules.ts
@@ -0,0 +1,6 @@
+console.log("INITIALIZING MODULES")
+// Initialize Angular Modules
+angular.module('services',[])
+angular.module('directives',[])
+angular.module('filters',[])
+angular.module('controllers',['services', 'filters', 'directives'])
View
2  public/partials/game.html
@@ -31,7 +31,7 @@
<h1 class="winner" ng-show="players.winner">{{players.winner.name}} Wins!</h1>
<div class="player {{player.avatar}}"
- ng-repeat="player in players.alivePlayers() | filter:{state:'alive'}"
+ ng-repeat="player in players.all | filter:{state:'alive'}"
ng-style="player | position"
sprite="player.sprite"
sprite-facing="player.facing"
View
3  public/services/AppVersion.js
@@ -1,3 +0,0 @@
-angular.module('services').factory('AppVersion', function($rootScope) {
- return "1.1"
-})
View
7 public/services/AppVersion.ts
@@ -0,0 +1,7 @@
+///<reference path="../def/angular.d.ts"/>
+
+angular.module('services')
+
+.factory('AppVersion', function():string {
+ return "1.1"
+})
View
98 public/services/Board.js
@@ -1,98 +0,0 @@
-angular.module('services')
-.factory('Board', function($rootScope) {
-
- var map = {
- width: 800,
- height: 600,
- unit: 50
- }
-
- map.grid = {
- x: map.width / map.unit,
- y: map.height / map.unit
- }
-
- console.log(map, map.grid)
-
- // Directions
- var LEFT = "left"
- var RIGHT = "right"
- var UP = "up"
- var DOWN = "down"
-
- function getPosition(direction) {
- var position = {}
-
- if(direction === UP) {
- position.axis = 'y'
- position.distance = -1;
- }
-
- else if(direction === RIGHT) {
- position.axis = 'x'
- position.distance = 1
- }
-
- else if(direction === DOWN) {
- position.axis = 'y'
- position.distance = 1
- }
-
- else if(direction === LEFT) {
- position.axis = 'x'
- position.distance = -1
- }
-
- else {
- console.log("BAD DIRECTION", direction)
- return false
- }
-
- return position;
- }
-
- function move(object, position) {
- var axis = position.axis
- var distance = position.distance
- var potential = object[axis] + distance;
- var direction;
- if (axis == 'x' && distance > 0) direction = RIGHT
- else if (axis == 'x' && distance < 0) direction = LEFT
- else if (axis == 'y' && distance > 0) direction = DOWN
- else if (axis == 'y' && distance < 0) direction = UP
- else console.log("BAD MOVE", axis, distance)
-
- if (map.grid[axis] <= potential || potential < 0) {
- return false
- }
-
- return {
- axis: axis,
- location: potential,
- facing: direction
- }
- }
-
- function isHit(one, two) {
- return (one.x == two.x && one.y == two.y)
- }
-
- function makeRandomN(max) {
- return function() {
- return Math.floor(Math.random() * max)
- }
- }
-
- return {
- move: move,
- getPosition: getPosition,
- unit: map.unit,
- isHit: isHit,
- randomX: makeRandomN(map.grid.x),
- randomY: makeRandomN(map.grid.y),
- LEFT: LEFT,
- RIGHT: RIGHT,
- UP: UP,
- DOWN: DOWN,
- }
-})
View
125 public/services/Board.ts
@@ -0,0 +1,125 @@
+///<reference path="../def/angular.d.ts"/>
+
+interface IPosition {
+ axis:string;
+ distance:number;
+}
+
+interface IPoint {
+ x:number;
+ y:number;
+}
+
+interface IBoard {
+ getPosition(direction:string):IPosition;
+ move(object:IPoint, position:IPosition);
+ isHit(one:IPoint, two:IPoint):bool;
+ randomX():number;
+ randomY():number;
+
+ // constants
+ LEFT: string;
+ RIGHT: string;
+ UP: string;
+ DOWN: string;
+
+ WIDTH: number;
+ HEIGHT: number;
+ UNIT: number;
+}
+
+// these are the worst variable names of all time
+interface IMove {
+ axis: string;
+ location: number;
+ facing: string;
+}
+
+angular.module('services')
+
+.factory('Board', function($rootScope:ng.IRootScopeService):IBoard {
+
+ var WIDTH = 800
+ var HEIGHT = 600
+ var UNIT = 50
+ var GRID = {
+ x: WIDTH / UNIT,
+ y: HEIGHT / UNIT,
+ }
+
+ var Board = {
+ move: move,
+ getPosition: getPosition,
+ isHit: isHit,
+ randomX: makeRandomN(GRID.x),
+ randomY: makeRandomN(GRID.y),
+
+ // Direction Constants
+ LEFT: "left",
+ RIGHT: "right",
+ UP: "up",
+ DOWN: "down",
+
+ UNIT:UNIT,
+ WIDTH:WIDTH,
+ HEIGHT:HEIGHT,
+ }
+
+ return Board
+
+ function getPosition(direction:string):IPosition {
+
+ if(direction === Board.UP) {
+ return {axis: 'y', distance: -1}
+ }
+
+ if(direction === Board.RIGHT) {
+ return {axis: 'x', distance: 1}
+ }
+
+ if(direction === Board.DOWN) {
+ return {axis: 'y', distance: 1}
+ }
+
+ if(direction === Board.LEFT) {
+ return {axis: 'x', distance: -1}
+ }
+
+ else {
+ console.log("BAD DIRECTION", direction)
+ return null
+ }
+ }
+
+ function move(object:IPoint, position:IPosition) {
+ var axis = position.axis
+ var distance = position.distance
+ var potential = object[axis] + distance;
+ var direction;
+ if (axis == 'x' && distance > 0) direction = Board.RIGHT
+ else if (axis == 'x' && distance < 0) direction = Board.LEFT
+ else if (axis == 'y' && distance > 0) direction = Board.DOWN
+ else if (axis == 'y' && distance < 0) direction = Board.UP
+ else console.log("BAD MOVE", axis, distance)
+
+ if (GRID[axis] <= potential || potential < 0) {
+ return null
+ }
+
+ return {
+ axis: axis,
+ location: potential,
+ facing: direction
+ }
+ }
+
+ function isHit(one:IPoint, two:IPoint):bool {
+ return (one.x == two.x && one.y == two.y)
+ }
+
+ function makeRandomN(max:number) {
+ return function():number {
+ return Math.floor(Math.random() * max)
+ }
+ }
+})
View
26 public/services/CurrentPlayer.js
@@ -1,26 +0,0 @@
-angular.module('services')
-.factory('CurrentPlayer', function() {
- // lets you share the current player
-
- function loadPreferences() {
- return {
- avatar: localStorage.avatar,
- name: localStorage.name,
- gameId: localStorage.gameId
- }
- }
-
- function savePreferences(player, gameId) {
- localStorage.avatar = player.avatar
- localStorage.name = player.name
- localStorage.gameId = gameId
- }
-
-
- return {
- player: null,
- loadPreferences: loadPreferences,
- savePreferences: savePreferences
- }
-})
-
View
39 public/services/CurrentPlayer.ts
@@ -0,0 +1,39 @@
+///<reference path="../def/angular.d.ts"/>
+
+interface IPreferences {
+ avatar:string;
+ name:string;
+ gameId:string;
+}
+
+interface ICurrentPlayerService {
+ player:IPlayer;
+ loadPreferences():IPreferences;
+ savePreferences(player:IPlayer, gameId:string);
+}
+
+angular.module('services')
+
+.factory('CurrentPlayer', function():ICurrentPlayerService {
+ // lets you share the current player
+
+ function loadPreferences():IPreferences {
+ return {
+ avatar: localStorage.getItem("avatar"),
+ name: localStorage.getItem("name"),
+ gameId: localStorage.getItem("gameId"),
+ }
+ }
+
+ function savePreferences(player:IPlayer, gameId:string) {
+ localStorage.setItem("avatar", player.avatar)
+ localStorage.setItem("name", player.name)
+ localStorage.setItem("gameId", gameId)
+ }
+
+ return {
+ player: null,
+ loadPreferences: loadPreferences,
+ savePreferences: savePreferences
+ }
+})
View
32 public/services/FB.js
@@ -1,32 +0,0 @@
-angular.module('services')
-.factory('FB', function($rootScope) {
- var FB = function(gameId) {
- var ref = new Firebase("https://seanhess.firebaseio.com/uarbg2/" + gameId)
- return ref
- }
-
- // helps you bind to firebase events
- FB.apply = function(f) {
- return function(ref) {
- if ($rootScope.$$phase)
- return f(ref.val())
- $rootScope.$apply(function() {
- f(ref.val())
- })
- }
- }
-
- // just updates everything, ignore angular $$hashKey
- FB.update = function(ref, obj) {
- //console.log("UPDATE", obj)
-
- for (var key in obj) {
- if (obj[key] === undefined)
- delete obj[key]
- }
-
- ref.set(_.omit(obj, "$$hashKey"))
- }
-
- return FB
-})
View
76 public/services/FB.ts
@@ -0,0 +1,76 @@
+///<reference path="../def/angular.d.ts"/>
+///<reference path="../def/underscore.d.ts"/>
+
+// TODO switch to firebase.d.ts
+declare var Firebase;
+
+module firebase {
+
+ export interface IRef {
+ child(name:string);
+ val();
+ on(event:string, cb:IRefCB);
+ set(val:any);
+ removeOnDisconnect();
+ }
+
+ export interface IRefCB {
+ (ref:IRef);
+ }
+
+ export interface IValueCB {
+ (val:any);
+ }
+
+ export interface IFB {
+ game(gameId:string):IRef;
+ apply(cb:IValueCB):IRefCB;
+ update(ref:IRef, obj:any);
+ }
+
+
+ // Functional Style Class: it's the same as the module that you were looking for!
+ // wait, this sucks. To call other functions in the module, you have to use this
+ // oh, it's not that bad
+
+ // KEEP AROUND: as an example of the class function method
+ // plus: you can define all the typing inline
+ // minus: you have to use "this" for all dependencies
+ // minus: can lose this pointer
+ // minus: you should be using an interface type, so you have to define the interface twice anyway
+
+ export class FB {
+
+ constructor(
+ private $rootScope:ng.IRootScopeService
+ ) { }
+
+ game(gameId:string):IRef {
+ var ref = new Firebase("https://seanhess.firebaseio.com/uarbg2/" + gameId)
+ return ref
+ }
+
+ apply(f:IValueCB):IRefCB {
+ return (ref:IRef) => {
+ if ((<any>this.$rootScope).$$phase)
+ return f(ref.val())
+ this.$rootScope.$apply(function() {
+ f(ref.val())
+ })
+ }
+ }
+
+ update(ref:IRef, obj:any) {
+ for (var key in obj) {
+ if (obj[key] === undefined)
+ delete obj[key]
+ }
+
+ ref.set(_.omit(obj, "$$hashKey"))
+ }
+ }
+}
+
+angular.module('services').factory('FB', function($rootScope) {
+ return new firebase.FB($rootScope)
+})
View
9 public/services/Missiles.js → public/services/Missiles.ts
@@ -1,9 +1,12 @@
+///<reference path="../def/angular.d.ts"/>
// This service keeps track of the missiles
-angular.module('services').factory('Missiles', function($rootScope, FB, Board) {
+angular.module('services')
+
+.factory('Missiles', function($rootScope, FB, Board) {
return function(gameId, Players) {
- var gameRef = new FB(gameId)
+ var gameRef = FB.game(gameId)
var missilesRef = gameRef.child('missiles')
var gameStatusRef = gameRef.child('gameStatus')
@@ -97,6 +100,4 @@ angular.module('services').factory('Missiles', function($rootScope, FB, Board) {
return missiles
}
-
})
-
View
229 public/services/Players.js
@@ -1,229 +0,0 @@
-// This service keeps track of all the current players (in an array), and merges moves into your stuff
-// Also lets you join
-
-angular.module('services').factory('Players', function($rootScope, FB, Board, AppVersion) {
- return function(gameId) {
-
- var taunt_list = [
- "Oooh yeah!",
- "I fart in your general direction.",
- "Your mother was a hamster and your father smelt of elderberries.",
- "All your base are belong to us!",
- "OK, next round, try it WITH your glasses on.",
- "If your daddy's aim is as bad as yours, I'm surprised you're here at all!"
- ]
-
- var STATE_ALIVE = "alive"
- var STATE_DEAD = "dead"
-
- var gameRef = new FB(gameId)
- var playersRef = gameRef.child('players')
-
- var all = []
- var myname = null
- var isPaidVal = isPaid();
-
- function join(player) {
- //console.log("Join:", player.name)
- myname = player.name
- player.x = Board.randomX()
- player.y = Board.randomY()
- player.sprite = '1'
- player.facing = "down"
- player.state = STATE_ALIVE
- player.wins = player.wins || 0
- player.losses = player.losses || 0
- player.message = null
- player.version = AppVersion
-
- var ref = playersRef.child(player.name)
- ref.removeOnDisconnect();
- FB.update(ref, player)
- }
-
- // what can change on a person?
- // position = {x, y, facing}
- // then you can bind to it separately
-
- function listen() {
- playersRef.on('child_added', FB.apply(onJoin))
- playersRef.on('child_changed', FB.apply(onUpdate))
- playersRef.on('child_removed', FB.apply(onQuit))
-
- gameRef.child('winner').on('value', FB.apply(onWinner))
- }
-
- function onJoin(player) {
- if (!players.current && player.name == myname) {
- players.current = player
- }
- all.push(player)
- }
-
- function onUpdate(remotePlayer) {
- var player = playerByName(remotePlayer.name)
- if (!player) {
- return console.log("Error, player not found: "+remotePlayer.name)
- }
-
- //console.log("Update:", player.name, "state="+player.state)
-
- // copy as many properites as you care about
- player.x = remotePlayer.x
- player.y = remotePlayer.y
- player.facing = remotePlayer.facing
- player.state = remotePlayer.state;
- player.wins = remotePlayer.wins;
- player.losses = remotePlayer.losses;
- player.walking = remotePlayer.walking;
- if (remotePlayer.killer) player.killer = remotePlayer.killer
-
- if (player.state == STATE_DEAD) {
- $rootScope.$broadcast("kill", player)
- checkWin()
- }
- }
-
- function onQuit(player) {
- all = all.filter(function(p) {
- return (p.name != player.name)
- })
- }
-
- function checkWin() {
- var alive = alivePlayers()
-
- if (alive.length > 1) return
- var winner = alive[0]
- if (players.current == null || winner != players.current) return
-
- // only if is ME
- // why not share the winner with everyone?
- winner.wins += 1
- playersRef.child(winner.name).child("wins").set(winner.wins)
- gameRef.child("winner").removeOnDisconnect();
- FB.update(gameRef.child("winner"), winner)
- // Nobody else should be able to act (already because they are dead)
-
- // game is set to OVER (missiles finish hitting? like, can you still die?)
- // save the WINNER!
-
- // YOU WIN
-
- // kick the game back to zero
- // restart the game in 3 seconds!
- // then turn everyone back to alive! (the winner does this?)
- }
-
- function onWinner(player) {
-
- // this can get called with null
- if (!player) {
- players.winner = null
- players.taunt = null
- return
- }
-
- // don't "WIN" twice if you're already the winner
- if (players.winner && players.winner.name == player.name) return
-
- // set the winner on all computers
- players.winner = player
- players.taunt = taunt_list[Math.floor(Math.random()*taunt_list.length)];
-
- // only one person should reset the game
- //console.log("ON WINNER")
- //if (players.current) console.log(" - me ", players.current.name)
- //if (player) console.log(" - win", player.name)
- //if (players.winner) console.log(" - old", players.winner.name)
- //console.log("PASSED")
-
- if (players.current && players.current.name == player.name) {
- setTimeout(resetGame, 3000)
- }
- }
-
- function resetGame() {
- console.log("Initialize Game")
- // build walls?? (how t
- // for each player, make them alive
- gameRef.child('winner').remove()
-
- all.forEach(function(player) {
- player.x = Board.randomX()
- player.y = Board.randomY()
- player.sprite = '1'
- player.facing = "down"
- player.state = STATE_ALIVE
- FB.update(playersRef.child(player.name), player)
- })
-
- }
-
- // killPlayer ONLY happens from the current player's perspective. yOu can only kill yourself
- function killPlayer(player, killerName) {
- player.state = STATE_DEAD
- player.losses += 1
- player.killer = killerName
- console.log("KILL PLAYER", player)
- FB.update(playersRef.child(player.name), player)
- }
-
- function move(player) {
- var playerRef = getPlayerRef(player.name)
- FB.update(playerRef, player)
- }
-
- function getPlayerRef(name) {
- return playersRef.child(name)
- }
-
- function playerByName(name) {
- return all.filter(function(p) {
- return (p.name == name)
- })[0]
- }
-
- function isAlive(p) {
- return (p.state == STATE_ALIVE)
- }
-
- function alivePlayers() {
- return all.filter(isAlive)
- }
-
-
- function isPaid() {
- return (localStorage.getItem("payment_status") == "paid");
- //return FB.apply(function () {return (localStorage.getItem("payment_status") == "paid")});
- }
- console.log("isPaid()= ",isPaid())
- console.log("isPaidVal= ",isPaidVal)
-
- function latestVersion() {
- return _(all).max(function(player) {
- return player.version
- })
- }
-
-
- var players = {
- current: null,
- winner: null,
- taunt: null,
- isPaid: isPaidVal,
- all: all,
- alivePlayers: alivePlayers,
- join: join,
- listen: listen,
- move: move,
- killPlayer: killPlayer,
- playerByName: playerByName,
- latestVersion: latestVersion
- }
-
- return players
- }
-
-})
-
View
285 public/services/Players.ts
@@ -0,0 +1,285 @@
+
+// And I like passing the state around instead of making it internal
+// but keep it minimal (use state.all instead of state)
+
+///<reference path="../def/angular.d.ts"/>
+///<reference path="./FB"/>
+///<reference path="./AppVersion"/>
+///<reference path="./Board"/>
+
+interface IPlayer {
+ x:number;
+ y:number;
+ facing:string;
+ state:string;
+ wins:number;
+ losses:number;
+ message:string;
+ version:string;
+ name:string;
+ killer:string;
+ avatar:string;
+ status:string;
+
+ // move this off of player
+ walking:bool;
+ sprite:number;
+}
+
+// only variables
+interface IPlayerState {
+ current: IPlayer;
+ winner: IPlayer;
+ taunt: string;
+ isPaid: bool;
+ all: IPlayer [];
+
+ // private stuff. not for binding
+ myname:string;
+ gameRef:firebase.IRef;
+ playersRef:firebase.IRef;
+}
+
+// only methods
+interface IPlayerService {
+
+ isAlive(p:IPlayer):bool;
+ alivePlayers(players:IPlayer[]):IPlayer[];
+ playerByName(players:IPlayer[], name:string):IPlayer;
+ latestVersion(players:IPlayer[]):string;
+
+ connect(gameId:string):IPlayerState;
+ join(state:IPlayerState, player:IPlayer);
+ killPlayer(state:IPlayerState, player:IPlayer, killerName:string);
+ move(state:IPlayerState, player:IPlayer);
+}
+
+angular.module('services')
+
+.factory('Players', function($rootScope:ng.IScope, FB:firebase.IFB, Board:IBoard, AppVersion:any):IPlayerService {
+ // the big cheese. Does the deed
+ // you can make fancy bindings here, no?
+
+ return {
+ isAlive: isAlive,
+ alivePlayers: alivePlayers,
+ playerByName: playerByName,
+ latestVersion: latestVersion,
+
+ connect: connect,
+ join: join,
+ killPlayer: killPlayer,
+ move: move
+ }
+
+ function connect(gameId:string):IPlayerState {
+
+ var gameRef = FB.game(gameId)
+ var playersRef = gameRef.child('players')
+
+ var state:IPlayerState = {
+ myname:null,
+ gameRef:gameRef,
+ playersRef:playersRef,
+
+ current: null,
+ winner: null,
+ taunt: null,
+ isPaid: isPaid(),
+ all: []
+ }
+
+ // better way to bind? nope! that's what they are for!
+ playersRef.on('child_added', FB.apply((p) => onJoin(state,p)))
+ playersRef.on('child_changed', FB.apply((p) => onUpdate(state,p)))
+ playersRef.on('child_removed', FB.apply((p) => onQuit(state,p)))
+
+ return state
+ }
+
+ function isAlive(p:IPlayer):bool {
+ return (p.state == STATE.ALIVE)
+ }
+
+ function alivePlayers(players:IPlayer[]):IPlayer[] {
+ return players.filter(isAlive)
+ }
+
+ // you need to define the functions in here, so they have access to the state!
+ function join(state:IPlayerState, player:IPlayer) {
+
+ state.myname = player.name
+
+ player.x = Board.randomX()
+ player.y = Board.randomY()
+ player.sprite = 1
+ player.facing = "down"
+ player.state = STATE.ALIVE
+ player.wins = player.wins || 0
+ player.losses = player.losses || 0
+ player.message = null
+ player.version = AppVersion.num
+
+ var ref = state.playersRef.child(player.name)
+ ref.removeOnDisconnect();
+ FB.update(ref, player)
+ }
+
+ // what can change on a person?
+ // position = {x, y, facing}
+ // then you can bind to it separately
+
+ function onJoin(state:IPlayerState, player:IPlayer) {
+ if (!state.current && player.name == state.myname) {
+ state.current = player
+ }
+ state.all.push(player)
+ }
+
+ function onUpdate(state:IPlayerState, remotePlayer:IPlayer) {
+ var player = playerByName(state.all, remotePlayer.name)
+ if (!player) {
+ return console.log("Error, player not found: "+remotePlayer.name)
+ }
+
+ //console.log("Update:", player.name, "state="+player.state)
+
+ // copy as many properites as you care about
+ player.x = remotePlayer.x
+ player.y = remotePlayer.y
+ player.facing = remotePlayer.facing
+ player.state = remotePlayer.state;
+ player.wins = remotePlayer.wins;
+ player.losses = remotePlayer.losses;
+ //player.walking = remotePlayer.walking;
+ if (remotePlayer.killer) player.killer = remotePlayer.killer
+
+ if (player.state == STATE.DEAD) {
+ $rootScope.$broadcast("kill", player)
+ checkWin(state)
+ }
+ }
+
+ function onQuit(state:IPlayerState, player:IPlayer) {
+ state.all = state.all.filter((p) => p.name != player.name)
+ }
+
+ function checkWin(state:IPlayerState) {
+ var alive = alivePlayers(state.all)
+
+ if (alive.length > 1) return
+ var winner = alive[0]
+ if (state.current == null || winner != state.current) return
+
+ // only if is ME
+ // why not share the winner with everyone?
+ winner.wins += 1
+ state.playersRef.child(winner.name).child("wins").set(winner.wins)
+ state.gameRef.child("winner").removeOnDisconnect();
+ FB.update(state.gameRef.child("winner"), winner)
+ // Nobody else should be able to act (already because they are dead)
+
+ // game is set to OVER (missiles finish hitting? like, can you still die?)
+ // save the WINNER!
+
+ // YOU WIN
+
+ // kick the game back to zero
+ // restart the game in 3 seconds!
+ // then turn everyone back to alive! (the winner does this?)
+ }
+
+ function onWinner(state:IPlayerState, player:IPlayer) {
+
+ // this can get called with null
+ if (!player) {
+ state.winner = null
+ state.taunt = null
+ return
+ }
+
+ // don't "WIN" twice if you're already the winner
+ if (state.winner && state.winner.name == player.name)
+ return
+
+ // set the winner on all computers
+ state.winner = player
+ state.taunt = TAUNT_LIST[Math.floor(Math.random()*TAUNT_LIST.length)];
+
+ // only one person should reset the game
+ //console.log("ON WINNER")
+ //if (players.current) console.log(" - me ", players.current.name)
+ //if (player) console.log(" - win", player.name)
+ //if (players.winner) console.log(" - old", players.winner.name)
+ //console.log("PASSED")
+
+ if (state.current && state.current.name == player.name) {
+ setTimeout(() => resetGame(state), 3000)
+ }
+ }
+
+ function resetGame(state:IPlayerState) {
+ console.log("Initialize Game")
+ // build walls?? (how t
+ // for each player, make them alive
+ state.gameRef.child('winner').remove()
+
+ state.all.forEach((player) => {
+ player.x = Board.randomX()
+ player.y = Board.randomY()
+ player.sprite = 1
+ player.facing = "down"
+ player.state = STATE.ALIVE
+ FB.update(state.playersRef.child(player.name), player)
+ })
+ }
+
+ // killPlayer ONLY happens from the current player's perspective. yOu can only kill yourself
+ function killPlayer(state:IPlayerState, player:IPlayer, killerName:string) {
+ player.state = STATE.DEAD
+ player.losses += 1
+ player.killer = killerName
+ FB.update(state.playersRef.child(player.name), player)
+ }
+
+ function move(state:IPlayerState, player:IPlayer) {
+ var playerRef = state.playersRef.child(player.name)
+ FB.update(playerRef, player)
+ }
+
+ // just make them class members?
+ // your function stuff is CRAP if you don't pass it in. no better than a class
+ // property of PLAYERS
+ function playerByName(players:IPlayer[], name:string):IPlayer {
+ return players.filter((p) => (p.name == name))[0]
+ }
+
+ function latestVersion(players:IPlayer[]):string {
+ return _.max(players, (player) => player.version)
+ }
+
+ // TODO move me into another service
+ function isPaid():bool {
+ return (localStorage.getItem("payment_status") == "paid");
+ //return FB.apply(function () {return (localStorage.getItem("payment_status") == "paid")});
+ }
+
+})
+
+// CONSTANTS
+
+var TAUNT_LIST = [
+ "Oooh yeah!"
+ , "I fart in your general direction."
+ , "Your mother was a hamster and your father smelt of elderberries."
+ , "All your base are belong to us!"
+ , "OK, next round, try it WITH your glasses on."
+ , "If your daddy's aim is as bad as yours, I'm surprised you're here at all!"
+ , "Boom!"
+]
+
+var STATE = {
+ DEAD: "dead",
+ ALIVE: "alive"
+}
+
View
48 public/services/SoundEffects.js → public/services/SoundEffects.ts
@@ -1,42 +1,42 @@
+interface ISoundEffectsService {
+ music();
+ explosion();
+ rocket();
+}
-angular.module('services').factory('SoundEffects', function() {
+declare class Audio {
+ currentTime: number;
+ play();
+ pause();
+}
+angular.module('services')
- // simple sound, lets you play/pause, with a beginning offset
- function simpleSound(file, seconds) {
- return {
- // plays the sound, starting at the offset
- play: function() {
- play(audio, seconds)
- }
- }
- }
+.factory('SoundEffects', function():ISoundEffectsService {
var bgMusic = new Audio("/audio/g-style.mp3")
//var underwater = new Audio("/audio/Underwater.mp3")
var epic = new Audio("/audio/UnderwaterEpicBattle.mp3")
- function makeMusic(audio, seconds) {
- console.log("makeMusic ",audio.networkState, " / ", audio.readyState)
+ function makeMusic(audio:any, seconds:number):() => void {
seconds = seconds || 0
-
return function() {
audio.play();
}
- /*
- var callback = function() {
- $(audio).bind("canplay", function() {
- console.log("makeMusic - canplay")
- audio.currentTime = seconds
- audio.play()
- })
- }
- audio.load()
- return callback*/
+
+ //var callback = function() {
+ //$(audio).bind("canplay", function() {
+ //console.log("makeMusic - canplay")
+ //audio.currentTime = seconds
+ //audio.play()
+ //})
+ //}
+ //audio.load()
+ //return callback
}
// all parameters required
- function makeSound(audio, seconds, duration) {
+ function makeSound(audio:any, seconds:number, duration:number):() => void {
return function() {
audio.pause()
// we don't want the canplay thing if we're going to play it after it's been really loaded.
View
1  server.js
View
21 server.js
@@ -0,0 +1,21 @@
+var PORT = process.env.PORT || 3000
+var express = require('express')
+var stylus = require('stylus')
+var nib = require('nib')
+
+app = express()
+
+app.configure(function() {
+ app.use(stylus.middleware({
+ src: 'public',
+ compile: function(str, path) {
+ return stylus(str).use(nib()).import('nib').set('filename', path)
+ }
+ }))
+ app.use(express.static(__dirname + '/public'))
+ app.use('/components', express.static(__dirname + '/components'))
+})
+
+app.listen(PORT, function() {
+ return console.log("RUNNING " + PORT)
+})

No commit comments for this range

Something went wrong with that request. Please try again.