Skip to content

Commit 4b5b232

Browse files
committed
first pass at updating for multiple pegmen
1 parent eff74f4 commit 4b5b232

File tree

9 files changed

+221
-96
lines changed

9 files changed

+221
-96
lines changed

src/animationsController.js

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ module.exports = class AnimationsController {
114114
this.scheduleTurn(this.maze.startDirection);
115115
}, danceTime + 150);
116116
} else {
117-
this.displayPegman(this.maze.pegmanX, this.maze.pegmanY, tiles.directionToFrame(this.maze.pegmanD));
117+
this.displayPegman(this.maze.getPegmanX(), this.maze.getPegmanY(), tiles.directionToFrame(this.maze.getPegmanD()));
118118

119119
const finishIcon = document.getElementById('finish');
120120
if (finishIcon) {
@@ -269,10 +269,10 @@ module.exports = class AnimationsController {
269269
* @param {number} endX X coordinate of the target position
270270
* @param {number} endY Y coordinate of the target position
271271
*/
272-
scheduleMove(endX, endY, timeForAnimation) {
273-
var startX = this.maze.pegmanX;
274-
var startY = this.maze.pegmanY;
275-
var direction = this.maze.pegmanD;
272+
scheduleMove(endX, endY, timeForAnimation, id = null) {
273+
var startX = this.maze.getPegmanX(id);
274+
var startY = this.maze.getPegmanY(id);
275+
var direction = this.maze.getPegmanD(id);
276276

277277
var deltaX = (endX - startX);
278278
var deltaY = (endY - startY);
@@ -338,15 +338,15 @@ module.exports = class AnimationsController {
338338
* Schedule the animations for a turn from the current direction
339339
* @param {number} endDirection The direction we're turning to
340340
*/
341-
scheduleTurn(endDirection) {
341+
scheduleTurn(endDirection, id = null) {
342342
var numFrames = 4;
343-
var startDirection = this.maze.pegmanD;
343+
var startDirection = this.maze.getPegmanD(id);
344344
var deltaDirection = endDirection - startDirection;
345345
utils.range(1, numFrames).forEach((frame) => {
346346
timeoutList.setTimeout(() => {
347347
this.displayPegman(
348-
this.maze.pegmanX,
349-
this.maze.pegmanY,
348+
this.maze.getPegmanX(id),
349+
this.maze.getPegmanY(id),
350350
tiles.directionToFrame(startDirection + deltaDirection * frame / numFrames));
351351
}, this.maze.stepSpeed * (frame - 1));
352352
});
@@ -392,8 +392,10 @@ module.exports = class AnimationsController {
392392
}
393393
}
394394

395-
scheduleWallHit(targetX, targetY, deltaX, deltaY, frame) {
395+
scheduleWallHit(targetX, targetY, deltaX, deltaY, frame, id = null) {
396396
// Play the animation of hitting the wall
397+
const pegmanX = this.maze.getPegmanX(id);
398+
const pegmanY = this.maze.getPegmanY(id);
397399
if (this.maze.skin.hittingWallAnimation) {
398400
var wallAnimationIcon = document.getElementById('wallAnimation');
399401
var numFrames = this.maze.skin.hittingWallAnimationFrameNumber || 0;
@@ -410,8 +412,8 @@ module.exports = class AnimationsController {
410412
// animate our sprite sheet
411413
var timePerFrame = 100;
412414
this.scheduleSheetedMovement_({
413-
x: this.maze.pegmanX,
414-
y: this.maze.pegmanY
415+
x: pegmanX,
416+
y: pegmanY
415417
}, {
416418
x: deltaX,
417419
y: deltaY
@@ -424,10 +426,10 @@ module.exports = class AnimationsController {
424426
// active our gif
425427
timeoutList.setTimeout(() => {
426428
wallAnimationIcon.setAttribute('x',
427-
this.maze.SQUARE_SIZE * (this.maze.pegmanX + 0.5 + deltaX * 0.5) -
429+
this.maze.SQUARE_SIZE * (pegmanX + 0.5 + deltaX * 0.5) -
428430
wallAnimationIcon.getAttribute('width') / 2);
429431
wallAnimationIcon.setAttribute('y',
430-
this.maze.SQUARE_SIZE * (this.maze.pegmanY + 1 + deltaY * 0.5) -
432+
this.maze.SQUARE_SIZE * (pegmanY + 1 + deltaY * 0.5) -
431433
wallAnimationIcon.getAttribute('height'));
432434
wallAnimationIcon.setAttribute('visibility', 'visible');
433435
wallAnimationIcon.setAttributeNS(
@@ -437,14 +439,14 @@ module.exports = class AnimationsController {
437439
}
438440
}
439441
timeoutList.setTimeout(() => {
440-
this.displayPegman(this.maze.pegmanX, this.maze.pegmanY, frame);
442+
this.displayPegman(pegmanX, pegmanY, frame, id);
441443
}, this.maze.stepSpeed);
442444
timeoutList.setTimeout(() => {
443-
this.displayPegman(this.maze.pegmanX + deltaX / 4, this.maze.pegmanY + deltaY / 4,
444-
frame);
445+
this.displayPegman(pegmanX + deltaX / 4, pegmanY + deltaY / 4,
446+
frame, id);
445447
}, this.maze.stepSpeed * 2);
446448
timeoutList.setTimeout(() => {
447-
this.displayPegman(this.maze.pegmanX, this.maze.pegmanY, frame);
449+
this.displayPegman(pegmanX, pegmanY, frame, id);
448450
}, this.maze.stepSpeed * 3);
449451

450452
if (this.maze.skin.wallPegmanAnimation) {
@@ -453,24 +455,24 @@ module.exports = class AnimationsController {
453455
pegmanIcon.setAttribute('visibility', 'hidden');
454456
this.updatePegmanAnimation_({
455457
idStr: 'wall',
456-
row: this.maze.pegmanY,
457-
col: this.maze.pegmanX,
458-
direction: this.maze.pegmanD
458+
row: pegmanY,
459+
col: pegmanX,
460+
direction: this.maze.getPegmanD(id)
459461
});
460462
}, this.maze.stepSpeed * 4);
461463
}
462464
}
463465

464-
scheduleObstacleHit(targetX, targetY, deltaX, deltaY, frame) {
466+
scheduleObstacleHit(targetX, targetY, deltaX, deltaY, frame, id = null) {
465467
// Play the animation
466468
var obsId = targetX + this.maze.map.COLS * targetY;
467469
var obsIcon = document.getElementById('obstacle' + obsId);
468470
obsIcon.setAttributeNS(
469471
'http://www.w3.org/1999/xlink', 'xlink:href',
470472
this.maze.skin.obstacleAnimation);
471473
timeoutList.setTimeout(() => {
472-
this.displayPegman(this.maze.pegmanX + deltaX / 2,
473-
this.maze.pegmanY + deltaY / 2,
474+
this.displayPegman(this.maze.getPegmanX(id) + deltaX / 2,
475+
this.maze.getPegmanY(id)+ deltaY / 2,
474476
frame);
475477
}, this.maze.stepSpeed);
476478

@@ -539,8 +541,10 @@ module.exports = class AnimationsController {
539541
* puzzle (vs. dancing on load).
540542
* @param {integer} timeAlloted How much time we have for our animations
541543
*/
542-
scheduleDance(victoryDance, timeAlloted) {
544+
scheduleDance(victoryDance, timeAlloted, id = null) {
543545
const finishIcon = document.getElementById('finish');
546+
const pegmanX = this.maze.getPegmanX(id);
547+
const pegmanY = this.maze.getPegmanY(id);
544548

545549
// Some skins (like scrat) have custom celebration animations we want to
546550
// suport
@@ -550,7 +554,7 @@ module.exports = class AnimationsController {
550554
}
551555
const numFrames = this.maze.skin.celebratePegmanRow;
552556
const timePerFrame = timeAlloted / numFrames;
553-
const start = { x: this.maze.pegmanX, y: this.maze.pegmanY };
557+
const start = { x: pegmanX, y: pegmanY };
554558

555559
this.scheduleSheetedMovement_(
556560
{ x: start.x, y: start.y },
@@ -564,8 +568,8 @@ module.exports = class AnimationsController {
564568
return;
565569
}
566570

567-
var originalFrame = tiles.directionToFrame(this.maze.pegmanD);
568-
this.displayPegman(this.maze.pegmanX, this.maze.pegmanY, 16);
571+
var originalFrame = tiles.directionToFrame(this.maze.getPegmanD(id));
572+
this.displayPegman(pegmanX, pegmanY, 16, id);
569573

570574
// If victoryDance === true, play the goal animation, else reset it
571575
if (victoryDance && finishIcon) {
@@ -575,21 +579,21 @@ module.exports = class AnimationsController {
575579

576580
var danceSpeed = timeAlloted / 5;
577581
timeoutList.setTimeout(() => {
578-
this.displayPegman(this.maze.pegmanX, this.maze.pegmanY, 18);
582+
this.displayPegman(pegmanX, pegmanY, 18, id);
579583
}, danceSpeed);
580584
timeoutList.setTimeout(() => {
581-
this.displayPegman(this.maze.pegmanX, this.maze.pegmanY, 20);
585+
this.displayPegman(pegmanX, pegmanY, 20, id);
582586
}, danceSpeed * 2);
583587
timeoutList.setTimeout(() => {
584-
this.displayPegman(this.maze.pegmanX, this.maze.pegmanY, 18);
588+
this.displayPegman(pegmanX, pegmanY, 18, id);
585589
}, danceSpeed * 3);
586590
timeoutList.setTimeout(() => {
587-
this.displayPegman(this.maze.pegmanX, this.maze.pegmanY, 20);
591+
this.displayPegman(pegmanX, pegmanY, 20, id);
588592
}, danceSpeed * 4);
589593

590594
timeoutList.setTimeout(() => {
591595
if (!victoryDance || this.maze.skin.turnAfterVictory) {
592-
this.displayPegman(this.maze.pegmanX, this.maze.pegmanY, originalFrame);
596+
this.displayPegman(pegmanX, pegmanY, originalFrame, id);
593597
}
594598

595599
if (victoryDance && this.maze.skin.transparentTileEnding) {
@@ -642,7 +646,7 @@ module.exports = class AnimationsController {
642646
* @param {number} y Vertical grid (or fraction thereof).
643647
* @param {number} frame Direction (0 - 15) or dance (16 - 17).
644648
*/
645-
displayPegman(x, y, frame) {
649+
displayPegman(x, y, frame, id = null) {
646650
var pegmanIcon = document.getElementById('pegman');
647651
var clipRect = document.getElementById('clipRect');
648652
displayPegman(this.maze.skin, pegmanIcon, clipRect, x, y, frame);

src/bee.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ module.exports = class Bee extends Gatherer {
278278
* @return {boolean} whether or not this attempt was successful
279279
*/
280280
tryGetNectar() {
281-
const col = this.maze_.pegmanX;
282-
const row = this.maze_.pegmanY;
281+
const col = this.maze_.getPegmanX();
282+
const row = this.maze_.getPegmanY();
283283

284284
// Make sure we're at a flower.
285285
if (!this.isFlower(row, col)) {
@@ -309,8 +309,8 @@ module.exports = class Bee extends Gatherer {
309309
* @return {boolean} whether or not this attempt was successful
310310
*/
311311
tryMakeHoney() {
312-
const col = this.maze_.pegmanX;
313-
const row = this.maze_.pegmanY;
312+
const col = this.maze_.getPegmanX();
313+
const row = this.maze_.getPegmanY();
314314

315315
if (!this.isHive(row, col)) {
316316
this.emit('notAtHive');
@@ -326,8 +326,8 @@ module.exports = class Bee extends Gatherer {
326326
}
327327

328328
nectarRemaining(userCheck=false) {
329-
const col = this.maze_.pegmanX;
330-
const row = this.maze_.pegmanY;
329+
const col = this.maze_.getPegmanX();
330+
const row = this.maze_.getPegmanY();
331331

332332
if (userCheck) {
333333
this.userChecks_[row][col].checkedForNectar = true;
@@ -337,8 +337,8 @@ module.exports = class Bee extends Gatherer {
337337
}
338338

339339
honeyAvailable() {
340-
const col = this.maze_.pegmanX;
341-
const row = this.maze_.pegmanY;
340+
const col = this.maze_.getPegmanX();
341+
const row = this.maze_.getPegmanY();
342342

343343
return this.hiveRemainingCapacity(row, col);
344344
}
@@ -354,8 +354,8 @@ module.exports = class Bee extends Gatherer {
354354
* @throws Will throw an error if the current cell has no nectar.
355355
*/
356356
animateGetNectar() {
357-
const col = this.maze_.pegmanX;
358-
const row = this.maze_.pegmanY;
357+
const col = this.maze_.getPegmanX();
358+
const row = this.maze_.getPegmanY();
359359

360360
if (this.getValue(row, col) <= 0) {
361361
throw new Error("Shouldn't be able to end up with a nectar animation if " +
@@ -378,8 +378,8 @@ module.exports = class Bee extends Gatherer {
378378
* @throws Will throw an error if the current cell is not a hive.
379379
*/
380380
animateMakeHoney() {
381-
const col = this.maze_.pegmanX;
382-
const row = this.maze_.pegmanY;
381+
const col = this.maze_.getPegmanX();
382+
const row = this.maze_.getPegmanY();
383383

384384
if (!this.isHive(row, col)) {
385385
throw new Error("Shouldn't be able to end up with a honey animation if " +

src/harvester.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module.exports = class Harvester extends Gatherer {
4242
}
4343

4444
hasCrop(crop) {
45-
const col = this.maze_.pegmanX;
46-
const row = this.maze_.pegmanY;
45+
const col = this.maze_.getPegmanX();
46+
const row = this.maze_.getPegmanY();
4747

4848
const cell = this.getCell(row, col);
4949

@@ -63,8 +63,8 @@ module.exports = class Harvester extends Gatherer {
6363
}
6464

6565
atCrop(crop) {
66-
const col = this.maze_.pegmanX;
67-
const row = this.maze_.pegmanY;
66+
const col = this.maze_.getPegmanX();
67+
const row = this.maze_.getPegmanY();
6868

6969
const cell = this.getCell(row, col);
7070

@@ -100,8 +100,8 @@ module.exports = class Harvester extends Gatherer {
100100
* @return {boolean} whether or not this attempt was successful
101101
*/
102102
tryGetCrop(crop) {
103-
const col = this.maze_.pegmanX;
104-
const row = this.maze_.pegmanY;
103+
const col = this.maze_.getPegmanX();
104+
const row = this.maze_.getPegmanY();
105105

106106
const cell = this.getCell(row, col);
107107

@@ -143,8 +143,8 @@ module.exports = class Harvester extends Gatherer {
143143
* available to harvest.
144144
*/
145145
animateGetCrop(crop) {
146-
const col = this.maze_.pegmanX;
147-
const row = this.maze_.pegmanY;
146+
const col = this.maze_.getPegmanX();
147+
const row = this.maze_.getPegmanY();
148148

149149
const cell = this.getCell(row, col);
150150

0 commit comments

Comments
 (0)