Skip to content

Instantly share code, notes, and snippets.

@aaaaagold
Last active July 15, 2021 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaaaagold/6d5aee3cee2fc3ee243198a029abeb8b to your computer and use it in GitHub Desktop.
Save aaaaagold/6d5aee3cee2fc3ee243198a029abeb8b to your computer and use it in GitHub Desktop.
an rmmv plugin
"use strict";
(()=>{
Game_Player.prototype.moveStraight = function(d) {
const dpf=this.distancePerFrame();
const dpf2=dpf*2,x=this.x,y=this.y;
const rd=this.reverseDir(d),rx=Math.round(x),ry=Math.round(y);
let canPass=1;
switch(d){
default: canPass=0; break;
case 2: {
const fy=Math.floor(y);
canPass=(Math.round(y+dpf2)===ry)||this.canPass(rx,fy,d);
}break;
case 4: {
const cx=Math.ceil(x);
canPass=(Math.round(x-dpf2)===rx)||this.canPass(cx,ry,d);
}break;
case 6: {
const fx=Math.floor(x);
canPass=(Math.round(x+dpf2)===rx)||this.canPass(fx,ry,d);
}break;
case 8: {
const cy=Math.ceil(y);
canPass=(Math.round(y-dpf2)===ry)||this.canPass(rx,cy,d);
}break;
}
if (canPass) {
this._followers.updateMove();
}
this.setMovementSuccess(canPass);
if (this.isMovementSucceeded()) {
this.setDirection(d);
this._x = this._realX+(d===6?1:d===4?-1:0)*dpf2;
this._y = this._realY+(d===2?1:d===8?-1:0)*dpf2;
this.increaseSteps();
} else {
this.setDirection(d);
this.checkEventTriggerTouchFront(d);
}
};
Game_Player.prototype.stopMove=function(){
this._x=this._realX;
this._y=this._realY;
};
Game_Player.prototype.moveByInput = function() {
if (!this.isMoving() && this.canMove()) {
var direction = this.getInputDirection();
if (direction > 0) {
$gameTemp.clearDestination();
} else if ($gameTemp.isDestinationValid()){
var x = $gameTemp.destinationX();
var y = $gameTemp.destinationY();
direction = this.findDirectionTo(x, y);
}
if (direction > 0) {
this.executeMove(direction);
}else this.stopMove();
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment