Character Movements (Idle, Walk and Run)

fbu

Villager
Member
Joined
Mar 22, 2013
Messages
10
Reaction score
11
First Language
Portuguese
Primarily Uses
Character Movements (Idle, Walk and Run)

DESCRIPTION:
Allows for player movement to cycle between 3 character sheets: idle, walk and run.

EXAMPLE:


CODE:

Code:
/*
  <Character Movement>
  v 0.1 - 31 August 2019
  GIT_HUB:
  https://github.com/andrefcasimiro/rpg_maker_mv_js/blob/master/Project1/js/plugins/CharacterMovement.js
  DESCRIPTION:
  Allows for switching between 3 different character sheets: Idle, Walk and Run, according to our movement state.
  INSTRUCTIONS:
  1. Copy and paste plugin.
  2. Choose Idle, Walk and Run character sheets in the plugin's parameters window.
  3. Run game.
  PARAMS:
  @param Actor_{ID}
  ID - must be equal to the actor index in the database
  @param {Pose}_{ID}
  Pose - must be one of the following: 'Idle', 'Walk' or 'Run'
  ID - can be anything as long as you don't repeate @param names
*/

/*:
* @plugindesc Allow for player movement to cycle between 3 character sheets: idle, walk and run.
* @author FBU <andrefcasimiro(at)gmail.com>
*
* // ACTOR 1 --------------------------------
* @param Actor_1
*
* @param Idle_Actor1
* @desc "The character set for idle movement"
* @require 1
* @dir img/characters/
* @type file
* @parent Actor_1
*
* @param Walk_Actor1
* @desc "The character set for walk movement"
* @require 1
* @dir img/characters/
* @type file
* @parent Actor_1
*
* @param Run_Actor1
* @desc "The character set for running movement"
* @require 1
* @dir img/characters/
* @type file
* @parent Actor_1
*
*/

(function() {
  var Parameters = PluginManager.parameters('CharacterMovement');

  var bank = [];
  Object.keys(Parameters).forEach((parameterKey, index) => {
    var parameterKeyArray = parameterKey.split('_');
    var lastIndex = parameterKeyArray && parameterKeyArray[parameterKeyArray.length - 1];

    var isID = parameterKeyArray[0] === 'Actor' && !isNaN(lastIndex);
    if (isID) {
      bank = bank.concat({
        actor: lastIndex,
        sheet: {},
      });
    } else {
      if (!Parameters[parameterKey]) {
        return;
      }
      var key = parameterKeyArray;
      key.length = key.length - 1;
      key = key.join('_');

      if (bank[bank.length - 1]) {
        bank[bank.length - 1].sheet = {
          ...bank[bank.length - 1].sheet,
          [key]: Parameters[parameterKey],
        };
      }
    }
  })

  var actors = [];
  var isDashing, isWalking = false;
  var isStopped = true;
  var action = 0;
  var _cachedAction;

  var Scene_Map_Create = Scene_Map.prototype.create;
  Scene_Map.prototype.create = function() {
    Scene_Map_Create.call(this);

    actors = bank.map(entry => $gameActors.actor(entry.actor));
  };

  var Scene_Map_Update = Scene_Map.prototype.update;
  Scene_Map.prototype.update = function() {
    Scene_Map_Update.call(this);

    managePlayerMovement();
  };

  var setSheet = function(action) {
    actors.forEach(function (actor, index) {
      if (!Object.keys(bank[index].sheet).length) {
        return;
      }

      actor.setCharacterImage(bank[index].sheet[action], actor.characterIndex())
    });
  }

  var managePlayerMovement = function() {
    isDashing = (!!$gamePlayer.getInputDirection() && $gamePlayer.isDashing()) || !!$gameTemp.isDestinationValid();
    isWalking = !!$gamePlayer.getInputDirection() && !isDashing;
    isStopped = !isWalking && !isDashing;

    if (isStopped) {
      action = 0;
    } else if (isDashing) {
      action = 1;
    } else if (isWalking) {
      action = 2;
    }

    if (action !== _cachedAction) {
      action === 0
        ? setSheet('Idle')
        : action === 2
            ? setSheet('Walk')
            : setSheet('Run');

      $gamePlayer.refresh();
    }

    _cachedAction = action;
  }
})();
[See also on Github]

TERMS:
Can be used freely in commercial and non-commercial projects. No credits required.

Any code suggestions / improvements are welcome.

Enjoy!
 
Last edited:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
14,159
Reaction score
7,807
First Language
English
Primarily Uses
RMMV
@fbu Can you please add credits and terms of use to your original post?
 
  • Like
Reactions: fbu

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

40 card deck size, the plugin seems more sluggish.
Village theme I composed for a commission!
Stream will be live shortly with some Haunting Ground! Feel free to drop by!
welp, the stock market went down by 7% because of corona today. Time to buy stocks?

Forum statistics

Threads
94,563
Messages
921,921
Members
124,429
Latest member
sheepman
Top