Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minor perf tweaks to gameloop. Players were being repositioned even i…

…f they weren't moving.
  • Loading branch information...
commit 4a1a5bdc244e184827afbd3834f256937d0f082d 1 parent 843c8b7
@jagregory jagregory authored
Showing with 18 additions and 18 deletions.
  1. +0 −2  public/js/game/client.js
  2. +18 −16 public/js/game/kaboom.game.js
View
2  public/js/game/client.js
@@ -37,7 +37,6 @@ KaboomClient.prototype = {
var key = $.hotkeys.specialKeys[event.which] || String.fromCharCode(event.which).toLowerCase();
var playerActuallyChanged = window.player.go(key);
if (playerActuallyChanged) this.notifyPlayerChanged();
- console.log(event, window.player);
return (this.sendKeyToBrowser(key));
},
@@ -50,7 +49,6 @@ KaboomClient.prototype = {
var key = $.hotkeys.specialKeys[event.which] || String.fromCharCode(event.which).toLowerCase();
window.player.stop(key);
this.notifyPlayerChanged();
- console.log(event, window.player);
return (this.sendKeyToBrowser(key));
},
notifyPlayerChanged: function() {
View
34 public/js/game/kaboom.game.js
@@ -89,25 +89,27 @@ KaboomGame.prototype = {
var game = this;
/* For each player, assume they have moved DISTANCE in their own velocity */
this.players.forEach(function(p, idx) {
- if (p) {
- var playerRect = p
- .getBounds(game)
- .translate({
- x: game.DISTANCE * p.velocity.dx,
- y: game.DISTANCE * p.velocity.dy
- });
- var hitTestRect = playerRect.contract(4);
- var canMove = true;
+ if (!p) return;
+ if (p.velocity.dx == 0 && p.velocity.dy == 0) return;
- game.level.forEachIntersectingTile(hitTestRect, game, function(tile) {
- if (tile.solid) {
- canMove = false;
- }
+ var playerRect = p
+ .getBounds(game)
+ .translate({
+ x: game.DISTANCE * p.velocity.dx,
+ y: game.DISTANCE * p.velocity.dy
});
-
- if (canMove) {
- p.position = playerRect.topLeft;
+
+ var hitTestRect = playerRect.contract(4);
+ var canMove = true;
+
+ game.level.forEachIntersectingTile(hitTestRect, game, function(tile) {
+ if (tile.solid) {
+ canMove = false;
}
+ });
+
+ if (canMove) {
+ p.position = playerRect.topLeft;
}
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.