import pygame, random, os
weak = 1
strong = 2
class Enemy(pygame.sprite.Sprite):
def __init__(self,disp,enemytype):
pygame.init()
self.screen = disp
pygame.sprite.Sprite.__init__(self)
if enemytype == weak:
self.enemytype = weak
self.image = pygame.image.load(os.path.join("images", "enemy1.png"))
self.dx = 2.5
self.hp = 1
if enemytype == strong:
self.enemytype = strong
self.image = pygame.image.load(os.path.join("images", "enemy2.png"))
self.dx = 5
self.hp = 2
self.image = self.image.convert()
self.rect = self.image.get_rect()
self.rect.left = self.screen.get_width()
self.rect.centery = random.randrange(0, self.screen.get_height())
self.moving = False
def update(self):
if self.moving == True:
self.rect.centerx -= self.dx
if self.rect.right < 0:
self.reset()
if self.hp == 0:
self.reset()
def reset(self):
self.rect.left = self.screen.get_width()
self.rect.centery = random.randrange(0, self.screen.get_height())
self.moving = False
if self.enemytype == weak:
self.hp = 1
elif self.enemytype == strong:
self.hp = 2
Не удаляется фон, после смены картинки