diff --git a/pyshoot.py b/pyshoot.py index 7c88945..832c6b9 100755 --- a/pyshoot.py +++ b/pyshoot.py @@ -8,7 +8,7 @@ import pygame from pygame.locals import * import os import random - +from math import sqrt,pow,ceil,floor # constants SCREEN_X = 640 @@ -248,13 +248,24 @@ class Enemy(Object): def aim_player(self): """ compute speed vector to aim at current player position """ # get player position + localspeed = 5 + player_pos = globals.player.rect direction = (player_pos[0] - self.rect[0], player_pos[1] - self.rect[1]) - # norm = + norm = sqrt(pow(direction[0], 2) + pow(direction[1], 2)) + speed = (direction[0] / norm, direction[1] / norm) + speed2 = (ceil(speed[0] * localspeed), floor(speed[1]) * localspeed) + print "direction: " + str(direction) + print "norm: " + str(norm) + print "speed: " + str(speed) + print "speed2: " + str(speed2) + print + return speed2 def aim(self): """ set bullet speed """ - return (-10, 0) + return self.aim_player() + # return (-10, 0) def die(self):