You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.5 KiB
74 lines
2.5 KiB
class Enemy(pygame.sprite.Sprite):
|
|
def __init__(self, x, y, heart, health):
|
|
super().__init__()
|
|
self.image = pygame.image.load("elf.png").convert_alpha()
|
|
self.rect = self.image.get_rect()
|
|
self.rect.center = (x, y)
|
|
|
|
self.image = pygame.transform.smoothscale(self.image, (self.rect.w * screen_scale_factor, self.rect.h * screen_scale_factor) )
|
|
|
|
|
|
self.path = 0
|
|
self.health = health
|
|
self.alive = 1
|
|
self.heart = heart
|
|
self.speed = 2 *screen_scale_factor
|
|
|
|
def damage(self, amount):
|
|
self.health = self.health - amount
|
|
if(self.health <= 0):
|
|
self.alive = 0
|
|
|
|
|
|
def move(self, player):
|
|
if (self.path == 0):
|
|
if (self.rect.right < 300 *screen_scale_factor):
|
|
self.rect.move_ip(self.speed,0)
|
|
else:
|
|
self.path = 1
|
|
if (self.path == 1):
|
|
if(self.rect.bottom < 890 *screen_scale_factor):
|
|
self.rect.move_ip(0,self.speed)
|
|
else:
|
|
self.path = 2
|
|
if(self.path == 2):
|
|
if(self.rect.right < 1128 *screen_scale_factor):
|
|
self.rect.move_ip(self.speed,0)
|
|
else:
|
|
self.path = 3
|
|
if (self.path == 3):
|
|
if(self.rect.top > 516*screen_scale_factor):
|
|
self.rect.move_ip(0,-self.speed)
|
|
else:
|
|
self.path = 4
|
|
if (self.path == 4):
|
|
if(self.rect.left > 847*screen_scale_factor):
|
|
self.rect.move_ip(-self.speed,0)
|
|
else:
|
|
self.path = 5
|
|
if (self.path == 5):
|
|
if(self.rect.top > 246*screen_scale_factor):
|
|
self.rect.move_ip(0,-self.speed)
|
|
else:
|
|
self.path = 6
|
|
if (self.path == 6):
|
|
if (self.rect.right < 1248*screen_scale_factor):
|
|
self.rect.move_ip(self.speed,0)
|
|
else:
|
|
self.path = 7
|
|
if (self.path == 7):
|
|
if (self.rect.bottom < 570*screen_scale_factor):
|
|
self.rect.move_ip(0,self.speed)
|
|
else:
|
|
self.path = 8
|
|
if (self.path == 8):
|
|
if (self.rect.right < 1548*screen_scale_factor):
|
|
self.rect.move_ip(self.speed,0)
|
|
else:
|
|
self.path = 'end'
|
|
if (self.path == 'end'):
|
|
self.alive = 0
|
|
self.heart.lives -= 20
|
|
|
|
def draw(self, surface):
|
|
surface.blit(self.image, self.rect)
|