Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # diagonal movement fixes
- # Author Molegato
- # Version 1.0
- #------------------------------------------------------------------------------
- # Fixes a number of issues with diagonal movement
- #------------------------------------------------------------------------------
- #
- # NOTE: this script doesn't add diagonal movement. Other scripts do, like
- # for example my 'SideTop Characters' script.
- #
- # What this script does:
- # -Makes possible for events to keep their diagonal direction even
- # when they are not moving. (By default they snap to a cardinal one)
- # -Allows events to move diagonally when chasing the player of fleeing
- # from it. (By default they'll retardedly zig-zag their way)
- # -Makes the event condition 'event/player looking this direction'
- # detect diagonal directions as both cardinal directions combined
- # (by default, moving diagonally won't trigger any direction in the events)
- #==============================================================================
- $imported = {} if $imported.nil?
- $imported['Molegato-diagonal_fixes'] = true
- class Game_Character
- def move_toward_character(character)
- sx = distance_x_from(character.x)
- sy = distance_y_from(character.y)
- if (sx==0 || sy==0)
- #straight
- if sx.abs > sy.abs
- move_straight(sx > 0 ? 4 : 6)
- move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0
- elsif sy != 0
- move_straight(sy > 0 ? 8 : 2)
- move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0
- end
- else
- #diagonal
- move_diagonal(sx > 0 ? 4 : 6,sy > 0 ? 8 : 2)
- end
- end
- def move_away_from_character(character)
- sx = distance_x_from(character.x)
- sy = distance_y_from(character.y)
- if (sx==0 || sy==0)
- if sx.abs > sy.abs
- move_straight(sx > 0 ? 6 : 4)
- move_straight(sy > 0 ? 2 : 8) if !@move_succeed && sy != 0
- elsif sy != 0
- move_straight(sy > 0 ? 2 : 8)
- move_straight(sx > 0 ? 6 : 4) if !@move_succeed && sx != 0
- end
- else
- #diagonal
- move_diagonal(sx > 0 ? 6 : 4,sy > 0 ? 2 : 8)
- end
- end
- end
- #==============================================================================
- # ■ Game_Interpreter fix
- #==============================================================================
- class Game_Interpreter
- alias molegato_command_111 command_111
- def command_111
- result = false
- if @params[0]==6
- character = get_character(@params[1])
- if character
- case @params[2]
- when 8 #up
- result = (character.direction == 8 or character.angledirection==9 or character.angledirection==7)
- when 4 #left
- result = (character.direction == 4 or character.angledirection==1 or character.angledirection==7)
- when 6 #right
- result = (character.direction == 6 or character.angledirection==9 or character.angledirection==3)
- when 2 #down
- result = (character.direction == 2 or character.angledirection==1 or character.angledirection==3)
- end
- end
- @branch[@indent] = result
- command_skip if !@branch[@indent]
- else
- molegato_command_111
- end
- end
- end
- #==============================================================================
- # ■ Game_Character
- #==============================================================================
- class Game_Character
- def move_forward
- if @direction==2 or @direction==4 or @direction==6 or @direction==8
- move_straight(@direction)
- else
- if @direction==1
- move_diagonal(4, 2)
- end
- if @direction==3
- move_diagonal(6, 2)
- end
- if @direction==7
- move_diagonal(4, 8)
- end
- if @direction==9
- move_diagonal(6, 8)
- end
- end
- end
- def move_backward
- last_direction_fix = @direction_fix
- @direction_fix = true
- if @direction==2 or @direction==4 or @direction==6 or @direction==8
- move_straight(reverse_dir(@direction), false)
- else
- if @direction==9
- move_diagonal(4, 2)
- end
- if @direction==7
- move_diagonal(6, 2)
- end
- if @direction==3
- move_diagonal(4, 8)
- end
- if @direction==1
- move_diagonal(6, 8)
- end
- end
- @direction_fix = last_direction_fix
- end
- end
- #==============================================================================
- # ■ Game_CharacterBase
- #==============================================================================
- class Game_CharacterBase
- attr_reader :direction
- attr_reader :angledirection
- def movedirection
- return @angledirection
- end
- alias diagofix_direction set_direction
- def set_direction(d)
- diagofix_direction(d)
- @angledirection = @direction
- end
- alias diagofix_straight move_straight
- def move_straight(d, turn_ok = true)
- diagofix_straight(d, turn_ok)
- @angledirection = @direction
- end
- alias diagofix_diagonal move_diagonal
- def move_diagonal(horz, vert)
- diagofix_diagonal(horz, vert)
- if horz==4 and vert==2
- @angledirection=1
- end
- if horz==6 and vert==2
- @angledirection=3
- end
- if horz==4 and vert==8
- @angledirection=7
- end
- if horz==6 and vert==8
- @angledirection=9
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment