赞 | 673 |
VIP | 62 |
好人卡 | 144 |
积分 | 335 |
经验 | 110435 |
最后登录 | 2024-11-1 |
在线时间 | 5108 小时 |
Lv5.捕梦者
- 梦石
- 0
- 星屑
- 33512
- 在线时间
- 5108 小时
- 注册时间
- 2012-11-19
- 帖子
- 4878
|
这样试下:- #==============================================================================
- # ■ Game_Player
- #------------------------------------------------------------------------------
- # 处理主角的类。事件启动的判定、以及地图的滚动等功能。
- # 本类的实例请参考 $game_player。
- #==============================================================================
- class Game_Player < Game_Character
- if @self_alias == nil
- alias self_update update
- @self_alias = true
- end
- #--------------------------------------------------------------------------
- # X☆R 添加:鼠标指向位置是否是NPC
- #--------------------------------------------------------------------------
- def get_npc
- x, y = Mouse.get_mouse_pos
- for event in $game_map.events.values
- next if event.character_name == ""
- if x > event.screen_x - 16 and x < event.screen_x + 16 and
- y > event.screen_y - 64 and y < event.screen_y
- return event
- end
- end
- return nil
- end
- #--------------------------------------------------------------------------
- # ● 完整鼠标系统
- #--------------------------------------------------------------------------
- def update
-
- # X☆R 添加:点击鼠标左键,并且距离小于 7 ,启动事件。
- if Mouse.trigger?(0x01)
- if get_npc != nil and (self.x-get_npc.x).abs + (self.y-get_npc.y).abs < 7
- get_npc.start
- return
- end
- end
-
- # 搜索路径
- seek_path
-
- # 当持续按下鼠标左键时
- if Mouse.press?(0x01)
- return if !System.whether_move
- @count = 20 if @count.nil?
- @count -= 1
- if @count <= 0
- @self_state = 2
- @count = nil
- end
- follow(true) if @self_state != 2 and @count < 18
- elsif Mouse.trigger?(0x02)
- @self_state = 0
- follow(false)
- else
- @count = 20
- end
- # 移动
- if @self_state == 1
- player_move
- elsif @paths != nil and @self_state == 2
- follow(true)
- end
- # 别名
- self_update
- end
- #--------------------------------------------------------------------------
- # ● 搜索路径
- #--------------------------------------------------------------------------
- def seek_path
- # 获取鼠标在画面的坐标
- x, y = Mouse.get_mouse_pos
- # 当按下鼠标左键时
- if Mouse.trigger?(0x01)
- # 禁止移动的情况下返回
- return if !System.whether_move
- # 排除各种无效的情况
- unless $game_system.map_interpreter.running? or
- @move_route_forcing or $game_temp.message_window_showing
- # 获取目标点
- trg_x = (x + $game_map.display_x / 4) / 32
- trg_y = (y + $game_map.display_y / 4) / 32
- # 目标点不可以通行的情况下返回
- return unless target_passable?(trg_x,trg_y)
- # 初始化未开启事件
- @event = nil
- # 判断是否可以打开事件
- event_start = check_event_custom_start(x, y)
- # 若不能开启事件
- if !event_start
- # 初始化
- @paths = []
- @steps = 0
- @self_state = 1
- # 若存在未开启事件
- if @event != nil
- trg_x,trg_y = @event.x,@event.y
- end
- # 若目标不为自身则开始寻路
- if trg_x != self.x or trg_y != self.y
- # 添加点击动画
- add_animation if @event.nil?
- # 获得路径
- @paths = Find_Path.new.find_player_short_path(trg_x, trg_y, x, y)
- end
- else
- # 角色面向事件
- self.turn_toward_player(@event) if [email protected]? and !self.moving?
- @steps = @paths = nil
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 可以通行判定
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def target_passable?(x, y)
- # 获取地图通行表
- passages = $data_tilesets[$game_map.tileset_id].passages
- # 从层按从上到下的顺序调查循环
- for i in [2, 1, 0]
- # 取得元件 ID
- tile_id = $game_map.data[x, y, i]
- # 取得元件 ID 失败
- if tile_id == nil
- # 不能通行
- return false
- # 如果全方向的障碍物的接触被设置的情况下
- elsif passages[tile_id] & 0x0f == 0x0f
- # 不能通行
- return false
- # 这以外的优先度为 0 的情况下
- elsif $game_map.priorities[tile_id] == 0
- # 可以通行
- return true
- end
- end
- # 可以通行
- return true
- end
- #--------------------------------------------------------------------------
- # ● 判断是否可以打开事件
- #--------------------------------------------------------------------------
- def check_event_custom_start(x, y)
- # 循环检查所有事件
- for event in $game_map.events.values
- bitmap = RPG::Cache.character(event.character_name,event.character_hue)
- cw = bitmap.width / 9#event.animation_frame
- ch = bitmap.height / 8#event.direction_frame
- _x = event.screen_x
- _y = event.screen_y
- d = event.direction
- case event.direction_frame
- when 4
- sy = d > 8 ? 2 : d > 7 ? 3 : d > 6 ? 3 : d > 5 ? 2 : d > 3 ? 1 : d > 2 ? 0 : d > 1 ? 0 : d > 0 ? 1 : 5
- when 8
- sy = d > 8 ? 7 : d > 7 ? 3 : d > 6 ? 6 : d > 5 ? 2 : d > 3 ? 1 : d > 2 ? 5 : d > 1 ? 0 : d > 0 ? 4 : 5
- end
- if x >= _x - cw / 2 and x <= _x + cw / 2 and y >= _y - ch and y <= _y and
- bitmap.get_pixel(x - _x + cw / 2 + event.pattern * cw, y - _y + ch + sy * ch).alpha > 0
- for i in 0...event.list.size
- if ["Item", "Npc"].include?(event.list[i].parameters[0])
- way_x = self.x - event.x
- way_y = self.y - event.y
- if way_x.abs + way_y.abs <= 8 and !self.moving?
- # 矫正主角姿势
- self.straighten
- # 角色面向事件
- # 开启事件
- event.start
- return true
- self.pattern
- else
- @event = event
- return self.moving? ? true : false
- end
- end
- end
- end
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 添加鼠标点击动画
- #--------------------------------------------------------------------------
- def add_animation
- x, y = Mouse.get_mouse_pos
- animation = Sprite.new
- animation.visible = false
- animation.bitmap = Bitmap.new("UI/鼠标效果序列图")
- map_x = x - 10 + $game_map.display_x / 4
- map_y = y - 5 + $game_map.display_y / 4
- animation.src_rect.set(0, 0, 24, 13)
- $鼠标效果.push([animation,0,map_x,map_y])
- end
- #--------------------------------------------------------------------------
- # ● 开始移动
- #--------------------------------------------------------------------------
- def player_move
- # 排除无效情况
- unless moving? or $game_system.map_interpreter.running? or
- @move_route_forcing or $game_temp.message_window_showing
- # 若没有完成路径
- if @steps != nil and @paths != nil and @steps <= @paths.size
- # 判断路径
- case @paths[@steps]
- when 6
- move_right
- @steps += 1
- when 4
- move_left
- @steps += 1
- when 2
- move_down
- @steps += 1
- when 8
- move_up
- @steps += 1
- when 1
- move_lower_left
- @steps += 1
- when 3
- move_lower_right
- @steps += 1
- when 7
- move_upper_left
- @steps += 1
- when 9
- move_upper_right
- @steps += 1
- end
- # 若存在未开启事件
- if @event != nil
- way_x = self.x - @event.x
- way_y = self.y - @event.y
- if way_x.abs + way_y.abs <= 8
- # 角色面向事件
- self.turn_toward_player(@event)
- # 矫正主角姿势
- self.straighten
- # 开启事件
- @event.start
- # 终止路径
- @paths = nil
- return
- end
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 跟随/转向
- #--------------------------------------------------------------------------
- def follow(move = true)
- # 禁止移动的情况下返回
- return if !System.whether_move
- # 选择主角的情况下
- if $select_player
- for i in $鼠标效果
- Picture.dispose(i[0])
- end
- return
- end
- # 鼠标在移动或者转向的情况下
- x, y = Mouse.get_mouse_pos
- # 鼠标在移动中的情况下
- if @mouse_x != x or @mouse_y != y or @display_x != $game_map.display_x or @display_y != $game_map.display_y
- # 添加点击动画
- add_animation if move
- # 获取角色位置
- self_x = self.screen_x
- self_y = self.screen_y
- # 排除无效情况
- unless moving? or $game_system.map_interpreter.running? or
- @move_route_forcing or $game_temp.message_window_showing
- if x > self_x
- if y - self_y > - 0.4 * (x - self_x) and y - self_y < 0.4 * (x - self_x)
- move_right if move
- @direction = 6
- end
- if y - self_y > 0.4 * (x - self_x) and y - self_y < 2.4 * (x - self_x)
- move_lower_right if move
- @direction = 3
- end
- if y - self_y < - 0.4 * (x - self_x) and y - self_y > - 2.4 * (x - self_x)
- move_upper_right if move
- @direction = 9
- end
- if y - self_y > 2.4 * (x - self_x)
- move_down if move
- @direction = 2
- end
- if y - self_y < - 2.4 * (x - self_x)
- move_up if move
- @direction = 8
- end
- end
- if x < self_x
- if y - self_y > - 0.4 * (self_x - x) and y - self_y < 0.4 * (self_x - x)
- move_left if move
- @direction = 4
- end
- if y - self_y > 0.4 * (self_x - x) and y - self_y < 2.4 * (self_x - x)
- move_lower_left if move
- @direction = 1
- end
- if y - self_y < - 0.4 * (self_x - x) and y - self_y > - 2.4 * (self_x - x)
- move_upper_left if move
- @direction = 7
- end
- if y - self_y > 2.4 * (self_x - x)
- move_down if move
- @direction = 2
- end
- if y - self_y < - 2.4 * (self_x - x)
- move_up if move
- @direction = 8
- end
- end
- end
- # 记忆变量
- @mouse_x,@mouse_y = Mouse.get_mouse_pos
- @display_x = $game_map.display_x
- @display_y = $game_map.display_y
- end
- end
- end
复制代码 |
|