health bar

This commit is contained in:
wojciech goralewski 2023-04-18 21:38:22 +02:00
parent 82b21db6c4
commit a8036b32a1
9 changed files with 44 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -29,9 +29,15 @@ class Agent(pygame.sprite.Sprite):
self.rect.y = self.y self.rect.y = self.y
self.level = 1 self.level = 1
self.health = 10000*self.level
self.current_health = 500
self.max_health = 1000
self.health_bar_length = 300
self.health_ratio = self.max_health/self.health_bar_length
def update(self): def update(self):
self.health_bar()
self.movement() self.movement()
self.collide_mob() self.collide_mob()
@ -46,13 +52,13 @@ class Agent(pygame.sprite.Sprite):
def movement(self): def movement(self):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
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/2 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:
self.x_change += TILE_SIZE/2 self.x_change += TILE_SIZE
if keys[pygame.K_UP] and self.rect.y > 0: if keys[pygame.K_UP] and self.rect.y > 0:
self.y_change -= TILE_SIZE/2 self.y_change -= TILE_SIZE
if keys[pygame.K_DOWN] and self.rect.y < 832 - 64: if keys[pygame.K_DOWN] and self.rect.y < 768 - 64:
self.y_change += TILE_SIZE/2 self.y_change += TILE_SIZE
def collide_blocks(self, direction): def collide_blocks(self, direction):
if direction == "x": if direction == "x":
@ -87,37 +93,37 @@ class Agent(pygame.sprite.Sprite):
if hits_archer_ork: if hits_archer_ork:
if self.game.archer_ork.level > self.level or self.game.archer_ork.damage > self.health: if self.game.archer_ork.level > self.level or self.game.archer_ork.damage > self.current_health:
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
self.game.archer_ork.kill() self.game.archer_ork.kill()
self.health=self.health-self.game.archer_ork.damage self.get_damage(self.game.archer_ork.damage)
self.level+=self.level self.level+=self.level
#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.health: if self.game.infantry_ork.level > self.level or self.game.infantry_ork.damage > self.current_health:
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
self.game.infantry_ork.kill() self.game.infantry_ork.kill()
self.health=self.health-self.game.infantry_ork.damage self.get_damage(self.game.infantry_ork.damage)
self.level+=self.level self.level+=self.level
#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.health: if self.game.infantry_ork2.level > self.level or self.game.infantry_ork2.damage > self.current_health:
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
self.game.infantry_ork2.kill() self.game.infantry_ork2.kill()
self.health=self.health-self.game.infantry_ork2.damage self.get_damage(self.game.infantry_ork2.damage)
self.level+=self.level self.level+=self.level
#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.health: if self.game.sauron.level > self.level or self.game.sauron.damage > self.current_health:
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
@ -127,6 +133,30 @@ class Agent(pygame.sprite.Sprite):
#zmniejszenie życia o damage moba #zmniejszenie życia o damage moba
#level up #level up
def get_damage(self,amount):
if self.current_health > 0:
self.current_health -= amount
if self.current_health <= 0:
self.current_health = 0
#zmienic potem na smierc oraz później trzeba będzie tutaj ująć wszystkie statystyki
#i ze statystyk obliczyć ile dmg dostanie agent
def get_health(self, amount):
if self.current_health < self.max_health:
self.current_health += amount
if self.current_health >= self.max_health:
self.current_health = self.max_health
def health_bar(self):
pygame.draw.rect(self.game.SCREEN, (255,0,0), (10,780,self.health_bar_length,25))
pygame.draw.rect(self.game.SCREEN, (0,255,0), (10,780,self.current_health/self.health_ratio,25))
pygame.draw.rect(self.game.SCREEN, (255,255,255), (10,780,self.health_bar_length, 25),2)
# 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

@ -54,7 +54,7 @@ class Game:
def map(self): # tworzenie mapy def map(self): # tworzenie mapy
self.clock.tick(FRAMERATE) self.clock.tick(FRAMERATE)
for x in range(0, WIDTH, TILE_SIZE): for x in range(0, WIDTH, TILE_SIZE):
for y in range(0, HEIGHT, TILE_SIZE): for y in range(0, 768, TILE_SIZE):
self.SCREEN.blit(self.BACKGROUND,(x,y)) self.SCREEN.blit(self.BACKGROUND,(x,y))
self.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE) self.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)
pygame.draw.rect(self.SCREEN, BLACK, self.rect, 1) pygame.draw.rect(self.SCREEN, BLACK, self.rect, 1)