检查许多导弹和敌人之间是否有交集?
我想创建一个类,可以说称为敌人 1、敌人 2 和敌人 3。
敌人 1:很容易杀死,但很多。 敌人2:较难杀死,但数量较少。 敌人3:Boss,超级难杀,只有一个。
假设很多将是 1,000。少了就会有100个。Boss当然是1个。
因此,为一场只有敌人的游戏创建 1,101 个不同的实例是愚蠢的。这将需要大量代码。
现在我的战斗机,病了,可以发射很多导弹。为了好玩,我们假设每分钟 2,000 次。
我需要检查敌人和所有导弹之间的碰撞情况。我计划只使用 4 个不同的实例。这将是敌人 1、敌人 2、敌人 3 和导弹。
关于如何解决这个问题有什么想法吗?显然我需要线程,但我不确定如何在这种情况下检查冲突。
I want to create a class lets say called enemy 1, enemy 2, and enemy 3.
Enemy 1: Very easy to kill, but many.
Enemy 2: Harder to kill, but less of them.
Enemy 3: Boss, super hard to kill, only one.
Lets say that many is going to be 1,000. Less of them will be 100. Boss is of course one.
So it would be stupid to make 1,101 different instances for a game of just enemy. It would require to much code.
Now my fighter, which is sick, can fire a lot of missiles. Lets say 2,000 a minute for the sake of fun.
I need to check for collisions between the enemy and all the missiles. I plan only using 4 different instances. Which would be enemy1, enemy2, enemy3, and a missile.
Any ideas on how to go about this? Obviously I would need threads, but I am not sure how to check for collisions in this instance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你有 1101 个敌人在这个地方徘徊,那么每个人都会有他们的位置、他们的伤害、他们的弹药库存等等,所以你将需要 1101 个实例。您只需要四个类。然后,您创建每个类的完整实例数组。
您还需要为每枚导弹提供一个实例。
碰撞?那么,您打算为此使用一些 3D 图形游戏库吗?它可能会处理碰撞检测。或者你的敌人都是领域吗?你需要几何...
If you've got 1101 enemies wandering around the place then each of them will have their location, their damage, their ammo stock and so on, so you will need 1101 instances. You only need four classes. Then you create a whole array of instances of each class.
You also need an instance for every missile.
Collisions? Well, are you planning on using some 3d graphics gaming library for this? It'll probably handle collision detection. Or are your enemies all spheres? You need geometry...
一点也不。您可能会将类与实例混淆,因为实际上您必须创建这些对象的 1,101 个实例,但只需要 3 个 Enemy 类的代码(或者 1 个类,如果您能说明杀死该类的属性有多么困难) )。您可能会有一个集合,例如 Enemy 的 ArrayList。
另一个答案处理碰撞,但您可能会在模型中而不是在视图代码中执行此部分。
Not at all. You may be confusing class with instance because you will in fact have to create 1,101 instances of these objects, but will only need code for 3 Enemy classes (or 1 class perhaps if you can make how hard it is to kill a property of the class). Likely you will have a collection, such as an ArrayList of Enemy.
The other answer handles collisions, but likely you will do this part in your model, not in your view code.