Group: Member
Posts: 12
Type: Artist
RM Skill: Beginner
I'm using Paradog's 8-Direction Movement v1.01 script (allowing the main character to move diagonal, as well as adding the option for an additional sprite screen for when the player uses those directions; it's compatible with Paradog's Dash Script, but I'm not using that one at this time):
CODE
#============================================================================== #�€€�‹�‹�€€8-Direction Characterset Edit�€€ver. 1.01�€€�‹�‹ #�€€�€€Script by ParaDog #�€€�€€http://2d6.parasite.jp/ #------------------------------------------------------------------------------ # Additional 'diagonal' movement is now possible by pushing combinations of the # vertical and horizontal controls (up & left, etc) simultaneously. # # Additional charsets for the 8-directional movement are to be stored within # the "Graphics/Characters" folder, just like the regular charactersets. # # Name the new diagonal movement charactersets the same as the regular ones, # but with a new '_quarter' extension. As such, you would name the very first # characterset: 001-Fighter01_quarter. #------------------------------------------------------------------------------ # Additional notes: # This system can be used with the 'Dash Characterset Edit' system, but please # place this script 'BELOW' the fore-mentioned Dash script for it to work. # # As you can combine the two scripts (Dash and 8-Directional), you can also use # charactersets that show diagonal running action, also stored within the same # "Graphics/Characters" folder. # # Naming the new graphics would require the inclusion of both '_dash' and the # '_quarter' extensions as shown here: 001-Fighter01_dash_quarter. #==============================================================================
#============================================================================== # ** Game_Player #------------------------------------------------------------------------------ # This class handles the player. Its functions include event starting # determinants and map scrolling. Refer to "$game_player" for the one # instance of this class. #==============================================================================
class Game_Player < Game_Character #-------------------------------------------------------------------------- # * Frame update #-------------------------------------------------------------------------- alias update_para_quarter update def update update_para_quarter unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing # If the direction button is pushed, move the player in that direction case Input.dir8 when 1 # Move Lower Left move_lower_left when 3 # Move Lower Right move_lower_right when 7 # Move Upper Left move_upper_left when 9 # Move Upper Right move_upper_right end end end end
#============================================================================== # ** Sprite_Character #------------------------------------------------------------------------------ # This sprite is used to display the character.It observes the Game_Character # class and automatically changes sprite conditions. #==============================================================================
class Sprite_Character < RPG::Sprite #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias update_para_quarter update def update update_para_quarter if @tile_id == 0 if (@character.direction - 2) % 2 == 1 # Checking the presence of the diagonal charset if quarter_graphic_exist?(@character) # Set the diagonal charset if character.dash_on and dash_quarter_graphic_exist?(@character) @character_name = @character.character_name + "_dash_quarter" else @character_name = @character.character_name + "_quarter" end self.bitmap = RPG::Cache.character(@character_name, @character.character_hue) # Acquire direction case @character.direction when 1 n = 0 when 3 n = 2 when 7 n = 1 when 9 n = 3 end else @character.direction = @character.sub_direction # When the diagonal charset does not exist, direction n = (@character.direction - 2) / 2 end # Set original transfer rectangle sx = @character.pattern * @cw sy = n * @ch self.src_rect.set(sx, sy, @cw, @ch) else self.bitmap = RPG::Cache.character(@character.character_name, @character.character_hue) # Set original transfer rectangle sx = @character.pattern * @cw sy = (@character.direction - 2) / 2 * @ch self.src_rect.set(sx, sy, @cw, @ch) end end end #-------------------------------------------------------------------------- # * Diagonal Charset? #-------------------------------------------------------------------------- def quarter_graphic_exist?(character) # Reading check begin RPG::Cache.character(character.character_name.to_s + "_quarter", character.character_hue) rescue return false end return true end #-------------------------------------------------------------------------- # * Dashing Diagonal Charset? #-------------------------------------------------------------------------- def dash_quarter_graphic_exist?(character) # Reading check begin RPG::Cache.character(character.character_name.to_s + "_dash_quarter", character.character_hue) rescue return false end return true end end
#============================================================================== # ** Game_Character #------------------------------------------------------------------------------ # This class deals with characters. It's used as a superclass for the # Game_Player and Game_Event classes. #==============================================================================
class Game_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :direction # direction attr_accessor :sub_direction # sub_direction #-------------------------------------------------------------------------- # * Move Lower Left #-------------------------------------------------------------------------- def move_lower_left # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 1 # Face left if facing right, and face down if facing up @sub_direction = (@sub_direction == 6 ? 4 : @sub_direction == 8 ? 2 : @sub_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 -= 1 @y += 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Lower Right #-------------------------------------------------------------------------- def move_lower_right # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 3 # Face right if facing left, and face down if facing up @sub_direction = (@sub_direction == 4 ? 6 : @sub_direction == 8 ? 2 : @sub_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 += 1 @y += 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Upper Left #-------------------------------------------------------------------------- def move_upper_left # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 7 # Face left if facing right, and face up if facing down @sub_direction = (@sub_direction == 6 ? 4 : @sub_direction == 2 ? 8 : @sub_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 -= 1 @y -= 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Upper Right #-------------------------------------------------------------------------- def move_upper_right # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 9 # Face right if facing left, and face up if facing down @sub_direction = (@sub_direction == 4 ? 6 : @sub_direction == 2 ? 8 : @sub_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 += 1 @y -= 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Dash #-------------------------------------------------------------------------- def dash_on if @dash_on != nil return @dash_on else return false end end end
I'm also using eventing to have enemies visible before the battle (set with player touch as the trigger for battle and the event's movement set to approach). Is it possible to modify the script to allow events to have 8-direction movement as well or would that be too outlandishly complicated to attempt? Admittedly, I'm not that great at scripting if my endless questions didn't clue anyone in, but I can do some basic changes myself.
It looks awkward that the events only move in the typical 4-directions while the main character can move in 8 and it makes the enemies extremely easy to avoid since the player has a movement advantage.
Thanks for your time.
EDIT: The issue's been resolved. The script is in Night_Runner's post below.
This post has been edited by KezzieZ: Jul 11 2011, 07:27 AM
Group: +Gold Member
Posts: 1,529
Type: Scripter
RM Skill: Undisclosed
code
CODE
#============================================================================== # ++ 8-Direction Characterset Edit ver. 1.01 ++ #  Script by ParaDog #  http://2d6.parasite.jp/ #------------------------------------------------------------------------------ # Additional 'diagonal' movement is now possible by pushing combinations of the # vertical and horizontal controls (up & left, etc) simultaneously. # # Additional charsets for the 8-directional movement are to be stored within # the "Graphics/Characters" folder, just like the regular charactersets. # # Name the new diagonal movement charactersets the same as the regular ones, # but with a new '_quarter' extension. As such, you would name the very first # characterset: 001-Fighter01_quarter. #------------------------------------------------------------------------------ # Additional notes: # This system can be used with the 'Dash Characterset Edit' system, but please # place this script 'BELOW' the fore-mentioned Dash script for it to work. # # As you can combine the two scripts (Dash and 8-Directional), you can also use # charactersets that show diagonal running action, also stored within the same # "Graphics/Characters" folder. # # Naming the new graphics would require the inclusion of both '_dash' and the # '_quarter' extensions as shown here: 001-Fighter01_dash_quarter. #==============================================================================
#============================================================================== # ** Game_Player #------------------------------------------------------------------------------ # This class handles the player. Its functions include event starting # determinants and map scrolling. Refer to "$game_player" for the one # instance of this class. #==============================================================================
class Game_Player < Game_Character #-------------------------------------------------------------------------- # * Frame update #-------------------------------------------------------------------------- alias update_para_quarter update def update update_para_quarter unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing # If the direction button is pushed, move the player in that direction case Input.dir8 when 1 # Move Lower Left move_lower_left when 3 # Move Lower Right move_lower_right when 7 # Move Upper Left move_upper_left when 9 # Move Upper Right move_upper_right end end end end
#============================================================================== # ** Sprite_Character #------------------------------------------------------------------------------ # This sprite is used to display the character.It observes the Game_Character # class and automatically changes sprite conditions. #==============================================================================
class Sprite_Character < RPG::Sprite #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias update_para_quarter update def update update_para_quarter if @tile_id == 0 if (@character.direction - 2) % 2 == 1 # Checking the presence of the diagonal charset if quarter_graphic_exist?(@character) # Set the diagonal charset if character.dash_on and dash_quarter_graphic_exist?(@character) @character_name = @character.character_name + "_dash_quarter" else @character_name = @character.character_name + "_quarter" end self.bitmap = RPG::Cache.character(@character_name, @character.character_hue) # Acquire direction case @character.direction when 1 n = 0 when 3 n = 2 when 7 n = 1 when 9 n = 3 end else @character.direction = @character.sub_direction # When the diagonal charset does not exist, direction n = (@character.direction - 2) / 2 end # Set original transfer rectangle sx = @character.pattern * @cw sy = n * @ch self.src_rect.set(sx, sy, @cw, @ch) else self.bitmap = RPG::Cache.character(@character.character_name, @character.character_hue) # Set original transfer rectangle sx = @character.pattern * @cw sy = (@character.direction - 2) / 2 * @ch self.src_rect.set(sx, sy, @cw, @ch) end end end #-------------------------------------------------------------------------- # * Diagonal Charset? #-------------------------------------------------------------------------- def quarter_graphic_exist?(character) # Reading check begin RPG::Cache.character(character.character_name.to_s + "_quarter", character.character_hue) rescue return false end return true end #-------------------------------------------------------------------------- # * Dashing Diagonal Charset? #-------------------------------------------------------------------------- def dash_quarter_graphic_exist?(character) # Reading check begin RPG::Cache.character(character.character_name.to_s + "_dash_quarter", character.character_hue) rescue return false end return true end end
#============================================================================== # ** Game_Character #------------------------------------------------------------------------------ # This class deals with characters. It's used as a superclass for the # Game_Player and Game_Event classes. #==============================================================================
class Game_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :direction # direction attr_accessor :sub_direction # sub_direction #-------------------------------------------------------------------------- # * Move at Random #-------------------------------------------------------------------------- def move_random case rand(9) when 0 # Move down move_down(false) when 1 # Move left move_left(false) when 2 # Move right move_right(false) when 3 # Move up move_up(false) when 5 # Move lower_left move_lower_left when 6 # Move lower_right move_lower_right when 7 # Move upper left move_upper_left when 8 # Move upper right move_upper_right end end #-------------------------------------------------------------------------- # * Move toward Player #-------------------------------------------------------------------------- def move_toward_player # Get difference in player coordinates sx = @x - $game_player.x sy = @y - $game_player.y # If coordinates are equal if sx == 0 and sy == 0 return end # Get absolute value of difference abs_sx = sx.abs abs_sy = sy.abs # If horizontal and vertical distances are equal if abs_sx == abs_sy # Move diagonally if sx < 0 && sy < 0 return move_lower_right elsif sx < 0 && sy > 0 return move_upper_right elsif sx > 0 && sy < 0 return move_lower_left elsif sx > 0 && sy > 0 return move_upper_left else rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end end # If horizontal distance is longer if abs_sx > abs_sy # Move towards player, prioritize left and right directions sx > 0 ? move_left : move_right if not moving? and sy != 0 sy > 0 ? move_up : move_down end # If vertical distance is longer else # Move towards player, prioritize up and down directions sy > 0 ? move_up : move_down if not moving? and sx != 0 sx > 0 ? move_left : move_right end end end #-------------------------------------------------------------------------- # * Move away from Player #-------------------------------------------------------------------------- def move_away_from_player # Get difference in player coordinates sx = @x - $game_player.x sy = @y - $game_player.y # If coordinates are equal if sx == 0 and sy == 0 return end # Get absolute value of difference abs_sx = sx.abs abs_sy = sy.abs # If horizontal and vertical distances are equal if abs_sx == abs_sy # Move diagonally if sx < 0 && sy < 0 return move_upper_left elsif sx < 0 && sy > 0 return move_lower_left elsif sx > 0 && sy < 0 return move_upper_right elsif sx > 0 && sy > 0 return move_lower_right else rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end end # If horizontal distance is longer if abs_sx > abs_sy # Move away from player, prioritize left and right directions sx > 0 ? move_right : move_left if not moving? and sy != 0 sy > 0 ? move_down : move_up end # If vertical distance is longer else # Move away from player, prioritize up and down directions sy > 0 ? move_down : move_up if not moving? and sx != 0 sx > 0 ? move_right : move_left end end end #-------------------------------------------------------------------------- # * 1 Step Forward #-------------------------------------------------------------------------- def move_forward case @direction when 1 move_lower_left when 2 move_down(false) when 3 move_lower_right when 4 move_left(false) when 6 move_right(false) when 7 move_upper_left when 8 move_up(false) when 9 move_upper_right end end #-------------------------------------------------------------------------- # * 1 Step Backward #-------------------------------------------------------------------------- def move_backward # Remember direction fix situation last_direction_fix = @direction_fix # Force directino fix @direction_fix = true # Branch by direction case @direction when 1 move_upper_right when 2 # Down move_up(false) when 3 move_upper_left when 4 # Left move_right(false) when 6 # Right move_left(false) when 7 move_lower_right when 8 # Up move_down(false) when 9 move_lower_left end # Return direction fix situation back to normal @direction_fix = last_direction_fix end #-------------------------------------------------------------------------- # * Move Lower Left #-------------------------------------------------------------------------- def move_lower_left # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 1 # Face left if facing right, and face down if facing up @sub_direction = (@sub_direction == 6 ? 4 : @sub_direction == 8 ? 2 : @sub_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 -= 1 @y += 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Lower Right #-------------------------------------------------------------------------- def move_lower_right # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 3 # Face right if facing left, and face down if facing up @sub_direction = (@sub_direction == 4 ? 6 : @sub_direction == 8 ? 2 : @sub_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 += 1 @y += 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Upper Left #-------------------------------------------------------------------------- def move_upper_left # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 7 # Face left if facing right, and face up if facing down @sub_direction = (@sub_direction == 6 ? 4 : @sub_direction == 2 ? 8 : @sub_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 -= 1 @y -= 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Upper Right #-------------------------------------------------------------------------- def move_upper_right # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 9 # Face right if facing left, and face up if facing down @sub_direction = (@sub_direction == 4 ? 6 : @sub_direction == 2 ? 8 : @sub_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 += 1 @y -= 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Dash #-------------------------------------------------------------------------- def dash_on if @dash_on != nil return @dash_on else return false end end end
That should make enemies approach diagonally if the player is diagonally away
__________________________
K.I.S.S. Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.
Group: Member
Posts: 12
Type: Artist
RM Skill: Beginner
QUOTE (Night_Runner @ Jul 11 2011, 09:12 AM)
code
CODE
#============================================================================== # ++ 8-Direction Characterset Edit ver. 1.01 ++ #  Script by ParaDog #  http://2d6.parasite.jp/ #------------------------------------------------------------------------------ # Additional 'diagonal' movement is now possible by pushing combinations of the # vertical and horizontal controls (up & left, etc) simultaneously. # # Additional charsets for the 8-directional movement are to be stored within # the "Graphics/Characters" folder, just like the regular charactersets. # # Name the new diagonal movement charactersets the same as the regular ones, # but with a new '_quarter' extension. As such, you would name the very first # characterset: 001-Fighter01_quarter. #------------------------------------------------------------------------------ # Additional notes: # This system can be used with the 'Dash Characterset Edit' system, but please # place this script 'BELOW' the fore-mentioned Dash script for it to work. # # As you can combine the two scripts (Dash and 8-Directional), you can also use # charactersets that show diagonal running action, also stored within the same # "Graphics/Characters" folder. # # Naming the new graphics would require the inclusion of both '_dash' and the # '_quarter' extensions as shown here: 001-Fighter01_dash_quarter. #==============================================================================
#============================================================================== # ** Game_Player #------------------------------------------------------------------------------ # This class handles the player. Its functions include event starting # determinants and map scrolling. Refer to "$game_player" for the one # instance of this class. #==============================================================================
class Game_Player < Game_Character #-------------------------------------------------------------------------- # * Frame update #-------------------------------------------------------------------------- alias update_para_quarter update def update update_para_quarter unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing # If the direction button is pushed, move the player in that direction case Input.dir8 when 1 # Move Lower Left move_lower_left when 3 # Move Lower Right move_lower_right when 7 # Move Upper Left move_upper_left when 9 # Move Upper Right move_upper_right end end end end
#============================================================================== # ** Sprite_Character #------------------------------------------------------------------------------ # This sprite is used to display the character.It observes the Game_Character # class and automatically changes sprite conditions. #==============================================================================
class Sprite_Character < RPG::Sprite #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias update_para_quarter update def update update_para_quarter if @tile_id == 0 if (@character.direction - 2) % 2 == 1 # Checking the presence of the diagonal charset if quarter_graphic_exist?(@character) # Set the diagonal charset if character.dash_on and dash_quarter_graphic_exist?(@character) @character_name = @character.character_name + "_dash_quarter" else @character_name = @character.character_name + "_quarter" end self.bitmap = RPG::Cache.character(@character_name, @character.character_hue) # Acquire direction case @character.direction when 1 n = 0 when 3 n = 2 when 7 n = 1 when 9 n = 3 end else @character.direction = @character.sub_direction # When the diagonal charset does not exist, direction n = (@character.direction - 2) / 2 end # Set original transfer rectangle sx = @character.pattern * @cw sy = n * @ch self.src_rect.set(sx, sy, @cw, @ch) else self.bitmap = RPG::Cache.character(@character.character_name, @character.character_hue) # Set original transfer rectangle sx = @character.pattern * @cw sy = (@character.direction - 2) / 2 * @ch self.src_rect.set(sx, sy, @cw, @ch) end end end #-------------------------------------------------------------------------- # * Diagonal Charset? #-------------------------------------------------------------------------- def quarter_graphic_exist?(character) # Reading check begin RPG::Cache.character(character.character_name.to_s + "_quarter", character.character_hue) rescue return false end return true end #-------------------------------------------------------------------------- # * Dashing Diagonal Charset? #-------------------------------------------------------------------------- def dash_quarter_graphic_exist?(character) # Reading check begin RPG::Cache.character(character.character_name.to_s + "_dash_quarter", character.character_hue) rescue return false end return true end end
#============================================================================== # ** Game_Character #------------------------------------------------------------------------------ # This class deals with characters. It's used as a superclass for the # Game_Player and Game_Event classes. #==============================================================================
class Game_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :direction # direction attr_accessor :sub_direction # sub_direction #-------------------------------------------------------------------------- # * Move at Random #-------------------------------------------------------------------------- def move_random case rand(9) when 0 # Move down move_down(false) when 1 # Move left move_left(false) when 2 # Move right move_right(false) when 3 # Move up move_up(false) when 5 # Move lower_left move_lower_left when 6 # Move lower_right move_lower_right when 7 # Move upper left move_upper_left when 8 # Move upper right move_upper_right end end #-------------------------------------------------------------------------- # * Move toward Player #-------------------------------------------------------------------------- def move_toward_player # Get difference in player coordinates sx = @x - $game_player.x sy = @y - $game_player.y # If coordinates are equal if sx == 0 and sy == 0 return end # Get absolute value of difference abs_sx = sx.abs abs_sy = sy.abs # If horizontal and vertical distances are equal if abs_sx == abs_sy # Move diagonally if sx < 0 && sy < 0 return move_lower_right elsif sx < 0 && sy > 0 return move_upper_right elsif sx > 0 && sy < 0 return move_lower_left elsif sx > 0 && sy > 0 return move_upper_left else rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end end # If horizontal distance is longer if abs_sx > abs_sy # Move towards player, prioritize left and right directions sx > 0 ? move_left : move_right if not moving? and sy != 0 sy > 0 ? move_up : move_down end # If vertical distance is longer else # Move towards player, prioritize up and down directions sy > 0 ? move_up : move_down if not moving? and sx != 0 sx > 0 ? move_left : move_right end end end #-------------------------------------------------------------------------- # * Move away from Player #-------------------------------------------------------------------------- def move_away_from_player # Get difference in player coordinates sx = @x - $game_player.x sy = @y - $game_player.y # If coordinates are equal if sx == 0 and sy == 0 return end # Get absolute value of difference abs_sx = sx.abs abs_sy = sy.abs # If horizontal and vertical distances are equal if abs_sx == abs_sy # Move diagonally if sx < 0 && sy < 0 return move_upper_left elsif sx < 0 && sy > 0 return move_lower_left elsif sx > 0 && sy < 0 return move_upper_right elsif sx > 0 && sy > 0 return move_lower_right else rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end end # If horizontal distance is longer if abs_sx > abs_sy # Move away from player, prioritize left and right directions sx > 0 ? move_right : move_left if not moving? and sy != 0 sy > 0 ? move_down : move_up end # If vertical distance is longer else # Move away from player, prioritize up and down directions sy > 0 ? move_down : move_up if not moving? and sx != 0 sx > 0 ? move_right : move_left end end end #-------------------------------------------------------------------------- # * 1 Step Forward #-------------------------------------------------------------------------- def move_forward case @direction when 1 move_lower_left when 2 move_down(false) when 3 move_lower_right when 4 move_left(false) when 6 move_right(false) when 7 move_upper_left when 8 move_up(false) when 9 move_upper_right end end #-------------------------------------------------------------------------- # * 1 Step Backward #-------------------------------------------------------------------------- def move_backward # Remember direction fix situation last_direction_fix = @direction_fix # Force directino fix @direction_fix = true # Branch by direction case @direction when 1 move_upper_right when 2 # Down move_up(false) when 3 move_upper_left when 4 # Left move_right(false) when 6 # Right move_left(false) when 7 move_lower_right when 8 # Up move_down(false) when 9 move_lower_left end # Return direction fix situation back to normal @direction_fix = last_direction_fix end #-------------------------------------------------------------------------- # * Move Lower Left #-------------------------------------------------------------------------- def move_lower_left # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 1 # Face left if facing right, and face down if facing up @sub_direction = (@sub_direction == 6 ? 4 : @sub_direction == 8 ? 2 : @sub_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 -= 1 @y += 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Lower Right #-------------------------------------------------------------------------- def move_lower_right # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 3 # Face right if facing left, and face down if facing up @sub_direction = (@sub_direction == 4 ? 6 : @sub_direction == 8 ? 2 : @sub_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 += 1 @y += 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Upper Left #-------------------------------------------------------------------------- def move_upper_left # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 7 # Face left if facing right, and face up if facing down @sub_direction = (@sub_direction == 6 ? 4 : @sub_direction == 2 ? 8 : @sub_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 -= 1 @y -= 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Upper Right #-------------------------------------------------------------------------- def move_upper_right # If no direction fix unless @direction_fix @sub_direction = @direction @direction = 9 # Face right if facing left, and face up if facing down @sub_direction = (@sub_direction == 4 ? 6 : @sub_direction == 2 ? 8 : @sub_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 += 1 @y -= 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Dash #-------------------------------------------------------------------------- def dash_on if @dash_on != nil return @dash_on else return false end end end
That should make enemies approach diagonally if the player is diagonally away