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.

8-directional movement, on call

Code:
#-----------------------------------------------------------------------#
#  8-Way Character Movement                                             #
#-----------------------------------------------------------------------#
# Created by Daniel Morell 'Windu' or 'Scorpius' March 25th, 2008                     #
# Modified by DeM0nFiRe to add toggle
#-----------------------------------------------------------------------#
$toggle_8way = false
class Game_Player
  def update_player_movement
    # Remember whether or not moving in local variables
    last_moving = moving?
    # If moving, event running, move route forcing, and message window
    # display are all not occurring
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      # Move player in the direction the directional button is being pressed
      if $toggle_8way
          case Input.dir8
          when 1
            move_lower_left
          when 2
            move_down
          when 3
           move_lower_right
          when 4
            move_left
          when 6
            move_right
          when 7
            move_upper_left
          when 8
            move_up
          when 9
            move_upper_right
          end
     else
      case Input.dir8
      when 2
        move_down
      when 4
        move_left
      when 6
        move_right
      when 8
        move_up
      end
    end
    end
  end
end

And in a call event script do $toggle_8way = true to activate 8 way and = false to deactivate it.

(I could have mixed up the scope of the variable, though)
 
DeM0nFiRe":32ac9ccw said:
(I could have mixed up the scope of the variable, though)
You actually did, as a global variable isn't needed at all for a single class...

Code:
class Game_Player
  #--------------------------------------------------------------------------
  alias 8way_initialize initialize
  def initialize
    8way_initialize
    @toggle_8way = false
  end
  #--------------------------------------------------------------------------
  def update_player_movement
    last_moving = moving?
    unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing
      if @toggle_8way
        case Input.dir8
        when 1
          move_lower_left
        when 2
          move_down
        when 3
         move_lower_right
        when 4
          move_left
        when 6
          move_right
        when 7
          move_upper_left
        when 8
          move_up
        when 9
          move_upper_right
        end
      else
        case Input.dir8
        when 2
          move_down
        when 4
          move_left
        when 6
          move_right
        when 8
          move_up
        end
      end
    end
  end
  #--------------------------------------------------------------------------
end

Also @Bruno: This is possible with events as well, Mr. Proud of being an Event Scripter ;)
 

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