[脚本]敌人选择框替换成“移动光标”
RUBY 代码class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# * 开始目标敌人选择 - 创建选择敌人指令光标
#--------------------------------------------------------------------------
def start_target_enemy_selection
@target_enemy_window = Window_TargetEnemy.new
@target_enemy_window.back_opacity = 100# 设置窗口不透明度
@target_enemy_window.opacity = 255 # 设置窗口内容不透明
@target_enemy_window.height = 40 # 设置窗口高度
@target_enemy_window.width = 40 # 设置窗口宽度
@target_enemy_index = 0 # 初始化选择的敌人索引
@info_viewport.rect.x += @target_enemy_window.width
@info_viewport.ox += @target_enemy_window.width
@actor_command_window.active = false
@target_enemies = get_alive_enemies # 获取活着的敌人
update_enemy_cursor # 更新光标位置
end
#--------------------------------------------------------------------------
# * 获取活着的敌人实例
#--------------------------------------------------------------------------
def get_alive_enemies
alive_enemies = []
$game_troop.members.eachdo |enemy|
alive_enemies.push(enemy)if enemy.exist? && !enemy.dead?
end
alive_enemies
end
#--------------------------------------------------------------------------
# * 更新目标敌人选择
#--------------------------------------------------------------------------
def update_target_enemy_selection
if Input.trigger?(Input::B)
Sound.play_cancel
@enemy_name.visible = false
end_target_enemy_selection
elsif Input.trigger?(Input::C)
Sound.play_decision
select_enemy(@target_enemies[@target_enemy_index])if@target_enemies
end_target_enemy_selection
end_skill_selection
end_item_selection
next_actor
elsif Input.trigger?(Input::RIGHT) || Input.trigger?(Input::DOWN)
@target_enemy_index = (@target_enemy_index + 1) % @target_enemies.sizeif@target_enemies
@enemy_name.visible = false
update_enemy_cursor
elsif Input.trigger?(Input::LEFT) || Input.trigger?(Input::UP)
@target_enemy_index = (@target_enemy_index - 1 + @target_enemies.size) % @target_enemies.sizeif@target_enemies
@enemy_name.visible = false
update_enemy_cursor
end
end
#--------------------------------------------------------------------------
# * 更新敌人光标的位置和名称窗口
#--------------------------------------------------------------------------
def update_enemy_cursor
returnunless@target_enemies && @target_enemies[@target_enemy_index]# 确保数组存在且有元素
enemy = @target_enemies[@target_enemy_index]# 获取当前选中的敌人
@target_enemy_window.x = enemy.screen_x - 18# 更新光标位置到敌人的坐标
@target_enemy_window.y = enemy.screen_y - 40
ememy = get_alive_enemies
@target_enemy_window.visible = true# 确保光标窗口可见
# 创建敌人名称显示窗口
@enemy_name = Window_Base.new(@target_enemy_window.x - 60, @target_enemy_window.y + 46, 160, 50)
@enemy_name.back_opacity = 180
@enemy_name.contents.clear
@enemy_name.contents.draw_text(0, 0, enemy.name.length * 22, 22, enemy.name)
@enemy_name.visible = true# 确保敌人名称可见
end
#--------------------------------------------------------------------------
# * 光标选定敌人
#--------------------------------------------------------------------------
def select_enemy(enemy)
@active_battler.action.target_index = enemy.indexif enemy
end
#--------------------------------------------------------------------------
# * 结束目标敌人选择
#--------------------------------------------------------------------------
def end_target_enemy_selection
@info_viewport.rect.x -= @target_enemy_window.width
@info_viewport.ox -= @target_enemy_window.width
@target_enemy_window.dispose
@target_enemy_window = nil
@enemy_name.dispose
@enemy_name = nil
@actor_command_window.active = trueif@actor_command_window.index == 0
end
end
https://rpg.blue/data/attachment/forum/202410/19/221429c2o6nzufwof5afo2.png
本帖来自P1论坛作者swbsl,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=497209若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页:
[1]