gdy agent walczy ze zbyt wysokim poziomem ginie

This commit is contained in:
Weranda 2023-03-30 22:09:13 +02:00
parent 562ad9efdd
commit c5f00fc058
11 changed files with 42 additions and 4 deletions

Binary file not shown.

Binary file not shown.

View File

@ -32,6 +32,7 @@ class Agent(pygame.sprite.Sprite):
def update(self):
self.movement()
self.collide_mob()
self.rect.x += self.x_change
self.collide_blocks('x')
@ -68,3 +69,36 @@ class Agent(pygame.sprite.Sprite):
self.rect.y = hits[0].rect.top - self.rect.height
if self.y_change < 0:
self.rect.y = hits[0].rect.bottom
def collide_mob(self):
hits_archer_ork = pygame.sprite.spritecollide(self, self.game.archer_orks, False)
hits_infantry_ork = pygame.sprite.spritecollide(self, self.game.infantry_orks, False)
hits_infantry_ork2 = pygame.sprite.spritecollide(self, self.game.infantry_orks2, False)
hits_sauron = pygame.sprite.spritecollide(self, self.game.sauronL, False)
if hits_archer_ork:
if self.game.archer_ork.level > self.level:
self.kill()
self.game.new()
else:
self.game.archer_ork.kill()
if hits_infantry_ork:
if self.game.infantry_ork.level > self.level:
self.kill()
self.game.new()
else:
self.game.infantry_ork.kill()
if hits_infantry_ork2:
if self.game.infantry_ork2.level > self.level:
self.kill()
self.game.new()
else:
self.game.infantry_ork2.kill()
if hits_sauron:
if self.game.sauron.level > self.level:
self.kill()
self.game.new()
else:
self.game.sauron.kill()
# brakuje levelowania postaci gdy zabije moba, jest zrobione tylko, że jeśli za wysoki poziom to ginie i od nowa zaczyna

View File

@ -6,7 +6,7 @@ class Archer_ork(pygame.sprite.Sprite):
def __init__(self, game, x, y):
self.game = game
self.groups = self.game.all_sprites
self.groups = self.game.all_sprites, self.game.archer_orks
pygame.sprite.Sprite.__init__(self, self.groups)
self.x = x * TILE_SIZE

View File

@ -6,7 +6,7 @@ class Infantry_ork(pygame.sprite.Sprite):
def __init__(self, game, x, y):
self.game = game
self.groups = self.game.all_sprites
self.groups = self.game.all_sprites, self.game.infantry_orks
pygame.sprite.Sprite.__init__(self, self.groups)
self.x = x * TILE_SIZE

View File

@ -6,7 +6,7 @@ class Infantry_ork2(pygame.sprite.Sprite):
def __init__(self, game, x, y):
self.game = game
self.groups = self.game.all_sprites
self.groups = self.game.all_sprites, self.game.infantry_orks2
pygame.sprite.Sprite.__init__(self, self.groups)
self.x = x * TILE_SIZE

View File

@ -25,6 +25,10 @@ class Game:
def new(self): # tworzy się nowa sesja grania
self.all_sprites = pygame.sprite.LayeredUpdates()
self.rock_sprites = pygame.sprite.LayeredUpdates()
self.archer_orks = pygame.sprite.LayeredUpdates()
self.infantry_orks = pygame.sprite.LayeredUpdates()
self.infantry_orks2 = pygame.sprite.LayeredUpdates()
self.sauronL = pygame.sprite.LayeredUpdates()
self.agent = Agent(self,1,1)
self.archer_ork = Archer_ork(self,10,10)
self.infantry_ork = Infantry_ork(self,5,1)

View File

@ -6,7 +6,7 @@ class Sauron(pygame.sprite.Sprite):
def __init__(self, game, x, y):
self.game = game
self.groups = self.game.all_sprites
self.groups = self.game.all_sprites, self.game.sauronL
pygame.sprite.Sprite.__init__(self, self.groups)
self.x = x * TILE_SIZE