-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEnemy.py
58 lines (52 loc) · 2.27 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
51
52
53
54
55
56
57
58
#A villianous enemy
import pygame
import os
class Enemy(pygame.sprite.Sprite):
def __init__(self, right, speed):
pygame.sprite.Sprite.__init__(self)
self.HP = 5
self.image = 0
self.framenumber = 0
self.right = right
self.images = [pygame.image.load(os.path.join(os.curdir, 'groundenemy1.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'groundenemy2.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'groundenemy3.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'groundenemy4.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'groundenemy5.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'groundenemy6.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'groundenemy7.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'groundenemy8.png')).convert_alpha()]
self.rect = self.images[self.image].get_rect()
if right == True:
self.x = 1280
self.y = 600
self.speed = -speed
else:
self.x = 0
self.y = 600
self.speed = speed
self.rect = self.rect.move(self.x, self.y)
self.boss = False
def updateEnemySprite(self, framestart, totalframes):
self.framenumber += 0.33
if(self.framenumber > framestart + totalframes or self.framenumber < framestart):
self.framenumber = framestart
self.image = (int(self.framenumber)) % totalframes + framestart
def updateEnemyPos(self,enemyList, index):
#self.image = (self.image + 1) % 8
if(self.right):
self.updateEnemySprite(4,4)
else:
self.updateEnemySprite(0,4)
if self.x + self.speed < 513 or self.x + self.speed > 715:
self.x += self.speed
self.rect = self.rect.move(self.speed,0)
else:
enemyList.pop(index)
return True
return False
def Hit(self, enemyList, index, dmg):
self.HP = self.HP - dmg
if self.HP < 1:
enemyList.pop(index)
return True;