Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[VX] 8-Directional Movement with Sprite Support 1.1

Requested by Arrow-1 and produced by me, the amazingly new but old 8-way movement script!  The part that makes it new is that this one is for VX!!!

Now you can enjoy walking diagonally through your blocky VX maps! (wooo!)

This script supports 8-directional movement along with diagonally oriented sprites so you can actually see them walking diagonally, it doesn't look like some weird line-dancing half diagonal strafe thing! YAY!

Please be advised that this script has only included methods for the hero/party to move diagonally and eventas are at this time unsupported.  I can update it, but that would take more time and there might be an update later on if people need it.

Updates: 1.1
* Fixed compatibility with Anaryu's Anti-Lag script (this script must be loaded before the anti-lag script)
* Fixed option that disables the use of custom diagonal sprites

Code:
 

#==============================================================================

# 8 Way Directional Movement

#------------------------------------------------------------------------------

# Kylock

# 21.3.2008

# Version 1.1

#==============================================================================

# Special thanks to Arrow-1 for the script request and supplying sprites for

#   testing purposes.

#==============================================================================

# Instructions:

#    Add this script towards the top, since methods are rewritten and not 

#      aliased.  Once you add it and run your game, the script will 

#      automagically enable 8-way directional movement for your hero.

# Features:

#    * Added movement functionality to allow your hero to move in diagonal

#        directions

#    * Corrects directional issues resulting from trying to activate events

#        while facing a diaganol direction. (could be better implemented,

#        but does work as it is)

#==============================================================================

# Changelog

#   1.0 Initial Release

#   1.1 Added support for no custom sprites and added compatibility with

#         Anaryu's Anti-Lag script (must be loaded above the anti-lag script)

#==============================================================================

 

#==============================================================================

# ** Script Configuration

#==============================================================================

module KMDM

  DIRSPRITE = false          # set to true if you are using a custom 

                             # character sprite for diagonal movement

end

 

#==============================================================================

# ** Game_Player

#------------------------------------------------------------------------------

#  rewrote def move_by-input to enable extra directions

#==============================================================================

 

class Game_Player < Game_Character

  def move_by_input

    return unless movable?

    return if $game_map.interpreter.running?

    case Input.dir8

      when 1;  move_lower_left

      when 2;  move_down

      when 3;  move_lower_right 

      when 4;  move_left

      when 7;  move_upper_left

      when 6;  move_right

      when 8;  move_up

      when 9;  move_upper_right

    end

  end

end

 

#==============================================================================

# ** Game_Character

#------------------------------------------------------------------------------

# Corrects direction so events will respond when hero is facing diagonal.

#  Modifies: def move_lower_left, def move_lower_right, def move_upper_left, 

#            and def move_upper_right

#==============================================================================

 

class Game_Character

  #--------------------------------------------------------------------------

  # * Move Lower Left

  #--------------------------------------------------------------------------

  def move_lower_left(turn_ok = true)

    set_direction(5)

    if (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or

       (passable?(@x-1, @y) and passable?(@x-1, @y+1))

      @x -= 1

      @y += 1

      increase_steps

      @move_failed = false

    else

      @move_failed = true

    end

  end

  #--------------------------------------------------------------------------

  # * Move Lower Right

  #--------------------------------------------------------------------------

  def move_lower_right(turn_ok = true)

    set_direction(3)

    if (passable?(@x, @y+1) and passable?(@x+1, @y+1)) or

       (passable?(@x+1, @y) and passable?(@x+1, @y+1))

      @x += 1

      @y += 1

      increase_steps

      @move_failed = false

    else

      @move_failed = true

    end

  end

  #--------------------------------------------------------------------------

  # * Move Upper Left

  #--------------------------------------------------------------------------

  def move_upper_left(turn_ok = true)

    if KMDM::DIRSPRITE == true

      set_direction(7)

    else

      set_direction(8)

    end

    if (passable?(@x, @y-1) and passable?(@x-1, @y-1)) or

       (passable?(@x-1, @y) and passable?(@x-1, @y-1))

      @x -= 1

      @y -= 1

      increase_steps

      @move_failed = false

    else

      @move_failed = true

    end

  end

  #--------------------------------------------------------------------------

  # * Move Upper Right

  #--------------------------------------------------------------------------

  def move_upper_right(turn_ok = true)

    set_direction(9)

    if (passable?(@x, @y-1) and passable?(@x+1, @y-1)) or

       (passable?(@x+1, @y) and passable?(@x+1, @y-1))

      @x += 1

      @y -= 1

      increase_steps

      @move_failed = false

    else

      @move_failed = true

    end

  end

end

 

#==============================================================================

# ** Sprite_Character

#------------------------------------------------------------------------------

# Adds functionality for diagonal character sprites.

#  Modifies: def update_src_rect

#==============================================================================

 

class Sprite_Character < Sprite_Base

  #--------------------------------------------------------------------------

  # * Update Transfer Origin Rectangle

  #--------------------------------------------------------------------------

  def update_src_rect

    if @tile_id == 0

      index = @character.character_index

      #if the character is facing diagonally, use the second spriteset

      if @character.direction % 2 != 0 && KMDM::DIRSPRITE == true

        index = @character.character_index + 1

      end

      pattern = @character.pattern < 3 ? @character.pattern : 1

      sx = (index % 4 * 3 + pattern) * @cw

      sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch

      self.src_rect.set(sx, sy, @cw, @ch)

    end

  end

end

 

Also need to create a custom sprite sheet for your heroes and import it into the Characters section/folder.  It should look something like what I have sampled below.

http://i218.photobucket.com/albums/cc308/kylock1/sam.png[/img]

Oh yeah, almost forgot.  To use this script, be sure the character sprite sheet is named as .png or whatever.
 
challudym":2vid8eyw said:
Could this be made to support more frames of animation for the hero?
Not easily.  It'd be the same as writing a completely new script for 4 frame heroes.  All I do here is use existing code (3 frame animation) to draw the hero diagonally.
 
cwj5050":1inx9rke said:

Thanks!

DerVVulfman":1inx9rke said:
Since this affects "Sprite_Character", this affects all sprites... players walking, trailing characters (if using fukuyama's or Sephiroth Spawn's - editing required - ) and any "Event" sprites (chests, doors or what have you).

SO, while the RTP sprites holds 4 frames of animation for a door... IF you choose to have your character use 12 frames per step (and you set it as such), you will have to redraw (yuck) your door charsets to have 12 frames as well.

Likewise, they'd also need 8 directions as well.  For a system that enhances your character's movement animation, you will have to accomodate every other animated sprite to match.

'Tis the only downside... but it would make your game look less RTP.

Eww.  I can't see it being that widely used, although it wouldn't be an impossible task (re-spriting the RTP might be though)...
 
Nice. I did notice when using this with Trickter's Caterpillar script, the trailing character would after a few diagonal movements translate so far away that he's walking on the edge of the screen, then eventually offscreen completely. I like this script, and when it's eventually combined with pixel movement and a good abs, we have Zelda!

Here's the glitch: When I diagonally try to walk into a blocked tile, the trailing character keeps moving through the blocked tiles as if he were following me through them, but he's actually walking farther away from my character, who is stuck back near the blocked tile.

So the problem is caterpillar followers when it comes to recognizing and stopping for blocked tiles.
 
westingtyler06":n8b9eoe6 said:
Nice. I did notice when using this with Trickter's Caterpillar script, the trailing character would after a few diagonal movements translate so far away that he's walking on the edge of the screen, then eventually offscreen completely. I like this script, and when it's eventually combined with pixel movement and a good abs, we have Zelda!

Here's the glitch: When I diagonally try to walk into a blocked tile, the trailing character keeps moving through the blocked tiles as if he were following me through them, but he's actually walking farther away from my character, who is stuck back near the blocked tile.

So the problem is caterpillar followers when it comes to recognizing and stopping for blocked tiles.

In order to resolve this issue, I suggest posting a script request for compatibility in the requests forum.  My apologies, but I don't have the time to do this, and my attention right now is more focused on modifying the sideview system.
 
um your post says pixel movement this isn ot pixel movement....

the character clearly moves one tile at a time.


pixel move would belikle if i tapped the control stick for the tinerst frac of a second i would move just a pixelk or 2


Hope you get it working to do real pixel movement though!

BTW would it be hard to give like 4 + frames to movement? then i could an9imate a flapping cloak etc
 
I cant seem to be able to make this work the sprite's not appearing as it should?
where do I place the script? and about renaming the sprite template -when I try to rename it it says symbols <> and such are not allowed? I'm so new with this stuff pls help..
 
jetseter":3i4mqokr said:
I cant seem to be able to make this work the sprite's not appearing as it should?
where do I place the script? and about renaming the sprite template -when I try to rename it it says symbols <> and such are not allowed? I'm so new with this stuff pls help..
You shouldn't put special characters in filenames.
 
Kylock does this script support your sidebattle view script because in your sbs script your characters spritesheet need to be in a specific way?
edit:nvm!
 
You didn't include the demo? Too bad, I have this script with the demo but don't know how this script exactly work. I don't mean to insult or something but I need some graphic for Alex and friends (XP) and Ralph (VX), you know? If somebody know how to make a graphic for this, I really appreciate that.
 
I'm super new to scripting. I've gotten pretty good at every aspect of RMXP and now i'm trying to get into scripting. I like the 8 direction idea. The only thing is I don't know where to put the code in the script editor and was wondering if I could get some help with it.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top