Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Closed TopicStart new topic
> Eight directional movement scripts., Credits to Cogwheel and Co.
darkhalo
post Mar 14 2010, 02:22 PM
Post #1


The RM Warlock
Group Icon

Group: +Gold Member
Posts: 2,178
Type: Developer
RM Skill: Advanced




Not so sure this has been submitted before, such a useful script.
Anyway, here you are.
And for the optional Octagon script, see following post further down.

CODE
#==============================================================================
# Game_Player
#==============================================================================
class Game_Player < Game_Character
UP    = 0
DOWN  = 0
SIDE  = 0
SLANT = true
#--------------------------------------------------------------------------
attr_reader   :event
attr_accessor :move_speed
#--------------------------------------------------------------------------
alias :update_original :update
def update
  @walk  = 4
  @dash  = 5
  @event = 4
  @dot_m = true
  unless moving? or $game_system.map_interpreter.running? or
          @move_route_forcing or $game_temp.message_window_showing
    if @walk != @dash
      if Input.press?(Input::C)
        if @move_speed != @dash
          @move_speed = @dash
        end
      else
        if @move_speed != @walk
          @move_speed = @walk
        end
      end
    end
  end
  if @revise_x == nil and @revise_y == nil
    @revise_x = 0
    @revise_y = 0
  end
  unless @dot_m
    update_original
    return
  end
  if @move_route_forcing
    last_moving = moving?
    last_real_x = @real_x
    last_real_y = @real_y
    if (@revise_x != 0 or @revise_y != 0) and not jumping? and @move == true
      if @revise_x != @real_x - @x * 128 or @revise_y != @real_y - @y * 128
        @revise_x = @real_x - @x * 128
        @revise_y = @real_y - @y * 128
      end
      distance1 = 2 ** @move_speed
      distance2 = Math.sqrt(@revise_x ** 2 + @revise_y ** 2)
      if distance1 > distance2
        @real_x = @real_x - @revise_x
        @real_y = @real_y - @revise_y
        @revise_x = 0
        @revise_y = 0
        anime_update
      else
        @real_x -= (distance1 * @revise_x / distance2).round
        @real_y -= (distance1 * @revise_y / distance2).round
        @revise_x = @real_x - @x * 128
        @revise_y = @real_y - @y * 128
        anime_update
      end
    else
      super
    end
  else
    @move = false
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      @event_run = false
      case Input.dir8
      when 1
        move_lower_left_p
      when 2
        move_down_p
      when 3
        move_lower_right_p
      when 4
        move_left_p
      when 6
        move_right_p
      when 7
        move_upper_left_p
      when 8
        move_up_p
      when 9
        move_upper_right_p
      end
    end
    last_real_x = @real_x
    last_real_y = @real_y
    @real_x = @x * 128 + @revise_x
    @real_y = @y * 128 + @revise_y
    last_moving = moving?
    move_on
    if (last_real_x != @real_x or last_real_y != @real_y)
      @move_distance = 0 if @move_distance == nil
      @move_distance += Math.sqrt((last_real_x - @real_x) ** 2 +
                                    (last_real_y - @real_y) ** 2)
      if @move_distance >= 128
        @move_distance %= 128
        increase_steps
      end
      anime_update
    else
      @pattern = 0
    end
  end
  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
  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
#--------------------------------------------------------------------------
def initialize
  @revise_x = 0
  @revise_y = 0
  @move == false
  super
end
#--------------------------------------------------------------------------
def moving?
  unless @dot_m
    result = super
    return result
  end
  if @move_route_forcing
    if @move == false
      return false
    end
    super
  else
    return (@x != (@real_x / 128.0).round or @y != (@real_y / 128.0).round)
  end
end
#--------------------------------------------------------------------------
def moving_a?
  if @move == false
    if (@move_route.list[@move_route_index].code <= 14 or
        @move_route.list[@move_route_index].code == 25)
      @move = true
    end
    return false
  end
  moving?
end
#--------------------------------------------------------------------------
def update_jump
  @jump_count -= 1
  @real_x = (@real_x * @jump_count + @x * 128) / (@jump_count + 1)
  @real_y = (@real_y * @jump_count + @y * 128) / (@jump_count + 1)
  if @jump_count == 0
    @revise_x = 0
    @revise_y = 0
  end
end
#--------------------------------------------------------------------------
def move_type_custom
  unless @dot_m
    super
    return
  end
  if jumping? or moving_a?
    return
  end
  while @move_route_index < @move_route.list.size
    command = @move_route.list[@move_route_index]
    if command.code == 0
      if @move_route.repeat
        @move_route_index = 0
      end
      unless @move_route.repeat
        if @move_route_forcing and not @move_route.repeat
          @move_route_forcing = false
          @move_route = @original_move_route
          @move_route_index = @original_move_route_index
          @original_move_route = nil
        end
        @stop_count = 0
      end
      return
    end
    if command.code <= 14
      case command.code
      when 1
        move_down
      when 2
        move_left
      when 3
        move_right
      when 4
        move_up
      when 5
        move_lower_left
      when 6
        move_lower_right
      when 7
        move_upper_left
      when 8
        move_upper_right
      when 9
        move_random
      when 10
        move_toward_player
      when 11
        move_away_from_player
      when 12
        move_forward
      when 13
        move_backward
      when 14
        jump(command.parameters[0], command.parameters[1])
      end
      if not @move_route.skippable and not moving? and not jumping?
        return
      end
      @move_route_index += 1
      return
    end
    if command.code == 15
      @wait_count = command.parameters[0] * 2 - 1
      @move_route_index += 1
      return
    end
    if command.code >= 16 and command.code <= 26
      case command.code
      when 16
        turn_down
      when 17
        turn_left
      when 18
        turn_right
      when 19
        turn_up
      when 20
        turn_right_90
      when 21
        turn_left_90
      when 22
        turn_180
      when 23
        turn_right_or_left_90
      when 24
        turn_random
      when 25
        turn_toward_player
      when 26
        turn_away_from_player
      end
      @move_route_index += 1
      return
    end
    if command.code >= 27
      case command.code
      when 27
        $game_switches[command.parameters[0]] = true
        $game_map.need_refresh = true
      when 28
        $game_switches[command.parameters[0]] = false
        $game_map.need_refresh = true
      when 29
        @move_speed = command.parameters[0]
      when 30
        @move_frequency = command.parameters[0]
      when 31
        @walk_anime = true
      when 32
        @walk_anime = false
      when 33
        @step_anime = true
      when 34
        @step_anime = false
      when 35
        @direction_fix = true
      when 36
        @direction_fix = false
      when 37
        @through = true
      when 38
        @through = false
      when 39
        @always_on_top = true
      when 40
        @always_on_top = false
      when 41
        @tile_id = 0
        @character_name = command.parameters[0]
        @character_hue = command.parameters[1]
        if @original_direction != command.parameters[2]
          @direction = command.parameters[2]
          @original_direction = @direction
          @prelock_direction = 0
        end
        if @original_pattern != command.parameters[3]
          @pattern = command.parameters[3]
          @original_pattern = @pattern
        end
      when 42
        @opacity = command.parameters[0]
      when 43
        @blend_type = command.parameters[0]
      when 44
        $game_system.se_play(command.parameters[0])
      when 45
        result = eval(command.parameters[0])
      end
      @move_route_index += 1
      return
    end
  end
end
#--------------------------------------------------------------------------
def move_down_p
  turn_down
  distance = 2 ** @move_speed
  down1(((@x * 128 + @revise_x) / 128.0).round,
        ((@y * 128 + @revise_y) / 128.0).round, distance, true)
end
#--------------------------------------------------------------------------
def down1(x, y, distance, down = false)
  result = down2(x, y, distance)
  if result == false
    @event_run = check_event_trigger_touch(x, y+1)
    return result
  end
  if @revise_x < -SIDE
    result = down2(x, y + 1, distance, 4)
    result &= down2(x - 1, y, distance)
    if result == false
      if down
        move_lower_right_p
        if @revise_x > SIDE
          @revise_x = SIDE
        end
      end
      return result
    end
  elsif @revise_x > SIDE
    result = down2(x, y + 1, distance, 6)
    result &= down2(x + 1, y, distance)
    if result == false
      if down
        move_lower_left_p
        if @revise_x < -SIDE
          @revise_x = -SIDE
        end
      end
      return result
    end
  end
  @revise_y += distance
  return result
end
#--------------------------------------------------------------------------
def down2(x, y, distance, d = 2)
  if @revise_y + distance > DOWN
    unless passable?(x, y, d)
      if @revise_y < DOWN
        @revise_y = DOWN
      end
      return false
    end
  end
  return true
end
#--------------------------------------------------------------------------
def move_left_p
  turn_left
  distance = 2 ** @move_speed
  left1(((@x * 128 + @revise_x) / 128.0).round,
        ((@y * 128 + @revise_y) / 128.0).round, distance, true)
end
#--------------------------------------------------------------------------
def left1(x, y, distance, left = false)
  result = left2(x, y, distance)
  if result == false
    @event_run = check_event_trigger_touch(x-1, y)
    return result
  end
  if @revise_y < -UP
    result = left2(x - 1, y, distance, 8)
    result &= left2(x, y - 1, distance)
    if result == false
      if left
        move_lower_left_p
        if @revise_y > DOWN
          @revise_y = DOWN
        end
      end
      return result
    end
  elsif @revise_y > DOWN
    result = left2(x - 1, y, distance, 2)
    result &= left2(x, y + 1, distance)
    if result == false
      if left
        move_upper_left_p
        if @revise_y < -UP
          @revise_y = -UP
        end
      end
      return result
    end
  end
  @revise_x -= distance
  return result
end
#--------------------------------------------------------------------------
def left2(x, y, distance, d = 4)
  if @revise_x - distance < -SIDE
    unless passable?(x, y, d)
      if @revise_x > -SIDE
        @revise_x = -SIDE
      end
      return false
    end
  end
  return true
end
#--------------------------------------------------------------------------
def move_right_p
    turn_right
  distance = 2 ** @move_speed
  right1(((@x * 128 + @revise_x) / 128.0).round,
          ((@y * 128 + @revise_y) / 128.0).round, distance, true)
end
#--------------------------------------------------------------------------
def right1(x, y, distance, right = false)
  result = right2(x, y, distance)
  if result == false
    @event_run = check_event_trigger_touch(x+1, y)
    return result
  end
  if @revise_y < -UP
    result = right2(x + 1, y, distance, 8)
    result &= right2(x, y - 1, distance)
    if result == false
      if right
        move_lower_right_p
        if @revise_y > DOWN
          @revise_y = DOWN
        end
      end
      return result
    end
  elsif @revise_y > DOWN
    result = right2(x + 1, y, distance, 2)
    result &= right2(x, y + 1, distance)
    if result == false
      if right
        move_upper_right_p
        if @revise_y < -UP
          @revise_y = -UP
        end
      end
      return result
    end
  end
  @revise_x += distance
  return result
end
#--------------------------------------------------------------------------
def right2(x, y, distance, d = 6)
  if @revise_x + distance > SIDE
    unless passable?(x, y, d)
      if @revise_x < SIDE
        @revise_x = SIDE
      end
      return false
    end
  end
  return true
end
#--------------------------------------------------------------------------
def move_up_p
  turn_up
  distance = 2 ** @move_speed
  up1(((@x * 128 + @revise_x) / 128.0).round,
      ((@y * 128 + @revise_y) / 128.0).round, distance, true)
end
#--------------------------------------------------------------------------
def up1(x, y, distance, up = false)
  result = up2(x, y, distance)
  if result == false
    @event_run = check_event_trigger_touch(x, y-1)
    return result
  end
  if @revise_x < -SIDE
    result = up2(x, y - 1, distance, 4)
    result &= up2(x - 1, y, distance)
    if result == false
      if up
        move_upper_right_p
        if @revise_x > SIDE
          @revise_x = SIDE
        end
      end
      return result
    end
  elsif @revise_x > SIDE
    result = up2(x, y - 1, distance, 6)
    result &= up2(x + 1, y, distance)
    if result == false
      if up
        move_upper_left_p
        if @revise_x < -SIDE
          @revise_x = -SIDE
        end
      end
      return result
    end
  end
  @revise_y -= distance
  return result
end
#--------------------------------------------------------------------------
def up2(x, y, distance, d = 8)
  if @revise_y - distance < -UP
    unless passable?(x, y, d)
      if @revise_y > -UP
        @revise_y = -UP
      end
      return false
    end
  end
  return true
end
#--------------------------------------------------------------------------
def move_lower_left_p
  unless @direction_fix
    @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  end
  distance = (2 ** @move_speed) / Math.sqrt(2)
  turn_left unless down1(((@x * 128 + @revise_x) / 128.0).round,
                          ((@y * 128 + @revise_y) / 128.0).round, distance)
  turn_down if @event_run
  unless @event_run
    if last_move?(@real_x, @real_y, 2, distance)
      result = check_event_trigger_here([1,2], false)
      if result == true
        return
      end
    end
    move_on
    if @revise_y > DOWN and -UP > @revise_y - distance
      @revise_y = DOWN
    end
    turn_down unless left1(((@x * 128 + @revise_x) / 128.0).round,
                          ((@y * 128 + @revise_y) / 128.0).round, distance)
    turn_left if @event_run
  end
end
#--------------------------------------------------------------------------
def move_lower_right_p
  unless @direction_fix
    @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  end
  distance = (2 ** @move_speed) / Math.sqrt(2)
  turn_right unless down1(((@x * 128 + @revise_x) / 128.0).round,
                          ((@y * 128 + @revise_y) / 128.0).round, distance)
  turn_down if @event_run
  unless @event_run
    if last_move?(@real_x, @real_y, 2, distance)
      result = check_event_trigger_here([1,2], false)
      if result == true
        return
      end
    end
    move_on
    if @revise_y > DOWN and -UP > @revise_y - distance
      @revise_y = DOWN
    end
    turn_down unless right1(((@x * 128 + @revise_x) / 128.0).round,
                          ((@y * 128 + @revise_y) / 128.0).round, distance)
    turn_right if @event_run
  end
end
#--------------------------------------------------------------------------
def move_upper_left_p
  unless @direction_fix
    @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  end
  distance = (2 ** @move_speed) / Math.sqrt(2)
  turn_left unless up1(((@x * 128 + @revise_x) / 128.0).round,
                        ((@y * 128 + @revise_y) / 128.0).round, distance)
  turn_up if @event_run
  unless @event_run
    if last_move?(@real_x, @real_y, 8, distance)
      result = check_event_trigger_here([1,2], false)
      if result == true
        return
      end
    end
    move_on
    if @revise_y + distance > DOWN and -UP > @revise_y
      @revise_y = -UP
    end
    turn_up unless left1(((@x * 128 + @revise_x) / 128.0).round,
                          ((@y * 128 + @revise_y) / 128.0).round, distance)
    turn_left if @event_run
  end
end
#--------------------------------------------------------------------------
def move_upper_right_p
  unless @direction_fix
    @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  end
  distance = (2 ** @move_speed) / Math.sqrt(2)
  turn_right unless up1(((@x * 128 + @revise_x) / 128.0).round,
                        ((@y * 128 + @revise_y) / 128.0).round, distance)
  turn_up if @event_run
  unless @event_run
    if last_move?(@real_x, @real_y, 8, distance)
      result = check_event_trigger_here([1,2], false)
      if result == true
        return
      end
    end
    move_on
    if @revise_y + distance > DOWN and -UP > @revise_y
      @revise_y = -UP
    end
    turn_up unless right1(((@x * 128 + @revise_x) / 128.0).round,
                          ((@y * 128 + @revise_y) / 128.0).round, distance)
    turn_right if @event_run
  end
end
#--------------------------------------------------------------------------
def check_event_trigger_here(triggers, run = true)
  result = false
  if $game_system.map_interpreter.running?
    return result
  end
  for event in $game_map.events.values
    if event.x == ((@x * 128 + @revise_x) / 128.0).round and
        event.y == ((@y * 128 + @revise_y) / 128.0).round and
        triggers.include?(event.trigger)
      if not event.jumping? and event.over_trigger?
        if event.list.size > 1
          if run == true
            event.start
          end
          result = true
        end
      end
    end
  end
  return result
end
#--------------------------------------------------------------------------
def move_on
  if @y < (@y + @revise_y / 128.0).round
    @y += 1
    @revise_y -= 128
  end
  if @x > (@x + @revise_x / 128.0).round
    @x -= 1
    @revise_x += 128
  end
  if @x < (@x + @revise_x / 128.0).round
    @x += 1
    @revise_x -= 128
  end
  if @y > (@y + @revise_y / 128.0).round
    @y -= 1
    @revise_y += 128
  end
end
#--------------------------------------------------------------------------
def anime_update
  if @walk_anime
    @anime_count += 1.5
  elsif @step_anime
    @anime_count += 1
  end
  if @anime_count > 18 - @move_speed * 2
    if not @step_anime and @stop_count > 0
      @pattern = @original_pattern
    else
      @pattern = (@pattern + 1) % 4
    end
    @anime_count = 0
  end
end
#--------------------------------------------------------------------------
alias :moveto_original :moveto
def moveto(x, y)
  @revise_x = 0
  @revise_y = 0
  moveto_original(x, y)
end
#--------------------------------------------------------------------------
def last_move?(x, y, direction, distance)
  if direction == 2 or direction == 6
    distance *= -1
  end
  if (direction == 2 or direction == 8) and
      (y / 128.0).round != ((y - distance) / 128.0).round
    return true
  end
  if (direction == 4 or direction == 6) and
      (x / 128.0).round != ((x - distance) / 128.0).round
    return true
  end
  return false
end
end

#==============================================================================
# Game_Character
#==============================================================================
class Game_Character
def update_move
  distance = 2 ** @move_speed
  if @x * 128 != @real_x and @y * 128 != @real_y and Game_Player::SLANT
    distance /= Math.sqrt(2)
  end
  if @y * 128 > @real_y
    @real_y = [@real_y + distance, @y * 128].min
  end
  if @x * 128 < @real_x
    @real_x = [@real_x - distance, @x * 128].max
  end
  if @x * 128 > @real_x
    @real_x = [@real_x + distance, @x * 128].min
  end
  if @y * 128 < @real_y
    @real_y = [@real_y - distance, @y * 128].max
  end
  if @walk_anime
    @anime_count += 1.5
  elsif @step_anime
    @anime_count += 1
  end
end
end
#==============================================================================
# Game_Event
#==============================================================================
class Game_Event < Game_Character
def start
  if @list.size > 1
    if $game_player.event != 0
      $game_player.move_speed = $game_player.event
    end
    @starting = true
  end
end
end


Simply copy n paste above Main.


__________________________

Go to the top of the page
 
+Quote Post
   
Holder
post Mar 14 2010, 03:12 PM
Post #2


Spoilers.
Group Icon

Group: Revolutionary
Posts: 4,204
Type: Developer
RM Skill: Advanced
Rev Points: 250




Nice nice nice, something I've always thought about including but never felt like giving myself that much more work tongue.gif

Which way does the sprite sheet work?
Normally on the four directional it's:
Down
Left
Right
Up

Or is this a separate sheet for the Down-Right etc directions?


__________________________

 I'm running the Great North Run in September in aid of NACC. A condition my wife has in it's severe form.
Please sponsor me with whatever you can, thank you.
If you'd like to help spread the word please share the image and link to my fundraising page.

Go to the top of the page
 
+Quote Post
   
Darkreaper
post Mar 14 2010, 11:06 PM
Post #3


Level 11
Group Icon

Group: Revolutionary
Posts: 171
Type: Developer
RM Skill: Advanced




do you have an example sprite sheet that works with this script?


__________________________



Go to the top of the page
 
+Quote Post
   
darkhalo
post Mar 16 2010, 11:17 AM
Post #4


The RM Warlock
Group Icon

Group: +Gold Member
Posts: 2,178
Type: Developer
RM Skill: Advanced




First of, yes it works in both X and Y directions and of course diagonally, great for isometric maps. The sprites
however, are as you'd expect different too. Here's a simple sprite sheet, which is a compromising but workable
use for the script.


In one of my games, they walk fine with a gamepad controller. I'm including a forgotten link in R3 re a template for
8 way sprites for anyone patient enough to make them. This was made by blackhand back in 08.
For some reason the link was broken.




__________________________

Go to the top of the page
 
+Quote Post
   
Holder
post Mar 16 2010, 11:22 AM
Post #5


Spoilers.
Group Icon

Group: Revolutionary
Posts: 4,204
Type: Developer
RM Skill: Advanced
Rev Points: 250




The image there seems to be broken Halo, and you've got http:// twice in the topic link.


__________________________

 I'm running the Great North Run in September in aid of NACC. A condition my wife has in it's severe form.
Please sponsor me with whatever you can, thank you.
If you'd like to help spread the word please share the image and link to my fundraising page.

Go to the top of the page
 
+Quote Post
   
darkhalo
post Mar 16 2010, 11:58 AM
Post #6


The RM Warlock
Group Icon

Group: +Gold Member
Posts: 2,178
Type: Developer
RM Skill: Advanced




Thanks Holder, for some weird reason still a broken link.
Anyways, not to be done by, Iv'e added the images by blackhand. Great guy.
Will put this up in the template section in resources too.


__________________________

Go to the top of the page
 
+Quote Post
   
Darkreaper
post Mar 16 2010, 09:56 PM
Post #7


Level 11
Group Icon

Group: Revolutionary
Posts: 171
Type: Developer
RM Skill: Advanced




seems an odd setup for the sprites... not seeing how this would work, specially considering theres only one walking animation and half the sprites are a different size..


__________________________



Go to the top of the page
 
+Quote Post
   
thefun389
post Jun 1 2010, 03:33 PM
Post #8



Group Icon

Group: Member
Posts: 3
Type: Mapper
RM Skill: Intermediate




Hey, this is a nice and usefull script but I used a jump script that doesnt work when i bring this script, do you mind helping me when you get the chance, that would be great, heres the script. thumbsup.gif

CODE
#==============================================================================
# â–  Jump Script
#------------------------------------------------------------------------------
# Enables jumping around the map
# Made by: Huitzilopoctli @ rmxp.net
#------------------------------------------------------------------------------
# Press the A Input (ShiftKey) to jump
# The player will be able to jump over any passable tile, or any tile with a
# TerrainID the same as the JumpID
# The player must land on a passable tile without a solid event blocking it
# If the player can't jump the full 2 tiles, it will go 1 or, failing that, none
# To stop the player from jumping over a particular event, make the first
# command for the event a comment, containing this word: Tall
# To create a 'tall' tile that will stop the player from jumping over it even if
# the tile below is jumpable, set the tile's id to not the JumpID or 0
#==============================================================================

#==============================================================================
# â—� Customisation
#==============================================================================

JumpID = 1 #0

#==============================================================================
# â—� Game_Player
#==============================================================================

class Game_Player < Game_Character

def leap
xdir = (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
ydir = (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

dist = 0

clear_jump = true
clear_land1 = true
e = $game_map.events[$game_map.check_event(@x + xdir, @y + ydir)]
if e
clear_jump = !(e.list[0].code == 108 && e.list[0].parameters[0] =~ "Tall")
clear_land1 = e.through
end

clear_land2 = true
e = $game_map.events[$game_map.check_event(@x + xdir * 2, @y + ydir * 2)]
if e
clear_land2 = e.through
end

pass1 = $game_map.passable?(@x + xdir, @y + ydir, @direction)
pass2 = $game_map.passable?(@x + xdir * 2, @y + ydir * 2, @direction)

jumpid = $game_map.terrain_tag(@x + xdir, @y + ydir) == JumpID

dist = 0
if clear_jump
if clear_land2 & pass2 & (jumpid | pass1)
dist = 2
elsif clear_land1 & pass1
dist = 1
end
end

route = RPG::MoveRoute.new
route.list.clear
route.list.push(RPG::MoveCommand.new(37))
route.list.push(RPG::MoveCommand.new(14, [xdir * dist, ydir * dist]))
route.list.push(RPG::MoveCommand.new(38))
route.list.push(RPG::MoveCommand.new(0))
route.repeat = false
$route = route

$game_player.force_move_route(route)
end

alias update_primary update
def update
update_primary

leap if Input.trigger?(Input::A) && !moving?
end

end
Go to the top of the page
 
+Quote Post
   
darkhalo
post Oct 14 2010, 02:05 PM
Post #9


The RM Warlock
Group Icon

Group: +Gold Member
Posts: 2,178
Type: Developer
RM Skill: Advanced




Okay, time to bring this 8 way direction script up to speed
Heres a script I found called the octagon script, kinda speaks for itself. However, its in japanese, but put the following scripts
into your script menu and youll have a true working 8 way script in RGSS 102E. This took me ages to find out.
Anyone wanting to do an iso walking character for instance, than this is for you.

Firstly, replace game character 3 with this script.
(Spoilers aint working)

CODE
#==============================================================================
# ■ Game_Character (分割定义 3)
#------------------------------------------------------------------------------
#  处�角色的类。本类作为 Game_Player 类与 Game_Event
# 类的超级类使用。
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # â—� å�‘下移动
  #     turn_enabled : 本场地ä½�置更改许å�¯æ ‡å¿—
  #--------------------------------------------------------------------------
  def move_down(turn_enabled = true)
    # é�¢å�‘下
    if turn_enabled
      turn_down
    end
    # å�¯ä»¥é€šè¡Œçš„场å�ˆ
    if passable?(@x, @y, 2)
      # é�¢å�‘下
      turn_down
      # æ›´æ–°å��æ ‡
      @y += 1
      # 增加步数
      increase_steps
    # ä¸�能通行的情况下
    else
      # 接触事件的å�¯åŠ¨åˆ¤å®š
      check_event_trigger_touch(@x, @y+1)
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�‘左移动
  #     turn_enabled : 本场地ä½�置更改许å�¯æ ‡å¿—
  #--------------------------------------------------------------------------
  def move_left(turn_enabled = true)
    # é�¢å�‘å·¦
    if turn_enabled
      turn_left
    end
    # å�¯ä»¥é€šè¡Œçš„æƒ…况下
    if passable?(@x, @y, 4)
      # é�¢å�‘å·¦
      turn_left
      # æ›´æ–°å��æ ‡
      @x -= 1
      # 增加步数
      increase_steps
    # ä¸�能通行的情况下
    else
      # 接触事件的å�¯åŠ¨åˆ¤å®š
      check_event_trigger_touch(@x-1, @y)
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�‘å�³ç§»åЍ
  #     turn_enabled : 本场地ä½�置更改许å�¯æ ‡å¿—
  #--------------------------------------------------------------------------
  def move_right(turn_enabled = true)
    # é�¢å�‘å�³
    if turn_enabled
      turn_right
    end
    # å�¯ä»¥é€šè¡Œçš„场å�ˆ
    if passable?(@x, @y, 6)
      # é�¢å�‘å�³
      turn_right
      # æ›´æ–°å��æ ‡
      @x += 1
      # 增加部数
      increase_steps
    # ä¸�能通行的情况下
    else
      # 接触事件的å�¯åŠ¨åˆ¤å®š
      check_event_trigger_touch(@x+1, @y)
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�‘上移动
  #     turn_enabled : 本场地ä½�置更改许å�¯æ ‡å¿—
  #--------------------------------------------------------------------------
  def move_up(turn_enabled = true)
    # é�¢å�‘上
    if turn_enabled
      turn_up
    end
    # å�¯ä»¥é€šè¡Œçš„æƒ…况下
    if passable?(@x, @y, 8)
      # é�¢å�‘上
      turn_up
      # æ›´æ–°å��æ ‡
      @y -= 1
      # 歩数増加
      increase_steps
    # ä¸�能通行的情况下
    else
      # 接触事件的å�¯åŠ¨åˆ¤å®š
      check_event_trigger_touch(@x, @y-1)
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�‘左下移动
  #--------------------------------------------------------------------------
  def move_lower_left
    # 没有固定é�¢å�‘的场å�ˆ
    unless @direction_fix
      # æœ�å�‘是å�³çš„æƒ…况下适å�ˆçš„é�¢æ˜¯å·¦é�¢ã€�æœ�å�‘是上的情况下适å�ˆï¿
½ï¿½
��是下�
  ###########################################################################
      @direction = 1
  ###########################################################################
    end
    # 下→左ã€�左→下 的通é�“å�¯ä»¥é€šè¡Œçš„æƒ…况下
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
      # æ›´æ–°å��æ ‡
      @x -= 1
      @y += 1
      # 增加步数
      increase_steps
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�‘å�³ä¸‹ç§»åЍ
  #--------------------------------------------------------------------------
  def move_lower_right
    # 没有固定é�¢å�‘的场å�ˆ
    unless @direction_fix
      # æœ�å�‘是å�³çš„æƒ…况下适å�ˆçš„é�¢æ˜¯å·¦é�¢ã€�æœ�å�‘是上的情况下适å�ˆï¿
½ï¿½
��是下�
  ###########################################################################
      @direction = 3
  ###########################################################################
    end
    # 下→å�³ã€�å�³â†’下 的通é�“å�¯ä»¥é€šè¡Œçš„æƒ…况下
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
      # æ›´æ–°å��æ ‡
      @x += 1
      @y += 1
      # 增加步数
      increase_steps
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�‘左上移动
  #--------------------------------------------------------------------------
  def move_upper_left
    # 没有固定é�¢å�‘的场å�ˆ
    unless @direction_fix
      # æœ�å�‘是å�³çš„æƒ…况下适å�ˆçš„é�¢æ˜¯å·¦é�¢ã€�æœ�å�‘是上的情况下适å�ˆï¿
½ï¿½
��是下�
  ###########################################################################
      @direction = 7
  ###########################################################################
    end
    # 上→左ã€�左→上 的通é�“å�¯ä»¥é€šè¡Œçš„æƒ…况下
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
      # æ›´æ–°å��æ ‡
      @x -= 1
      @y -= 1
      # 增加步数
      increase_steps
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�‘å�³ä¸Šç§»åЍ
  #--------------------------------------------------------------------------
  def move_upper_right
    # 没有固定é�¢å�‘的场å�ˆ
    unless @direction_fix
      # æœ�å�‘是å�³çš„æƒ…况下适å�ˆçš„é�¢æ˜¯å·¦é�¢ã€�æœ�å�‘是上的情况下适å�ˆï¿
½ï¿½
��是下�
  ###########################################################################
      @direction = 9
  ###########################################################################
    end
    # 上→å�³ã€�å�³â†’上 的通é�“å�¯ä»¥é€šè¡Œçš„æƒ…况下
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
      # æ›´æ–°å��æ ‡
      @x += 1
      @y -= 1
      # 增加步数
      increase_steps
    end
  end
  #--------------------------------------------------------------------------
  # â—� éš�机移动
  #--------------------------------------------------------------------------
  def move_random
    case rand(4)
    when 0  # å�‘下移动
      move_down(false)
    when 1  # å�‘左移动
      move_left(false)
    when 2  # å�‘å�³ç§»åЍ
      move_right(false)
    when 3  # å�‘上移动
      move_up(false)
    end
  end
  #--------------------------------------------------------------------------
  # â—� 接近主角
  #--------------------------------------------------------------------------
  def move_toward_player
    # 求得与主角的å��标差
    sx = @x - $game_player.x
    sy = @y - $game_player.y
    # å��标相等情况下
    if sx == 0 and sy == 0
      return
    end
    # 求得差的ç»�对值
    abs_sx = sx.abs
    abs_sy = sy.abs
    # 横è·�离与纵è·�离相等的情况下
    if abs_sx == abs_sy
      # éš�机将边数增加 1
      rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
    end
    # 横侧è·�离长的情况下
    if abs_sx > abs_sy
      # å·¦å�³æ–¹å�‘优先。å�‘主角移动
      sx > 0 ? move_left : move_right
      if not moving? and sy != 0
        sy > 0 ? move_up : move_down
      end
    # ç«–ä¾§è·�离长的情况下
    else
      # 上下方å�‘优先。å�‘主角移动
      sy > 0 ? move_up : move_down
      if not moving? and sx != 0
        sx > 0 ? move_left : move_right
      end
    end
  end
  #--------------------------------------------------------------------------
  # â—� 远离主角
  #--------------------------------------------------------------------------
  def move_away_from_player
    # 求得与主角的å��标差
    sx = @x - $game_player.x
    sy = @y - $game_player.y
    # å��标相等情况下
    if sx == 0 and sy == 0
      return
    end
    # 求得差的ç»�对值
    abs_sx = sx.abs
    abs_sy = sy.abs
    # 横è·�离与纵è·�离相等的情况下
    if abs_sx == abs_sy
      # éš�机将边数增加 1
      rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
    end
    # 横侧è·�离长的情况下
    if abs_sx > abs_sy
      # å·¦å�³æ–¹å�‘优先。远离主角移动
      sx > 0 ? move_right : move_left
      if not moving? and sy != 0
        sy > 0 ? move_down : move_up
      end
    # ç«–ä¾§è·�离长的情况下
    else
      # 上下方å�‘优先。远离主角移动
      sy > 0 ? move_down : move_up
      if not moving? and sx != 0
        sx > 0 ? move_right : move_left
      end
    end
  end
  #--------------------------------------------------------------------------
  # â—� å‰�进一步
  #--------------------------------------------------------------------------
  def move_forward
    case @direction
    when 2
      move_down(false)
    when 4
      move_left(false)
    when 6
      move_right(false)
    when 8
      move_up(false)
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�Žé€€ä¸€æ­¥
  #--------------------------------------------------------------------------
  def move_backward
    # 记忆æœ�å�‘固定信æ�¯
    last_direction_fix = @direction_fix
    # 强制固定æœ�å�‘
    @direction_fix = true
    # æœ�å�‘分支
    case @direction
    when 2  # 下
      move_up(false)
    when 4  # å·¦
      move_right(false)
    when 6  # å�³
      move_left(false)
    when 8  # 上
      move_down(false)
    end
    # 还原æœ�å�‘固定信æ�¯
    @direction_fix = last_direction_fix
  end
  #--------------------------------------------------------------------------
  # â—� 跳跃
  #     x_plus : X å��标增加值
  #     y_plus : Y å��标增加值
  #--------------------------------------------------------------------------
  def jump(x_plus, y_plus)
    # 增加值ä¸�是 (0,0) 的情况下
    if x_plus != 0 or y_plus != 0
      # 横侧è·�离长的情况下
      if x_plus.abs > y_plus.abs
        # å�˜æ›´å·¦å�³æ–¹å�‘
        x_plus < 0 ? turn_left : turn_right
      # ç«–ä¾§è·�离长的情况下
      else
        # å�˜æ›´ä¸Šä¸‹æ–¹å�‘
        y_plus < 0 ? turn_up : turn_down
      end
    end
    # 计算新的å��æ ‡
    new_x = @x + x_plus
    new_y = @y + y_plus
    # 增加值为 (0,0) 的情况下ã€�跳跃目标å�¯ä»¥é€šè¡Œçš„场å�ˆ
    if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
      # 矫正姿势
      straighten
      # æ›´æ–°å��æ ‡
      @x = new_x
      @y = new_y
      # è·�计算è·�离
      distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
      # 设置跳跃记数
      @jump_peak = 10 + distance - @move_speed
      @jump_count = @jump_peak * 2
      # 清除å�œæ­¢è®°æ•°ä¿¡æ�¯
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # â—� é�¢å�‘å�‘下
  #--------------------------------------------------------------------------
  def turn_down
    unless @direction_fix
      @direction = 2
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # â—� é�¢å�‘å�‘å·¦
  #--------------------------------------------------------------------------
  def turn_left
    unless @direction_fix
      @direction = 4
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # â—� é�¢å�‘å�‘å�³
  #--------------------------------------------------------------------------
  def turn_right
    unless @direction_fix
      @direction = 6
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # â—� é�¢å�‘å�‘上
  #--------------------------------------------------------------------------
  def turn_up
    unless @direction_fix
      @direction = 8
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�‘å�³æ—‹è½¬ 90 度
  #--------------------------------------------------------------------------
  def turn_right_90
    case @direction
    when 2
      turn_left
    when 4
      turn_up
    when 6
      turn_down
    when 8
      turn_right
    end
  end
  #--------------------------------------------------------------------------
  # â—� å�‘左旋转 90 度
  #--------------------------------------------------------------------------
  def turn_left_90
    case @direction
    when 2
      turn_right
    when 4
      turn_down
    when 6
      turn_up
    when 8
      turn_left
    end
  end
  #--------------------------------------------------------------------------
  # â—� 旋转 180 度
  #--------------------------------------------------------------------------
  def turn_180
    case @direction
    when 2
      turn_up
    when 4
      turn_right
    when 6
      turn_left
    when 8
      turn_down
    end
  end
  #--------------------------------------------------------------------------
  # â—� 从å�³å�‘左旋转 90 度
  #--------------------------------------------------------------------------
  def turn_right_or_left_90
    if rand(2) == 0
      turn_right_90
    else
      turn_left_90
    end
  end
  #--------------------------------------------------------------------------
  # â—� éš�机å�˜æ�¢æ–¹å�‘
  #--------------------------------------------------------------------------
  def turn_random
    case rand(4)
    when 0
      turn_up
    when 1
      turn_right
    when 2
      turn_left
    when 3
      turn_down
    end
  end
  #--------------------------------------------------------------------------
  # â—� 接近主角的方å�‘
  #--------------------------------------------------------------------------
  def turn_toward_player
    # 求得与主角的å��标差
    sx = @x - $game_player.x
    sy = @y - $game_player.y
    # å��标相等的场å�ˆä¸‹
    if sx == 0 and sy == 0
      return
    end
    # 横侧è·�离长的情况下
    if sx.abs > sy.abs
      # 将左å�³æ–¹å�‘å�˜æ›´ä¸ºæœ�å�‘主角的方å�‘
      sx > 0 ? turn_left : turn_right
    # ç«–ä¾§è·�离长的情况下
    else
      # 将上下方å�‘å�˜æ›´ä¸ºæœ�å�‘主角的方å�‘
      sy > 0 ? turn_up : turn_down
    end
  end
  #--------------------------------------------------------------------------
  # â—� 背å�‘主角的方å�‘
  #--------------------------------------------------------------------------
  def turn_away_from_player
    # 求得与主角的å��标差
    sx = @x - $game_player.x
    sy = @y - $game_player.y
    # å��标相等的场å�ˆä¸‹
    if sx == 0 and sy == 0
      return
    end
    # 横侧è·�离长的情况下
    if sx.abs > sy.abs
      # 将左å�³æ–¹å�‘å�˜æ›´ä¸ºèƒŒç¦»ä¸»è§’的方å�‘
      sx > 0 ? turn_right : turn_left
    # ç«–ä¾§è·�离长的情况下
    else
      # 将上下方å�‘å�˜æ›´ä¸ºèƒŒç¦»ä¸»è§’的方å�‘
      sy > 0 ? turn_down : turn_up
    end
  end
end


Then replace Game Player with this:


CODE
#==============================================================================
# â–  Game_Player
#------------------------------------------------------------------------------
#  处ç�†ä¸»è§’的类。事件å�¯åŠ¨çš„åˆ¤å®šã€�以å�Šåœ°å›¾çš„æ»šåŠ¨ç­‰åŠŸèƒ½ï¿
½ï¿½
�
# 本类的实例请�考 $game_player。
#==============================================================================

class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # â—� æ�’é‡�
  #--------------------------------------------------------------------------
  CENTER_X = (320 - 16) * 4   # ç”»é�¢ä¸­å¤®çš„ X å��æ ‡ * 4
  CENTER_Y = (240 - 16) * 4   # ç”»é�¢ä¸­å¤®çš„ Y å��æ ‡ * 4
  #--------------------------------------------------------------------------
  # â—� å�¯ä»¥é€šè¡Œåˆ¤å®š
  #     x : X å��æ ‡
  #     y : Y å��æ ‡
  #     d : æ–¹å�‘ (0,2,4,6,8)  â€» 0 = 全方å�‘ä¸�能通行的情况判定 (跳跃用)
  #--------------------------------------------------------------------------
  def passable?(x, y, d)
    # 求得新的å��æ ‡
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # å��标在地图外的情况下
    unless $game_map.valid?(new_x, new_y)
      # ä¸�能通行
      return false
    end
    # 调试模å¼�为 ON 并且 按下 CTRL 键的情况下
    if $DEBUG and Input.press?(Input::CTRL)
      # å�¯ä»¥é€šè¡Œ
      return true
    end
    super
  end
  #--------------------------------------------------------------------------
  # â—� åƒ�通到画é�¢ä¸­å¤®ä¸€æ ·çš„设置地图的显示ä½�ç½®
  #--------------------------------------------------------------------------
  def center(x, y)
    max_x = ($game_map.width - 20) * 128
    max_y = ($game_map.height - 15) * 128
    $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
    $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
  end
  #--------------------------------------------------------------------------
  # â—� å�‘指定的ä½�置移动
  #     x : X 座標
  #     y : Y 座標
  #--------------------------------------------------------------------------
  def moveto(x, y)
    super
    # 自连接
    center(x, y)
    # 生æˆ�é�‡æ•Œè®¡æ•°
    make_encounter_count
  end
  #--------------------------------------------------------------------------
  # â—� 增加步数
  #--------------------------------------------------------------------------
  def increase_steps
    super
    # ä¸�是强制移动路线的场å�ˆ
    unless @move_route_forcing
      # 增加步数
      $game_party.increase_steps
      # 步数是å�¶æ•°çš„æƒ…况下
      if $game_party.steps % 2 == 0
        # 检查连续伤害
        $game_party.check_map_slip_damage
      end
    end
  end
  #--------------------------------------------------------------------------
  # â—� 获å�–é�‡æ•Œè®¡æ•°
  #--------------------------------------------------------------------------
  def encounter_count
    return @encounter_count
  end
  #--------------------------------------------------------------------------
  # â—� 生æˆ�é�‡æ•Œè®¡æ•°
  #--------------------------------------------------------------------------
  def make_encounter_count
    # 两ç§�颜色震动的图åƒ�
    if $game_map.map_id != 0
      n = $game_map.encounter_step
      @encounter_count = rand(n) + rand(n) + 1
    end
  end
  #--------------------------------------------------------------------------
  # â—� 刷新
  #--------------------------------------------------------------------------
  def refresh
    # å�Œä¼´äººæ•°ä¸º 0 的情况下
    if $game_party.actors.size == 0
      # 清除角色的文件å��å�Šå¯¹åƒ�
      @character_name = ""
      @character_hue = 0
      # 分支结æ�Ÿ
      return
    end
    # 获å�–带头的角色
    actor = $game_party.actors[0]
    # 设置角色的文件å��å�Šå¯¹åƒ�
    @character_name = actor.character_name
    @character_hue = actor.character_hue
    # åˆ�始化ä¸�é€�明度和å�ˆæˆ�æ–¹å¼�å­�
    @opacity = 255
    @blend_type = 0
  end
  #--------------------------------------------------------------------------
  # â—� å�Œä½�置的事件å�¯åŠ¨åˆ¤å®š
  #--------------------------------------------------------------------------
  def check_event_trigger_here(triggers)
    result = false
    # 事件执行中的情况下
    if $game_system.map_interpreter.running?
      return result
    end
    # 全部事件的循环
    for event in $game_map.events.values
      # 事件å��标与目标一致的情况下
      if event.x == @x and event.y == @y and triggers.include?(event.trigger)
        # 跳跃中以外的情况下ã€�å�¯åŠ¨åˆ¤å®šæ˜¯å�Œä½�置的事件
        if not event.jumping? and event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # â—� æ­£é�¢äº‹ä»¶çš„å�¯åŠ¨åˆ¤å®š
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers)
    result = false
    # 事件执行中的情况下
    if $game_system.map_interpreter.running?
      return result
    end
    # 计算正é�¢å��æ ‡
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    # 全部事件的循环
    for event in $game_map.events.values
      # 事件å��标与目标一致的情况下
      if event.x == new_x and event.y == new_y and
         triggers.include?(event.trigger)
        # 跳跃中以外的情况下ã€�å�¯åŠ¨åˆ¤å®šæ˜¯æ­£é�¢çš„事件
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    # 找ä¸�到符å�ˆæ�¡ä»¶çš„事件的情况下
    if result == false
      # æ­£é�¢çš„元件是计数器的情况下
      if $game_map.counter?(new_x, new_y)
        # 计算 1 元件里侧的å��æ ‡
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        # 全事件的循环
        for event in $game_map.events.values
          # 事件å��标与目标一致的情况下
          if event.x == new_x and event.y == new_y and
             triggers.include?(event.trigger)
            # 跳跃中以外的情况下ã€�å�¯åŠ¨åˆ¤å®šæ˜¯æ­£é�¢çš„事件
            if not event.jumping? and not event.over_trigger?
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # â—� 接触事件å�¯åŠ¨åˆ¤å®š
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = false
    # 事件执行中的情况下
    if $game_system.map_interpreter.running?
      return result
    end
    # 全事件的循环
    for event in $game_map.events.values
      # 事件å��标与目标一致的情况下
      if event.x == x and event.y == y and [1,2].include?(event.trigger)
        # 跳跃中以外的情况下ã€�å�¯åŠ¨åˆ¤å®šæ˜¯æ­£é�¢çš„事件
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # â—� ç”»é�¢æ›´æ–°
  #--------------------------------------------------------------------------
  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 2
        move_down
      when 4
        move_left
      when 6
        move_right
      when 8
        move_up
      when 1
        move_lower_left
      when 3
        move_lower_right
      when 7
        move_upper_left
      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
          # 调试模å¼�为 ON 并且按下 CTRL 键的情况下除外
          unless $DEBUG and Input.press?(Input::CTRL)
            # é�‡æ•Œè®¡æ•°ä¸‹é™�
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # 按下 C 键的情况下
      if Input.trigger?(Input::C)
        # 判定为å�Œä½�置以å�Šæ­£é�¢çš„事件å�¯åЍ
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end


Finally, replace Sprite Character with this:



CODE
#==============================================================================
# â–  Sprite_Character
#------------------------------------------------------------------------------
#  角色显示用脚本。监视 Game_Character 类的实例�
# 自动�化脚本状�。
#==============================================================================

class Sprite_Character < RPG::Sprite
  #--------------------------------------------------------------------------
  # â—� 定义实例å�˜é‡�
  #--------------------------------------------------------------------------
  attr_accessor :character                # 角色
  #--------------------------------------------------------------------------
  # â—� åˆ�始化对åƒ�
  #     viewport  : 查看端å�£
  #     character : 角色 (Game_Character)
  #--------------------------------------------------------------------------
  def initialize(viewport, character = nil)
    super(viewport)
    @character = character
    update
  end
  #--------------------------------------------------------------------------
  # â—� æ›´æ–°ç”»é�¢
  #--------------------------------------------------------------------------
  def update
    super
    # 元件 IDã€�文件å��ã€�色相与现在的情况存在差异的情况下
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue
      # 记忆元件 ID 与文件å��ã€�色相
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      # 元件 ID 为有效值的情况下
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue)
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      # 元件 ID 为无效值的情况下
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @cw = bitmap.width / 4
  ###########################################################################
        @ch = bitmap.height / 8
  ###########################################################################
        self.ox = @cw / 2
        self.oy = @ch
      end
    end
    # 设置å�¯è§†çжæ€�
    self.visible = (not @character.transparent)
    # 图形是角色的情况下
    if @tile_id == 0
      # 设置传é€�目标的矩形
      sx = @character.pattern * @cw
  ###########################################################################
      case @character.direction
      when 2
        sy = 0 * @ch
      when 4
        sy = 1 * @ch
      when 6
        sy = 2 * @ch
      when 8
        sy = 3 * @ch
      when 1
        sy = 4 * @ch
      when 3
        sy = 5 * @ch
      when 7
        sy = 6 * @ch
      when 9
        sy = 7 * @ch
      end
      self.src_rect.set(sx, sy, @cw, @ch)
  ###########################################################################
    end
    # 设置脚本的å��æ ‡
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    # 设置ä¸�é€�明度ã€�å�ˆæˆ�æ–¹å¼�ã€�茂密
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    # 动画
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end

This is the spritesheet type you need to work with.
Reason for edit: Edited to put Code into Code tags.


__________________________

Go to the top of the page
 
+Quote Post
   
Legacy
post Oct 14 2010, 05:36 PM
Post #10


B★RS Coding Ninja
Group Icon

Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15




I've put all the code into code tags, makes it better to read DH happy.gif


__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth


Have you seen the new Unity3D sections?..
Unity 3D Discussion
Unity Script Development
Unity Projects
Go to the top of the page
 
+Quote Post
   
darkhalo
post Oct 15 2010, 02:13 PM
Post #11


The RM Warlock
Group Icon

Group: +Gold Member
Posts: 2,178
Type: Developer
RM Skill: Advanced




Thanks Legacy wink.gif .
If anyone has any problems with this, I now have a working demo...which I'll upload soon.


__________________________

Go to the top of the page
 
+Quote Post
   
Rukiri
post Oct 15 2010, 08:02 PM
Post #12


emerge -avt awesome! Wait... it brings me.... HERE?!
Group Icon

Group: Revolutionary
Posts: 1,723
Type: Scripter
RM Skill: Advanced




There's allot of things in those scripts that can simply be done by events, 8 direction for example.
But.. It's still a pretty nice scrip.
Course..does no good for the C# guys.


__________________________
Xeilsoft
- Follow your dreams to the very end..

Kits that I'm working on.
[Unity3D 4.0] LTTP/Minish Cap - I don't have time for custom gfx like what the pze folks are doing but I will try and work on some enhanced LTTP graphics.

Main PC
Core i7 3820 overclocked @ 4.8GHZ
Galaxy: Nvidia Geforce GTX 680 GDDR5 2GB
Asrock X79 Extreme9 w' creative sound
64GB corsair platinum @ 1600MHZ
Muchkin 128GB SSD(boot), OZKIN 2TB SSD, Western Digital GREEN 1TB HDD.
Rosewill Lightning 1000W PSU
OS: Funtoo Linux, Windows 8 (Virtual Machine)

iMac (March 2013)
3.4GHz Quad-core Intel Core i7, Turbo Boost up to 3.9GHz
16GB 1600MHz DDR3 SDRAM - 2X8GB
1TB Serial ATA Drive @ 7200 rpm
NVIDIA GeForce GTX 680MX 2GB GDDR5
Go to the top of the page
 
+Quote Post
   

Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 22nd May 2013 - 12:02 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker