engine/actions.js
/*
      Call this after the round has been resolved to create the move animation
     */
Call this after the round has been resolved to create the move animation
Call this after the round has been resolved to create the move animation
animate(timeline, resolver) {
        if (this.speed == 0) return;
        if (this._moveFailedAt == undefined) {
            timeline.to(
                this.entity.sprite,
                resolver.sPerRound,
                {
                    x : this._toCell.pxX,
                    y : this._toCell.pxY,
                    ease : Power0.easeNone
                }
            );
        } else {
            let numCellsCovered =
                Math.floor(this._moveFailedAt / this._ticksPerCell);
            let moveTime = 0;
            const curCell = this.entity.cell;
            if (numCellsCovered > 1) {
                const moveTicks = numCellsCovered * this._ticksPerCell;
                const moveRatio = moveTicks / resolver.ticksPerRound;
                moveTime = moveRatio * resolver.sPerRound;
                timeline.to(
                    this.entity.sprite,
                    moveTime,
                    {x : curCell.pxX, y : curCell.pxY, ease : Power0.easeNone}
                );
            }
            const oneMoveRatio = this._ticksPerCell / resolver.ticksPerRound;
            let oneMoveTime = oneMoveRatio * resolver.sPerRound;
            const bumpForwardRatio = 0.75;
            const bumpBackwardRatio = 1 - bumpForwardRatio;
            timeline.to(
                this.entity.sprite,
                bumpForwardRatio * oneMoveTime,
                {
                    x : curCell.pxX + this.deltaX * bumpForwardRatio,
                    y : curCell.pxY + this.deltaY * bumpForwardRatio,
                    ease : Power0.easeNone
                }
            );
            timeline.to(
                this.entity.sprite,
                bumpBackwardRatio * oneMoveTime,
                {x : curCell.pxX, y : curCell.pxY}
            );
        }
    }
animate ( timeline , resolver ) { if ( this . speed == 0 ) return ; if ( this . _moveFailedAt == undefined ) { timeline . to ( this . entity . sprite , resolver . sPerRound , { x : this . _toCell . pxX , y : this . _toCell . pxY , ease : Power0 . easeNone } ) ; } else { let numCellsCovered = Math . floor ( this . _moveFailedAt / this . _ticksPerCell ) ; let moveTime = 0 ; const curCell = this . entity . cell ; if ( numCellsCovered > 1 ) { const moveTicks = numCellsCovered * this . _ticksPerCell ; const moveRatio = moveTicks / resolver . ticksPerRound ; moveTime = moveRatio * resolver . sPerRound ; timeline . to ( this . entity . sprite , moveTime , { x : curCell . pxX , y : curCell . pxY , ease : Power0 . easeNone } ) ; } const oneMoveRatio = this . _ticksPerCell / resolver . ticksPerRound ; let oneMoveTime = oneMoveRatio * resolver . sPerRound ; const bumpForwardRatio = 0.75 ; const bumpBackwardRatio = 1 - bumpForwardRatio ; timeline . to ( this . entity . sprite , bumpForwardRatio * oneMoveTime , { x : curCell . pxX + this . deltaX * bumpForwardRatio , y : curCell . pxY + this . deltaY * bumpForwardRatio , ease : Power0 . easeNone } ) ; timeline . to ( this . entity . sprite , bumpBackwardRatio * oneMoveTime , { x : curCell . pxX , y : curCell . pxY } ) ; } }
Call this after the round has been resolved to create the move animation
Call this after the round has been resolved to create the move animation
// the move succeeded // _toCell points to the latest successful 1 cell move // the move failed at some point // figure out how many moves were successful. /*
              Each move happens after waiting ticksPerCell ticks.
              So we can calculate how many cells we covered successfully.
             */ // now we need to animate the fact that we bumped into something // Q: how long should we spend doing that? // A: the time we spend in 1 cell // TODO: if a spd > ticks/round is allowed, this needs to be updated // move forward toward the occupied cell // bump backward to where successfully landed