added aiming to bullet type 2
This commit is contained in:
parent
1045707f72
commit
fb8a00a1da
1 changed files with 14 additions and 3 deletions
17
pyshoot.py
17
pyshoot.py
|
@ -8,7 +8,7 @@ import pygame
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
from math import sqrt,pow,ceil,floor
|
||||||
|
|
||||||
# constants
|
# constants
|
||||||
SCREEN_X = 640
|
SCREEN_X = 640
|
||||||
|
@ -248,13 +248,24 @@ class Enemy(Object):
|
||||||
def aim_player(self):
|
def aim_player(self):
|
||||||
""" compute speed vector to aim at current player position """
|
""" compute speed vector to aim at current player position """
|
||||||
# get player position
|
# get player position
|
||||||
|
localspeed = 5
|
||||||
|
|
||||||
player_pos = globals.player.rect
|
player_pos = globals.player.rect
|
||||||
direction = (player_pos[0] - self.rect[0], player_pos[1] - self.rect[1])
|
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):
|
def aim(self):
|
||||||
""" set bullet speed """
|
""" set bullet speed """
|
||||||
return (-10, 0)
|
return self.aim_player()
|
||||||
|
# return (-10, 0)
|
||||||
|
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
|
|
Loading…
Reference in a new issue