M
Matthew 123 S
Guest
So, I'm designing a tower defense game. I need to remove "bullets" from a list when they hit an enemy. Here, k is each bullet, and j is each tower. Each tower has a list of projectiles. I need to (at least I think I need to) remove the projectile from the list in this loop. However, when I remove it, the loop still executes the number of times it would have if there were no change so I get an error when I reference k inside the loop to check if the projectile hit the troll. I would appreciate help with this method as I don't have much time to learn a new strategy to accomplish my goal. You can ignore the 4 Pythagorean theorems to check if a bullet hit an enemy.
TL;DR: How do you/is it possible to modify the maximum value of the counter of a for loop inside the loop.
For k As Integer = 0 To tower1Projectiles(j).Count - 1
If ((Math.Sqrt(tower1ProjectilesAimLocation(i)(k)(0) - trollAimLocations(j)(0)) ^ 2) < tower1Projectiles(i)(k).Size.Width + trolls(j).Size.Width) Or ((Math.Sqrt(tower1ProjectilesAimLocation(i)(k)(0) - trollAimLocations(j)(0)) ^ 2) * -1 > tower1Projectiles(i)(k).Size.Width + trolls(j).Size.Width) * -1 Or ((Math.Sqrt(tower1ProjectilesAimLocation(i)(k)(1) - trollAimLocations(j)(1)) ^ 2) < tower1Projectiles(i)(k).Size.Height + trolls(j).Size.Height) Or ((Math.Sqrt(tower1ProjectilesAimLocation(i)(k)(1) - trollAimLocations(j)(1)) ^ 2) * -1 < tower1Projectiles(i)(k).Size.Height + trolls(j).Size.Height) * -1 Then
trollsHealth(j) -= tower1ProjectileDamage
Controls.Remove(tower1Projectiles(i)(j))
tower1ProjectilesTimerPerTower(i).RemoveAt(j)
tower1Projectiles(i).RemoveAt(j)
xMovement(i).RemoveAt(j)
yMovement(i).RemoveAt(j)
End If
Continue reading...
TL;DR: How do you/is it possible to modify the maximum value of the counter of a for loop inside the loop.
For k As Integer = 0 To tower1Projectiles(j).Count - 1
If ((Math.Sqrt(tower1ProjectilesAimLocation(i)(k)(0) - trollAimLocations(j)(0)) ^ 2) < tower1Projectiles(i)(k).Size.Width + trolls(j).Size.Width) Or ((Math.Sqrt(tower1ProjectilesAimLocation(i)(k)(0) - trollAimLocations(j)(0)) ^ 2) * -1 > tower1Projectiles(i)(k).Size.Width + trolls(j).Size.Width) * -1 Or ((Math.Sqrt(tower1ProjectilesAimLocation(i)(k)(1) - trollAimLocations(j)(1)) ^ 2) < tower1Projectiles(i)(k).Size.Height + trolls(j).Size.Height) Or ((Math.Sqrt(tower1ProjectilesAimLocation(i)(k)(1) - trollAimLocations(j)(1)) ^ 2) * -1 < tower1Projectiles(i)(k).Size.Height + trolls(j).Size.Height) * -1 Then
trollsHealth(j) -= tower1ProjectileDamage
Controls.Remove(tower1Projectiles(i)(j))
tower1ProjectilesTimerPerTower(i).RemoveAt(j)
tower1Projectiles(i).RemoveAt(j)
xMovement(i).RemoveAt(j)
yMovement(i).RemoveAt(j)
End If
Continue reading...