I’m working on a no-flag Apocalypse code. I have a nice and working code that does the following :
- Checks all the enemy missiles and for each i in missiles, I record the position (x_i,y_i) and time (t_i) of the explosion.
- Checks if my current position is safe, considering my (x, y) at the current time (t = this.now() )
- If the position is unsafe, I check all the positions in the area, and check which one is the closest safe-position.
It works fine. It’s unefficient on several levels, but I don’t want to optimize yet because it’s not fully functionning. The main flaw comes from the walk from one unsafe place to a safe one. If my hero were teleporting, this algorithm would be enough, but it’s not.
I need to check how safe is the walk toward the safe place, and in order to achieve this, I think I need to create a function with a similar structure to
but in my case, I need .isPathSafe.
I’m unsure of the proper way to code it. Is there better way to do it than get the equation of the line between pos1 and pos2, and for every X coordinate ( increasing 1 by 1 from pos1.x to pos2.x ), compute the associated Y closest to the line and check for each if the path is clear / safe.
Any tip ?