From fb8a00a1da3bdbb4c3dd9e4f043a7998b4ac5d41 Mon Sep 17 00:00:00 2001 From: kleph Date: Tue, 23 Feb 2010 23:24:35 +0100 Subject: [PATCH] added aiming to bullet type 2 --- pyshoot.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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):