Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // Plugin: ZE - Free Jump
- // Version: 1.0.0
- // Date: November 29th, 2015.
- //=============================================================================
- /*:
- * @plugindesc Allows the player to jump at anytime on the map, and can be used to allow the player to jump over certain tiles. <pluginID ZE - Free Jump>
- * @author Zalerinian
- *
- * @param Jump Key
- * @desc Press this key to jump. Default: ok
- * @default ok
- *
- * @param Check Terrain Tags
- * @desc While jumping, should Terrain Tags be checked? Default: false
- * @default false
- *
- * @param Default Terrain Tag
- * @desc If the above is false, this number will be used as the default terrain tag. Default: 0
- * @default 0
- *
- * @param Check Region IDs
- * @desc While jumping, should Region IDs be checked? Default: false
- * @default false
- *
- * @param Default Region ID
- * @desc If the above is false, this will be used as the default region. Default: 0
- * @default 0
- *
- * @param Passable Terrain Tag
- * @desc If the terrain tag below the player is this value, then the player can jump over this tile. See help. Default: -1
- * @default -1
- *
- * @param Passable Region ID
- * @desc If the region ID below the player is this value, then the player can jump over this tile. See help. Default: -1
- * @default -1
- *
- * @param Dash Jump Threshold
- * @desc If we were dashing for this many frames or more, then consider the jump a dash jump. Default: 6
- * @default 6
- *
- * @param Regular Peak Max
- * @desc The peak of the jump should be less than this value. Default: 8
- * @default 8
- *
- * @param Dash Peak Max
- * @desc The peak max when dashing. Default: 10
- * @default 10
- *
- * @param Min Peak
- * @desc The minimum jump peak. Jumps will be this height at the least. Default: 3
- * @default 3
- *
- * @param Count Decrease
- * @desc How much should be subtracted from the amount of time left to jump? Default: 0.8
- * @default 0.8
- *
- * @param Count Increase
- * @desc The amount of time in the jump to add per increase to the peak. Default: 2
- * @default 2
- *
- * @param X Increment
- * @desc How much should we increase the player's X value per update? Default: 0.125
- * @default 0.125
- *
- * @param Y Increment
- * @desc How much should we increase the player's Y value per update? Default 0.125
- * @default 0.125
- *
- * @param Grid Snap
- * @desc See help text. If true, the player is snapped back into the grid at the end of a jump. Default: true
- * @default true
- *
- * @param Tile Width
- * @desc The width of a tile. See help text.
- * @default 1
- *
- * @param Tile Height
- * @desc The height of a tile. See help text.
- * @default 1
- *
- * @param Enable Diagonal
- * @desc Enable diagonal movement during a jump. Default: true
- * @default true
- *
- * @help
- * Movement Count
- * ------------------------------------------------------------------------------
- * This is added to an internal counter every time the jump is updated. Once the
- * counter is at least 1, the player will be moved. Movement will work such that
- * the player is moved as many times as the counter is whole number.
- *
- * For example, if the counter becomes 2.25 at one point, the player will be
- * moved 2 times that frame, and may appear to move really quickly at once.
- *
- *
- * Tile Width/Height
- * ------------------------------------------------------------------------------
- * When jumping using decimal values, it's possible that the player may get stuck
- * oddly on the grid. These values are used to figure out how we should force the
- * player back onto the grid. Smaller decimals mean that tiles are split into
- * pieces. For example, 0.25 implies that when we move, we're moving 25% between
- * one tile and the next (meaning, internally, out X/Y position may be decimals
- * that are multiples of .25, such as 1.25 or 7.75).
- *
- * These values only have an affect if Grid Snap is enabled.
- *
- *
- * Grid Snap
- * ------------------------------------------------------------------------------
- * If this setting is enabled, once a jump has ended, we'll snap the player to
- * the tile-grid, since we don't necessarily limit jump movement by tile sizes,
- * and instead by pieces of tiles.
- *
- *
- * Diagonal Movement
- * ------------------------------------------------------------------------------
- * If diagonal movement is turned off, the player can only jump in the basic four
- * directions. The direction is determined by which key was last pressed, not
- * necessarily by the direction the character is facing.
- *
- *
- * Passable Terrain Tag / Region ID
- * ------------------------------------------------------------------------------
- * If these values are out of range of what the editor will allow you to input,
- * then this feature will be disabled. As neither terrain tags, nor region IDs
- * can be negative, the default value is -1, which disables this feature.
- *
- * In order to properly read terrain tags/region IDs on the maps, the player's
- * position is rounded using Math.round.
- *
- * In order to define multiple terrain tags or region IDs, simply separate each
- * number with a comma.
- * For example: -1, 2, 90, 4 for Region IDs will allow the player to jump over
- * any tile with the region ID -1, 2, 90, or 4. Please note that -1 is not a
- * valid region ID. Having -1 in an ID list will not disable the feature.
- * Disabling the feature is done by supplying a list of IDs that can never occur,
- * like -1.
- */
- var Input = Input || {};
- var Zale = Zale || {};
- Zale.FreeJump = {};
- (function() {
- if(Imported["MVCommons"] && PluginManager.version("MVCommons", ">=", "1.4.0")) {
- var author = [{
- name: "Zalerinian",
- website: "http://www.razelon.com"
- }];
- var v = PluginManager.register("ZE - Free Jump", "1.0.0", PluginManager.getBasicPlugin("ZE - Free Jump").description, author, "2015-11-18");
- if (v === false){
- PluginManager.printPlugin("ZE - Free Jump")
- throw new Error("Unable to load ZE - Free Jump due to registration failure! Is there another version running?");
- }
- } else {
- throw new Error("Error: ZE - Free Jump requires MVCommons 1.4.0 or higher!")
- }
- })();
- (function(){
- var params = PluginManager.parameters("ZE - Free Jump");
- Zale.FreeJump.PARAMS = params;
- Zale.FreeJump.JUMPKEY = params["Jump Key"];
- Zale.FreeJump.CHECKTAG = MVC.Boolean(params["Check Terrain Tags"]);
- Zale.FreeJump.CHECKREGION = MVC.Boolean(params["Check Region IDs"]);
- Zale.FreeJump.DEFAULTTAG = Number(params["Default Terrain Tag"]);
- Zale.FreeJump.DEFAULTREGION = Number(params["Default Region ID"]);
- Zale.FreeJump.IGNORETAG = params["Passable Terrain Tag"].split(",").map(function(v) { return Number(v); } );
- Zale.FreeJump.IGNOREREGION = params["Passable Region ID" ].split(",").map(function(v) { return Number(v); } );
- Zale.FreeJump.DASHTHRESHOLD = Number(params["Dash Jump Threshold"]);
- Zale.FreeJump.PEAKMAX = Number(params["Regular Peak Max"]);
- Zale.FreeJump.DASHPEAKMAX = Number(params["Dash Peak Max"]);
- Zale.FreeJump.PEAKMIN = Number(params["Min Peak"]);
- Zale.FreeJump.COUNTDECREASE = Number(params["Count Decrease"]);
- Zale.FreeJump.COUNTINCREASE = Number(params["Count Increase"]);
- Zale.FreeJump.XINC = Number(params["X Increment"]);
- Zale.FreeJump.YINC = Number(params["Y Increment"]);
- Zale.FreeJump.GRIDSNAP = MVC.Boolean(params["Grid Snap"]);
- Zale.FreeJump.TILEWIDTH = Number(params["Tile Width"]);
- Zale.FreeJump.TILEHEIGHT = Number(params["Tile Height"]);
- Zale.FreeJump.DIAGONAL = MVC.Boolean(params["Enable Diagonal"]);
- /*
- * Game_Player.prototype.initialize()
- * @note
- * Alias the initialize function to add in variable defaults for
- * free jumping.
- */
- Zale.FreeJump.GP_init_IOB43bqzog = Game_CharacterBase.prototype.initialize;
- Game_Player.prototype.initialize = function() {
- Zale.FreeJump.GP_init_IOB43bqzog.call(this);
- this._endJumpInput = false;
- this._freeJump = false;
- this._dashJump = false;
- this._dashCount = 0;
- this._jumpDir = 0;
- }
- /*
- * Game_Player.prototype.canMove()
- * @note
- * Make sure we're not jumping before we try to move.
- */
- Zale.FreeJump.GP_canmove_BVio32h8oh = Game_Player.prototype.canMove;
- Game_Player.prototype.canMove = function() {
- return Zale.FreeJump.GP_canmove_BVio32h8oh.call(this) && !this.isJumping();
- }
- /*
- * Game_Player.prototype.updateDashing()
- * @note
- * Alias the updateDashing function to also increment the dash count
- * if we're dashing, or set it to 9 if we aren't.
- */
- Zale.FreeJump.GP_udash_XZ9pohv2n = Game_Player.prototype.updateDashing;
- Game_Player.prototype.updateDashing = function() {
- Zale.FreeJump.GP_udash_XZ9pohv2n.call(this);
- if(this._dashing) {
- this._dashCount += 1;
- } else {
- this._dashCount = 0;
- }
- }
- /*
- * Game_Player.prototype.moveByInput()
- * @note
- * Alias the moveByInput function so that we can check for
- * the input required for jumping.
- */
- Zale.FreeJump.GP_mbi_IO98Cnkwa = Game_Player.prototype.moveByInput;
- Game_Player.prototype.moveByInput = function() {
- Zale.FreeJump.GP_mbi_IO98Cnkwa.call(this);
- if(Input.isTriggered(Zale.FreeJump.JUMPKEY) && this.canMove() && !this.triggerAction()) {
- this.freeJump();
- }
- }
- /*
- * Game_Player.prototype.isJumping()
- * @note
- * Aliases the isJumping function to include whether or not we are
- * doing free jumping.
- */
- Zale.FreeJump.GP_isjump_BCOlwnc9 = Game_Player.prototype.isJumping;
- Game_Player.prototype.isJumping = function() {
- return this.isFreeJumping() || Zale.FreeJump.GP_isjump_BCOlwnc9.call(this);
- }
- /*
- * Game_Player.prototype.freeJump()
- * @note
- * Sets initial values for the jump onto the player so that
- * the update function has all the information it needs.
- *
- * If Character Poses is included in the game project, the
- * jumping pose is set here so that our character changes
- */
- Game_Player.prototype.freeJump = function() {
- this._freeJump = true;
- this._endJumpInput = false;
- this._jumpPeak = Zale.FreeJump.PEAKMIN;
- this._jumpCount = this._jumpPeak * Zale.FreeJump.COUNTINCREASE;
- this._dashJump = this.isDashJump();
- this._jumpDir = Zale.FreeJump.DIAGONAL ? Input.dir8 : Input.dir4;
- if(Imported["ZE - Character Poses"]) {
- this.setPose(Zale.CharPose.JUMPPOSE);
- }
- }
- /*
- * Game_Player.prototype.isFreeJumping()
- * @return {Boolean} Whether or not we are free jumping.
- */
- Game_Player.prototype.isFreeJumping = function() {
- return this._freeJump;
- }
- /*
- * Game_Player.prototype.isDashJump()
- * @return {Boolean} Whether or not the current free jump is a dash jump.
- */
- Game_Player.prototype.isDashJump = function() {
- return this._dashCount >= Zale.FreeJump.DASHTHRESHOLD;
- }
- /*
- * Game_Player.prototype.updateJump()
- * @note
- * Alias updateJump to call our update separate function if the jump is a
- * freejump.
- */
- Zale.FreeJump.GP_ujump_UICiuoa91 = Game_Player.prototype.updateJump;
- Game_Player.prototype.updateJump = function() {
- if(this.isFreeJumping()) {
- this.updateFreeJump();
- } else {
- Zale.FreeJump.GP_ujump_UICiuoa91.call(this);
- }
- }
- /*
- * Game_Player.prototype._freeJumpMove(d)
- * @param {Number} d The direction we're moving in.
- * @note
- * A specific function to increment the player's position during the
- * freejump.
- */
- Game_Player.prototype._freeJumpMove = function(d) {
- if(this.canPass(this._x, this._y, d)){
- switch(d) {
- case 1:
- this._x -= Zale.FreeJump.XINC;
- this._y += Zale.FreeJump.YINC;
- break;
- case 2:
- this._y += Zale.FreeJump.YINC;
- break;
- case 3:
- this._x += Zale.FreeJump.XINC;
- this._y += Zale.FreeJump.YINC;
- break;
- case 4:
- this._x -= Zale.FreeJump.XINC;
- break;
- case 6:
- this._x += Zale.FreeJump.XINC;
- break;
- case 7:
- this._x -= Zale.FreeJump.XINC;
- this._y -= Zale.FreeJump.YINC;
- break;
- case 8:
- this._y -= Zale.FreeJump.YINC;
- break;
- case 9:
- this._x += Zale.FreeJump.XINC;
- this._y -= Zale.FreeJump.YINC;
- break;
- default:
- break;
- }
- }
- }
- /*
- * Game_Player.prototype.updateFreeJump
- * @note
- * Update the player's free jump. This function does pretty much all the
- * heavy-lifting of the plugin. It will allow for the variable jump height,
- * move the player, and also check if the jump is finished.
- * If Character Poses is imported, this will clear the jump pose when the
- * jump ends.
- */
- Game_Player.prototype.updateFreeJump = function() {
- if(!Input.isPressed(Zale.FreeJump.JUMPKEY)) {
- this._endJumpInput = true;
- }
- if(Input.isPressed(Zale.FreeJump.JUMPKEY) && !this._endJumpInput) {
- if(!this._dashJump && this._jumpPeak < Zale.FreeJump.PEAKMAX || this._dashJump && this._jumpPeak < Zale.FreeJump.DASHPEAKMAX) {
- this._jumpCount += Zale.FreeJump.COUNTINCREASE;
- this._jumpPeak += 1;
- }
- }
- this._jumpCount = [this._jumpCount - Zale.FreeJump.COUNTDECREASE, 0].max().fix();
- this._freeJumpMove(this._jumpDir);
- this._realX = this._x;
- this._realY = this._y;
- if(this._jumpCount === 0) {
- this._jumpCount = 0;
- this._freeJump = false;
- this._dashJump = false;
- if(Zale.FreeJump.GRIDSNAP) {
- this.snapX();
- this.snapY();
- }
- this._jumpDir = 0;
- if(Imported["ZE - Character Poses"]) {
- this.removePose(Zale.CharPose.JUMPPOSE);
- }
- }
- }
- /*
- * Game_Player.prototype.snapX()
- * @note
- * Snaps the player to the grid, based on the Tile Width parameter
- * set by the game dev. This does not check for passability. The
- * grid snap typically has to happen because when jumping and
- * hitting a wall, this.canPass returns false for the last small
- * bit, so the player gets stuck between the grid. Since we have
- * the game dev input the tile width, we really shouldn't get stuck
- * in any walls.
- *
- * This takes into account the player's direction.
- */
- Game_Player.prototype.snapX = function() {
- var dx = this._x % Zale.FreeJump.TILEWIDTH;
- if(dx !== 0) {
- if(dx >= Zale.FreeJump.TILEWIDTH / 2) {
- this._x += (Zale.FreeJump.TILEWIDTH - dx) * ([1, 4, 7].contains(this._jumpDir) ? -1 : 1);
- } else {
- this._x += dx * ([1, 4, 7].contains(this._jumpDir) ? -1 : 1);
- }
- }
- }
- /*
- * Game_Player.prototype.snapY()
- * @note
- * Snaps the player to the grid, based on the Tile Height parameter
- * set by the game dev. This does not check for passability. The
- * grid snap typically has to happen because when jumping and
- * hitting a wall, this.canPass returns false for the last small
- * bit, so the player gets stuck between the grid. Since we have
- * the game dev input the tile height, we really shouldn't get stuck
- * in any walls.
- */
- Game_Player.prototype.snapY = function() {
- var dy = this._y % Zale.FreeJump.TILEHEIGHT;
- if(dy !== 0) {
- if(dy >= Zale.FreeJump.TILEHEIGHT / 2) {
- //Round up
- this._y += (Zale.FreeJump.TILEHEIGHT - dy) * ([1, 2, 3].contains(this._jumpDir) ? 1 : -1);
- } else {
- this._y += dy * ([1, 2, 3].contains(this._jumpDir) ? 1 : -1);
- }
- }
- }
- /*
- * Game_Player.prototype.terrainTag()
- * @note
- * Adds a check to see if we're free jumping, and whether or not
- * terrain tags were disabled while doing so. If the conditions
- * are not true, the aliased function is called.
- *
- * If they are met, however, the predefined default terrain tag is
- * returned instead of checking the map.
- *
- * @returns {Number} A terrain tag.
- */
- Zale.FreeJump.GP_ttag_UIBw0nv83c0 = Game_Player.prototype.terrainTag;
- Game_Player.prototype.terrainTag = function() {
- if(this.isFreeJumping() && !Zale.FreeJump.CHECKTAG) {
- return Zale.FreeJump.DEFAULTTAG;
- } else {
- return Zale.FreeJump.GP_ttag_UIBw0nv83c0.call(this);
- }
- }
- /*
- * Game_Player.prototype.isMapPassable(x, y, d)
- * @param {Number} x The x coordinate to check.
- * @param {Number} y The y coordinate to check.
- * @param {Number} d The direction to check.
- * @note
- * Adds on a check to see if we should ignore a tile while free
- * jumping. The ignore is based on the passable region id and
- * terrain tag defined by parameters.
- */
- Zale.FreeJump.GP_imp = Game_Player.prototype.isMapPassable;
- Game_Player.prototype.isMapPassable = function(x, y, d) {
- return Zale.FreeJump.GP_imp.call(this, x, y, d) || this.canIgnoreTile(x, y, d);
- }
- /*
- * Game_Player.prototype.canIgnoreTile(x, y, d)
- * @param {Number} x The x coordinate to check.
- * @param {Number} y The y coordinate to check.
- * @param {Number} d The direction to check.
- * @note
- * This function will check if the tile at the given position can
- * be passed over while jumping. This checks the ignored terrain
- * tags and region IDs.
- */
- Game_Player.prototype.canIgnoreTile = function(x, y, d) {
- x = $gameMap.roundXWithDirection(x, d);
- y = $gameMap.roundYWithDirection(y, d);
- if(this.isFreeJumping()) {
- if(Zale.FreeJump.IGNORETAG.contains($gameMap.terrainTag(Math.round(x), Math.round(y)))) {
- return true;
- }
- if(Zale.FreeJump.IGNOREREGION.contains($gameMap.regionId(Math.round(x), Math.round(y)))) {
- return true;
- }
- }
- return false;
- }
- /*
- * Game_Player.prototype.regionId()
- * @note
- * Adds a check to see if we're free jumping, and whether or not
- * region IDs were disabled while doing so. If the conditions
- * are not true, the aliased function is called.
- *
- * If they are met, however, the predefined default region id is
- * returned instead of checking the map.
- *
- * @returns {Number} A region id.
- */
- Zale.FreeJump.GP_rid_XBDFj92nq = Game_Player.prototype.regionId;
- Game_Player.prototype.regionId = function() {
- if(this.isFreeJumping() && !Zale.FreeJump.CHECKREGION) {
- return Zale.FreeJump.DEFAULTREGION;
- } else {
- return Zale.FreeJump.GP_rid_XBDFj92nq.call(this);
- }
- }
- /*
- * Game_Player.prototype.isOnDamageFloor
- * @return {Boolean} Whether or not the player is on a adamaging tile.
- * @note
- * This function has been aliased to return false if the player is jumping.
- */
- Zale.FreeJump.GP_idf_ISbcyr6vAF = Game_Player.prototype.isOnDamageFloor;
- Game_Player.prototype.isOnDamageFloor = function() {
- return Zale.FreeJump.GP_idf_ISbcyr6vAF.call(this) && !this.isJumping();
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment