dodalem stan, postac sie rusza tylko do przodu

This commit is contained in:
Paralyzecl 2023-04-21 13:11:47 +02:00
parent bf66823c64
commit f5b66bcf83
7 changed files with 68 additions and 8 deletions

View File

@ -5,19 +5,22 @@ class Agent(pygame.sprite.Sprite):
def __init__(self, game, x, y): def __init__(self, game, x, y):
self.game = game self.game = game
self.groups = self.game.all_sprites self.groups = self.game.all_sprites
pygame.sprite.Sprite.__init__(self, self.groups) pygame.sprite.Sprite.__init__(self, self.groups)
# direction =['right','down','left','up'] 0 1 2 3 kierunek w ktory po kliknieciu do przodu pojdzie
self.AGENT_IMAGES =['gandalf-prawo','gandalf-dol','gandalf-lewo','gandalf-gora']
self.x = x * TILE_SIZE self.x = x * TILE_SIZE
self.y = y * TILE_SIZE self.y = y * TILE_SIZE
self.width = TILE_SIZE self.width = TILE_SIZE
self.height = TILE_SIZE self.height = TILE_SIZE
self.direction=0 #najpierw patrzy sie w prawo
self.x_change = 0 self.x_change = 0
self.y_change = 0 self.y_change = 0
self.AGENT_IMG = pygame.image.load("./zdjecia/gandalf.png") #self.AGENT_IMG = pygame.image.load("./zdjecia/"+self.AGENT_IMAGES[self.direction]+".png")
self.AGENT_IMG = pygame.image.load("./zdjecia/gandalf-dol.png")
self.AGENT = pygame.transform.scale(self.AGENT_IMG,(64,64)) self.AGENT = pygame.transform.scale(self.AGENT_IMG,(64,64))
self.image = pygame.Surface([self.width, self.height]) self.image = pygame.Surface([self.width, self.height])
@ -38,10 +41,15 @@ class Agent(pygame.sprite.Sprite):
def update(self): def update(self):
self.health_bar() self.health_bar()
self.movement() self.movement()
self.collide_mob() self.collide_mob()
#self.end_game() gra sie konczy gdy wie gdzie sa wszyscy
self.disp_level() self.disp_level()
self.rect.x += self.x_change self.rect.x += self.x_change
self.collide_blocks('x') self.collide_blocks('x')
@ -50,9 +58,31 @@ class Agent(pygame.sprite.Sprite):
self.x_change = 0 self.x_change = 0
self.y_change = 0 self.y_change = 0
def movement(self): def movement(self):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
self.direction=(self.direction-1)%4
print("DIRECTION: "+self.AGENT_IMAGES[self.direction])
if keys[pygame.K_RIGHT]:
self.direction=(self.direction+1)%4
print("DIRECTION: "+self.AGENT_IMAGES[self.direction])
if keys[pygame.K_UP]:
if self.direction==0 and self.rect.x < 832 - 64:
self.x_change += TILE_SIZE/2
if self.direction==1 and self.rect.y < 768 - 64:
self.y_change += TILE_SIZE/2
if self.direction==2 and self.rect.x > 0:
self.x_change -= TILE_SIZE/2
if self.direction==3 and self.rect.y > 0:
self.y_change -= TILE_SIZE/2
"""
if keys[pygame.K_LEFT] and self.rect.x > 0: if keys[pygame.K_LEFT] and self.rect.x > 0:
self.x_change -= TILE_SIZE self.x_change -= TILE_SIZE
if keys[pygame.K_RIGHT] and self.rect.x < 832 - 64: if keys[pygame.K_RIGHT] and self.rect.x < 832 - 64:
@ -61,7 +91,13 @@ class Agent(pygame.sprite.Sprite):
self.y_change -= TILE_SIZE self.y_change -= TILE_SIZE
if keys[pygame.K_DOWN] and self.rect.y < 768 - 64: if keys[pygame.K_DOWN] and self.rect.y < 768 - 64:
self.y_change += TILE_SIZE self.y_change += TILE_SIZE
"""
def end_game(self):
if (-1 in self.game.state)==False:
pygame.quit()
def collide_blocks(self, direction): def collide_blocks(self, direction):
if direction == "x": if direction == "x":
hits = pygame.sprite.spritecollide(self,self.game.rock_sprites, False) hits = pygame.sprite.spritecollide(self,self.game.rock_sprites, False)
@ -100,37 +136,58 @@ class Agent(pygame.sprite.Sprite):
self.game.new() self.game.new()
else: else:
self.game.archer_ork.kill() self.game.archer_ork.kill()
self.game.state[0]=self.game.archer_ork.x
self.game.state[1]=self.game.archer_ork.y
print(self.game.state)
self.get_damage(self.game.archer_ork.damage) self.get_damage(self.game.archer_ork.damage)
self.level+=self.level self.level=self.level+1
#zmniejszenie życia o damage moba #zmniejszenie życia o damage moba
#level up #level up
if hits_infantry_ork: if hits_infantry_ork:
if self.game.infantry_ork.level > self.level or self.game.infantry_ork.damage > self.current_health: if self.game.infantry_ork.level > self.level or self.game.infantry_ork.damage > self.current_health:
self.game.state[2]=self.game.infantry_ork.x
self.game.state[3]=self.game.infantry_ork.y
print(self.game.state)
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
self.game.state[2]=self.game.infantry_ork.x
self.game.state[3]=self.game.infantry_ork.y
print(self.game.state)
self.game.infantry_ork.kill() self.game.infantry_ork.kill()
self.get_damage(self.game.infantry_ork.damage) self.get_damage(self.game.infantry_ork.damage)
self.level+=self.level self.level=self.level+1
#zmniejszenie życia o damage moba #zmniejszenie życia o damage moba
#level up #level up
if hits_infantry_ork2: if hits_infantry_ork2:
if self.game.infantry_ork2.level > self.level or self.game.infantry_ork2.damage > self.current_health: if self.game.infantry_ork2.level > self.level or self.game.infantry_ork2.damage > self.current_health:
self.game.state[4]=self.game.infantry_ork2.x
self.game.state[5]=self.game.infantry_ork2.y
print(self.game.state)
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
self.game.state[4]=self.game.infantry_ork2.x
self.game.state[5]=self.game.infantry_ork2.y
print(self.game.state)
self.game.infantry_ork2.kill() self.game.infantry_ork2.kill()
self.get_damage(self.game.infantry_ork2.damage) self.get_damage(self.game.infantry_ork2.damage)
self.level+=self.level self.level=self.level+1
#zmniejszenie życia o damage moba #zmniejszenie życia o damage moba
#level up #level up
if hits_sauron: if hits_sauron:
if self.game.sauron.level > self.level or self.game.sauron.damage > self.current_health: if self.game.sauron.level > self.level or self.game.sauron.damage > self.current_health:
self.game.state[6]=self.game.sauron.x
self.game.state[7]=self.game.sauron.y
print(self.game.state)
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
self.game.state[6]=self.game.sauron.x
self.game.state[7]=self.game.sauron.y
print(self.game.state)
self.game.sauron.kill() self.game.sauron.kill()
self.level+=self.level self.level=self.level+1
pygame.quit() pygame.quit()
#zmniejszenie życia o damage moba #zmniejszenie życia o damage moba
#level up #level up
@ -158,9 +215,11 @@ class Agent(pygame.sprite.Sprite):
def disp_level(self): def disp_level(self):
font = pygame.font.SysFont(None, 40) font = pygame.font.SysFont(None, 40)
lvlDisplay = font.render(str(self.level), 1, WHITE) lvlDisplay = font.render(str(self.level)+" "+str(self.direction), 1, WHITE)
#lvlDisplay = font.render(str(self.level), 1, WHITE)
pygame.draw.rect(self.game.SCREEN, BLACK, (370, 780, 40, 40)) pygame.draw.rect(self.game.SCREEN, BLACK, (370, 780, 40, 40))
self.game.SCREEN.blit(lvlDisplay, (370,780)) self.game.SCREEN.blit(lvlDisplay, (370,780))
# brakuje levelowania postaci gdy zabije moba, jest zrobione tylko, że jeśli za wysoki poziom, lub brak życia to ginie i od nowa zaczyna # brakuje levelowania postaci gdy zabije moba, jest zrobione tylko, że jeśli za wysoki poziom, lub brak życia to ginie i od nowa zaczyna
# brakuje dodania miejsca w którym agent się leczy # brakuje dodania miejsca w którym agent się leczy

View File

@ -12,6 +12,7 @@ class Game:
def __init__(self): def __init__(self):
pygame.init() pygame.init()
self.state =[-1,-1,-1,-1,-1,-1,-1,-1]
self.SCREEN = pygame.display.set_mode((WIDTH, HEIGHT)) self.SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))
self.running = True self.running = True
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()

BIN
zdjecia/gandalf-dol.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

BIN
zdjecia/gandalf-gora.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

BIN
zdjecia/gandalf-lewo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

BIN
zdjecia/gandalf-prawo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 KiB