added aiming to bullet type 2

This commit is contained in:
kleph 2010-02-23 23:24:35 +01:00
parent 1045707f72
commit fb8a00a1da

View file

@ -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):