且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我应该如何让我的游戏实体了解他们周围的事物?

更新时间:2023-12-02 16:14:58

您需要构建一个多分支的树型结构(不是简单的二叉树).节点是游戏中的位置.每个节点可以包含多个简单的结构/对象指针(取决于您的编程语言).当玩家在游戏中移动时,您将玩家位置指针移动到表示位置的树节点.当您开始游戏时,这种树型结构中充满了要捡起的东西、怪物等.随机种子也可用于将怪物散布在周围.

Your need to build a multi-branched tree type structure (not simple binary tree). The nodes are the locations in the game. Each node can contain multiple simple stuctures/objects pointers (depending on your programming language). As the player moves around the game you move your player position pointer to the tree node representing the location. When you start the game this tree type stucture is populated with things to pick up, monsters etc. A random seed can also be use to scatter monsters around.

这有助于提高游戏速度,因为您只需搜索当前节点和离当前位置/节点一步之遥的节点.任何触发怪物前进或后退的例程只是将怪物指针移动到下一个或多个节点.如果使用了医疗包,那么它的指针将从它所在的房间/节点中销毁.

This helps the speed of the game as you only have to search current node and nodes one step away from your current location/node. Any routines triggered that monsters advance or retreat just move the monsters pointer to the next node or nodes. If a med pack is used then its pointer is destroyed from the room/node that it is in.

祝你好运