Browse files

Merge pull request #31 from stucampbell/master

Fixed scrolling problem
  • Loading branch information...
2 parents f039a81 + 32d8680 commit a7d1a1d6114997bfe49d4d8d00bec9fd292fc22d @jagregory jagregory committed Jun 4, 2011
Showing with 47 additions and 15 deletions.
  1. 0 .monitor
  2. +28 −12 public/js/game/client.js
  3. +19 −3 public/js/game/kaboom.player.js
View
0 .monitor
No changes.
View
40 public/js/game/client.js
@@ -25,47 +25,58 @@ KaboomClient.prototype = {
var key = $.hotkeys.specialKeys[event.which] || String.fromCharCode(event.which).toLowerCase();
var playerChanged = false;
+ var handled = false;
if (key == 'left') {
+ handled = true;
playerChanged = player.goLeft();
}
if (key == 'right') {
+ handled = true;
playerChanged = player.goRight();
}
if (key == 'up') {
+ handled = true;
playerChanged = player.goUp();
}
if (key == 'down') {
+ handled = true;
playerChanged = player.goDown();
}
- if (playerChanged)
+ if (playerChanged){
this.notifyPlayerChanged();
+ }
+ return !handled;
},
onKeyUp : function(event){
var player = window.player;
var key = $.hotkeys.specialKeys[event.which] || String.fromCharCode(event.which).toLowerCase();
-
+ var handled = false;
+
switch (key){
case 'left':
case 'right':
+ handled = true;
player.horizontalStop();
break
case 'up':
case 'down':
+ handled = true;
player.verticalStop();
break;
}
this.notifyPlayerChanged();
-
+ return !handled;
},
+
notifyPlayerChanged: function(){
this.socket.playerChangedDirection(player);
},
@@ -87,10 +98,10 @@ KaboomClient.prototype = {
console.log('Creating game...');
window.game = new KaboomGame();
window.game.copyStateFrom(gameState);
+
window.player = window.game.findPlayer(playerState);
-
- $(document).bind('keydown', this.onKeyDown.bind(this));
- $(document).bind('keyup', this.onKeyUp.bind(this));
+ $(document).bind('keydown', this.onKeyDown.tie(this));
+ $(document).bind('keyup', this.onKeyUp.tie(this));
var renderingTargets = {
arena: $('#arena'),
@@ -104,14 +115,19 @@ KaboomClient.prototype = {
window.game.update();
renderer.update();
}, 1000/this.fps);
-
-
-
+ },
+
+ playerJoined: function(playerState){
+ var newPlayer = new KaboomPlayer();
+ newPlayer.copyStateFrom(playerState);
+ window.game.addPlayer(newPlayer);
}
+
+
};
-Function.prototype.bind = function () {
+Function.prototype.tie = function () {
if (arguments.length < 2 && arguments[0] === undefined) {
return this;
@@ -130,8 +146,8 @@ Function.prototype.bind = function () {
-Function.bind = function () {
+Function.tie = function () {
var args = Array.prototype.slice.call(arguments);
- return Function.prototype.bind.apply(args.shift(), args);
+ return Function.prototype.tie.apply(args.shift(), args);
}
View
22 public/js/game/kaboom.player.js
@@ -26,19 +26,35 @@ function Velocity(dx, dy) {
KaboomPlayer.prototype = {
goLeft: function(){
- this.velocity.dx = -1;
+ if(this.velocity.dx != -1){
+ this.velocity.dx = -1;
+ return true;
+ }
+ return false;
},
goRight: function(){
- this.velocity.dx = 1;
+ if (this.velocity.dx != 1) {
+ this.velocity.dx = 1;
+ return true;
+ }
+ return false;
},
goUp: function(){
- this.velocity.dy = -1;
+ if(this.velocity.dy != -1){
+ this.velocity.dy = -1;
+ return true;
+ }
+ return false;
},
goDown: function(){
+ if(this.velocity.dy != 1){
this.velocity.dy = 1;
+ return true;
+ }
+ return false;
},
horizontalStop: function(){

0 comments on commit a7d1a1d

Please sign in to comment.