-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlien.py
More file actions
36 lines (30 loc) · 1.17 KB
/
Copy pathAlien.py
File metadata and controls
36 lines (30 loc) · 1.17 KB
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
import globals
from groups import *
class Alien(pg.sprite.Sprite):
def __init__(self, x, y, kind):
pg.sprite.Sprite.__init__(self)
self.kind = kind
self.anim = 1
self.image = pg.image.load(f"sprites/alien_{self.kind}_{self.anim}.png")
self.rect = self.image.get_rect()
self.rect.center = [x, y]
self.count = 0
self.dir = 18
self.delay = 42 - 12 * globals.difficult_aliens
def update(self):
self.count += self.dir // abs(self.dir)
if abs(self.count) >= self.delay * 10:
self.dir *= -1
self.rect.y += 20
elif self.count % self.delay == 0:
self.rect.x += self.dir
self.anim *= -1
self.image = pg.image.load(f"sprites/alien_{self.kind}_{self.anim}.png")
if pg.sprite.spritecollide(self, bullet_group, True):
globals.score += 10 + 10 * (2 - self.kind)
self.kill()
if self.rect.bottom > globals.player.rect.top:
globals.player.image = pg.image.load("sprites/player_death.png")
alien_group.empty()
globals.player.isKilled = True
globals.player.hp = 0