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 SIMPLE script.

Nachos

Sponsor

Simple 8-directional movement script.

Did you ever want to have an 8-directional movement script which:

-Doesn't use SDK.
-Has no other fancy functions
-It is compatible with almost everything (found an error with UCoders message system, but fixed)

Then this if for you!

Compatibility:

-Almost everything. It only overwrites Game_Player.


Credits:

-Vgvgf because he helps me with everything.


Script:


Paste above main

Code:
#======================================

# â–  Simple 8-directional movemento script

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

# By: Nachito (rmxp)

#   Date: 20.12.2008

#   Version: 1.0

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

 

class Game_Player < Game_Character

  def update

    last_moving = moving?

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing

        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

    end

    last_real_x = @real_x

    last_real_y = @real_y

    super

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      $game_map.scroll_down(@real_y - last_real_y)

    end

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      $game_map.scroll_left(last_real_x - @real_x)

    end

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      $game_map.scroll_right(@real_x - last_real_x)

    end

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      $game_map.scroll_up(last_real_y - @real_y)

    end

    unless moving?

      if last_moving

        result = check_event_trigger_here([1,2])

        if result == false

          unless $DEBUG and Input.press?(Input::CTRL)

            if @encounter_count > 0

              @encounter_count -= 1

            end

          end

        end

      end

      if Input.trigger?(Input::C)

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

end

 

There. I'm 90% sure someone will come and say "Hey this is stupid, there are a lot of 8-directional scripts!"
I DON'T CARE.

Be well
 
Actually this is just what I was looking for. Makes it a little more bareable when using a 360 controller instead of the default 4 direction movement :D
Thanks!
 
the thing about diagonally faster happens also with most 2d PROFESSIONAL games
Star Ocean 2---Bunny shoes+walk diagonally, enemies will barely hit you(example)
 
The mentioned speed increase for diagonal movement comes from the speed addition from both directional movements. Just in case anyone doesn't know the correct formula, lemme tell you you have to divide the move speed by 1.4 (root of 2).

@nahchito: You definately need to alias this... in fact, you should alias as much as possible for submitted scripts, but yeah... this is one you need ^^ Especially since you didn't change too much in there (which is good, because you're keeping it simple ;) ), and I think you have the double amount of lines you'd actually need.
 

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