Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/js/game/Entities/BaseEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ 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);
// play walk animation
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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand Down
36 changes: 13 additions & 23 deletions src/js/game/GameController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -916,18 +906,18 @@ 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
const canOpen = !frontBlock.isWalkable;
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();
});
});
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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";
Expand Down
10 changes: 5 additions & 5 deletions src/js/game/LevelMVC/LevelModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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, []);
}

Expand Down
18 changes: 9 additions & 9 deletions src/js/game/LevelMVC/LevelPlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()) {
Expand Down
Loading