Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'key-movement' into dev

  • Loading branch information...
commit 629174fd65dd447e04813ed965ebff87536276d5 2 parents c34103b + 8d58e13
Fielding Johnston justfielding authored
Showing with 145 additions and 10 deletions.
  1. +73 −9 client/js/game.js
  2. +51 −1 client/js/main.js
  3. +21 −0 shared/js/gametypes.js
82 client/js/game.js
View
@@ -1561,13 +1561,58 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
},
/**
+ *
+ */
+ makePlayerAttackNext: function()
+ {
+
+ pos = {
+ x: this.player.gridX,
+ y: this.player.gridY
+ };
+ switch(this.player.orientation)
+ {
+ case Types.Orientations.DOWN:
+ pos.y += 1;
+ this.makePlayerAttackTo(pos);
+ break;
+ case Types.Orientations.UP:
+ pos.y -= 1;
+ this.makePlayerAttackTo(pos);
+ break;
+ case Types.Orientations.LEFT:
+ pos.x -= 1;
+ this.makePlayerAttackTo(pos);
+ break;
+ case Types.Orientations.RIGHT:
+ pos.x += 1;
+ this.makePlayerAttackTo(pos);
+ break;
+
+ default:
+ break;
+ }
+ },
+
+ /**
+ *
+ */
+ makePlayerAttackTo: function(pos)
+ {
+ entity = this.getEntityAt(pos.x, pos.y);
+ if(entity instanceof Mob) {
+ this.makePlayerAttack(entity);
+ }
+ },
+
+ /**
* Moves the current player to a given target location.
* @see makeCharacterGoTo
*/
makePlayerGoTo: function(x, y) {
this.makeCharacterGoTo(this.player, x, y);
},
-
+
/**
* Moves the current player towards a specific item.
* @see makeCharacterGoTo
@@ -1899,20 +1944,39 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
}
},
- /**
- * Processes game logic when the user triggers a click/touch event during the game.
- */
- click: function() {
- var pos = this.getMouseGridPosition(),
- entity;
-
+ /**
+ * Moves the player one space, if possible
+ */
+ keys: function(pos, orientation) {
+ oldHoveringCollidingValue = this.hoveringCollidingTile;
+ this.hoveringCollidingTile = false;
+
+ this.processInput(pos);
+ this.player.turnTo(orientation);
+
+ this.hoveringCollidingTile = oldHoveringCollidingValue;
+ },
+
+ click: function()
+ {
+ var pos = this.getMouseGridPosition();
+
if(pos.x === this.previousClickPosition.x
&& pos.y === this.previousClickPosition.y) {
return;
} else {
this.previousClickPosition = pos;
}
-
+
+ this.processInput(pos);
+ },
+
+ /**
+ * Processes game logic when the user triggers a click/touch event during the game.
+ */
+ processInput: function(pos) {
+ var entity;
+
if(this.started
&& this.player
&& !this.isZoning()
52 client/js/main.js
View
@@ -307,13 +307,63 @@ define(['jquery', 'app'], function($, App) {
var key = e.which,
$chat = $('#chatinput');
- if(key === 13) {
+ if(key === Types.Keys.ENTER) {
if($('#chatbox').hasClass('active')) {
app.hideChat();
} else {
app.showChat();
}
}
+ if (game.started && !$('#chatbox').hasClass('active'))
+ {
+ pos = {
+ x: game.player.gridX,
+ y: game.player.gridY
+ };
+ switch(key) {
+ case Types.Keys.LEFT:
+ case Types.Keys.A:
+ case Types.Keys.KEYPAD_4:
+ pos.x -= 1;
+ game.keys(pos, Types.Orientations.LEFT);
+ break;
+ case Types.Keys.RIGHT:
+ case Types.Keys.D:
+ case Types.Keys.KEYPAD_6:
+ pos.x += 1;
+ game.keys(pos, Types.Orientations.RIGHT);
+ break;
+ case Types.Keys.UP:
+ case Types.Keys.W:
+ case Types.Keys.KEYPAD_8:
+ pos.y -= 1;
+ game.keys(pos, Types.Orientations.UP);
+ break;
+ case Types.Keys.DOWN:
+ case Types.Keys.S:
+ case Types.Keys.KEYPAD_2:
+ pos.y += 1;
+ game.keys(pos, Types.Orientations.DOWN);
+ break;
+ case Types.Keys.SPACE:
+ game.makePlayerAttackNext();
+ break;
+ case Types.Keys.I:
+ $('#achievementsbutton').click();
+ break;
+ case Types.Keys.H:
+ $('#helpbutton').click();
+ break;
+ case Types.Keys.M:
+ $('#mutebutton').click();
+ break;
+ case Types.Keys.P:
+ $('#playercount').click();
+ break;
+ default:
+ break;
+ }
+ }
});
$('#chatinput').keydown(function(e) {
21 shared/js/gametypes.js
View
@@ -97,6 +97,27 @@ Types = {
DOWN: 2,
LEFT: 3,
RIGHT: 4
+ },
+
+ Keys: {
+ ENTER: 13,
+ UP: 38,
+ DOWN: 40,
+ LEFT: 37,
+ RIGHT: 39,
+ W: 87,
+ A: 65,
+ S: 83,
+ D: 68,
+ SPACE: 32,
+ I: 73,
+ H: 72,
+ M: 77,
+ P: 80,
+ KEYPAD_4: 100,
+ KEYPAD_6: 102,
+ KEYPAD_8: 104,
+ KEYPAD_2: 98
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.