-
Notifications
You must be signed in to change notification settings - Fork 0
/
monster.py
41 lines (34 loc) · 1.37 KB
/
monster.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pygame
import random
class Monster(pygame.sprite.Sprite):
def __init__(self, game) -> None:
super().__init__()
self.game = game
self.health = 100
self.max_health = 100
self.attack = 1
self.image = pygame.image.load("assets/mummy.png")
self.rect = self.image.get_rect()
self.rect.x = 1000 + random.randint(0, 300)
self.rect.y = 540
self.velocity = random.randint(1,3)
def damage(self, amount):
self.health -= amount
if self.health <= 0:
self.rect.x = 1080 + random.randint(0, 300)
self.health = 100
if self.game.comet_event.is_full_loaded():
self.game.all_monsters.remove(self)
self.game.comet_event.attempt_fall()
def update_health_bar(self, surface):
bar_color = (111, 210, 46)
back_bar_color = (60, 63, 60)
bar_position = [self.rect.x + 10, self.rect.y - 20, self.health, 5]
back_bar_position = [self.rect.x + 10, self.rect.y - 20, self.max_health, 5]
pygame.draw.rect(surface, back_bar_color, back_bar_position)
pygame.draw.rect(surface, bar_color, bar_position)
def forward(self):
if not self.game.check_collision(self, self.game.all_players):
self.rect.x -= self.velocity
else:
self.game.player.damage(self.attack)