赞 | 0 |
VIP | 17 |
好人卡 | 0 |
积分 | 1 |
经验 | 1022914 |
最后登录 | 2017-2-4 |
在线时间 | 10 小时 |
Lv1.梦旅人 月下可怜人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 10 小时
- 注册时间
- 2005-11-23
- 帖子
- 4085
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
注:八方步行图拼自《3d rpgmaker》,仅作测试,请勿挪作他用。
功能:
行走格式如图:
独立脚本:
- module Standrad
-
- #八方向行走图纵向坐标基准常数
- #(0点,左下,下,右下,左,回中,右,左上,上,右上)
- DIR8_Y = [0, 4, 0, 5, 1, 0, 2, 6, 3, 7]
-
- end
- class Game_Player < Game_Character
- #--------------------------------------------------------------------------
- # ● 更新遇敌
- #--------------------------------------------------------------------------
- def update_encounter
- return if in_vehicle? # 乘座了交通工具?
- if $game_map.bush?(@x, @y) # 繁茂
- @encounter_count -= 2 # 计数减少 2
- else # 繁茂以外的情况
- @encounter_count -= 1 # 计数减少 1
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- last_real_x = @real_x
- last_real_y = @real_y
- last_moving = moving?
- #全方向移动
- all_move_by_input
- super
- update_scroll(last_real_x, last_real_y)
- update_vehicle
- update_nonmoving(last_moving)
- end
- #--------------------------------------------------------------------------
- # ● 判断是否接触事件(不可通行情况下)
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def all_check_event_trigger_touch(x, y)
- return false if $game_map.interpreter.running?
- result = false
- allEvents = $game_map.events_xy(x, y)
- result = true unless allEvents.empty?
- for event in allEvents
- if [1,2].include?(event.trigger) and event.priority_type == 1
- event.start
- end
- end
- return result
- end
- #--------------------------------------------------------------------------
- # ● 处理输入方向键后的移动
- #--------------------------------------------------------------------------
- def all_move_by_input
- return unless movable?
- return if $game_map.interpreter.running?
- move_dir(Input.dir8)
- end
- #--------------------------------------------------------------------------
- # ● 偏向判断
- #--------------------------------------------------------------------------
- def dir_fact(x1, y1, x2, y2, d1, d2)
- return if Input.press?(Input::CTRL)
- dir = 0
- dir +=1 if passable?(x1, y1)
- dir +=2 if passable?(x2, y2)
- if dir > 0
- return (rand(10) > 4 ? move_dir(d1) : move_dir(d2)) if dir == 3
- return move_dir(d2) if dir == 2
- return move_dir(d1) if dir == 1
- end
- end
- #--------------------------------------------------------------------------
- # ● 移动方向
- #--------------------------------------------------------------------------
- def move_dir(d)
- return all_move_lower_left if d == 1
- return all_move_down if d == 2
- return all_move_lower_right if d == 3
- return all_move_left if d == 4
- return all_move_right if d == 6
- return all_move_upper_left if d == 7
- return all_move_up if d == 8
- return all_move_upper_right if d == 9
- end
- #--------------------------------------------------------------------------
- # ● 向下移动
- # turn_ok : 此地可以更改朝向
- #--------------------------------------------------------------------------
- def all_move_down(turn_ok = true)
- turn_down if turn_ok
- if passable?(@x, @y+1) # 可以通过
- @y = $game_map.round_y(@y+1)
- @real_y = (@y-1)*256
- increase_steps
- @move_failed = false
- else # 下方向不可通过
- if all_check_event_trigger_touch(@x, @y+1) # 判断接触的事件启动
- @move_failed = true
- return
- end
- dir_fact(@x+1, @y+1, @x-1, @y+1, 3, 1)
- end
- end
- #--------------------------------------------------------------------------
- # ● 向左移动
- # turn_ok : 此地可以更改朝向
- #--------------------------------------------------------------------------
- def all_move_left(turn_ok = true)
- turn_left if turn_ok
- if passable?(@x-1, @y) # 可以通过
- @x = $game_map.round_x(@x-1)
- @real_x = (@x+1)*256
- increase_steps
- @move_failed = false
- else # 不可以通过
- if all_check_event_trigger_touch(@x-1, @y) # 判断接触的事件启动
- @move_failed = true
- return
- end
- dir_fact(@x-1, @y+1, @x-1, @y-1, 1, 7)
- end
- end
- #--------------------------------------------------------------------------
- # ● 向右移动
- # turn_ok : 此地可以更改朝向
- #--------------------------------------------------------------------------
- def all_move_right(turn_ok = true)
- turn_right if turn_ok
- if passable?(@x+1, @y) # 可以通过
- @x = $game_map.round_x(@x+1)
- @real_x = (@x-1)*256
- increase_steps
- @move_failed = false
- else # 不可以通过
- if all_check_event_trigger_touch(@x+1, @y) # 判断接触的事件启动
- @move_failed = true
- return
- end
- dir_fact(@x+1, @y-1, @x+1, @y+1, 9, 3)
- end
- end
- #--------------------------------------------------------------------------
- # ● 向上移动
- # turn_ok : 此地可以更改朝向
- #--------------------------------------------------------------------------
- def all_move_up(turn_ok = true)
- turn_up if turn_ok
- if passable?(@x, @y-1) # 可以通过
- @y = $game_map.round_y(@y-1)
- @real_y = (@y+1)*256
- increase_steps
- @move_failed = false
- else # 不可以通过
- if all_check_event_trigger_touch(@x, @y-1) # 判断接触的事件启动
- @move_failed = true
- return
- end
- dir_fact(@x-1, @y-1, @x+1, @y-1, 7, 9)
- end
- end
- #--------------------------------------------------------------------------
- # ● 向左下移动
- #--------------------------------------------------------------------------
- def all_move_lower_left
- if (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or
- (passable?(@x-1, @y) and passable?(@x-1, @y+1))
- turn_lower_left unless @direction_fix
- @x -= 1
- @y += 1
- increase_steps
- @move_failed = false
- else
- turn_lower_left if !@direction_fix and Input.dir8 == 1
- @move_failed = true
- end
- end
- #--------------------------------------------------------------------------
- # ● 向右下移动
- #--------------------------------------------------------------------------
- def all_move_lower_right
- if (passable?(@x, @y+1) and passable?(@x+1, @y+1)) or
- (passable?(@x+1, @y) and passable?(@x+1, @y+1))
- turn_lower_right unless @direction_fix
- @x += 1
- @y += 1
- increase_steps
- @move_failed = false
- else
- turn_lower_right if !@direction_fix and Input.dir8 == 3
- @move_failed = true
- end
- end
- #--------------------------------------------------------------------------
- # ● 向左上移动
- #--------------------------------------------------------------------------
- def all_move_upper_left
- if (passable?(@x, @y-1) and passable?(@x-1, @y-1)) or
- (passable?(@x-1, @y) and passable?(@x-1, @y-1))
- turn_upper_left unless @direction_fix
- @x -= 1
- @y -= 1
- increase_steps
- @move_failed = false
- else
- turn_upper_left if !@direction_fix and Input.dir8 == 7
- @move_failed = true
- end
- end
- #--------------------------------------------------------------------------
- # ● 向右上移动
- #--------------------------------------------------------------------------
- def all_move_upper_right
- if (passable?(@x, @y-1) and passable?(@x+1, @y-1)) or
- (passable?(@x+1, @y) and passable?(@x+1, @y-1))
- turn_upper_right unless @direction_fix
- @x += 1
- @y -= 1
- increase_steps
- @move_failed = false
- else
- turn_upper_right if !@direction_fix and Input.dir8 == 9
- @move_failed = true
- end
- end
- end
- class Game_Character
-
- #--------------------------------------------------------------------------
- # ● 判断可以通行
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def passable?(x, y)
- x = $game_map.round_x(x) # 横方向循环修正
- y = $game_map.round_y(y) # 纵方向循环修正
- return false unless $game_map.valid?(x, y) # 地图外?
- return true if @through # 穿越 ON?
- return false unless map_passable?(x, y) # 地图不能通行?
- return false if collide_with_characters?(x, y) # 与角色冲突?
- return true # 可以通行
- end
- #--------------------------------------------------------------------------
- # ● 向左下
- #--------------------------------------------------------------------------
- def turn_lower_left
- set_direction(1)
- end
- #--------------------------------------------------------------------------
- # ● 向右下
- #--------------------------------------------------------------------------
- def turn_lower_right
- set_direction(3)
- end
- #--------------------------------------------------------------------------
- # ● 向左上
- #--------------------------------------------------------------------------
- def turn_upper_left
- set_direction(7)
- end
- #--------------------------------------------------------------------------
- # ● 向右上
- #--------------------------------------------------------------------------
- def turn_upper_right
- set_direction(9)
- end
-
- end
- class Sprite_Character < Sprite_Base
-
- DIR8_SY = Standrad::DIR8_Y
-
- def update_src_rect
- if @tile_id == 0
- index = @character.character_index
- pattern = @character.pattern < 3 ? @character.pattern : 1
- sx = (index % 4 * 3 + pattern) * @cw
- sy = DIR8_SY[@character.direction] * @ch
- self.src_rect.set(sx, sy, @cw, @ch)
- end
- end
-
- end
复制代码
截图:
范例:
http://rpg.blue/upload_program/d ... ��图_104367331.rar |
|