@@ -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 ) {
@@ -267,15 +267,17 @@ module.exports = class AnimationsController {
267267 /**
268268 * Schedule the animations for a move from the current position
269269 * @param {number } endX X coordinate of the target position
270- * @param {number } endY Y coordinate of the target position
270+ * @param {number } endY Y coordinate of the target position
271+ * @param {string } id Optional id of pegman. If no id is provided,
272+ * will schedule move for default pegman.
271273 */
272- scheduleMove ( endX , endY , timeForAnimation ) {
273- var startX = this . maze . pegmanX ;
274- var startY = this . maze . pegmanY ;
275- var direction = this . maze . pegmanD ;
274+ scheduleMove ( endX , endY , timeForAnimation , id ) {
275+ const startX = this . maze . getPegmanX ( id ) ;
276+ const startY = this . maze . getPegmanY ( id ) ;
277+ const direction = this . maze . getPegmanD ( id ) ;
276278
277- var deltaX = ( endX - startX ) ;
278- var deltaY = ( endY - startY ) ;
279+ const deltaX = ( endX - startX ) ;
280+ const deltaY = ( endY - startY ) ;
279281 var numFrames ;
280282 var timePerFrame ;
281283
@@ -336,17 +338,19 @@ module.exports = class AnimationsController {
336338
337339 /**
338340 * Schedule the animations for a turn from the current direction
339- * @param {number } endDirection The direction we're turning to
341+ * @param {number } endDirection The direction we're turning to
342+ * @param {string } id Optional id of pegman. If no id is provided,
343+ * will schedule turn for default pegman.
340344 */
341- scheduleTurn ( endDirection ) {
345+ scheduleTurn ( endDirection , id ) {
342346 var numFrames = 4 ;
343- var startDirection = this . maze . pegmanD ;
347+ var startDirection = this . maze . getPegmanD ( id ) ;
344348 var deltaDirection = endDirection - startDirection ;
345349 utils . range ( 1 , numFrames ) . forEach ( ( frame ) => {
346350 timeoutList . setTimeout ( ( ) => {
347351 this . displayPegman (
348- this . maze . pegmanX ,
349- this . maze . pegmanY ,
352+ this . maze . getPegmanX ( id ) ,
353+ this . maze . getPegmanY ( id ) ,
350354 tiles . directionToFrame ( startDirection + deltaDirection * frame / numFrames ) ) ;
351355 } , this . maze . stepSpeed * ( frame - 1 ) ) ;
352356 } ) ;
@@ -392,8 +396,10 @@ module.exports = class AnimationsController {
392396 }
393397 }
394398
395- scheduleWallHit ( targetX , targetY , deltaX , deltaY , frame ) {
399+ scheduleWallHit ( targetX , targetY , deltaX , deltaY , frame , id ) {
396400 // Play the animation of hitting the wall
401+ const pegmanX = this . maze . getPegmanX ( id ) ;
402+ const pegmanY = this . maze . getPegmanY ( id ) ;
397403 if ( this . maze . skin . hittingWallAnimation ) {
398404 var wallAnimationIcon = document . getElementById ( 'wallAnimation' ) ;
399405 var numFrames = this . maze . skin . hittingWallAnimationFrameNumber || 0 ;
@@ -410,8 +416,8 @@ module.exports = class AnimationsController {
410416 // animate our sprite sheet
411417 var timePerFrame = 100 ;
412418 this . scheduleSheetedMovement_ ( {
413- x : this . maze . pegmanX ,
414- y : this . maze . pegmanY
419+ x : pegmanX ,
420+ y : pegmanY
415421 } , {
416422 x : deltaX ,
417423 y : deltaY
@@ -424,10 +430,10 @@ module.exports = class AnimationsController {
424430 // active our gif
425431 timeoutList . setTimeout ( ( ) => {
426432 wallAnimationIcon . setAttribute ( 'x' ,
427- this . maze . SQUARE_SIZE * ( this . maze . pegmanX + 0.5 + deltaX * 0.5 ) -
433+ this . maze . SQUARE_SIZE * ( pegmanX + 0.5 + deltaX * 0.5 ) -
428434 wallAnimationIcon . getAttribute ( 'width' ) / 2 ) ;
429435 wallAnimationIcon . setAttribute ( 'y' ,
430- this . maze . SQUARE_SIZE * ( this . maze . pegmanY + 1 + deltaY * 0.5 ) -
436+ this . maze . SQUARE_SIZE * ( pegmanY + 1 + deltaY * 0.5 ) -
431437 wallAnimationIcon . getAttribute ( 'height' ) ) ;
432438 wallAnimationIcon . setAttribute ( 'visibility' , 'visible' ) ;
433439 wallAnimationIcon . setAttributeNS (
@@ -437,14 +443,14 @@ module.exports = class AnimationsController {
437443 }
438444 }
439445 timeoutList . setTimeout ( ( ) => {
440- this . displayPegman ( this . maze . pegmanX , this . maze . pegmanY , frame ) ;
446+ this . displayPegman ( pegmanX , pegmanY , frame , id ) ;
441447 } , this . maze . stepSpeed ) ;
442448 timeoutList . setTimeout ( ( ) => {
443- this . displayPegman ( this . maze . pegmanX + deltaX / 4 , this . maze . pegmanY + deltaY / 4 ,
444- frame ) ;
449+ this . displayPegman ( pegmanX + deltaX / 4 , pegmanY + deltaY / 4 ,
450+ frame , id ) ;
445451 } , this . maze . stepSpeed * 2 ) ;
446452 timeoutList . setTimeout ( ( ) => {
447- this . displayPegman ( this . maze . pegmanX , this . maze . pegmanY , frame ) ;
453+ this . displayPegman ( pegmanX , pegmanY , frame , id ) ;
448454 } , this . maze . stepSpeed * 3 ) ;
449455
450456 if ( this . maze . skin . wallPegmanAnimation ) {
@@ -453,24 +459,24 @@ module.exports = class AnimationsController {
453459 pegmanIcon . setAttribute ( 'visibility' , 'hidden' ) ;
454460 this . updatePegmanAnimation_ ( {
455461 idStr : 'wall' ,
456- row : this . maze . pegmanY ,
457- col : this . maze . pegmanX ,
458- direction : this . maze . pegmanD
462+ row : pegmanY ,
463+ col : pegmanX ,
464+ direction : this . maze . getPegmanD ( id )
459465 } ) ;
460466 } , this . maze . stepSpeed * 4 ) ;
461467 }
462468 }
463469
464- scheduleObstacleHit ( targetX , targetY , deltaX , deltaY , frame ) {
470+ scheduleObstacleHit ( targetX , targetY , deltaX , deltaY , frame , id ) {
465471 // Play the animation
466472 var obsId = targetX + this . maze . map . COLS * targetY ;
467473 var obsIcon = document . getElementById ( 'obstacle' + obsId ) ;
468474 obsIcon . setAttributeNS (
469475 'http://www.w3.org/1999/xlink' , 'xlink:href' ,
470476 this . maze . skin . obstacleAnimation ) ;
471477 timeoutList . setTimeout ( ( ) => {
472- this . displayPegman ( this . maze . pegmanX + deltaX / 2 ,
473- this . maze . pegmanY + deltaY / 2 ,
478+ this . displayPegman ( this . maze . getPegmanX ( id ) + deltaX / 2 ,
479+ this . maze . getPegmanY ( id ) + deltaY / 2 ,
474480 frame ) ;
475481 } , this . maze . stepSpeed ) ;
476482
@@ -538,9 +544,13 @@ module.exports = class AnimationsController {
538544 * @param {boolean } victoryDance This is a victory dance after completing the
539545 * puzzle (vs. dancing on load).
540546 * @param {integer } timeAlloted How much time we have for our animations
547+ * @param {string } id Optional id of pegman. If no id is provided, will schedule
548+ * dance for default pegman.
541549 */
542- scheduleDance ( victoryDance , timeAlloted ) {
550+ scheduleDance ( victoryDance , timeAlloted , id ) {
543551 const finishIcon = document . getElementById ( 'finish' ) ;
552+ const pegmanX = this . maze . getPegmanX ( id ) ;
553+ const pegmanY = this . maze . getPegmanY ( id ) ;
544554
545555 // Some skins (like scrat) have custom celebration animations we want to
546556 // suport
@@ -550,7 +560,7 @@ module.exports = class AnimationsController {
550560 }
551561 const numFrames = this . maze . skin . celebratePegmanRow ;
552562 const timePerFrame = timeAlloted / numFrames ;
553- const start = { x : this . maze . pegmanX , y : this . maze . pegmanY } ;
563+ const start = { x : pegmanX , y : pegmanY } ;
554564
555565 this . scheduleSheetedMovement_ (
556566 { x : start . x , y : start . y } ,
@@ -564,8 +574,8 @@ module.exports = class AnimationsController {
564574 return ;
565575 }
566576
567- var originalFrame = tiles . directionToFrame ( this . maze . pegmanD ) ;
568- this . displayPegman ( this . maze . pegmanX , this . maze . pegmanY , 16 ) ;
577+ var originalFrame = tiles . directionToFrame ( this . maze . getPegmanD ( id ) ) ;
578+ this . displayPegman ( pegmanX , pegmanY , 16 , id ) ;
569579
570580 // If victoryDance === true, play the goal animation, else reset it
571581 if ( victoryDance && finishIcon ) {
@@ -575,21 +585,21 @@ module.exports = class AnimationsController {
575585
576586 var danceSpeed = timeAlloted / 5 ;
577587 timeoutList . setTimeout ( ( ) => {
578- this . displayPegman ( this . maze . pegmanX , this . maze . pegmanY , 18 ) ;
588+ this . displayPegman ( pegmanX , pegmanY , 18 , id ) ;
579589 } , danceSpeed ) ;
580590 timeoutList . setTimeout ( ( ) => {
581- this . displayPegman ( this . maze . pegmanX , this . maze . pegmanY , 20 ) ;
591+ this . displayPegman ( pegmanX , pegmanY , 20 , id ) ;
582592 } , danceSpeed * 2 ) ;
583593 timeoutList . setTimeout ( ( ) => {
584- this . displayPegman ( this . maze . pegmanX , this . maze . pegmanY , 18 ) ;
594+ this . displayPegman ( pegmanX , pegmanY , 18 , id ) ;
585595 } , danceSpeed * 3 ) ;
586596 timeoutList . setTimeout ( ( ) => {
587- this . displayPegman ( this . maze . pegmanX , this . maze . pegmanY , 20 ) ;
597+ this . displayPegman ( pegmanX , pegmanY , 20 , id ) ;
588598 } , danceSpeed * 4 ) ;
589599
590600 timeoutList . setTimeout ( ( ) => {
591601 if ( ! victoryDance || this . maze . skin . turnAfterVictory ) {
592- this . displayPegman ( this . maze . pegmanX , this . maze . pegmanY , originalFrame ) ;
602+ this . displayPegman ( pegmanX , pegmanY , originalFrame , id ) ;
593603 }
594604
595605 if ( victoryDance && this . maze . skin . transparentTileEnding ) {
@@ -640,9 +650,11 @@ module.exports = class AnimationsController {
640650 * Display Pegman at the specified location, facing the specified direction.
641651 * @param {number } x Horizontal grid (or fraction thereof).
642652 * @param {number } y Vertical grid (or fraction thereof).
643- * @param {number } frame Direction (0 - 15) or dance (16 - 17).
653+ * @param {number } frame Direction (0 - 15) or dance (16 - 17). *
654+ * @param {string } id Optional id of pegman. If no id is provided,
655+ * will display default pegman.
644656 */
645- displayPegman ( x , y , frame ) {
657+ displayPegman ( x , y , frame , id ) {
646658 var pegmanIcon = document . getElementById ( 'pegman' ) ;
647659 var clipRect = document . getElementById ( 'clipRect' ) ;
648660 displayPegman ( this . maze . skin , pegmanIcon , clipRect , x , y , frame ) ;
0 commit comments