-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.py
50 lines (43 loc) · 1.4 KB
/
Enemy.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
import pygame
from Weapons import Bullet
class Enemy(pygame.sprite.Sprite):
def __init__(self, pic, x, y):
pygame.sprite.Sprite.__init__(self)
self.pic = pic
self.image = pic[0]
self.rect = self.image.get_rect()
self.rect.left = x
self.rect.bottom = y
self.speed = 1
self.gravity = 3
self.fallSpeed = 0
self.toMove = True
self.picCount = 0
self.isFacing = "L"
self.timeAlive = 0
self.canGoR = True
self.canGoL = True
def move(self, x):
# the enemy moves towards the target it is given
if self.toMove:
if x > self.rect.right and self.canGoR:
self.rect.centerx += self.speed
self.image = self.pic[1]
self.isFacing = "R"
elif x < self.rect.left and self.canGoL:
self.rect.centerx -= self.speed
self.image = self.pic[0]
self.isFacing = "L"
else:
pass
def shoot(self, pic, group, x, y, direction):
# shoots a bullet
group.add(Bullet(pic, x, y, direction))
def kill(self):
pygame.sprite.Sprite.kill(self)
def fall(self):
self.rect.y += self.fallSpeed
self.fallSpeed += self.gravity
def changePic(self, pic):
# changes picture for the explosion animation
self.image = pic