-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
163 lines (124 loc) · 4.96 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import pygame
import time
from projectile import Projectile
from pygame.locals import *
import Classes
from Classes.Level import Level
class Player(pygame.sprite.Sprite) :
def __init__(self, game):
super().__init__()
self.game = game
self.max_health = 100
self.health = self.max_health
self.attack = 30
self.velocity = 3
self.est_vivant = True
self.dx = 0
self.dy = 0
self.image = pygame.image.load("images/personnage1.png").convert_alpha()
self.image = pygame.transform.scale(self.image, (64,64))
self.image.set_colorkey((240,241,241))
#self.rect = self.image.get_rect()
self.rect = Rect(0,0,40,64)
self.rect.x = 0
self.rect.y = 0
if Level.getNbLvl(self.game.level) == 0 :
self.rect.x = 120
self.rect.y = 500
elif Level.getNbLvl(self.game.level) == 1:
self.rect.x = 10
self.rect.y = 500
elif Level.getNbLvl(self.game.level) == 2:
self.rect.x = 10
self.rect.y = 10
elif Level.getNbLvl(self.game.level) == 3:
self.rect.x = 512
self.rect.y = 200
self.win = True
self.rect2 = Rect(0,0,40,63)
self.saut = 0
self.saut_monte = 0
self.nb_saut = 2
self.a_sauter = False
self.tt_projectiles1 = pygame.sprite.Group()
self.tt_projectiles2 = pygame.sprite.Group()
self.nb_projectiles = 30
def damage(self,amount):
if self.health - amount > amount:
self.health -=amount
if self.health <= 10 :
self.est_vivant = False
def gravite(self):
if not pygame.sprite.spritecollideany(self, self.game.all_walls) :
self.rect.y += 5
else :
self.nb_saut = 2
if self.rect.y >= 760:
self.est_vivant = False
def moveRight(self):
#moves the character to the Right and changes the character image accordingly
self.rect.x += self.velocity
self.printImage(1)
self.game.check_collisionFruit(self)
if self.game.check_collisionWallX(self, self.game.all_walls):
self.rect.x -= self.velocity
def moveLeft(self):
#moves the character to the Left and changes the character image accordingly
self.rect.x -= self.velocity
self.printImage(2)
self.game.check_collisionFruit(self)
if self.game.check_collisionWallX(self, self.game.all_walls):
self.rect.x += self.velocity
def printImage(self, nb):
if nb == 1:
self.image = pygame.image.load("images/personnage1.png").convert_alpha()
self.image = pygame.transform.scale(self.image, (64,64))
self.image.set_colorkey((240,241,241))
elif nb == 2:
self.image = pygame.image.load("images/personnage2.png").convert_alpha()
self.image = pygame.transform.scale(self.image, (64,64))
self.image.set_colorkey((240,240,240))
def moveSaut(self):
if self.a_sauter and self.nb_saut >= 0:
if self.saut_monte >= 10:
self.saut_monte = 0
self.saut = 0
self.a_sauter = False
else:
self.saut_monte += 2
self.saut = self.saut_monte
self.rect.y -= (10 * (self.saut/2))
if self.game.check_allCollisions(self, self.game.all_walls):
self.rect.y += (10 * (self.saut/2))
self.game.check_collisionFruit(self)
def draw(self, surface) :
surface.blit(self.image, self.rect)
#r = pygame.Surface((self.rect.width, self.rect.height))
#surface.blit(r, self.rect)
def lancer_projectile1(self):
self.tt_projectiles1.add(Projectile(self, "player"))
def lancer_projectile2(self):
self.tt_projectiles2.add(Projectile(self, "player"))
def update_health_bar(self, surface):
#couleur de la jauge (vert)
bar_color = (111, 210, 46)
#couleur de l'arriere plan de la jauge
back_bar_color = (60,63,60)
#definir la position de note jauge de vie
#ainsi que sa largeur et son epaisseur
bar_position = [self.rect.x - 25, self.rect.y, self.health ,7]
#definir la position de l'arriere plan
#de la jauge de vie
back_bar_position = [self.rect.x - 25, self.rect.y, self.max_health ,7]
#dessiner notre barre de vie
pygame.draw.rect(surface, back_bar_color, back_bar_position)
pygame.draw.rect(surface,bar_color, bar_position)
def checkfruitsGraille(self) :
for i in self.game.fruits_graille :
if i == "banane":
self.attack += 10
if i == "orange":
self.velocity += 1
if i == "fraise":
self.max_health += 50
self.health += 50