西部世界v5(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/westworld-v5-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2455 个词 阅读量 0西部世界v5(译文)
原文地址:https://www.codeproject.com/Articles/5246744/WestWorld-v5
原文作者:Terence Wallace
译文由本站 robot-v1.0 翻译
前言
A continuing series demonstration of Finite State Machines (FSM) where agents inhabit a small town called WestWorld.
有限状态机(FSM)的连续系列演示,代理商在一个名为WestWorld的小镇中居住.
-
下载源代码(WestWorld5)-906.5 KB(Download source code (WestWorld5) - 906.5 KB)
-
下载演示(WestWorld5)-935.1 KB(Download demo (WestWorld5) - 935.1 KB) 注意:(Note:)这是CodeProject文章系列的第5部分,标题为WestWorld.要获得本文的更多背景信息:(This is Part 5 of a CodeProject Article Series entitled WestWorld. To get more background information for this article:)
介绍(Introduction)
如何创建利用有限状态机的代理的实际示例.在本文中,我将重点放在基于图块的2D地图中的路径查找.我们将研究AStar PathFinding算法的游戏动态.西部世界有两个居民-一个名叫Miner Bob的金矿工和他的妻子Amanda.(A practical example of how to create agents that utilize finite state machines. In this article, I focus path finding in a tile based 2D Map. We are going to look at the game dynamics of the AStar PathFinding Algorithm. There are two inhabitants of WestWorld — a gold miner named Miner Bob and his Wife, Amanda.) 在本系列的历史中,我们涵盖了以下主题:(In the history of this series we have covered the following topics:)
WestWorld1
-有限状态机(FSM)的基础(- Basics of Finite State Machine(FSM))WestWorld2
-有两名特工的FSM(矿工和妻子)(- FSM with two agents (Miner & Wife))WestWorld3
-两个FSM代理之间的消息传递(- Messaging between two FSM Agents)WestWorld4
-WindowsForms GDI +简介(- Intro of WindowsForms GDI+)WestWorld5
-((- ()本文(this article))2D地图渲染() 2D Map Rendering)
背景(Background)
本教程的目的是向您展示如何从头开始创建简单的游戏,而无需XNA或DirectX或Unity的高级API的帮助,这些API会为您自动完成该过程.我们将使用的是Windows Form GDI +来执行基本的地图渲染.(The aim of this tutorial is to show you how to create a simple game, from scratch, without the help of higher level APIs like XNA or DirectX, or Unity which automate the process for you. All we will be using is Windows Form GDI+ to perform basic map rendering.)
地图生成(Map Generation)
在本系列文章中,我发现利用(In this series of the article I found it beneficial to utilize) 平铺(Tiled) 开源和免费的地图编辑器.(the open source and free map editor.) Tiled是通用的瓦片地图编辑器.它是一个免费工具,可轻松创建切片地图布局.它具有足够的通用性,可以允许抽象的事物,例如碰撞区域,敌人生成位置或加电位置.它将所有这些数据保存为方便的标准化* .tmx格式.(*Tiled is a general purpose tile map editor. It is a free tool that allows the easy creation of tile map layouts. It is versatile enough to allow abstract things such as collision areas, enemy spawn positions, or power-up positions. It saves all of this data in a convenient, standardized *.tmx format.*)
对象层(Object Layer)
出于本文的目的,我们仅需要利用一个对象层和几个平铺层.在"对象层"中,我们将指定特殊的游戏元素.使用对象,您可以向地图添加大量信息,以供您在游戏中使用.对象层中的对象可以替换源代码中的乏味替代方法,例如硬编码坐标(例如生成点,出口,入口等).您还可以维护有关对象图块的其他数据,以存储游戏元素.(For the purpose of this article we will only need to utilize an Object Layer and a couple of Tile Layers. The Object Layer is where we will specify special gameplay elements. Using objects you can add a great deal of information to your map for use in your game. The Objects in Object Layer can replace tedious alternatives like hardcoding coordinates (like spawn points, exits, entrances, etc.) in your source code. You can also maintain additional data about your Object tiles for storing gameplay elements.)
平铺层(Tile Layer)
为了使平铺层保持简单,该项目使用开源图形文件.可以在这里找到其中之一:(To keep the Tile Layer simple this project uses an open source graphics file. One of many can be located here:) Github上的OpenPixels.(OpenPixels on Github.)
自定义属性(Custom Properties)
使用Tiled的主要优点之一是它允许在其所有基本数据结构上设置自定义属性.出于<西部世界>的目的,我使用"自定义属性"来存储将与游戏中的Enum值匹配的信息.(One of the major strengths of using Tiled is that it allows setting custom properties on all of its basic data structures. For the purpose of WestWorld I am using Custom Properties to store information that will be used to match an Enum value in game.)
瓦数(TiledBasic)
要读取* .tmx文件,我使用的是(*To read the *.tmx file I am using a modified version of*) 平铺(TileSharp) 叫(*called*)**瓦数(*TiledBasic*)**.此实现使我可以阅读自己的课程和游戏信息. TiledBasic用于解析和导入Tiled生成的TMX文件.每(*. This implementation allows me to read into my class and game info. TiledBasic is used for parsing and importing TMX files generated by Tiled. Each*) Tile
在* .tmx中(*in a *.tmx*) Map
文件被读取到Map类中.(*file is read into a Map class.*)
瓷砖渲染(Tile Rendering)
读取完所有图块后,即可通过以下任意一种在屏幕上进行渲染(Once all of the tiles are read that can then be rendered on screen by one of the) Draw()
的方法(methods of the) Scene
类.(class.)
寻找路径(PathFinding)
游戏中的寻路有助于找到两点之间的最短路径.这就像解决迷宫的一种实用方法.基于A 网格的路径查找在游戏中效果很好,因为角色可以沿x轴和y轴移动.在<西部世界>中使用的自适应算法允许AI角色遵循根据其目标路线选择的路径.(Pathfinding in the game helps to find the shortest route between two points. It is like a practical way to solve a maze. A grid-based pathfinding works well for games because the characters can move along both the x- and y-axes. The adapted algorithm utilized in WestWorld allows the AI character to follow the path chosen based on the route to their goal.) 在此版本(WestWorld v.5)中,我们为NPC定义了"硬编码"路由.但是,在该系列的未来版本和最终版本中,我们将讨论一种更聪明的方法,使"不可玩角色"(NPC)“思考"并选择要追求的目标(即决策树).(In this version (WestWorld v.5) we have defined a ‘hard-coded’ route for the NPC. However, in a future and final version of the series we will discuss a more clever way to allow the Non-Playable Character(NPC) to ‘think’ and to choose (i.e. Decision Tree) which goal to pursue.)
参考文献(References)
- 阿拉斯泰尔`阿奇森(Alastair Aitchison)
- 几篇CodeProject文章(Several CodeProject articles)
- Apress,通过游戏编程学习VB .NET(2003年8月14日)(Apress, Learn VB .NET Through Game Programming (August 14, 2003))
- 开发人员参考:编程Microsoft Visual Basic(Developer Reference: Programming Microsoft Visual Basic)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VB.NET .NET GDI+ Design Dev 2D 新闻 翻译