1 / 26

罗培羽 — 教你用 VB 制作 RPG 游戏

罗培羽 — 教你用 VB 制作 RPG 游戏. 第三节 NPC 事件 NPC Events. 罗培羽 作品. 网名 碧俐千仞 QQ:345697666 E_mail : tyxxxx@qq.com 博客: http://hi.baidu.com/mhqy. 我们在这张地图中演示 Call MapStart(map1, 500, 500, 0). 假设我们的地图最多有 10 个 NPC (你可以根据实际情况修改) 添加 picturebox 对象,命名为 Npc, 然后创建控件数组,共 10 个。. 定义. 我们在每张地图的定义中加上

levia
Download Presentation

罗培羽 — 教你用 VB 制作 RPG 游戏

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 罗培羽—教你用VB制作RPG游戏 第三节 NPC事件 NPC Events

  2. 罗培羽 作品 • 网名 碧俐千仞 • QQ:345697666 • E_mail:tyxxxx@qq.com • 博客:http://hi.baidu.com/mhqy

  3. 我们在这张地图中演示Call MapStart(map1, 500, 500, 0)

  4. 假设我们的地图最多有10个NPC(你可以根据实际情况修改)假设我们的地图最多有10个NPC(你可以根据实际情况修改) • 添加picturebox对象,命名为Npc,然后创建控件数组,共10个。

  5. 定义 • 我们在每张地图的定义中加上 NpcPicture(9) As String’Npc的图片 NpcX(9) As Single’ Npc的横坐标 NpcY(9) As Single’ Npc的纵坐标 变量后面加括号如a(5),表示一个变量数组,我们这就定义了6个变量,分别为a(0)、 a(1)、 a(2)、 a(3) 、a(4) 、a(5)

  6. 定义NPC • 我们先添加一个文件夹npc用来放Npc的图片

  7. 我们把GoDimMap()添加以下 With map1 'npc定义 .NpcX(0) = 800 .NpcY(0) = 400 .NpcPicture(0) = AppDisk + "npc/sm.bmp" End With 分别赋值第一个Npc(编号为0)开始时的坐标和图片地址

  8. MapStart()中我们添加 For循环 for i= 0 to 9……Next i的意思就是i从0到9循环。 'npc处理 For i = 0 To 9 With main.Npc(i) .Picture = LoadPicture(mapx.NpcPicture(i)) .Left = mapx.NpcX(i) .Top = mapx.NpcY(i) End With Next i 在我们添加的10各图片控件中,载入图片。以及设置他们的位置

  9. 让Npc显示 在Draw()中添加 '画Npc(角色之下) For i = 0 To 9 GdiTransparentBlt main.hDC, main.Npc(i).Left + Xm, main.Npc(i).Top + Ym, main.Npc(i).Width, main.Npc(i).Height, main.Npc(i).hDC, 0, 0, main.Npc(i).Width, main.Npc(i).Height, RGB(255, 255, 255) '画图 Next i

  10. 但……我们通过两次画Npc来解决

  11. '画Npc底(角色之下) For i = 0 To 9 If Ym + main.Npc(i).Top + main.Npc(i).Height / 1.5 <= Ys + main.Role.Height / 1.5 Then GdiTransparentBlt …… End if Next i 【相对屏幕位置】如果Npc的纵坐标小于角色纵坐标

  12. ‘画Npc底(角色之上) For i = 0 To 9 If Ym + main.Npc(i).Top + main.Npc(i).Height / 1.5 > Ys + main.Role.Height / 1.5 Then GdiTransparentBlt …… End if Next i 【相对屏幕位置】如果Npc的纵坐标大于角色纵坐标

  13. NPC事件 • 先让点击NPC时有反应

  14. Form_MouseDown()添加 For i = 0 To 9 If x > main.Npc(i).Left + Xm And x < main.Npc(i).Left + main.Npc(i).Width + Xm And y > main.Npc(i).Top + Ym And y < main.Npc(i).Top + main.Npc(i).Height + Ym Then MsgBox "你好" Exit Sub End If Next i 提示框 鼠标的坐标在NPC的图片内 【相对屏幕】 退出过程

  15. 事件 • 添加Do_Npc模块 • 在地图模块中添加变量 • Public MapNow As String ‘标记现在在用那张地图 • 在地图启动函数中添加 • MapNow = mapx.Bottom • 我们把地图的底层图片地址当作图片的特征标识

  16. Npc模块中 Public Sub CallNpc(i As Integer) If MapNow = map1.Bottom And i = 0 Then MsgBox "你好" Exit Sub End If End Sub 在哪张地图的那个对象

  17. Form_MouseDown中 • 把msgbox换成Call CallNpc(i) • 我们要定义一下i • Dim i As Integer

  18. 地图转换 • 完善下MapMove() • 相应位置添加代码,以便使地图转换时不会发生意外 Xm = 0 Xm = main.Width / 15 - main.MapB.Width Ym = 0 Ym = main.Height / 15 - main.MapB.Height

  19. 地图转换 • 地图1中定义NPC .NpcX(1) = 1000 .NpcY(1) = 880 .NpcPicture(1) = AppDisk + "npc/door.bmp"

  20. 地图转换 • 地图2中定义NPC With map2 'npc定义 .NpcX(0) = 2350 .NpcY(0) = 216 .NpcPicture(0) = AppDisk + "npc/door.bmp" End With

  21. 事件 地图转换 If MapNow = map1.Bottom And i = 1 Then Call MapStart(map2, 2350, 216, 0) Exit Sub End If If MapNow = map2.Bottom And i = 0 Then Call MapStart(map1, 1000, 880, 0) Exit Sub End If

  22. Npc转移 • MsgBox “你好”改为 MsgBox "王小虎,你怎么来了。但多年不见……" MsgBox "我先走了" map1.NpcX(i) = 600 main.Npc(i).Left = map1.NpcX(i) map1.NpcY(i) = 600 main.Npc(i).Top = map1.NpcY(i) Call Draw(Xs, Ys) 单独添加红色两句即可实现Npc的移动,但换地图后又会还原

  23. 如果换成 map1.NpcX(i) = -600 main.Npc(i).Left = map1.NpcX(i) map1.NpcY(i) = -600 main.Npc(i).Top = map1.NpcY(i) Call Draw(Xs, Ys) • Npc就消失了

  24. 扩展 • 我们添加一些变量控制剧情就可以达到剧情的演绎 • 这样子的剧情编程会比较乱,我们还需要剧情策划和其他一些工具的协助,这些我们在后面会讲到

  25. NEXT • 如今你已经能做成一个NPC游戏的框架了 • 但如何制作一个精美的对话框? • 下一节我们继续学习

  26. 碧俐千仞qq空间欢迎你 谢谢支持 http://user.qzone.qq.com/345697666

More Related