- 打卡等级:祈祷套勇士
- 打卡总天数:49
- 打卡月天数:3
- 打卡总奖励:6584
- 最近打卡:2025-06-03 00:36:17
管理员
本站站长
- 积分
- 5271
|
NPC外观的特殊实现
(一)NPC渲染主函数
lua
--[[
* NPC渲染主函数
* 用途:根据NPC状态绘制对应形象
* 调用时机:NPC可见时每帧调用
* 参数:
* npc: NPC对象
]]
function RenderNPC(npc)
local frame = 0
if npc.isTalking then
frame = GetTalkFrame(npc.id)
elseif npc.isMoving then
frame = GetWalkFrame(npc.id, npc.direction)
else
frame = GetIdleFrame(npc.id)
end
DrawImage(NPC_WZL, frame, npc.x, npc.y)
if npc.hasQuest then
DrawQuestMark(npc.x, npc.y + 20)
end
end
(二)对话气泡渲染类
python
#
# 对话气泡渲染类
# 用途:显示NPC对话内容
# 调用时机:NPC开始说话时创建实例
#
class SpeechBubble:
def __init__(self, text):
self.text = text
self.life = 150 # 显示帧数
#
# 渲染气泡
# 参数:
# npc_pos: NPC当前位置
# 返回:气泡是否继续显示
#
def render(self, npc_pos):
x = npc_pos[0] + sin(time * 0.1) * 3
y = npc_pos[1] - 50 - abs(sin(time * 0.2)) * 5
width = len(self.text) * 8 + 20
height = 30
DrawRoundRect(x, y, width, height, 5)
DrawText(x+10, y+10, self.text)
self.life -= 1
return self.life > 0
|
|