WMICraft/models/monster.py

47 lines
1.6 KiB
Python

import pygame.image
import random
from common.helpers import parse_cord
from logic.health_bar import HealthBar
monster_images = [
pygame.image.load("./resources/textures/dragon2.png"),
pygame.image.load("./resources/textures/birb.png"),
pygame.image.load("./resources/textures/wolfart.png"),
pygame.image.load("./resources/textures/goblin.png"),
]
class Monster(pygame.sprite.Sprite):
def __init__(self, screen, position, group):
super().__init__(group)
self._layer = 1
self.image = random.choice(monster_images)
self.image = pygame.transform.scale(self.image, (40, 40))
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
self.rect = self.image.get_rect(topleft=position_in_px)
self.max_hp = random.randrange(15, 25)
self.current_hp = random.randint(1, self.max_hp)
self.health_bar = HealthBar(screen, self.rect, current_hp=self.current_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True)
self.attack = random.randrange(2, 10)
if self.image == monster_images[0]:
self.max_hp = 20
self.attack = 9
self.points = 10
elif self.image == monster_images[1]:
self.max_hp = 15
self.attack = 7
self.points = 7
elif self.image == monster_images[2]:
self.max_hp = 10
self.attack = 4
self.points = 4
elif self.image == monster_images[3]:
self.max_hp = 7
self.attack = 2
self.points = 2
def update(self):
self.health_bar.update()