-
Notifications
You must be signed in to change notification settings - Fork 0
/
comet.py
44 lines (34 loc) · 1.29 KB
/
comet.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
42
43
import pygame
import random
class Comet(pygame.sprite.Sprite):
def __init__(self,comet_event):
super().__init__()
self.comet_event = comet_event
# Definir l'image associee a cette comette
self.image = pygame.image.load("assets/comet.png")
self.rect = self.image.get_rect()
self.rect.x = random.randint(80,1000)
self.rect.y = - random.randint(150,300)
self.velocity = random.randint(1,3)
self.temps = 0
def remove(self) -> None:
self.comet_event.all_comets.remove(self)
if len(self.comet_event.all_comets) == 0:
self.comet_event.reset_percent()
self.comet_event.game.spawn_monster()
self.comet_event.game.spawn_monster()
def fall(self):
self.temps += 1
temps = self.temps/1000
self.rect.y = self.rect.y + 5*self.velocity*temps*temps
if self.rect.y >=500:
self.remove()
if len(self.comet_event.all_comets) == 0:
self.comet_event.reset_percent()
self.comet_event.fall_mode = False
if self.comet_event.game.check_collision(
self,
self.comet_event.game.all_players
):
self.remove()
self.comet_event.game.player.damage(20)