-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
43 lines (33 loc) · 1.26 KB
/
player.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
from projectile import Projectile
class Player(pygame.sprite.Sprite):
def __init__(self, game):
super().__init__()
self.game = game
self.health = 100
self.max_health = 100
self.attack = 10
self.velocity = 5
self.all_projectiles = pygame.sprite.Group()
self.image = pygame.image.load('assets/player.png')
self.rect = self.image.get_rect()
self.rect.x = 400
self.rect.y = 500
def damage(self, amount):
if self.health - amount:
self.health -= amount
else:
# si plus de vie
self.game.game_over()
def update_health_bar(self, surface):
# dessiner barre de vie
pygame.draw.rect(surface, (60, 63, 60), [self.rect.x + 50, self.rect.y + 20, self.max_health, 7])
pygame.draw.rect(surface, (111, 210, 46), [self.rect.x + 50, self.rect.y + 20, self.health, 7])
def launch_projectile(self):
self.all_projectiles.add(Projectile(self))
def move_right(self):
# si le joueur n'est pas en collision avec un monstre
if not self.game.check_collision(self, self.game.all_monsters):
self.rect.x += self.velocity
def move_left(self):
self.rect.x -= self.velocity