英文:
Java Game: Shooting multiple players at same time
问题
我正在开发一个游戏,玩家可以射击子弹。我正在遍历游戏中活跃玩家的列表,并在玩家附近开枪射击。它基本上是有效的,除了一个情况:当两名或更多玩家同时彼此射击时。
**问题:**
当两名玩家互相射击(同时射出相同数量的子弹)时,一名玩家死亡,但另一名玩家仍然存活。
**结果:**
两名玩家应该同时死亡。
在这种情况下,我该如何实现两名玩家都应该死亡?
我认为这与其中一个for循环有关。因为列表中的第一个玩家会先射击,所以第二名玩家将首先达到最大伤害,然而我希盼他们能够同时达到最大伤害。
游戏的运行方式:
动画在单个回合内发生,倒计时并执行放置的移动。
每个回合有4个移动槽
```python
对于(玩家p:listRegisteredPlayers()){
如果(!p.isDamageMaxed()&&!p.isSunk()){
// 如果他们与任何人发生碰撞,则应用伤害
damagePlayers(leftShoots,p,Direction.LEFT,slot);
damagePlayers(rightShoots,p,Direction.RIGHT,slot);
}
如果(p.isDamageMaxed()&&!p.isSunk()){
p.setSunk(slot);
}
}
}
英文:
I'm working on a game where players can shoot bullets. I am iterating through list of active players in the game, and shooting at players if they are near. It works mostly except for a case when two or more players are shooting at each other at the same time.
Issue:
When two players shoot at each other (same amount of bullets at same time), one dies but other still stays alive.
Result:
Both players should die at the same time.
How would I implement this case where both players should die?
I think it has to deal with one of the for loop. Since the first player in the list will shoot first the second player will reach maxDamage first, however I want them to reach maxDamage at the same time.
How the game works:
The animations happen in a single turn which counts down and executes the moves placed.
There are 4 move slots for every turn
for (Player p : listRegisteredPlayers()) {
if (!p.isDamageMaxed() && !p.isSunk()) {
// Apply damages if they collided with anyone
damagePlayers(leftShoots, p, Direction.LEFT, slot);
damagePlayers(rightShoots, p, Direction.RIGHT, slot);
}
if (p.isDamageMaxed() && !p.isSunk()) {
p.setSunk(slot);
}
}
}
答案1
得分: 3
你描述的行为明确表示,如果有人死亡,那么他就不能再射击。现在,玩家1向玩家2开火,玩家2向玩家1开火。现在,在您的情况下似乎发生了这种情况:
玩家1向玩家2开枪
玩家2死亡
玩家2因为已经死亡而无法进行射击
解决方案似乎是将射击与伤害分开。您需要实现一个循环,在这个循环中进行射击,但玩家还不会立即死亡。您只需计算他们的伤害,并从他们的生命值中减去,但在循环结束时,他们仍应该活着。然后,在下一个循环中评估玩家的健康状况,并确保应该死亡的玩家确实死亡。
如果您需要更多细节,您需要提供更多细节。
英文:
The behavior you describe clearly means that if someone is dead, then he no longer can shoot. Now, player1 shoots on player2 and player2 shoots on player1. Now, this seems to happen in your case:
> player1 shoots player2
>
> player2 dies
>
> player2 does not shoot because
> he's dead
The solution seems to be to separate shooting from damage. You need to implement a loop where the shooting happens, but the players do not die yet. You just compute their damage and reduce that from their life, but they should be still alive at the end of the loop. Then, in a next loop evaluate the health of players and ensure that whoever should die dies.
If you need more details, then you will need to provide more details.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论