检查许多导弹和敌人之间是否有交集?

发布于 2024-10-16 00:52:13 字数 358 浏览 0 评论 0原文

我想创建一个类,可以说称为敌人 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只为一人 2024-10-23 00:52:13

如果你有 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...

悸初 2024-10-23 00:52:13

因此,为一场只有敌人的游戏创建 1,101 个不同的实例是愚蠢的。这将需要大量代码。

一点也不。您可能会将类与实例混淆,因为实际上您必须创建这些对象的 1,101 个实例,但只需要 3 个 Enemy 类的代码(或者 1 个类,如果您能说明杀死该类的属性有多么困难) )。您可能会有一个集合,例如 Enemy 的 ArrayList。

另一个答案处理碰撞,但您可能会在模型中而不是在视图代码中执行此部分。

So it would be stupid to make 1,101 different instances for a game of just enemy. It would require to much code.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文