-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
58 lines (44 loc) · 1.77 KB
/
game.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pygame
from player import Player
from monster import Monster
from comet_event import CometFallEvent
class Game:
def __init__(self) -> None:
self.is_playing = False
self.all_players = pygame.sprite.Group()
self.player = Player(self)
self.all_players.add(self.player)
# generer l'evenement
self.comet_event = CometFallEvent(self)
self.all_monsters = pygame.sprite.Group()
self.pressed = {}
def start(self):
self.is_playing = True
self.spawn_monster()
self.spawn_monster()
def game_over(self):
self.all_monsters = pygame.sprite.Group()
self.player.health = self.player.max_health
self.is_playing = False
def update(self,screen):
screen.blit(self.player.image, self.player.rect)
self.player.update_health_bar(screen)
self.comet_event.update_bar(screen)
for projectile in self.player.all_projectiles:
projectile.move()
self.player.all_projectiles.draw(screen)
for monster in self.all_monsters:
monster.forward()
monster.update_health_bar(screen)
self.all_monsters.draw(screen)
for comet in self.comet_event.all_comets:
comet.fall()
self.comet_event.all_comets.draw(screen)
if self.pressed.get(pygame.K_RIGHT) and self.player.rect.x + self.player.rect.width <= screen.get_width( ):
self.player.move_right()
elif self.pressed.get(pygame.K_LEFT) and self.player.rect.x >= 0:
self.player.move_left()
def check_collision(self, sprite, group):
return pygame.sprite.spritecollide(sprite, group, False, pygame.sprite.collide_mask)
def spawn_monster(self):
self.all_monsters.add(Monster(self))