WMICraft/models/monster.py

49 lines
1.7 KiB
Python
Raw Permalink Normal View History

2022-03-24 12:54:22 +01:00
import random
2022-03-10 18:34:58 +01:00
2022-05-08 20:36:33 +02:00
import pygame.image
2022-04-11 00:01:57 +02:00
from common.helpers import parse_cord
2022-04-28 14:13:59 +02:00
from logic.health_bar import HealthBar
2022-04-11 00:01:57 +02:00
2022-04-10 20:28:50 +02:00
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"),
]
2022-03-10 18:34:58 +01:00
2022-04-10 20:28:50 +02:00
class Monster(pygame.sprite.Sprite):
2022-04-28 14:13:59 +02:00
def __init__(self, screen, position, group):
2022-04-10 20:28:50 +02:00
super().__init__(group)
self._layer = 1
2022-04-10 20:28:50 +02:00
self.image = random.choice(monster_images)
self.image = pygame.transform.scale(self.image, (40, 40))
2022-04-11 12:00:15 +02:00
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
2022-04-11 00:01:57 +02:00
self.rect = self.image.get_rect(topleft=position_in_px)
2022-05-08 20:36:33 +02:00
self.position = position
2022-04-28 14:13:59 +02:00
self.max_hp = random.randrange(15, 25)
self.current_hp = random.randint(1, self.max_hp)
2022-05-08 20:36:33 +02:00
self.health_bar = HealthBar(screen, self.rect, current_hp=self.current_hp, max_hp=self.max_hp,
calculate_xy=True, calculate_size=True)
2022-03-24 12:54:22 +01:00
self.attack = random.randrange(2, 10)
2022-04-10 20:28:50 +02:00
if self.image == monster_images[0]:
2022-04-28 14:13:59 +02:00
self.max_hp = 20
self.attack = 9
self.points = 10
2022-04-10 20:28:50 +02:00
elif self.image == monster_images[1]:
2022-04-28 14:13:59 +02:00
self.max_hp = 15
self.attack = 7
self.points = 7
2022-04-10 20:28:50 +02:00
elif self.image == monster_images[2]:
2022-04-28 14:13:59 +02:00
self.max_hp = 10
self.attack = 4
self.points = 4
2022-04-10 20:28:50 +02:00
elif self.image == monster_images[3]:
2022-04-28 14:13:59 +02:00
self.max_hp = 7
self.attack = 2
self.points = 2
def update(self):
self.health_bar.update()