health bar
This commit is contained in:
parent
82b21db6c4
commit
a8036b32a1
Binary file not shown.
BIN
__pycache__/archer_ork.cpython-39.pyc
Normal file
BIN
__pycache__/archer_ork.cpython-39.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
__pycache__/infantry_ork.cpython-39.pyc
Normal file
BIN
__pycache__/infantry_ork.cpython-39.pyc
Normal file
Binary file not shown.
BIN
__pycache__/infantry_ork2.cpython-39.pyc
Normal file
BIN
__pycache__/infantry_ork2.cpython-39.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
__pycache__/sauron.cpython-39.pyc
Normal file
BIN
__pycache__/sauron.cpython-39.pyc
Normal file
Binary file not shown.
56
agent.py
56
agent.py
@ -29,9 +29,15 @@ class Agent(pygame.sprite.Sprite):
|
||||
self.rect.y = self.y
|
||||
|
||||
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):
|
||||
self.health_bar()
|
||||
self.movement()
|
||||
self.collide_mob()
|
||||
|
||||
@ -46,13 +52,13 @@ class Agent(pygame.sprite.Sprite):
|
||||
def movement(self):
|
||||
keys = pygame.key.get_pressed()
|
||||
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:
|
||||
self.x_change += TILE_SIZE/2
|
||||
self.x_change += TILE_SIZE
|
||||
if keys[pygame.K_UP] and self.rect.y > 0:
|
||||
self.y_change -= TILE_SIZE/2
|
||||
if keys[pygame.K_DOWN] and self.rect.y < 832 - 64:
|
||||
self.y_change += TILE_SIZE/2
|
||||
self.y_change -= TILE_SIZE
|
||||
if keys[pygame.K_DOWN] and self.rect.y < 768 - 64:
|
||||
self.y_change += TILE_SIZE
|
||||
|
||||
def collide_blocks(self, direction):
|
||||
if direction == "x":
|
||||
@ -87,37 +93,37 @@ class Agent(pygame.sprite.Sprite):
|
||||
|
||||
|
||||
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.game.new()
|
||||
else:
|
||||
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
|
||||
#zmniejszenie życia o damage moba
|
||||
#level up
|
||||
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.game.new()
|
||||
else:
|
||||
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
|
||||
#zmniejszenie życia o damage moba
|
||||
#level up
|
||||
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.game.new()
|
||||
else:
|
||||
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
|
||||
#zmniejszenie życia o damage moba
|
||||
#level up
|
||||
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.game.new()
|
||||
else:
|
||||
@ -127,6 +133,30 @@ class Agent(pygame.sprite.Sprite):
|
||||
#zmniejszenie życia o damage moba
|
||||
#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 dodania miejsca w którym agent się leczy
|
||||
|
||||
|
2
main.py
2
main.py
@ -54,7 +54,7 @@ class Game:
|
||||
def map(self): # tworzenie mapy
|
||||
self.clock.tick(FRAMERATE)
|
||||
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.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)
|
||||
pygame.draw.rect(self.SCREEN, BLACK, self.rect, 1)
|
||||
|
Loading…
Reference in New Issue
Block a user