清单:
领队切换
惯性行走
弹性滚动
八方向键移动
(如果有其他需要可以回帖(?))
- #==============================================================================# ** Player_Add#==============================================================================#==============================================================================# ■ Game_Player#------------------------------------------------------------------------------# 处理主角的类。事件启动的判定、以及地图的滚动等功能。# 本类的实例请参考 $game_player。#==============================================================================class Game_Player < Game_Character #-------------------------------------------------------------------------- # ● 常量 #-------------------------------------------------------------------------- TRUE_SPEED = 4 BEGIN_SPEED = 2 #-------------------------------------------------------------------------- # ● 刷新 #-------------------------------------------------------------------------- def refresh @character_name = "" @character_hue = 0 return if $game_party.actors.size.zero? @leader_id = 0 if @leader_id.nil? or $game_party.actors[@leader_id].nil? actor = $game_party.actors[@leader_id] @character_name = actor.character_name @character_hue = actor.character_hue end #-------------------------------------------------------------------------- # ● 更新惯性 #-------------------------------------------------------------------------- def update_inertia return @move_speed = BEGIN_SPEED if Input.dir8 == 0 return @move_speed += 0.5 if @move_speed < TRUE_SPEED end #-------------------------------------------------------------------------- # ● 更新领队切换 #-------------------------------------------------------------------------- def update_captain @leader_id += 1 if Input.trigger?(Input::R) @leader_id -= 1 if Input.trigger?(Input::L) refresh if Input.trigger?(Input::L) or Input.trigger?(Input::R) end #-------------------------------------------------------------------------- # ● 方向键移动处理 #-------------------------------------------------------------------------- def move_by_input return unless movable? return if $game_system.map_interpreter.running? 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 update_inertia end #-------------------------------------------------------------------------- # ● 可以行动判定 #-------------------------------------------------------------------------- def movable? return false if moving? return false if @move_route_forcing return false if $game_temp.message_window_showing return true end #-------------------------------------------------------------------------- # ● 更新画面 #-------------------------------------------------------------------------- def update update_captain last_real_x = @real_x last_real_y = @real_y last_moving = moving? move_by_input super update_scroll(last_real_x, last_real_y) update_nomoving(last_moving) end #-------------------------------------------------------------------------- # ● 更新滚动 #-------------------------------------------------------------------------- def update_scroll(last_real_x, last_real_y) ax1 = $game_map.adjust_x(last_real_x) ay1 = $game_map.adjust_y(last_real_y) ax2 = $game_map.adjust_x(@real_x) ay2 = $game_map.adjust_y(@real_y) slowmove = (2 ** (@move_speed - 1)).to_i fastmove = (2 ** @move_speed).to_i length = (2 ** (@move_speed + 4)).to_i if ax2 < CENTER_X - 8 if (ax2 - CENTER_X) CENTER_X + 8 if (ax2 - CENTER_X) >= length $game_map.scroll_right(fastmove) else $game_map.scroll_right(slowmove) end end if ay2 < CENTER_Y - 8 if (ay2 - CENTER_Y) CENTER_Y + 8 if (ay2 - CENTER_Y) >= length $game_map.scroll_down(fastmove) else $game_map.scroll_down(slowmove) end end end #-------------------------------------------------------------------------- # ● 非移动中更新 # last_moving : 之前是否正在移动 #-------------------------------------------------------------------------- def update_nomoving(last_moving) return if $game_system.map_interpreter.running? return if moving? return if check_touch_event if last_moving if not $game_temp.message_window_showing and Input.trigger?(Input::C) return if check_action_event end update_encounter if last_moving end #-------------------------------------------------------------------------- # ● 更新遇敌 #-------------------------------------------------------------------------- def update_encounter return if $DEBUG and Input.press?(Input::CTRL) if $game_map.bush?(@x, @y) @encounter_count -= 2 else @encounter_count -= 1 end end #-------------------------------------------------------------------------- # ● 判断事件是否由接触触发(重叠) #-------------------------------------------------------------------------- def check_touch_event return check_event_trigger_here([1,2]) end #-------------------------------------------------------------------------- # ● 判断事件是否由确认键触发 #-------------------------------------------------------------------------- def check_action_event return true if check_event_trigger_here([0]) return check_event_trigger_there([0,1,2]) endend#==============================================================================# ■ Game_Map#------------------------------------------------------------------------------# 处理地图的类。包含卷动以及可以通行的判断功能。本类的实例请参考 $game_map 。#==============================================================================class Game_Map #-------------------------------------------------------------------------- # ● 计算 X 座标减去显示座标 # x : X 座标 #-------------------------------------------------------------------------- def adjust_x(x) return x - @display_x end #-------------------------------------------------------------------------- # ● 计算 Y 座标减去显示座标 # y : Y 座标 #-------------------------------------------------------------------------- def adjust_y(y) return y - @display_y endend复制代码
复制代码 本帖来自P1论坛作者忧雪の伤,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址: https://rpg.blue/forum.php?mod=viewthread&tid=177264 若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。 |