我应该怎么会有我的游戏实体知识渊博的身边的东西呢? [英] How should I have my game entities knowledgeable of the things around them?

查看:118
本文介绍了我应该怎么会有我的游戏实体知识渊博的身边的东西呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的游戏中的每个敌人类型是不同的类,和实例存储在C数组。在游戏主循环的update()运行对每个敌人/项实例,并绘制​​()运行。一些更新的()命令要求的,其主要的球员是知识。什么是获得信息到该实例的最佳途径?我不认为一个全局变量做聪明的方式,因为多人游戏选项可以在以后添加。

Every enemy type in my game is a different class, and the instances are stored in a C array. In the main game loop update() is run for each enemy/item instance, and draw() is run. Some of the update() commands require knowledge of where the main player is. What would be the best route to get that information to the instance? I don't think a global variable is the smart way to do it, since multiplayer options may be added later.

这仅仅是更大的问题,这是在游戏中的东西应该如何了解对方的一个例子。敌人怎么会知道他们正在与其他敌人,例如碰撞。

This is only an example of the bigger problem, which is how things in the game are supposed to know about each other. How would enemies know they're colliding with other enemies for example.

推荐答案

您需要建立多支链树型结构(没有简单的二进制树)。节点是在游戏中的位置。每个节点可以包含多个简单的钢结构制品/对象的指针(取决于你的编程语言)。由于周围的游戏玩家移动你移动你的球员的位置指针树节点重新presenting的位置。当您启动游戏这棵树类型stucture与东西回暖,怪物等随机种子填充,也可以利用周围散落的怪物。

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.

好运气

这篇关于我应该怎么会有我的游戏实体知识渊博的身边的东西呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆