Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'key-movement' into dev

  • Loading branch information...
commit 629174fd65dd447e04813ed965ebff87536276d5 2 parents c34103b + 8d58e13
Fielding Johnston justfielding authored
82 client/js/game.js
@@ -1561,13 +1561,58 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
1561 1561 },
1562 1562
1563 1563 /**
  1564 + *
  1565 + */
  1566 + makePlayerAttackNext: function()
  1567 + {
  1568 +
  1569 + pos = {
  1570 + x: this.player.gridX,
  1571 + y: this.player.gridY
  1572 + };
  1573 + switch(this.player.orientation)
  1574 + {
  1575 + case Types.Orientations.DOWN:
  1576 + pos.y += 1;
  1577 + this.makePlayerAttackTo(pos);
  1578 + break;
  1579 + case Types.Orientations.UP:
  1580 + pos.y -= 1;
  1581 + this.makePlayerAttackTo(pos);
  1582 + break;
  1583 + case Types.Orientations.LEFT:
  1584 + pos.x -= 1;
  1585 + this.makePlayerAttackTo(pos);
  1586 + break;
  1587 + case Types.Orientations.RIGHT:
  1588 + pos.x += 1;
  1589 + this.makePlayerAttackTo(pos);
  1590 + break;
  1591 +
  1592 + default:
  1593 + break;
  1594 + }
  1595 + },
  1596 +
  1597 + /**
  1598 + *
  1599 + */
  1600 + makePlayerAttackTo: function(pos)
  1601 + {
  1602 + entity = this.getEntityAt(pos.x, pos.y);
  1603 + if(entity instanceof Mob) {
  1604 + this.makePlayerAttack(entity);
  1605 + }
  1606 + },
  1607 +
  1608 + /**
1564 1609 * Moves the current player to a given target location.
1565 1610 * @see makeCharacterGoTo
1566 1611 */
1567 1612 makePlayerGoTo: function(x, y) {
1568 1613 this.makeCharacterGoTo(this.player, x, y);
1569 1614 },
1570   -
  1615 +
1571 1616 /**
1572 1617 * Moves the current player towards a specific item.
1573 1618 * @see makeCharacterGoTo
@@ -1899,20 +1944,39 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
1899 1944 }
1900 1945 },
1901 1946
1902   - /**
1903   - * Processes game logic when the user triggers a click/touch event during the game.
1904   - */
1905   - click: function() {
1906   - var pos = this.getMouseGridPosition(),
1907   - entity;
1908   -
  1947 + /**
  1948 + * Moves the player one space, if possible
  1949 + */
  1950 + keys: function(pos, orientation) {
  1951 + oldHoveringCollidingValue = this.hoveringCollidingTile;
  1952 + this.hoveringCollidingTile = false;
  1953 +
  1954 + this.processInput(pos);
  1955 + this.player.turnTo(orientation);
  1956 +
  1957 + this.hoveringCollidingTile = oldHoveringCollidingValue;
  1958 + },
  1959 +
  1960 + click: function()
  1961 + {
  1962 + var pos = this.getMouseGridPosition();
  1963 +
1909 1964 if(pos.x === this.previousClickPosition.x
1910 1965 && pos.y === this.previousClickPosition.y) {
1911 1966 return;
1912 1967 } else {
1913 1968 this.previousClickPosition = pos;
1914 1969 }
1915   -
  1970 +
  1971 + this.processInput(pos);
  1972 + },
  1973 +
  1974 + /**
  1975 + * Processes game logic when the user triggers a click/touch event during the game.
  1976 + */
  1977 + processInput: function(pos) {
  1978 + var entity;
  1979 +
1916 1980 if(this.started
1917 1981 && this.player
1918 1982 && !this.isZoning()
52 client/js/main.js
@@ -307,13 +307,63 @@ define(['jquery', 'app'], function($, App) {
307 307 var key = e.which,
308 308 $chat = $('#chatinput');
309 309
310   - if(key === 13) {
  310 + if(key === Types.Keys.ENTER) {
311 311 if($('#chatbox').hasClass('active')) {
312 312 app.hideChat();
313 313 } else {
314 314 app.showChat();
315 315 }
316 316 }
  317 + if (game.started && !$('#chatbox').hasClass('active'))
  318 + {
  319 + pos = {
  320 + x: game.player.gridX,
  321 + y: game.player.gridY
  322 + };
  323 + switch(key) {
  324 + case Types.Keys.LEFT:
  325 + case Types.Keys.A:
  326 + case Types.Keys.KEYPAD_4:
  327 + pos.x -= 1;
  328 + game.keys(pos, Types.Orientations.LEFT);
  329 + break;
  330 + case Types.Keys.RIGHT:
  331 + case Types.Keys.D:
  332 + case Types.Keys.KEYPAD_6:
  333 + pos.x += 1;
  334 + game.keys(pos, Types.Orientations.RIGHT);
  335 + break;
  336 + case Types.Keys.UP:
  337 + case Types.Keys.W:
  338 + case Types.Keys.KEYPAD_8:
  339 + pos.y -= 1;
  340 + game.keys(pos, Types.Orientations.UP);
  341 + break;
  342 + case Types.Keys.DOWN:
  343 + case Types.Keys.S:
  344 + case Types.Keys.KEYPAD_2:
  345 + pos.y += 1;
  346 + game.keys(pos, Types.Orientations.DOWN);
  347 + break;
  348 + case Types.Keys.SPACE:
  349 + game.makePlayerAttackNext();
  350 + break;
  351 + case Types.Keys.I:
  352 + $('#achievementsbutton').click();
  353 + break;
  354 + case Types.Keys.H:
  355 + $('#helpbutton').click();
  356 + break;
  357 + case Types.Keys.M:
  358 + $('#mutebutton').click();
  359 + break;
  360 + case Types.Keys.P:
  361 + $('#playercount').click();
  362 + break;
  363 + default:
  364 + break;
  365 + }
  366 + }
317 367 });
318 368
319 369 $('#chatinput').keydown(function(e) {
21 shared/js/gametypes.js
@@ -97,6 +97,27 @@ Types = {
97 97 DOWN: 2,
98 98 LEFT: 3,
99 99 RIGHT: 4
  100 + },
  101 +
  102 + Keys: {
  103 + ENTER: 13,
  104 + UP: 38,
  105 + DOWN: 40,
  106 + LEFT: 37,
  107 + RIGHT: 39,
  108 + W: 87,
  109 + A: 65,
  110 + S: 83,
  111 + D: 68,
  112 + SPACE: 32,
  113 + I: 73,
  114 + H: 72,
  115 + M: 77,
  116 + P: 80,
  117 + KEYPAD_4: 100,
  118 + KEYPAD_6: 102,
  119 + KEYPAD_8: 104,
  120 + KEYPAD_2: 98
100 121 }
101 122 };
102 123

0 comments on commit 629174f

Please sign in to comment.
Something went wrong with that request. Please try again.