Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- move: function(x, y) {
- var player = this;
- var originCell = Board.grid[player.y][player.x];
- var targetCell = Board.grid[y][x];
- var dir;
- var steps;
- if (originCell.x < targetCell.x) {
- dir = 'E';
- steps = targetCell.x - originCell.x;
- } else if (originCell.x > targetCell.x) {
- dir = 'W';
- steps = originCell.x - targetCell.x;
- } else if (originCell.y > targetCell.y) {
- dir = 'N';
- steps = originCell.y - targetCell.y;
- } else if (originCell.y < targetCell.y) {
- dir = 'S';
- steps = targetCell.y - originCell.y;
- }
- var moveInterval = setInterval(function() {
- var currentCell = Board.grid[player.y][player.x]
- var newCoords = Board.moveCoords(dir, player.x, player.y, 1);
- var newCell = Board.grid[newCoords.y][newCoords.x];
- currentCell.removePlayer();
- newCell.addPlayer(player.id);
- // pickup weapon
- if (newCell.hasWeapon) {
- var oldWeapon = player.weapon.id;
- player.weapon = Game.weapons[newCell.weaponId];
- newCell.weaponId = oldWeapon;
- }
- player.x = newCoords.x;
- player.y = newCoords.y;
- Board.render();
- steps --;
- if (steps === 0) {
- clearInterval(moveInterval);
- player.isMoving = false;
- Game.currentTurn = (Game.currentTurn === 0) ? 1 : 0;
- Board.renderMoves();
- }
- }, 300);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement