Skip to content

Instantly share code, notes, and snippets.

@satoshun
Created March 30, 2013 10:13
Show Gist options
  • Save satoshun/5276205 to your computer and use it in GitHub Desktop.
Save satoshun/5276205 to your computer and use it in GitHub Desktop.
bomber1
var app = angular.module("game", [], function($routeProvider, $locationProvider){
// $routeProvider.when("test", {
// templateUrl: "index.html",
// controller: MyCtrl2
// });
// $locationProvider.html5Mode(true);
});
app.config(function($interpolateProvider){
$interpolateProvider.startSymbol('((');
$interpolateProvider.endSymbol('))');
});
app.directive("keypress", function(){
return {
restrict: "A",
require: "?ngModel",
link: function(scope){
$(window).keydown(function(e){
var KEY = {
left: 37,
up: 38,
right: 39,
down: 40,
attack: 32
};
var position = scope.player.position;
switch(e.keyCode){
case KEY.left:
position.x -= 1;
break;
case KEY.right:
position.x += 1;
break;
case KEY.up:
position.y -= 1;
break;
case KEY.down:
position.y += 1;
break;
case KEY.attack:
break;
}
scope.$digest();
});
}
};
});
app.controller("MyCtrl", function($scope){
$scope.player = {};
$scope.player.position = new Spec.position();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment