'Finding the distance between points, specifically in x and y values
I've been trying to develop a sort of, arena shooter using John Zelle's graphics library, and I've run into a snag when trying to make the enemies move. Zelle's graphics.move() function only takes an x value (x distance) and a y value (y distance), so finding the distance between the player and the enemy using the distance formula won't work. Is there any way I could get the distance between these point in a form of like, Move 3 meters x and 5 meters y? If I had that I could fix this problem.
Here's the code portion I have so far, you can see I've been trying things.
def moveEnemies(self, target):
#Tells enemies to move towards the player using rise over run calculation
for enemy in self.enemyList:
#dTarget = sqrt(pow((target.xpos-enemy.xpos),2)+pow((target.ypos-enemy.ypos),2))
#enemy.move(dTarget//120,dTarget//120)
enemy.move()
if enemy.visual == True:
bullet = enemy.fire(player)
self.bulletList.append(bullet)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
