Skip to content

Commit

Permalink
Merge branch 'key-movement' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fielding committed Apr 4, 2012
2 parents c34103b + 8d58e13 commit 629174f
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 10 deletions.
82 changes: 73 additions & 9 deletions client/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -1560,14 +1560,59 @@ 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
Expand Down Expand Up @@ -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()
Expand Down
52 changes: 51 additions & 1 deletion client/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions shared/js/gametypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};

Expand Down

0 comments on commit 629174f

Please sign in to comment.