-
Notifications
You must be signed in to change notification settings - Fork 0
/
laser.py
54 lines (44 loc) · 2.17 KB
/
laser.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
from player import Player
from states import States
class Laser(Player):
def __init__(self, x, y, sprite):
Player.__init__(self, x, y - 7, sprite)
self.inActiveY = y - 7
self.active = False
def move(self, rocketShipX, galaxians):
if self.active:
# updates the sprite and hit rectangle
Player.move(self)
state = States()
for f in range(len(galaxians)):
if self.hitArea.colliderect(galaxians[f].hitArea):
x_offset = self.hitArea[0] - galaxians[f].hitArea[0]
y_offset = self.hitArea[1] - galaxians[f].hitArea[1]
if galaxians[f].getMask().overlap(self.mask, (x_offset, y_offset)):
galaxians[f].destroyed = True
if galaxians[f].state == state.FORMATION_DIVING and galaxians[f].colour == "red":
self.adjustTeam(galaxians, galaxians[f])
self.active = False
# no BREAK - let it run through array of galaxians,
# because a laser can destroy multiple galaxians
# only move if active other wise reinitialise back to rocket ship position
if self.active:
self.y -= 12
if self.y < 30:
self.active = False
self.reinit(rocketShipX)
else:
self.reinit(rocketShipX)
else:
self.reinit(rocketShipX)
def reinit(self, x):
self.x = x
self.y = self.inActiveY
"""
if the laser hits a red galaxian and it's state is FORMATION_DIVING then the leader needs to adjust it's
diving team to reflect 1 less in team and increases bonus score if the leader gets destroyed as well"""
def adjustTeam(self, galaxians, redGalaxian):
for f in range(len(galaxians)):
if galaxians[f].number == redGalaxian.leadNumber:
galaxians[f].reduceDivingArray(redGalaxian.number)
return