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.

Diagonal Movement only

My first request for an actual script, TBH I can prolly figure out how to do this, but I have so much already to do just with ripping images that I need >_<

I want to replace Up, down, left, right with diagonal movement. The game I am making only uses diagonal movement so itd be like this

LEFT = Northwest
UP = Northeast
DOWN = Southwest
RIGHT = Southeast
 
I'll just tread this as a Script Support topic because of the simplicity :p

Check Game_Player for the specific movement commands (i.e. move_down, move_upleft, ...) - if your entire game is supposed to use diagonal movement instead of regular UDLR, you're best off replacing the single-direction move commands with the multidirectional ones directly, as that might give you the one or other compatibility improvement... nevermind shorter method names.
If you want it nice and shiney, you need to go to... Scene_Map.update, if I'm not mistaken, and exchange the command names there. Might be possible that they're directly within Game_Player, though... you need to check.

Also, for future topics, please add which maker you're using. We got those fancy badges for topic titles for a reason...
 
OH shoot, sorry lol RMXP hehe, thanks I had no idea this was so simple

I basically did this, and I get diagonal movement but now my touch events arent working lol
Code:
 

    alias isometric_update update

  def update

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

             @move_route_forcing or $game_temp.message_window_showing

        case Input.dir8

        when 1..2

          move_lower_left

        when 3

          move_lower_right

        when 4

          move_upper_left

        when 7

          move_upper_left

        when 6

          move_lower_right

        when 8..9

          move_upper_right

        end

      end

      unless moving?

        if Input.trigger?(Input::C)

          check_event_trigger_here([0])

          check_event_trigger_there([0,1,2])

        end

      end

    else

      isometric_update

    end

 

Alright so this works fine, BUT..it moves 1:1 X:Y, I need it to be 2:1 for correct movement, I know I will have to replace this bit in the movement commands
Code:
 

def move_lower_left

...

      @x -= 1

      @y += 1

...

end

 
with say this? and then halve my movement speed?
Code:
 

def move_lower_left

...

      @x -= 2

      @y += 1

...

end

 

Here is an example of one of the maps I am using
http://img847.imageshack.us/i/screenshot1n.png/

UPDATE: answered my own questions with this, tho i will probably alias it
Code:
 

class Game_Character

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

  # * Move Lower Left

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

  def move_lower_left

    # If no direction fix

    unless @direction_fix

      # Face down is facing right or up

      @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)

    end

    # When a down to left or a left to down course is passable

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

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

      # Update coordinates

      @x -= 2

      @y += 1

      # Increase steps

      increase_steps

    end

  end

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

  # * Move Lower Right

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

  def move_lower_right

    # If no direction fix

    unless @direction_fix

      # Face right if facing left, and face down if facing up

      @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)

    end

    # When a down to right or a right to down course is passable

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

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

      # Update coordinates

      @x += 2

      @y += 1

      # Increase steps

      increase_steps

    end

  end

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

  # * Move Upper Left

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

  def move_upper_left

    # If no direction fix

    unless @direction_fix

      # Face left if facing right, and face up if facing down

      @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)

    end

    # When an up to left or a left to up course is passable

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

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

      # Update coordinates

      @x -= 2

      @y -= 1

      # Increase steps

      increase_steps

    end

  end

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

  # * Move Upper Right

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

  def move_upper_right

    # If no direction fix

    unless @direction_fix

      # Face right if facing left, and face up if facing down

      @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)

    end

    # When an up to right or a right to up course is passable

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

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

      # Update coordinates

      @x += 2

      @y -= 1

      # Increase steps

      increase_steps

    end

  end

end

 

now it just struck me I have to modify event handling and collision (since I can diagonally sneak through stuff now getting stuck, and events on touch no longer trigger)
 

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