39传奇素材网 发表于 2025-5-29 12:43:00

传奇游戏外观系统核心技术解析(五)

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 + sin(time * 0.1) * 3
      y = npc_pos - 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

页: [1]
查看完整版本: 传奇游戏外观系统核心技术解析(五)