Project1
标题: 求真·斜四方向脚本(论坛以前貌似有但是现在没了) [打印本页]
作者: xzqcm111    时间: 2011-4-25 10:38
标题: 求真·斜四方向脚本(论坛以前貌似有但是现在没了)
 本帖最后由 xzqcm111 于 2011-4-26 10:40 编辑 
我只需要留下斜四方向的,按“上”的话往右上走,下为左下,左为左上,右为右下,应该如何修改??另外命名方式改为@+行走图名    单张的行走图。NPC无要求,当然如果连NPC一起做了的话可追加VIP悬赏。
PS:要考虑到事件触发,因为全部采用斜四方向的话,主角和NPC之间的最小距离也是二,会导致按确定键无法触发事件。
附一个八方向脚本供参考。
- #==============================================================================
 - # ■ Game_Character
 - #==============================================================================
 
- class Game_Character
 -   #--------------------------------------------------------------------------
 -   # ● 八方向
 -   #--------------------------------------------------------------------------
 -   def direction_8dir
 -     return @direction
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 变成指定方向
 -   #     direction : 方向
 -   #--------------------------------------------------------------------------
 -   alias set_direction_8fangxiang set_direction
 -   def set_direction(direction)
 -     last_dir = @direction
 -     set_direction_8fangxiang(direction)
 -     if !@direction_fix && direction != 0
 -       @direction_8dir = direction
 -     end
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 向左下移动
 -   #--------------------------------------------------------------------------
 -   alias move_lower_left_8fangxiang move_lower_left
 -   def move_lower_left
 -     move_lower_left_8fangxiang
 -     @direction_8dir = 1 unless @direction_fix
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 向右下移动
 -   #--------------------------------------------------------------------------
 -   alias move_lower_right_8fangxiang move_lower_right
 -   def move_lower_right
 -     move_lower_right_8fangxiang
 -     @direction_8dir = 3 unless @direction_fix
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 向左上移动
 -   #--------------------------------------------------------------------------
 -   alias move_upper_left_8fangxiang move_upper_left
 -   def move_upper_left
 -     move_upper_left_8fangxiang
 -     @direction_8dir = 7 unless @direction_fix
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 向右上移动
 -   #--------------------------------------------------------------------------
 -   alias move_upper_right_8fangxiang move_upper_right
 -   def move_upper_right
 -     move_upper_right_8fangxiang
 -     @direction_8dir = 9 unless @direction_fix
 -   end
 - end
 - #==============================================================================
 - # ■ Game_Party
 - #==============================================================================
 
- class Game_Party < Game_Unit
 -   def decrease_steps
 -     @steps -= 1
 -   end
 - end
 
- #==============================================================================
 - # ■ Game_Player
 - #==============================================================================
 
- class Game_Player < Game_Character
 
-   #--------------------------------------------------------------------------
 -   # ●八方向
 -   #--------------------------------------------------------------------------
 -   def direction_8dir
 -     @direction_8dir = @direction if @direction_8dir == nil
 -     return @direction_8dir
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 八方向按键
 -   #--------------------------------------------------------------------------
 -   def move_by_input
 -     return unless movable?
 -     return if $game_map.interpreter.running?
 -     last_steps = $game_party.steps
 -     case Input.dir8
 -     when 1;  move_down; move_left; @direction = 2
 -     when 2;  move_down
 -     when 3;  move_down; move_right; @direction = 6
 -     when 4;  move_left
 -     when 6;  move_right
 -     when 7;  move_up; move_left; @direction = 4
 -     when 8;  move_up
 -     when 9;  move_up; move_right; @direction = 8
 -     else;    return
 -     end
 -     @direction_8dir = Input.dir8
 -     # 斜方向移动正确步数计算
 -     if $game_party.steps - last_steps == 2
 -       $game_party.decrease_steps
 -     end
 -   end
 -   
 -   #--------------------------------------------------------------------------
 -   # ● 移动更新
 -   #--------------------------------------------------------------------------
 -   def update_move
 -     distance = 2 ** @move_speed   
 -     if dash?                      
 -       distance *= 2
 -     end
 -     distance = Integer(distance)
 -     @real_x = [@real_x - distance, @x * 256].max if @x * 256 < @real_x
 -     @real_x = [@real_x + distance, @x * 256].min if @x * 256 > @real_x
 -     @real_y = [@real_y - distance, @y * 256].max if @y * 256 < @real_y
 -     @real_y = [@real_y + distance, @y * 256].min if @y * 256 > @real_y
 -     update_bush_depth unless moving?
 -     if @walk_anime
 -       @anime_count += 1.5
 -     elsif @step_anime
 -       @anime_count += 1
 -     end
 -   end
 - end
 - #==============================================================================
 - # ■ Sprite_Character
 - #==============================================================================
 - class Sprite_Character < Sprite_Base
 -   
 -   ANIME_TABLE = { 1=>2, 3=>6, 7=>4, 9=>8 }
 -   #--------------------------------------------------------------------------
 -   # ● 更新位图
 -   #--------------------------------------------------------------------------
 -   alias update_bitmap_8fangxiang update_bitmap
 -   def update_bitmap
 -     name_changed = (@character_name != @character.character_name)
 -     update_bitmap_8fangxiang
 -     if @tile_id > 0             
 -       @enable_slant = false
 -       return
 -     end
 -     return unless name_changed  
 -     @enable_slant = true
 -     begin
 -       @character_name_slant = @character_name + "#"
 -       Cache.character(@character_name_slant)
 -     rescue
 -       @enable_slant = false
 -     end
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 更新传送矩形
 -   #--------------------------------------------------------------------------
 -   alias update_src_rect_8fangxiang update_src_rect
 -   def update_src_rect
 -     return if @tile_id > 0  
 -     if @enable_slant
 -       update_src_rect_for_slant
 -     else
 -       update_src_rect_8fangxiang
 -     end
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 更新斜方向传送矩形
 -   #--------------------------------------------------------------------------
 -   def update_src_rect_for_slant
 -     index = @character.character_index
 -     pattern = @character.pattern < 3 ? @character.pattern : 1
 -     sx = (index % 4 * 3 + pattern) * @cw
 -     dir = @character.direction_8dir
 -     case dir % 2
 -     when 0  # 上下左右
 -       if @last_slant
 -         self.bitmap = Cache.character(@character_name)
 -         @last_slant = false
 -       end
 -     else    
 -       unless @last_slant
 -         self.bitmap = Cache.character(@character_name_slant)
 -         @last_slant = true
 -       end
 -       dir = ANIME_TABLE[dir]
 -     end
 -     sy = (index / 4 * 4 + (dir - 2) / 2) * @ch
 -     self.src_rect.set(sx, sy, @cw, @ch)
 -   end
 - end
 
 复制代码