diff --git a/src/js/game/Entities/BaseEntity.js b/src/js/game/Entities/BaseEntity.js index 67668352..3ae01b85 100644 --- a/src/js/game/Entities/BaseEntity.js +++ b/src/js/game/Entities/BaseEntity.js @@ -85,7 +85,7 @@ module.exports = class BaseEntity { var levelView = this.controller.levelView; var tween; // update z order - var zOrderYIndex = position[1] + (facing === FacingDirection.North ? 1 : 0); + var zOrderYIndex = position.y + (facing === FacingDirection.North ? 1 : 0); this.sprite.sortOrder = this.controller.levelView.yToIndex(zOrderYIndex) + 1; // stepping sound levelView.playBlockSound(groundType); @@ -93,7 +93,7 @@ module.exports = class BaseEntity { levelView.playScaledSpeed(this.sprite.animations, this.getWalkAnimation()); setTimeout(() => { tween = this.controller.levelView.addResettableTween(this.sprite).to({ - x: (this.offset[0] + 40 * position[0]), y: (this.offset[1] + 40 * position[1]) + x: (this.offset.x + 40 * position.x), y: (this.offset.y + 40 * position.y) }, 300, Phaser.Easing.Linear.None); tween.onComplete.add(() => { levelView.playScaledSpeed(this.sprite.animations, this.getIdleAnimation()); @@ -308,7 +308,7 @@ module.exports = class BaseEntity { var moveAwayPosition = moveAwayFrom.position; var bestPosition = []; let comparePositions = function (moveAwayPosition, position1, position2) { - return Position.absoluteDistanceSquare(position1[1], moveAwayPosition) < Position.absoluteDistanceSquare(position2[1], moveAwayPosition) ? position2 : position1; + return Position.absoluteDistanceSquare(position1.y, moveAwayPosition) < Position.absoluteDistanceSquare(position2.y, moveAwayPosition) ? position2 : position1; }; var currentDistance = Position.absoluteDistanceSquare(moveAwayPosition, this.position); @@ -362,8 +362,8 @@ module.exports = class BaseEntity { var moveTowardPosition = moveTowardTo.position; var bestPosition = []; let comparePositions = function (moveTowardPosition, position1, position2) { - return Position.absoluteDistanceSquare(position1[1], moveTowardPosition) > - Position.absoluteDistanceSquare(position2[1], moveTowardPosition) + return Position.absoluteDistanceSquare(position1.y, moveTowardPosition) > + Position.absoluteDistanceSquare(position2.y, moveTowardPosition) ? position2 : position1; }; @@ -527,7 +527,7 @@ module.exports = class BaseEntity { this.position = pushBackPosition; this.updateHidingTree(); var tween = this.controller.levelView.addResettableTween(this.sprite).to({ - x: (this.offset[0] + 40 * this.position[0]), y: (this.offset[1] + 40 * this.position[1]) + x: (this.offset.x + 40 * this.position.x), y: (this.offset.y + 40 * this.position.y) }, movementTime, Phaser.Easing.Linear.None); tween.onComplete.add(() => { setTimeout(() => { @@ -612,19 +612,19 @@ module.exports = class BaseEntity { blowUp(commandQueueItem, explosionPosition) { let pushBackDirection = FacingDirection.South; - if (explosionPosition[0] > this.position[0]) { + if (explosionPosition.x > this.position.x) { pushBackDirection = FacingDirection.West; this.facing = FacingDirection.East; this.updateAnimationDirection(); - } else if (explosionPosition[0] < this.position[0]) { + } else if (explosionPosition.x < this.position.x) { pushBackDirection = FacingDirection.East; this.facing = FacingDirection.West; this.updateAnimationDirection(); - } else if (explosionPosition[1] > this.position[1]) { + } else if (explosionPosition.y > this.position.y) { pushBackDirection = FacingDirection.North; this.facing = FacingDirection.South; this.updateAnimationDirection(); - } else if (explosionPosition[1] < this.position[1]) { + } else if (explosionPosition.y < this.position.y) { pushBackDirection = FacingDirection.South; this.facing = FacingDirection.North; this.updateAnimationDirection(); @@ -657,16 +657,18 @@ module.exports = class BaseEntity { remainOn = true; } this.controller.levelEntity.entityMap.forEach((workingEntity) => { - if (workingEntity.identifier !== this.identifier - && workingEntity.canTriggerPressurePlates() - && this.controller.positionEquivalence(workingEntity.position, previousPosition)) { + if ( + workingEntity.identifier !== this.identifier && + workingEntity.canTriggerPressurePlates() && + Position.equals(workingEntity.position, previousPosition) + ) { remainOn = true; } }); if (isMovingOffOf && !remainOn) { this.controller.audioPlayer.play("pressurePlateClick"); const block = new LevelBlock('pressurePlateUp'); - this.controller.levelModel.actionPlane.setBlockAt(previousPosition, block, moveOffset[0], moveOffset[1]); + this.controller.levelModel.actionPlane.setBlockAt(previousPosition, block, moveOffset.x, moveOffset.y); } } diff --git a/src/js/game/GameController.js b/src/js/game/GameController.js index a747712e..4444131c 100755 --- a/src/js/game/GameController.js +++ b/src/js/game/GameController.js @@ -608,10 +608,6 @@ class GameController { } } - positionEquivalence(lhs, rhs) { - return (lhs[0] === rhs[0] && lhs[1] === rhs[1]); - } - /** * Run a command. If no `commandQueueItem.target` is provided, the command * will be applied to all targets. @@ -725,18 +721,12 @@ class GameController { let entities = this.levelEntity.entityMap; for (let value of entities) { let entity = value[1]; - for (let i = -1; i <= 1; i++) { - for (let j = -1; j <= 1; j++) { - if (i === 0 && j === 0) { - continue; - } - let position = [targetEntity.position[0] + i, targetEntity.position[1] + j]; - this.destroyBlockWithoutPlayerInteraction(position); - if (entity.position[0] === targetEntity.position[0] + i && entity.position[1] === targetEntity.position[1] + j) { - entity.blowUp(commandQueueItem, targetEntity.position); - } + Position.getOrthogonalPositions(targetEntity.position).forEach(function (position) { + this.destroyBlockWithoutPlayerInteraction(position); + if (Position.equals(entity.position, position)) { + entity.blowUp(commandQueueItem, targetEntity.position); } - } + }); } let callbackCommand = new CallbackCommand(this, () => { }, () => { this.destroyEntity(callbackCommand, targetEntity.identifier); }, targetEntity.identifier); @@ -894,7 +884,7 @@ class GameController { const isFrontBlockDoor = frontBlock === undefined ? false : frontBlock.blockType === "door"; if (frontEntity !== null && frontEntity !== this.agent) { // push use command to execute general use behavior of the entity before executing the event - this.levelView.setSelectionIndicatorPosition(frontPosition[0], frontPosition[1]); + this.levelView.setSelectionIndicatorPosition(frontPosition.x, frontPosition.y); this.levelView.onAnimationEnd(this.levelView.playPlayerAnimation("punch", player.position, player.facing, false), () => { frontEntity.queue.startPushHighPriorityCommands(); @@ -916,10 +906,10 @@ class GameController { } else { commandQueueItem.waitForOtherQueue = true; } - setTimeout(() => { this.levelView.setSelectionIndicatorPosition(player.position[0], player.position[1]); }, 0); + setTimeout(() => { this.levelView.setSelectionIndicatorPosition(player.position.x, player.position.y); }, 0); }); } else if (isFrontBlockDoor) { - this.levelView.setSelectionIndicatorPosition(frontPosition[0], frontPosition[1]); + this.levelView.setSelectionIndicatorPosition(frontPosition.x, frontPosition.y); this.levelView.onAnimationEnd(this.levelView.playPlayerAnimation("punch", player.position, player.facing, false), () => { this.audioPlayer.play("doorOpen"); // if it's not walable, then open otherwise, close @@ -927,7 +917,7 @@ class GameController { this.levelView.playDoorAnimation(frontPosition, canOpen, () => { frontBlock.isWalkable = !frontBlock.isWalkable; this.levelView.playIdleAnimation(player.position, player.facing, player.isOnBlock); - this.levelView.setSelectionIndicatorPosition(player.position[0], player.position[1]); + this.levelView.setSelectionIndicatorPosition(player.position.x, player.position.y); commandQueueItem.succeeded(); }); }); @@ -936,7 +926,7 @@ class GameController { commandQueueItem.succeeded(); } else { this.levelView.playPunchDestroyAirAnimation(player.position, player.facing, this.levelModel.getMoveForwardPosition(), () => { - this.levelView.setSelectionIndicatorPosition(player.position[0], player.position[1]); + this.levelView.setSelectionIndicatorPosition(player.position.x, player.position.y); this.levelView.playIdleAnimation(player.position, player.facing, player.isOnBlock); this.delayPlayerMoveBy(0, 0, () => { commandQueueItem.succeeded(); @@ -1000,7 +990,7 @@ class GameController { // if there is a entity in front of the player } else { this.levelView.playPunchDestroyAirAnimation(player.position, player.facing, this.levelModel.getMoveForwardPosition(player), () => { - this.levelView.setSelectionIndicatorPosition(player.position[0], player.position[1]); + this.levelView.setSelectionIndicatorPosition(player.position.x, player.position.y); this.levelView.playIdleAnimation(player.position, player.facing, player.isOnBlock, player); this.delayPlayerMoveBy(0, 0, () => { commandQueueItem.succeeded(); @@ -1046,7 +1036,7 @@ class GameController { } this.levelView.destroyBlockWithoutPlayerInteraction(destroyPosition); this.levelView.playExplosionAnimation(this.levelModel.player.position, this.levelModel.player.facing, position, blockType, () => { }, false); - this.levelView.createMiniBlock(destroyPosition[0], destroyPosition[1], blockType); + this.levelView.createMiniBlock(destroyPosition.x, destroyPosition.y, blockType); this.updateFowPlane(); this.updateShadingPlane(); } else if (block.isUsable) { @@ -1094,7 +1084,7 @@ class GameController { this.levelModel.player.updateHidingBlock(player.position); if (this.checkMinecartLevelEndAnimation() && blockType === "rail") { // Special 'minecart' level places a mix of regular and powered tracks, depending on location. - if (player.position[1] < 7) { + if (player.position.y < 7) { blockType = "railsUnpoweredVertical"; } else { blockType = "rails"; diff --git a/src/js/game/LevelMVC/LevelModel.js b/src/js/game/LevelMVC/LevelModel.js index db6ed4aa..bf05779f 100644 --- a/src/js/game/LevelMVC/LevelModel.js +++ b/src/js/game/LevelMVC/LevelModel.js @@ -31,8 +31,8 @@ module.exports = class LevelModel { } inBounds(position) { - const x = position[0]; - const y = position[1]; + const x = position.x; + const y = position.y; return x >= 0 && x < this.planeWidth && y >= 0 && y < this.planeHeight; } @@ -432,7 +432,7 @@ module.exports = class LevelModel { } coordinatesToIndex(coordinates) { - return this.yToIndex(coordinates[1]) + coordinates[0]; + return this.yToIndex(coordinates.y) + coordinates.x; } checkPositionForTypeAndPush(blockType, position, objectArray) { @@ -500,8 +500,8 @@ module.exports = class LevelModel { var woolType = "wool_orange"; //Place this block here - //this.createBlock(this.groundPlane, startingPosition[0], startingPosition[1], woolType); - var helperStartData = [0, startingPosition[0], startingPosition[1]]; + //this.createBlock(this.groundPlane, startingPosition.x, startingPosition.y, woolType); + var helperStartData = [0, startingPosition.x, startingPosition.y]; return this.houseGroundToFloorHelper(helperStartData, woolType, []); } diff --git a/src/js/game/LevelMVC/LevelPlane.js b/src/js/game/LevelMVC/LevelPlane.js index 7a0c7d86..4ae30276 100644 --- a/src/js/game/LevelMVC/LevelPlane.js +++ b/src/js/game/LevelMVC/LevelPlane.js @@ -468,7 +468,7 @@ module.exports = class LevelPlane { } let captureReturn = false; this.levelModel.controller.levelEntity.entityMap.forEach((workingEntity) => { - if (this.levelModel.controller.positionEquivalence(position, workingEntity.position)) { + if (Position.equals(position, workingEntity.position)) { captureReturn = true; } }); @@ -666,19 +666,19 @@ module.exports = class LevelPlane { * Goes through a list of blocks and shuffles them over 1 index in a given direction. * * @param {Position[]} blocksPositions - * @param {Position} [offset=[0, 0]] + * @param {Position} [offset=new Position(0, 0)] */ - pushBlocks(blocksPositions, offset = [0, 0]) { + pushBlocks(blocksPositions, offset = new Position(0, 0)) { let pistonType = ""; let redo = false; - if (offset[0] === 1) { + if (offset.x === 1) { pistonType = "pistonArmRight"; - } else if (offset[0] === -1) { + } else if (offset.x === -1) { pistonType = "pistonArmLeft"; } else { - if (offset[1] === 1) { + if (offset.y === 1) { pistonType = "pistonArmDown"; - } else if (offset[1] === -1) { + } else if (offset.y === -1) { pistonType = "pistonArmUp"; } else { // There is no offset, so we're not putting down anything. @@ -707,9 +707,9 @@ module.exports = class LevelPlane { /** * Returns a list of blocks in a given direction to be shuffled over later. * @param {Position} position - * @param {Position} [offset=[0, 0]] + * @param {Position} [offset=new Position(0, 0)] */ - getBlocksToPush(position, offset = [0, 0]) { + getBlocksToPush(position, offset = new Position(0, 0)) { let pushingBlocks = []; let workingPosition = position; while (this.inBounds(workingPosition) && this.getBlockAt(workingPosition).getIsPushable()) { diff --git a/src/js/game/LevelMVC/LevelView.js b/src/js/game/LevelMVC/LevelView.js index a3837d3c..fddbd6f7 100644 --- a/src/js/game/LevelMVC/LevelView.js +++ b/src/js/game/LevelMVC/LevelView.js @@ -22,7 +22,7 @@ module.exports = class LevelView { this.fluffGroup = null; this.fowGroup = null; this.collectibleItems = []; - //{sprite : sprite, type : blockType, position : [x,y]} + //{sprite : sprite, type : blockType, position : Position} this.trees = []; this.miniBlocks = { @@ -375,7 +375,7 @@ module.exports = class LevelView { entity.sprite.animations.stop(); this.setPlayerPosition(entity.position, entity.isOnBlock, entity); if (entity.shouldUpdateSelectionIndicator()) { - this.setSelectionIndicatorPosition(entity.position[0], entity.position[1]); + this.setSelectionIndicatorPosition(entity.position.x, entity.position.y); this.selectionIndicator.visible = true; } this.playIdleAnimation(entity.position, entity.facing, entity.isOnBlock, entity); @@ -458,13 +458,13 @@ module.exports = class LevelView { updatePlayerDirection(position, facing) { let direction = this.getDirectionName(facing); - this.setSelectionIndicatorPosition(position[0], position[1]); + this.setSelectionIndicatorPosition(position.x, position.y); this.playScaledSpeed(this.player.sprite.animations, "idle" + direction); } // animations playDoorAnimation(position, open, completionHandler) { - let blockIndex = (this.yToIndex(position[1])) + position[0]; + let blockIndex = (this.yToIndex(position.y)) + position.x; let block = this.actionPlaneBlocks[blockIndex]; let animationName = open ? "open" : "close"; const animation = this.playScaledSpeed(block.animations, animationName); @@ -476,7 +476,7 @@ module.exports = class LevelView { playPlayerAnimation(animationName, position, facing, isOnBlock = false, entity = this.player) { let direction = this.getDirectionName(facing); - entity.sprite.sortOrder = this.yToIndex(position[1]) + entity.getSortOrderOffset(); + entity.sprite.sortOrder = this.yToIndex(position.y) + entity.getSortOrderOffset(); let animName = animationName + direction; return this.playScaledSpeed(entity.sprite.animations, animName); @@ -517,7 +517,7 @@ module.exports = class LevelView { tween; this.playPlayerAnimation("fail", position, facing, isOnBlock); - this.createBlock(this.fluffGroup, position[0], position[1], "bubbles"); + this.createBlock(this.fluffGroup, position.x, position.y, "bubbles"); sprite = this.fluffGroup.create(0, 0, "finishOverlay"); var [scaleX, scaleY] = this.controller.scaleFromOriginal(); @@ -542,7 +542,7 @@ module.exports = class LevelView { tween; this.playPlayerAnimation("jumpUp", position, facing, isOnBlock); - this.createBlock(this.fluffGroup, position[0], position[1], "fire"); + this.createBlock(this.fluffGroup, position.x, position.y, "fire"); sprite = this.fluffGroup.create(0, 0, "finishOverlay"); var [scaleX, scaleY] = this.controller.scaleFromOriginal(); @@ -604,7 +604,7 @@ module.exports = class LevelView { } flashBlock(position) { - let blockIndex = (this.yToIndex(position[1])) + position[0]; + let blockIndex = (this.yToIndex(position.y)) + position.x; let block = this.actionPlaneBlocks[blockIndex]; return this.flashSpriteToWhite(block); } @@ -653,7 +653,7 @@ module.exports = class LevelView { } playExplodingCreeperAnimation(position, facing, destroyPosition, isOnBlock, completionHandler) { - let blockIndex = (this.yToIndex(destroyPosition[1])) + destroyPosition[0]; + let blockIndex = (this.yToIndex(destroyPosition.y)) + destroyPosition.x; let blockToExplode = this.actionPlaneBlocks[blockIndex]; var creeperExplodeAnimation = blockToExplode.animations.getAnimation("explode"); @@ -672,11 +672,11 @@ module.exports = class LevelView { } playExplosionCloudAnimation(position) { - this.createBlock(this.fluffGroup, position[0], position[1], "explosion"); + this.createBlock(this.fluffGroup, position.x, position.y, "explosion"); } coordinatesToIndex(coordinates) { - return (this.yToIndex(coordinates[1])) + coordinates[0]; + return (this.yToIndex(coordinates.y)) + coordinates.x; } playMinecartTurnAnimation(position, isUp, isOnBlock, completionHandler, turnDirection) { @@ -694,7 +694,7 @@ module.exports = class LevelView { tween = this.addResettableTween(this.player.sprite).to( this.positionToScreen(nextPosition), speed, Phaser.Easing.Linear.None); tween.start(); - this.player.sprite.sortOrder = this.yToIndex(nextPosition[1]) + 10; + this.player.sprite.sortOrder = this.yToIndex(nextPosition.y) + 10; return tween; } @@ -905,7 +905,7 @@ module.exports = class LevelView { */ playMoveForwardAnimation(entity, oldPosition, facing, shouldJumpDown, isOnBlock, groundType, completionHandler) { // make sure to render high for when moving north after placing a block - const targetYIndex = entity.position[1] + (facing === FacingDirection.North ? 1 : 0); + const targetYIndex = entity.position.y + (facing === FacingDirection.North ? 1 : 0); this.playWalkAnimation(entity, oldPosition, facing, shouldJumpDown, isOnBlock, groundType, targetYIndex, completionHandler); } @@ -914,7 +914,7 @@ module.exports = class LevelView { */ playMoveBackwardAnimation(entity, oldPosition, facing, shouldJumpDown, isOnBlock, groundType, completionHandler) { // make sure to render high for when moving north after placing a block - const targetYIndex = entity.position[1] + (facing === FacingDirection.South ? 1 : 0); + const targetYIndex = entity.position.y + (facing === FacingDirection.South ? 1 : 0); this.playWalkAnimation(entity, oldPosition, facing, shouldJumpDown, isOnBlock, groundType, targetYIndex, completionHandler); } @@ -926,7 +926,7 @@ module.exports = class LevelView { this.playBlockSound(groundType); if (entity.shouldUpdateSelectionIndicator()) { - this.setSelectionIndicatorPosition(position[0], position[1]); + this.setSelectionIndicatorPosition(position.x, position.y); } if (!shouldJumpDown) { @@ -982,10 +982,10 @@ module.exports = class LevelView { playPlaceBlockAnimation(position, facing, blockType, blockTypeAtPosition, entity, completionHandler) { var jumpAnimName; - let blockIndex = this.yToIndex(position[1]) + position[0]; + let blockIndex = this.yToIndex(position.y) + position.x; if (entity.shouldUpdateSelectionIndicator()) { - this.setSelectionIndicatorPosition(position[0], position[1]); + this.setSelectionIndicatorPosition(position.x, position.y); } if (entity === this.agent || LevelBlock.isWalkable(blockType)) { @@ -1007,7 +1007,7 @@ module.exports = class LevelView { this.playScaledSpeed(this.player.sprite.animations, jumpAnimName); var placementTween = this.addResettableTween(this.player.sprite).to({ - y: (-55 + 40 * position[1]) + y: (-55 + 40 * position.y) }, 125, Phaser.Easing.Cubic.EaseOut); placementTween.onComplete.addOnce(() => { @@ -1023,7 +1023,7 @@ module.exports = class LevelView { } playPlaceBlockInFrontAnimation(entity = this.player, playerPosition, facing, blockPosition, completionHandler) { - this.setSelectionIndicatorPosition(blockPosition[0], blockPosition[1]); + this.setSelectionIndicatorPosition(blockPosition.x, blockPosition.y); this.playPlayerAnimation("punch", playerPosition, facing, false, entity).onComplete.addOnce(() => { completionHandler(); @@ -1038,7 +1038,7 @@ module.exports = class LevelView { createActionPlaneBlock(position, blockType) { const block = new LevelBlock(blockType); - const blockIndex = (this.yToIndex(position[1])) + position[0]; + const blockIndex = (this.yToIndex(position.y)) + position.x; // Remove the old sprite at this position, if there is one. this.actionGroup.remove(this.actionPlaneBlocks[blockIndex]); @@ -1054,7 +1054,7 @@ module.exports = class LevelView { if (block.getIsMiniblock()) { // miniblocks defined on the action plane like this should have a // closer collectible range and a narrower drop offset than normal - sprite = this.createMiniBlock(position[0], position[1], blockType, { + sprite = this.createMiniBlock(position.x, position.y, blockType, { collectibleDistance: 1, xOffsetRange: 10, yOffsetRange: 10 @@ -1062,11 +1062,11 @@ module.exports = class LevelView { } else { const group = block.shouldRenderOnGroundPlane() ? this.groundGroup : this.actionGroup; const offset = block.shouldRenderOnGroundPlane() ? -0.5 : 0; - sprite = this.createBlock(group, position[0], position[1] + offset, blockType); + sprite = this.createBlock(group, position.x, position.y + offset, blockType); } if (sprite) { - sprite.sortOrder = this.yToIndex(position[1]); + sprite.sortOrder = this.yToIndex(position.y); this.correctForShadowOverlay(blockType, sprite); } @@ -1074,7 +1074,7 @@ module.exports = class LevelView { } playShearAnimation(playerPosition, facing, destroyPosition, blockType, completionHandler) { - let blockIndex = this.yToIndex(destroyPosition[1]) + destroyPosition[0]; + let blockIndex = this.yToIndex(destroyPosition.y) + destroyPosition.x; let blockToShear = this.actionPlaneBlocks[blockIndex]; blockToShear.animations.stop(null, true); @@ -1086,10 +1086,10 @@ module.exports = class LevelView { } playShearSheepAnimation(playerPosition, facing, destroyPosition, blockType, completionHandler) { - this.setSelectionIndicatorPosition(destroyPosition[0], destroyPosition[1]); + this.setSelectionIndicatorPosition(destroyPosition.x, destroyPosition.y); this.onAnimationEnd(this.playPlayerAnimation("punch", playerPosition, facing, false), () => { - let blockIndex = (this.yToIndex(destroyPosition[1])) + destroyPosition[0]; + let blockIndex = (this.yToIndex(destroyPosition.y)) + destroyPosition.x; let blockToShear = this.actionPlaneBlocks[blockIndex]; blockToShear.animations.stop(null, true); @@ -1102,11 +1102,11 @@ module.exports = class LevelView { } destroyBlockWithoutPlayerInteraction(destroyPosition) { - let blockIndex = (this.yToIndex(destroyPosition[1])) + destroyPosition[0]; + let blockIndex = (this.yToIndex(destroyPosition.y)) + destroyPosition.x; let blockToDestroy = this.actionPlaneBlocks[blockIndex]; - let destroyOverlay = this.actionGroup.create(-12 + 40 * destroyPosition[0], -22 + 40 * destroyPosition[1], "destroyOverlay", "destroy1"); - destroyOverlay.sortOrder = this.yToIndex(destroyPosition[1]) + 2; + let destroyOverlay = this.actionGroup.create(-12 + 40 * destroyPosition.x, -22 + 40 * destroyPosition.y, "destroyOverlay", "destroy1"); + destroyOverlay.sortOrder = this.yToIndex(destroyPosition.y) + 2; this.onAnimationEnd(destroyOverlay.animations.add("destroy", Phaser.Animation.generateFrameNames("destroy", 1, 12, "", 0), 30, false), () => { this.actionPlaneBlocks[blockIndex] = null; @@ -1126,7 +1126,7 @@ module.exports = class LevelView { playDestroyBlockAnimation(playerPosition, facing, destroyPosition, blockType, entity, completionHandler) { if (entity.shouldUpdateSelectionIndicator()) { - this.setSelectionIndicatorPosition(destroyPosition[0], destroyPosition[1]); + this.setSelectionIndicatorPosition(destroyPosition.x, destroyPosition.y); } var playerAnimation = undefined; @@ -1150,7 +1150,7 @@ module.exports = class LevelView { playPunchAnimation(playerPosition, facing, destroyPosition, animationType, completionHandler, entity = this.player) { if (entity.shouldUpdateSelectionIndicator()) { - this.setSelectionIndicatorPosition(destroyPosition[0], destroyPosition[1]); + this.setSelectionIndicatorPosition(destroyPosition.x, destroyPosition.y); } this.onAnimationEnd(this.playPlayerAnimation(animationType, playerPosition, facing, false, entity), () => { completionHandler(); @@ -1167,7 +1167,7 @@ module.exports = class LevelView { * immediately. */ playBlockDestroyOverlayAnimation(playerPosition, facing, destroyPosition, blockType, entity, completionHandler) { - const blockIndex = (this.yToIndex(destroyPosition[1])) + destroyPosition[0]; + const blockIndex = (this.yToIndex(destroyPosition.y)) + destroyPosition.x; const blockToDestroy = this.actionPlaneBlocks[blockIndex]; const afterDestroy = () => { @@ -1180,7 +1180,7 @@ module.exports = class LevelView { this.controller.updateFowPlane(); if (entity.shouldUpdateSelectionIndicator()) { - this.setSelectionIndicatorPosition(playerPosition[0], playerPosition[1]); + this.setSelectionIndicatorPosition(playerPosition.x, playerPosition.y); } this.audioPlayer.play('dig_wood1'); @@ -1193,13 +1193,13 @@ module.exports = class LevelView { // block immediately without waiting for the animation. afterDestroy(); } else { - const destroyOverlay = this.actionGroup.create(-12 + 40 * destroyPosition[0], -22 + 40 * destroyPosition[1], "destroyOverlay", "destroy1"); + const destroyOverlay = this.actionGroup.create(-12 + 40 * destroyPosition.x, -22 + 40 * destroyPosition.y, "destroyOverlay", "destroy1"); if (LevelBlock.isFlat(blockType)) { const cropRect = new Phaser.Rectangle(0, 0, 60, 40); destroyOverlay.position.y += 20; destroyOverlay.crop(cropRect); } - destroyOverlay.sortOrder = this.yToIndex(destroyPosition[1]) + 2; + destroyOverlay.sortOrder = this.yToIndex(destroyPosition.y) + 2; this.onAnimationEnd(destroyOverlay.animations.add("destroy", Phaser.Animation.generateFrameNames("destroy", 1, 12, "", 0), 30, false), () => { destroyOverlay.kill(); this.toDestroy.push(destroyOverlay); @@ -1223,8 +1223,8 @@ module.exports = class LevelView { let miningParticlesFirstFrame = miningParticlesData[miningParticlesIndex][0]; let miningParticlesOffsetX = miningParticlesData[miningParticlesIndex][1]; let miningParticlesOffsetY = miningParticlesData[miningParticlesIndex][2]; - let miningParticles = this.actionGroup.create(miningParticlesOffsetX + 40 * destroyPosition[0], miningParticlesOffsetY + 40 * destroyPosition[1], "miningParticles", "MiningParticles" + miningParticlesFirstFrame); - miningParticles.sortOrder = this.yToIndex(destroyPosition[1]) + 2; + let miningParticles = this.actionGroup.create(miningParticlesOffsetX + 40 * destroyPosition.x, miningParticlesOffsetY + 40 * destroyPosition.y, "miningParticles", "MiningParticles" + miningParticlesFirstFrame); + miningParticles.sortOrder = this.yToIndex(destroyPosition.y) + 2; this.onAnimationEnd(miningParticles.animations.add("miningParticles", Phaser.Animation.generateFrameNames("MiningParticles", miningParticlesFirstFrame, miningParticlesFirstFrame + 11, "", 0), 30, false), () => { miningParticles.kill(); this.toDestroy.push(miningParticles); @@ -1233,7 +1233,7 @@ module.exports = class LevelView { } playExplosionAnimation(playerPosition, facing, destroyPosition, blockType, completionHandler, placeBlock, entity = this.player) { - var explodeAnim = this.actionGroup.create(-36 + 40 * destroyPosition[0], -30 + 40 * destroyPosition[1], "blockExplode", "BlockBreakParticle0"); + var explodeAnim = this.actionGroup.create(-36 + 40 * destroyPosition.x, -30 + 40 * destroyPosition.y, "blockExplode", "BlockBreakParticle0"); switch (blockType) { case "treeAcacia": @@ -1322,7 +1322,7 @@ module.exports = class LevelView { break; } - explodeAnim.sortOrder = this.yToIndex(destroyPosition[1]) + 2; + explodeAnim.sortOrder = this.yToIndex(destroyPosition.y) + 2; this.onAnimationEnd(explodeAnim.animations.add("explode", Phaser.Animation.generateFrameNames("BlockBreakParticle", 0, 7, "", 0), 30, false), () => { explodeAnim.kill(); this.toDestroy.push(explodeAnim); @@ -1345,10 +1345,10 @@ module.exports = class LevelView { } playItemDropAnimation(destroyPosition, blockType, completionHandler) { - var sprite = this.createMiniBlock(destroyPosition[0], destroyPosition[1], blockType); + var sprite = this.createMiniBlock(destroyPosition.x, destroyPosition.y, blockType); if (sprite) { - sprite.sortOrder = this.yToIndex(destroyPosition[1]) + 2; + sprite.sortOrder = this.yToIndex(destroyPosition.y) + 2; } if (this.controller.getIsDirectPlayerControl()) { @@ -1411,8 +1411,8 @@ module.exports = class LevelView { * @return {{x: number, y: number}} */ positionToScreen(position, isOnBlock = false, entity = this.player) { - const x = position[0]; - const y = position[1]; + const x = position.x; + const y = position.y; const xOffset = entity.offset[0]; const yOffset = entity.offset[1]; return { @@ -2237,7 +2237,7 @@ module.exports = class LevelView { } var fluffPositions = this.treeFluffTypes[this.trees[treeIndex].type]; for (var i = 0; i < fluffPositions.length; i++) { - if (this.trees[treeIndex].position[0] + fluffPositions[i][0] === position[0] && this.trees[treeIndex].position[1] + fluffPositions[i][1] === position[1]) { + if (this.trees[treeIndex].position.x + fluffPositions[i][0] === position.x && this.trees[treeIndex].position.y + fluffPositions[i][1] === position.y) { return true; } } @@ -2296,7 +2296,7 @@ module.exports = class LevelView { // Iron doors don't need to set the player animation to Idle, because they're not opened with 'use'. this.playIdleAnimation(player.position, player.facing, player.isOnBlock, player); } - this.setSelectionIndicatorPosition(player.position[0], player.position[1]); + this.setSelectionIndicatorPosition(player.position.x, player.position.y); }); } diff --git a/test/unit/AdjacencySetTest.js b/test/unit/AdjacencySetTest.js index 02bf6992..c95fa9e2 100644 --- a/test/unit/AdjacencySetTest.js +++ b/test/unit/AdjacencySetTest.js @@ -34,7 +34,7 @@ test('AdjacencySets', t => { test('AdjacencySets - custom comparison function', t => { // can override the comparison function const sameColumn = (left, right) => { - return left[0] === right[0]; + return left.x === right.x; }; t.deepEqual(new AdjacencySet([