0

I am making game in Python with Pygame in which you spawn your soldiers wich are moving to enemy base. Problem is I can only create melee soldiers, and when they collide with enemy spirte they hit each other, but I dont know how to check for example if a sprite is 100px from enemy sprite so that soldier can shoot and deal damage? If anyone knows how is this done please answer, thank you!

  • 1
    Pythagoras: `a^2 + b^2 = c^2` where `a = soldier_x - enemy_x`, `b = solder_y - enemy_y` and `c` is distance between soldier and enemy. https://en.wikipedia.org/wiki/Pythagorean_theorem – furas Dec 16 '15 at 11:42
  • 1
    You could use the square of the distance to save doing a square root operation. – Peter Wood Dec 16 '15 at 11:56

0 Answers0