3 lines
24 KiB
JavaScript
3 lines
24 KiB
JavaScript
var gdjs;(function(n){const m=class extends n.RuntimeBehavior{constructor(e,t,i){super(e,t,i);this._ignoreTouchingEdges=!0;this._slopeClimbingFactor=1;this._useLegacyTrajectory=!0;this._canGoDownFromJumpthru=!1;this._currentSpeed=0;this._requestedDeltaX=0;this._requestedDeltaY=0;this._lastDeltaY=0;this._currentFallSpeed=0;this._canJump=!1;this._lastDirectionIsLeft=!1;this._leftKey=!1;this._rightKey=!1;this._ladderKey=!1;this._upKey=!1;this._downKey=!1;this._jumpKey=!1;this._releasePlatformKey=!1;this._releaseLadderKey=!1;this._wasLeftKeyPressed=!1;this._wasRightKeyPressed=!1;this._wasLadderKeyPressed=!1;this._wasUpKeyPressed=!1;this._wasDownKeyPressed=!1;this._wasJumpKeyPressed=!1;this._wasReleasePlatformKeyPressed=!1;this._wasReleaseLadderKeyPressed=!1;this._hasReallyMoved=!1;this._hasMovedAtLeastOnePixel=!1;this._gravity=t.gravity,this._maxFallingSpeed=t.maxFallingSpeed,this._ladderClimbingSpeed=t.ladderClimbingSpeed||150,this._acceleration=t.acceleration,this._deceleration=t.deceleration,this._maxSpeed=t.maxSpeed,this._jumpSpeed=t.jumpSpeed,this._canGrabPlatforms=t.canGrabPlatforms||!1,this._canGrabWithoutMoving=t.canGrabWithoutMoving,this._yGrabOffset=t.yGrabOffset||0,this._xGrabTolerance=t.xGrabTolerance||10,this._jumpSustainTime=t.jumpSustainTime||0,this._ignoreDefaultControls=t.ignoreDefaultControls,this._useLegacyTrajectory=t.useLegacyTrajectory===void 0?!0:t.useLegacyTrajectory,this._canGoDownFromJumpthru=t.canGoDownFromJumpthru,this._slopeMaxAngle=0,this.setSlopeMaxAngle(t.slopeMaxAngle),this._potentialCollidingObjects=[],this._overlappedJumpThru=[],this._manager=n.PlatformObjectsManager.getManager(e),this._falling=new S(this),this._onFloor=new y(this),this._jumping=new M(this),this._grabbingPlatform=new Y(this),this._onLadder=new j(this),this._state=this._falling}updateFromBehaviorData(e,t){return e.gravity!==t.gravity&&this.setGravity(t.gravity),e.maxFallingSpeed!==t.maxFallingSpeed&&this.setMaxFallingSpeed(t.maxFallingSpeed),e.acceleration!==t.acceleration&&this.setAcceleration(t.acceleration),e.deceleration!==t.deceleration&&this.setDeceleration(t.deceleration),e.maxSpeed!==t.maxSpeed&&this.setMaxSpeed(t.maxSpeed),e.jumpSpeed!==t.jumpSpeed&&this.setJumpSpeed(t.jumpSpeed),e.canGrabPlatforms!==t.canGrabPlatforms&&this.setCanGrabPlatforms(t.canGrabPlatforms),e.canGrabWithoutMoving!==t.canGrabWithoutMoving&&(this._canGrabWithoutMoving=t.canGrabWithoutMoving),e.yGrabOffset!==t.yGrabOffset&&(this._yGrabOffset=t.yGrabOffset),e.xGrabTolerance!==t.xGrabTolerance&&(this._xGrabTolerance=t.xGrabTolerance),e.jumpSustainTime!==t.jumpSustainTime&&this.setJumpSustainTime(t.jumpSustainTime),e.useLegacyTrajectory!==t.useLegacyTrajectory&&(this._useLegacyTrajectory=t.useLegacyTrajectory),e.canGoDownFromJumpthru!==t.canGoDownFromJumpthru&&(this._canGoDownFromJumpthru=t.canGoDownFromJumpthru),!0}doStepPreEvents(e){const t=37,i=38,s=39,r=40,l=1016,o=2016,f=32,a=this.owner,h=this.owner.getElapsedTime()/1e3;this._requestedDeltaX=0,this._requestedDeltaY=0;const _=e.getGame().getInputManager();this._leftKey||(this._leftKey=!this._ignoreDefaultControls&&_.isKeyPressed(t)),this._rightKey||(this._rightKey=!this._ignoreDefaultControls&&_.isKeyPressed(s)),this._jumpKey||(this._jumpKey=!this._ignoreDefaultControls&&(_.isKeyPressed(l)||_.isKeyPressed(o)||_.isKeyPressed(f))),this._ladderKey||(this._ladderKey=!this._ignoreDefaultControls&&_.isKeyPressed(i)),this._upKey||(this._upKey=!this._ignoreDefaultControls&&_.isKeyPressed(i)),this._downKey||(this._downKey=!this._ignoreDefaultControls&&_.isKeyPressed(r)),this._releasePlatformKey||(this._releasePlatformKey=!this._ignoreDefaultControls&&_.isKeyPressed(r)),this._requestedDeltaX+=this._updateSpeed(h),this._leftKey!==this._rightKey&&(this._lastDirectionIsLeft=this._leftKey),this._state.beforeUpdatingObstacles(h),this._onFloor._oldHeight=a.getHeight(),this._updatePotentialCollidingObjects(Math.max(this._requestedDeltaX,this._maxFallingSpeed*h)),this._updateOverlappedJumpThru();const d=this._state;this._state.checkTransitionBeforeX(),this._state.beforeMovingX(),this._separateFromPlatforms(this._potentialCollidingObjects,!0)&&(this._canJump=!0);const u=a.getX();this._moveX();const p=a.getX()!==u+this._requestedDeltaX,F=this._state;this._state.checkTransitionBeforeY(h),this._state.beforeMovingY(h,u);const P=a.getY();this._moveY();const O=this._state;this._state!==this._onLadder&&this._checkTransitionOnFloorOrFalling(),p&&this._state===d&&this._state===F&&this._state===O&&this._state!==this._onFloor&&(this._currentSpeed=0),this._wasLeftKeyPressed=this._leftKey,this._wasRightKeyPressed=this._rightKey,this._wasLadderKeyPressed=this._ladderKey,this._wasUpKeyPressed=this._upKey,this._wasDownKeyPressed=this._downKey,this._wasJumpKeyPressed=this._jumpKey,this._wasReleasePlatformKeyPressed=this._releasePlatformKey,this._wasReleaseLadderKeyPressed=this._releaseLadderKey,this._leftKey=!1,this._rightKey=!1,this._ladderKey=!1,this._upKey=!1,this._downKey=!1,this._jumpKey=!1,this._releasePlatformKey=!1,this._releaseLadderKey=!1,this._hasReallyMoved=Math.abs(a.getX()-u)>m.epsilon||Math.abs(a.getY()-P)>m.epsilon,this._hasMovedAtLeastOnePixel=Math.abs(a.getX()-u)>=1||Math.abs(a.getY()-P)>=1,this._lastDeltaY=a.getY()-P}doStepPostEvents(e){}_updateSpeed(e){const t=this._currentSpeed;if(this._leftKey&&(this._currentSpeed-=this._acceleration*e),this._rightKey&&(this._currentSpeed+=this._acceleration*e),this._leftKey===this._rightKey){const i=this._currentSpeed>0;this._currentSpeed-=this._deceleration*e*(i?1:-1),i&&this._currentSpeed<0&&(this._currentSpeed=0),!i&&this._currentSpeed>0&&(this._currentSpeed=0)}return this._currentSpeed>this._maxSpeed&&(this._currentSpeed=this._maxSpeed),this._currentSpeed<-this._maxSpeed&&(this._currentSpeed=-this._maxSpeed),(this._currentSpeed+t)*e/2}_moveX(){const e=this.owner,t=e.getX();if(this._requestedDeltaX!==0){let i=this._onFloor.getFloorPlatform()!==null?this._onFloor.getFloorPlatform().owner.id:null;e.setX(e.getX()+this._requestedDeltaX);let s=!0;for(;this._isCollidingWithOneOf(this._potentialCollidingObjects,i,!0);){if(this._requestedDeltaX>0&&e.getX()<=t||this._requestedDeltaX<0&&e.getX()>=t){e.setX(t);break}s?(e.setX(Math.round(e.getX())),s=!1):e.setX(Math.round(e.getX())+(this._requestedDeltaX>0?-1:1))}}}_moveY(){const e=this.owner;if(this._requestedDeltaY!==0)if(this._requestedDeltaY>0){const{highestGround:t}=this._findHighestFloorAndMoveOnTop(this._potentialCollidingObjects,0,this._requestedDeltaY);t||e.setY(e.getY()+this._requestedDeltaY)}else{let t=e.getY();for(e.setY(e.getY()+this._requestedDeltaY);this._requestedDeltaY<0&&this._isCollidingWithOneOf(this._potentialCollidingObjects,null,!0)||this._requestedDeltaY>0&&this._isCollidingWithOneOfExcluding(this._potentialCollidingObjects,this._overlappedJumpThru);){if(this._state===this._jumping&&this._setFalling(),this._requestedDeltaY>0&&e.getY()<=t||this._requestedDeltaY<0&&e.getY()>=t){e.setY(t);break}e.setY(Math.floor(e.getY())+(this._requestedDeltaY>0?-1:1))}}}_setFalling(){this._state.leave();const e=this._state;this._state=this._falling,this._falling.enter(e)}_setOnFloor(e){this._state.leave(),this._state=this._onFloor,this._onFloor.enter(e)}_setJumping(){this._state.leave();const e=this._state;this._state=this._jumping,this._jumping.enter(e)}_setGrabbingPlatform(e){this._state.leave(),this._state=this._grabbingPlatform,this._grabbingPlatform.enter(e)}_setOnLadder(){this._state.leave(),this._state=this._onLadder,this._onLadder.enter()}_checkTransitionOnLadder(){this._ladderKey&&this._isOverlappingLadder()&&this._setOnLadder()}_checkTransitionJumping(){this._canJump&&this._jumpKey&&this._setJumping()}_checkGrabPlatform(){const e=this.owner;let t=e.getX();e.setX(e.getX()+(this._requestedDeltaX<0||this._requestedDeltaX===0&&this._lastDirectionIsLeft?-this._xGrabTolerance:this._xGrabTolerance));const i=n.staticArray(m.prototype._checkGrabPlatform);i.length=0;for(const r of this._potentialCollidingObjects)this._isCollidingWith(r)&&this._canGrab(r)&&i.push(r);e.setX(t);let s=e.getY();for(const r of i){if(e.setY(r.owner.getY()+r.getYGrabOffset()-this._yGrabOffset),!this._isCollidingWithOneOf(this._potentialCollidingObjects,null,!0)){this._setGrabbingPlatform(r),this._requestedDeltaY=0,i.length=0;return}e.setY(s)}i.length=0}_checkTransitionOnFloorOrFalling(){const e=this.owner,t=e.getY(),i=this._requestedDeltaY>=0,{highestGround:s}=this._findHighestFloorAndMoveOnTop(this._potentialCollidingObjects,-1,1);this._state===this._onFloor?s?s===this._onFloor.getFloorPlatform()?this._onFloor.updateFloorPosition():this._setOnFloor(s):this._setFalling():s&&i?this._setOnFloor(s):e.setY(t)}_fall(e){const t=this._currentFallSpeed;this._currentFallSpeed+=this._gravity*e,this._currentFallSpeed>this._maxFallingSpeed&&(this._currentFallSpeed=this._maxFallingSpeed),this._useLegacyTrajectory?this._requestedDeltaY+=this._currentFallSpeed*e:this._requestedDeltaY+=(this._currentFallSpeed+t)/2*e}_canGrab(e){const t=this.owner.getY()+this._yGrabOffset-this._lastDeltaY,i=this.owner.getY()+this._yGrabOffset,s=e.owner.getY()+e.getYGrabOffset();return e.canBeGrabbed()&&(t<s&&s<=i||i<=s&&s<t)}_releaseGrabbedPlatform(){this._state===this._grabbingPlatform&&this._setFalling()}_releaseLadder(){this._state===this._onLadder&&this._setFalling()}_separateFromPlatforms(e,t){t=!!t;const i=n.staticArray(m.prototype._separateFromPlatforms);i.length=0;for(let s=0;s<e.length;++s){const r=e[s];r.getPlatformType()!==n.PlatformRuntimeBehavior.LADDER&&(t&&r.getPlatformType()===n.PlatformRuntimeBehavior.JUMPTHRU||i.push(r.owner))}return this.owner.separateFromObjects(i,this._ignoreTouchingEdges)}_isCollidingWithOneOf(e,t,i){i=!!i;for(let s=0;s<e.length;++s){const r=e[s];if(r.owner.id!==t&&r.getPlatformType()!==n.PlatformRuntimeBehavior.LADDER&&!(i&&r.getPlatformType()===n.PlatformRuntimeBehavior.JUMPTHRU)&&n.RuntimeObject.collisionTest(this.owner,r.owner,this._ignoreTouchingEdges))return!0}return!1}_findHighestFloorAndMoveOnTop(e,t,i){const s=b.instance;s.initializeBeforeSearch(this,t,i);let r=Number.MAX_VALUE,l=null,o=!1;for(const a of e){if(a.getPlatformType()===n.PlatformRuntimeBehavior.LADDER||a.getPlatformType()===n.PlatformRuntimeBehavior.JUMPTHRU&&(this._state===this._onFloor&&a!==this._onFloor.getFloorPlatform()&&i<0||this._state!==this._onFloor&&this._isIn(this._overlappedJumpThru,a.owner.id)))continue;const h=s.allowedMinDeltaY,_=s.allowedMaxDeltaY;this._findPlatformHighestRelativeYUnderObject(a,s);let d=s.getFloorDeltaY();if(a.getPlatformType()===n.PlatformRuntimeBehavior.JUMPTHRU&&(this._state===this._onFloor&&a!==this._onFloor.getFloorPlatform()&&d<0||s.allowedMinDeltaY!==h)){s.revertTo(h,_);continue}if(s.isCollidingAnyPlatform()&&(o=!0),s.floorIsTooHigh()){l=null;break}s.isCollidingAnyPlatform()&&d<r&&(r=d,l=a)}if(l){const a=this.owner;a.setY(a.getY()+r)}const f=n.PlatformerObjectRuntimeBehavior._platformSearchResult;return f.highestGround=l,f.isCollidingAnyPlatform=o,f}_findPlatformHighestRelativeYUnderObject(e,t){const i=e.owner,s=i.getAABB();if(s.max[0]<=t.ownerMinX||s.min[0]>=t.ownerMaxX||s.max[1]<=t.headMinY||s.min[1]>t.floorMaxY)return t;for(const r of i.getHitBoxesAround(t.ownerMinX,t.headMinY,t.ownerMaxX,t.floorMaxY)){if(r.vertices.length<3)continue;t.initializeBeforeHitboxCheck();let l=r.vertices[r.vertices.length-2],o=r.vertices[r.vertices.length-1];for(const f of r.vertices){(t.ownerMinX<o[0]&&o[0]<t.ownerMaxX||o[0]===t.ownerMinX&&(l[0]>o[0]||f[0]>o[0])||o[0]===t.ownerMaxX&&(l[0]<o[0]||f[0]<o[0]))&&t.addPointConstraint(o[1]);const a=o[0]-l[0];if(a!==0){if(o[0]<t.ownerMinX&&t.ownerMinX<l[0]||l[0]<t.ownerMinX&&t.ownerMinX<o[0]){const h=o[1]-l[1],_=l[1]+(t.ownerMinX-l[0])*h/a;t.addPointConstraint(_)}if(o[0]<t.ownerMaxX&&t.ownerMaxX<l[0]||l[0]<t.ownerMaxX&&t.ownerMaxX<o[0]){const h=o[1]-l[1],_=l[1]+(t.ownerMaxX-l[0])*h/a;t.addPointConstraint(_)}}if(t.floorIsTooHigh())return t;l=o,o=f}}return t}_isCollidingWithOneOfExcluding(e,t){for(let i=0;i<e.length;++i){const s=e[i];if(!(t&&this._isIn(t,s.owner.id))&&s.getPlatformType()!==n.PlatformRuntimeBehavior.LADDER&&n.RuntimeObject.collisionTest(this.owner,s.owner,this._ignoreTouchingEdges))return!0}return!1}_isCollidingWith(e){return e.getPlatformType()!==n.PlatformRuntimeBehavior.LADDER&&!this._isIn(this._overlappedJumpThru,e.owner.id)&&n.RuntimeObject.collisionTest(this.owner,e.owner,this._ignoreTouchingEdges)}_updateOverlappedJumpThru(){this._overlappedJumpThru.length=0;for(let e=0;e<this._potentialCollidingObjects.length;++e){const t=this._potentialCollidingObjects[e];t.getPlatformType()===n.PlatformRuntimeBehavior.JUMPTHRU&&n.RuntimeObject.collisionTest(this.owner,t.owner,this._ignoreTouchingEdges)&&this._overlappedJumpThru.push(t)}}_isOverlappingLadder(){for(let e=0;e<this._potentialCollidingObjects.length;++e){const t=this._potentialCollidingObjects[e];if(t.getPlatformType()===n.PlatformRuntimeBehavior.LADDER&&n.RuntimeObject.collisionTest(this.owner,t.owner,this._ignoreTouchingEdges))return!0}return!1}_isIn(e,t){for(let i=0;i<e.length;++i)if(e[i].owner.id===t)return!0;return!1}_updatePotentialCollidingObjects(e){const t=this.owner;this._manager.getAllPlatformsAround(t,e,this._potentialCollidingObjects);for(let i=0;i<this._potentialCollidingObjects.length;)this._potentialCollidingObjects[i].owner===t?this._potentialCollidingObjects.splice(i,1):i++}simulateControl(e){e==="Left"?this._leftKey=!0:e==="Right"?this._rightKey=!0:e==="Up"?this._upKey=!0:e==="Down"?this._downKey=!0:e==="Ladder"?this._ladderKey=!0:e==="Jump"?this._jumpKey=!0:e==="Release"?this._releasePlatformKey=!0:e==="Release Ladder"&&(this._releaseLadderKey=!0)}isUsingControl(e){return e==="Left"?this._wasLeftKeyPressed:e==="Right"?this._wasRightKeyPressed:e==="Up"?this._wasUpKeyPressed:e==="Down"?this._wasDownKeyPressed:e==="Ladder"?this._wasLadderKeyPressed:e==="Jump"?this._wasJumpKeyPressed:e==="Release"?this._wasReleasePlatformKeyPressed:e==="Release Ladder"?this._wasReleaseLadderKeyPressed:!1}getGravity(){return this._gravity}getSlopeMaxAngle(){return this._slopeMaxAngle}getMaxFallingSpeed(){return this._maxFallingSpeed}getLadderClimbingSpeed(){return this._ladderClimbingSpeed}getAcceleration(){return this._acceleration}getDeceleration(){return this._deceleration}getMaxSpeed(){return this._maxSpeed}getJumpSpeed(){return this._jumpSpeed}getJumpSustainTime(){return this._jumpSustainTime}getCurrentFallSpeed(){return this._currentFallSpeed}getCurrentSpeed(){return this._currentSpeed}setCurrentSpeed(e){this._currentSpeed=n.evtTools.common.clamp(e,-this._maxSpeed,this._maxSpeed)}getCurrentJumpSpeed(){return this._jumping.getCurrentJumpSpeed()}canGrabPlatforms(){return this._canGrabPlatforms}canJump(){return this._canJump}setGravity(e){this._gravity=e}setMaxFallingSpeed(e,t=!1){if(t&&this._state===this._jumping){const i=this._currentFallSpeed-e;i>0&&(this._currentFallSpeed-=i,this._jumping.setCurrentJumpSpeed(Math.max(0,this._jumping.getCurrentJumpSpeed()-i)))}this._maxFallingSpeed=e}setLadderClimbingSpeed(e){this._ladderClimbingSpeed=e}setAcceleration(e){this._acceleration=e}setDeceleration(e){this._deceleration=e}setMaxSpeed(e){this._maxSpeed=e}setJumpSpeed(e){this._jumpSpeed=e}setJumpSustainTime(e){this._jumpSustainTime=e}setSlopeMaxAngle(e){e<0||e>=90||(this._slopeMaxAngle=e,e===45?this._slopeClimbingFactor=1:this._slopeClimbingFactor=Math.tan(e*3.1415926/180),this._slopeClimbingFactor<1/1024&&(this._slopeClimbingFactor=1/1024))}setCanJump(){this._canJump=!0}setCanNotAirJump(){(this._state===this._jumping||this._state===this._falling)&&(this._canJump=!1)}abortJump(){this._state===this._jumping&&(this._currentFallSpeed=0,this._setFalling())}setCurrentFallSpeed(e){this._state===this._falling&&(this._currentFallSpeed=n.evtTools.common.clamp(e,0,this._maxFallingSpeed))}setCanGrabPlatforms(e){this._canGrabPlatforms=e,this._canGrabPlatforms||this._releaseGrabbedPlatform()}ignoreDefaultControls(e){this._ignoreDefaultControls=e}simulateLeftKey(){this._leftKey=!0}simulateRightKey(){this._rightKey=!0}simulateLadderKey(){this._ladderKey=!0}simulateReleaseLadderKey(){this._releaseLadderKey=!0}simulateUpKey(){this._upKey=!0}simulateDownKey(){this._downKey=!0}simulateJumpKey(){this._jumpKey=!0}simulateReleasePlatformKey(){this._releasePlatformKey=!0}isOnFloor(){return this._state===this._onFloor}isOnFloorObject(e){if(this.isOnFloor()){const t=this._onFloor.getFloorPlatform();return!!t&&t.owner.id===e.id}return!1}isOnLadder(){return this._state===this._onLadder}isJumping(){return this._state===this._jumping}isGrabbingPlatform(){return this._state===this._grabbingPlatform}isFallingWithoutJumping(){return this._state===this._falling}isFalling(){return this._state===this._falling||this._state===this._jumping&&this._currentFallSpeed>this._jumping.getCurrentJumpSpeed()}isMoving(){return this._hasMovedAtLeastOnePixel&&(this._currentSpeed!==0||this._state===this._onLadder)||this._jumping.getCurrentJumpSpeed()!==0||this._currentFallSpeed!==0}isMovingEvenALittle(){return this._hasReallyMoved&&(this._currentSpeed!==0||this._state===this._onLadder)||this._jumping.getCurrentJumpSpeed()!==0||this._currentFallSpeed!==0}};let c=m;c._platformSearchResult={highestGround:null,isCollidingAnyPlatform:!1},c.epsilon=2**-20,n.PlatformerObjectRuntimeBehavior=c;class y{constructor(e){this._floorPlatform=null;this._floorLastX=0;this._floorLastY=0;this._oldHeight=0;this._behavior=e}getFloorPlatform(){return this._floorPlatform}enter(e){this._floorPlatform=e,this.updateFloorPosition(),this._behavior._canJump=!0,this._behavior._currentFallSpeed=0}leave(){this._floorPlatform=null}updateFloorPosition(){this._floorLastX=this._floorPlatform.owner.getX(),this._floorLastY=this._floorPlatform.owner.getY()}beforeUpdatingObstacles(e){const t=this._behavior.owner;this._oldHeight!==t.getHeight()&&t.setY(this._floorLastY-t.getHeight()+(t.getY()-t.getDrawableY()));const i=this._floorPlatform.owner.getY()-this._floorLastY;i!==0&&Math.abs(i)<=Math.abs(this._behavior._maxFallingSpeed*e)&&t.setY(t.getY()+i)}checkTransitionBeforeX(){const e=this._behavior;e._isIn(e._potentialCollidingObjects,this._floorPlatform.owner.id)?this._behavior._downKey&&this._floorPlatform._platformType===n.PlatformRuntimeBehavior.JUMPTHRU&&e._canGoDownFromJumpthru&&(e._overlappedJumpThru.push(this._floorPlatform),e._setFalling()):e._setFalling(),e._checkTransitionJumping()}beforeMovingX(){const e=this._behavior;e._requestedDeltaX+=this._floorPlatform.owner.getX()-this._floorLastX}checkTransitionBeforeY(e){this._behavior._checkTransitionOnLadder()}beforeMovingY(e,t){const i=this._behavior,s=i.owner;if(s.getX()===t+i._requestedDeltaX){const r=Math.abs(i._requestedDeltaX*i._slopeClimbingFactor),{highestGround:l,isCollidingAnyPlatform:o}=i._findHighestFloorAndMoveOnTop(i._potentialCollidingObjects,-r,r);l&&l!==this._floorPlatform&&i._setOnFloor(l),l===null&&o&&i.owner.setX(t)}else{const{highestGround:r,isCollidingAnyPlatform:l}=i._findHighestFloorAndMoveOnTop(i._potentialCollidingObjects,Math.min(0,-Math.abs(s.getX()-t)*i._slopeClimbingFactor),0);if(r===null&&l)i.owner.setX(t);else{const o=i._requestedDeltaX,f=o-(s.getX()-t),a=s.getY(),h=s.getX();s.setX(s.getX()+Math.sign(o));const{highestGround:_}=i._findHighestFloorAndMoveOnTop(i._potentialCollidingObjects,Math.min(-1,-1*i._slopeClimbingFactor),0);if(_){const d=Math.sign(o)*Math.max(1,Math.abs(f)-1);s.setX(s.getX()+d);const{highestGround:u}=i._findHighestFloorAndMoveOnTop(i._potentialCollidingObjects,-Math.abs(d)*i._slopeClimbingFactor,0);if(u)if(Math.abs(f)>=2)i._setOnFloor(u);else{s.setPosition(t+o,a);const{highestGround:p}=i._findHighestFloorAndMoveOnTop(i._potentialCollidingObjects,Math.min(-1,-Math.abs(f)*i._slopeClimbingFactor),0);p&&i._setOnFloor(p)}else Math.sign(h-t)===Math.sign(o)?s.setPosition(h,a):s.setPosition(t,a),i._currentSpeed=0}else Math.sign(h-t)===Math.sign(o)?s.setPosition(h,a):s.setPosition(t,a),i._currentSpeed=0}}}toString(){return"OnFloor"}}class S{constructor(e){this._behavior=e}enter(e){e!==this._behavior._jumping&&e!==this&&(this._behavior._canJump=!1)}leave(){}beforeUpdatingObstacles(e){}checkTransitionBeforeX(){}beforeMovingX(){}checkTransitionBeforeY(e){const t=this._behavior;t._checkTransitionOnLadder(),t._checkTransitionJumping(),t._canGrabPlatforms&&(t._requestedDeltaX!==0||t._canGrabWithoutMoving)&&t._checkGrabPlatform()}beforeMovingY(e,t){this._behavior._fall(e)}toString(){return"Falling"}}class M{constructor(e){this._currentJumpSpeed=0;this._timeSinceCurrentJumpStart=0;this._jumpKeyHeldSinceJumpStart=!1;this._jumpingFirstDelta=!1;this._behavior=e}getCurrentJumpSpeed(){return this._currentJumpSpeed}setCurrentJumpSpeed(e){this._currentJumpSpeed=e}enter(e){const t=this._behavior;this._timeSinceCurrentJumpStart=0,this._jumpKeyHeldSinceJumpStart=!0,e!==t._jumping&&e!==t._falling&&(this._jumpingFirstDelta=!0),t._canJump=!1,this._currentJumpSpeed=t._jumpSpeed,t._currentFallSpeed=0}leave(){this._currentJumpSpeed=0}beforeUpdatingObstacles(e){}checkTransitionBeforeX(){}beforeMovingX(){}checkTransitionBeforeY(e){const t=this._behavior;t._checkTransitionOnLadder(),t._checkTransitionJumping(),t._canGrabPlatforms&&(t._requestedDeltaX!==0||t._canGrabWithoutMoving)&&t._lastDeltaY>=0&&t._checkGrabPlatform()}beforeMovingY(e,t){const i=this._behavior;i._jumpKey||(this._jumpKeyHeldSinceJumpStart=!1),this._timeSinceCurrentJumpStart+=e;const s=this._currentJumpSpeed;this._jumpKeyHeldSinceJumpStart&&this._timeSinceCurrentJumpStart<i._jumpSustainTime||(this._currentJumpSpeed-=i._gravity*e),this._behavior._useLegacyTrajectory?(i._requestedDeltaY-=s*e,this._jumpingFirstDelta||i._fall(e)):(i._requestedDeltaY+=(-s-this._currentJumpSpeed)/2*e,i._fall(e)),this._jumpingFirstDelta=!1,this._currentJumpSpeed<0&&i._setFalling()}toString(){return"Jumping"}}class Y{constructor(e){this._grabbedPlatform=null;this._behavior=e}enter(e){this._grabbedPlatform=e,this._behavior._canJump=!0,this._behavior._currentFallSpeed=0}leave(){this._grabbedPlatform=null}beforeUpdatingObstacles(e){}checkTransitionBeforeX(){const e=this._behavior;e._isIn(e._potentialCollidingObjects,this._grabbedPlatform.owner.id)||e._releaseGrabbedPlatform()}beforeMovingX(){const e=this._behavior;e._requestedDeltaX=this._grabbedPlatform.owner.getX()-this._grabbedPlatformLastX,e._requestedDeltaY=this._grabbedPlatform.owner.getY()-this._grabbedPlatformLastY}checkTransitionBeforeY(e){const t=this._behavior;t._checkTransitionOnLadder(),t._releasePlatformKey&&t._releaseGrabbedPlatform(),t._checkTransitionJumping()}beforeMovingY(e,t){this._grabbedPlatformLastX=this._grabbedPlatform.owner.getX(),this._grabbedPlatformLastY=this._grabbedPlatform.owner.getY()}toString(){return"GrabbingPlatform"}}class j{constructor(e){this._behavior=e}enter(){this._behavior._canJump=!0,this._behavior._currentFallSpeed=0}leave(){}beforeUpdatingObstacles(e){}checkTransitionBeforeX(){}beforeMovingX(){}checkTransitionBeforeY(e){const t=this._behavior;t._isOverlappingLadder()||t._setFalling(),t._checkTransitionJumping(),t._releaseLadderKey&&t._releaseLadder()}beforeMovingY(e,t){const i=this._behavior;i._upKey&&(i._requestedDeltaY-=i._ladderClimbingSpeed*e),i._downKey&&(i._requestedDeltaY+=i._ladderClimbingSpeed*e)}toString(){return"OnLadder"}}const v=class{constructor(){this.ownerMinX=0;this.ownerMaxX=0;this.headMinY=0;this.ownerMinY=0;this.headMaxY=0;this.floorMinY=0;this.ownerMaxY=0;this.floorMaxY=0;this.allowedMinDeltaY=0;this.allowedMaxDeltaY=0;this.foundOverHead=!1;this.foundUnderBottom=!1}initializeBeforeSearch(e,t,i){let s=Number.MAX_VALUE,r=-Number.MAX_VALUE,l=Number.MAX_VALUE,o=-Number.MAX_VALUE;for(const f of e.owner.getHitBoxes())for(const a of f.vertices)s=Math.min(s,a[0]),r=Math.max(r,a[0]),l=Math.min(l,a[1]),o=Math.max(o,a[1]);this.ownerMinX=s,this.ownerMaxX=r,this.headMinY=l+t,this.ownerMinY=l,this.headMaxY=l+i,this.floorMinY=o+t,this.ownerMaxY=o,this.floorMaxY=o+i,this.allowedMinDeltaY=t,this.allowedMaxDeltaY=Number.MAX_VALUE}initializeBeforeHitboxCheck(){this.foundOverHead=!1,this.foundUnderBottom=!1}revertTo(e,t){this.allowedMinDeltaY=e,this.allowedMaxDeltaY=t}setFloorIsTooHigh(){this.allowedMinDeltaY=Number.MAX_VALUE,this.allowedMaxDeltaY=-Number.MAX_VALUE}floorIsTooHigh(){return this.allowedMinDeltaY>this.allowedMaxDeltaY}isCollidingAnyPlatform(){return this.ownerMaxY+this.allowedMaxDeltaY<=this.floorMaxY}getFloorDeltaY(){return this.allowedMaxDeltaY}addPointConstraint(e){if(e<this.floorMinY){if(e>this.headMaxY){this.setFloorIsTooHigh();return}if(this.foundOverHead=!0,this.foundUnderBottom){this.setFloorIsTooHigh();return}this.allowedMinDeltaY=Math.max(this.allowedMinDeltaY,e-this.ownerMinY)}else{if(this.foundUnderBottom=!0,this.foundOverHead){this.setFloorIsTooHigh();return}this.allowedMaxDeltaY=Math.min(this.allowedMaxDeltaY,e-this.ownerMaxY)}}};let b=v;b.instance=new v,n.registerBehavior("PlatformBehavior::PlatformerObjectBehavior",n.PlatformerObjectRuntimeBehavior)})(gdjs||(gdjs={}));
|
|
//# sourceMappingURL=platformerobjectruntimebehavior.js.map
|