-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlackGhost.py
89 lines (72 loc) · 2.18 KB
/
BlackGhost.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pygame, sys, SpriteSheet, HitHexagon, Level, Globals, soundplay, math
import Entity, HurtBox, HurtBoxHandler, random, VectorMath, Attack, Enemy
SHOTCOOLDOWN = 30
class BlackGhost( Enemy.Enemy):
def __init__(self, spriteSheet, game):
super(BlackGhost, self).__init__(spriteSheet, game)
def generateProjectile(self, pos):
shotLifeLength = 200
shotSpeed = 1
attack = Attack.Attack("shot.png", self.game, pos, (4,4))
attack.damage = 5
attack.velocity = VectorMath.normalize(VectorMath.sub
(self.game.player.getMidPos(),self.getMidPos()),shotSpeed)
attack.framesToLive = shotLifeLength
return attack
def attack(self):
if(self.shotCoolDown == 0):
distance = self.distanceToPoint(self.game.player.getMidPos())
shotInitPos = VectorMath.add(self.pos, (6,3))
self.game.simpleSprites.append(self.generateProjectile(shotInitPos))
self.shotCoolDown = SHOTCOOLDOWN
Globals.SOUNDPLAYER.playSound("shoot.wav")
if(self.shotCoolDown >= 1):
self.shotCoolDown -=1
def distanceToPoint(self, point):
return VectorMath.magnitude((VectorMath.sub(self.pos,point)))
def act( self, level):
distance = self.distanceToPoint(self.game.player.getMidPos())
if(distance > 256):
speed = 0
elif(distance > 80):
self.attack()
speed = 1
elif(distance > 64):
self.attack()
speed = 0
if(random.randrange(10) == 0):
self.moveRandom()
elif(distance > 32):
speed = -2
else:
speed = -3
self.move(speed)
def moveRandom(self):
UP = 0
DOWN = 1
LEFT = 2
RIGHT = 3
speed = 1
choices = [UP, DOWN, LEFT, RIGHT]
decision = random.choice(choices)
if(decision == UP):
self.pos = (self.pos[0], self.pos[1] -speed)
if(decision == DOWN):
self.pos = (self.pos[0], self.pos[1] +speed)
if(decision == LEFT):
self.pos = (self.pos[0] -speed, self.pos[1])
if(decision == RIGHT):
self.pos = (self.pos[0] +speed, self.pos[1])
def move(self, speed):
if(speed == 0):
return
sx = self.pos[0]
sy = self.pos[1]
px = self.game.player.pos[0]
py = self.game.player.pos[1]
if(sx > px): sx -= speed
if(sx < px): sx += speed
if(sy > py): sy -= speed
if(sy < py): sy += speed
if(sy >= py): sy -= 1
self.pos = (sx,sy)