塔防问题

发布于 2024-11-02 12:36:21 字数 248 浏览 5 评论 0原文

我正在创建一个塔防游戏,我想制作一座发射子弹的塔,子弹击中的每个敌人都会受到损坏。子弹可以伤害多个单位。我的问题是检测子弹是否击中敌人。

现在,我已经把敌人排成了阵列。对于其他塔,当敌人在射程内时,塔会开火,当它击中原始目标时,会对该目标造成伤害。

对于我想要建造的塔,它每次都会将子弹射到最大射程,我需要它来损坏它在到达最终目的地的途中击中的每个单位。

有人对如何最好地做到这一点有任何想法吗?我想了很久,并没有想到什么有用的东西。

I am creating a tower defense game and I want to make a tower that shoots a bullet and every enemy that the bullet hits is damaged. The bullet can hurt multiple units. My problem is detecting if the bullet hits the enemies.

Right now, I have the enemies in an array. With other towers, when an enemy is in range, the tower fires and when it hits its original target, it causes damage to that target.

For the tower I want to make, it will shoot the bullet the maximum range every time and I need it to damage every unit it hits on the way to that final destination.

Anyone have any ideas on how best to do this? I been thinking it through for a while and haven't come up with anything useful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

萤火眠眠 2024-11-09 12:36:21

挑战是确定炮塔瞄准何处,还是如何确定线上目标是否被击中?

例如,创建线条的简单方法可能是:炮塔瞄准射程内的第一个敌人,绘制一条从炮塔延伸穿过该敌人的线,长度为炮塔射程的长度。在这种情况下,问题就归结为确定当前敌人是否在可接受的战线范围内。

如果你的问题是如何划清界限,也许你可以澄清问题的哪一部分是特别有问题的。

Is the challenge identifying where to aim the turret, or how to identify whether the targets on the line are struck?

For a example, a simple way to create the line might be: Turret targets first enemy in range, draw a line extending from turret through that enemy for the length of the turret range. In that case, the problem comes down to determining whether the current enemies are within acceptable range of the line.

If your problem is instead how to draw the line, perhaps you could clarify what part of the problem is an issue in particular.

回忆那么伤 2024-11-09 12:36:21

最好的方法是在火灾事件上创建一个子弹对象。子弹需要跟踪几件事。

  • 速度
  • 击中时行进的距离
  • 敌人

按每帧的速度移动子弹。检查距离是否大于塔的最大范围。如果是,就毁掉它。仅当敌人尚未被击中时才创建与敌人的碰撞事件。

The best way to do this is to create a bullet object on the fire event. There are several things a bullet needs to keep track of.

  • velocity
  • distance traveled
  • enemy hit

Move the bullet by its velocity each frame. Check if the distance is greater than the tower's maximum range. If it is, destroy it. Only create a collision event with enemies if the enemy has not been hit yet.

挽手叙旧 2024-11-09 12:36:21

使用命中测试点方法。

if(enemy.hitTestPoint(bullet.x,buttet.y) {
  dosomething()
}

对于数组:

for (var i:int = 0;i<enemyArray.lenght;i++) 
if(enemyArray[i].hitTestPoint(bullet.x,buttet.y) {
  dosomething()
}

Use hittestpoint method.

if(enemy.hitTestPoint(bullet.x,buttet.y) {
  dosomething()
}

for the array:

for (var i:int = 0;i<enemyArray.lenght;i++) 
if(enemyArray[i].hitTestPoint(bullet.x,buttet.y) {
  dosomething()
}
卖梦商人 2024-11-09 12:36:21

这个问题很模糊。

一般来说,你想要:

每帧创建一颗子弹

更新它的位置

检查它是否击中了距塔的最大距离,如果是的话杀死子弹

检查子弹是否击中了阵列中的敌人

如果击中敌人会触发爆炸或某些某种视觉提示和/或声音效果,并施加伤害等

——只允许它击中敌人一次——你可以通过在子弹中跟踪它来做到这一点。 ——也就是说,它已经击中了一系列敌人。

您了解如何对这些项目中的每一项进行编码吗?

This question is very vague.

In general you want to :

create a bullet

each frame update it's location

check if it has hit the max distance from tower, if so kill the bullet

check if bullet has hit an enemy in your array

if an enemy is hit trigger an explosion or some kind of visual cue and or sound effect, and apply damage etc.

--only allow it to hit the enemy once - you can do this by tracking it in the bullet. -- ie have an array of enemies it has hit.

Do you understand how to code each of these items ?

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