|
|
@@ -14,19 +14,25 @@ class Player:
|
|
|
self.world: World = world
|
|
|
self.next_move = "up"
|
|
|
self.moving = True
|
|
|
- self.egg = 0
|
|
|
self.actions_till_next_farmer = 10
|
|
|
self.last_tile = self.find_current_tile()
|
|
|
+ self.pos_history = [(self.x, self.y)]
|
|
|
+ self.piou_piou_number = 0
|
|
|
|
|
|
def draw(self):
|
|
|
"""Affiche le joueur"""
|
|
|
image = pygame.transform.scale(self.picture, (self.world.tile_width, self.world.tile_height))
|
|
|
self.display.blit(image, (self.x - self.world.tile_width // 2, self.y - self.world.tile_height // 2)) #la valeur ici est arbitraire mais marche. elle est la pour centrer l'affichage du joueur sur une tuile, a changer dans le futur
|
|
|
- # On dessine l'oeuf si besoin
|
|
|
+ # On dessine tous les poussins
|
|
|
+ for i in range(2, self.piou_piou_number + 2):
|
|
|
+ pioumage = pygame.transform.scale(PIOU_PIOU, (self.world.tile_width, self.world.tile_height))
|
|
|
+ self.display.blit(pioumage, (self.pos_history[-i][0] - self.world.tile_width // 2, self.pos_history[-i][1] - self.world.tile_height // 2))
|
|
|
|
|
|
|
|
|
def move(self, direction: str):
|
|
|
"""Modifie les coordonnées x et y du joueur en fonction de la direction donnée"""
|
|
|
+ really_move = True
|
|
|
+
|
|
|
if direction == "up":
|
|
|
if self.y - self.world.gap - self.world.tile_height >= self.world.top_border: # Il faut que ça soit supérieur parce que les coos descendent
|
|
|
self.y -= self.world.gap + self.world.tile_height
|
|
|
@@ -35,6 +41,13 @@ class Player:
|
|
|
self.picture = PLAYER_LU
|
|
|
elif self.picture == PLAYER_RD:
|
|
|
self.picture = PLAYER_RU
|
|
|
+ # Si un poussin est déjà là
|
|
|
+ if self.piou_piou_number > 1:
|
|
|
+ if (self.x, self.y) in self.pos_history[-self.piou_piou_number:]:
|
|
|
+ really_move = False
|
|
|
+ self.move("up")
|
|
|
+ else:
|
|
|
+ really_move = False
|
|
|
|
|
|
elif direction == "down":
|
|
|
if self.y + self.world.gap + self.world.tile_height <= self.world.bottom_border: # Inversement ici
|
|
|
@@ -44,6 +57,13 @@ class Player:
|
|
|
self.picture = PLAYER_LD
|
|
|
elif self.picture == PLAYER_RU:
|
|
|
self.picture = PLAYER_RD
|
|
|
+ # Si un poussin est déjà là
|
|
|
+ if self.piou_piou_number > 1:
|
|
|
+ if (self.x, self.y) in self.pos_history[-self.piou_piou_number:]:
|
|
|
+ really_move = False
|
|
|
+ self.move("down")
|
|
|
+ else:
|
|
|
+ really_move = False
|
|
|
|
|
|
elif direction == "left":
|
|
|
if self.x - self.world.gap - 3 * self.world.tile_width // 4 >= self.world.left_border:
|
|
|
@@ -53,9 +73,15 @@ class Player:
|
|
|
self.y -= self.world.gap // 2 + self.world.tile_height // 2
|
|
|
self.next_move = "down"
|
|
|
self.picture = PLAYER_LD
|
|
|
+ # Si un poussin est déjà là
|
|
|
+ if self.piou_piou_number > 1:
|
|
|
+ if (self.x, self.y) in self.pos_history[-self.piou_piou_number:]:
|
|
|
+ really_move = False
|
|
|
+ self.move("left")
|
|
|
else:
|
|
|
self.next_move = "down"
|
|
|
self.move("left")
|
|
|
+ really_move = False
|
|
|
|
|
|
elif self.next_move == "down":
|
|
|
if self.y + self.world.gap // 2 + self.world.tile_height // 2 <= self.world.bottom_border:
|
|
|
@@ -63,9 +89,17 @@ class Player:
|
|
|
self.y += self.world.gap // 2 + self.world.tile_height // 2
|
|
|
self.next_move = "up"
|
|
|
self.picture = PLAYER_LU
|
|
|
+ # Si un poussin est déjà là
|
|
|
+ if self.piou_piou_number > 1:
|
|
|
+ if (self.x, self.y) in self.pos_history[-self.piou_piou_number:]:
|
|
|
+ really_move = False
|
|
|
+ self.move("left")
|
|
|
else:
|
|
|
self.next_move = "up"
|
|
|
self.move("left")
|
|
|
+ really_move = False
|
|
|
+ else:
|
|
|
+ really_move = False
|
|
|
|
|
|
elif direction == "right":
|
|
|
if self.x + self.world.gap + 3 * self.world.tile_width // 4 <= self.world.right_border:
|
|
|
@@ -75,9 +109,15 @@ class Player:
|
|
|
self.y -= self.world.gap // 2 + self.world.tile_height // 2
|
|
|
self.next_move = "down"
|
|
|
self.picture = PLAYER_RD
|
|
|
+ # Si un poussin est déjà là
|
|
|
+ if self.piou_piou_number > 1:
|
|
|
+ if (self.x, self.y) in self.pos_history[-self.piou_piou_number:]:
|
|
|
+ really_move = False
|
|
|
+ self.move("right")
|
|
|
else:
|
|
|
self.next_move = "down"
|
|
|
self.move("right")
|
|
|
+ really_move = False
|
|
|
|
|
|
elif self.next_move == "down":
|
|
|
if self.y + self.world.gap // 2 + self.world.tile_height // 2 <= self.world.bottom_border:
|
|
|
@@ -85,9 +125,21 @@ class Player:
|
|
|
self.y += self.world.gap // 2 + self.world.tile_height // 2
|
|
|
self.next_move = "up"
|
|
|
self.picture = PLAYER_RU
|
|
|
+ # Si au moins deux poussins sont là
|
|
|
+ if self.piou_piou_number > 1:
|
|
|
+ if (self.x, self.y) in self.pos_history[-self.piou_piou_number:]:
|
|
|
+ really_move = False
|
|
|
+ self.move("right")
|
|
|
else:
|
|
|
self.next_move = "up"
|
|
|
self.move("right")
|
|
|
+ really_move = False
|
|
|
+ else:
|
|
|
+ really_move = False
|
|
|
+
|
|
|
+ if really_move:
|
|
|
+ self.handle_egg()
|
|
|
+ self.pos_history.append((self.x, self.y))
|
|
|
|
|
|
|
|
|
def find_current_tile(self):
|
|
|
@@ -122,7 +174,35 @@ class Player:
|
|
|
|
|
|
|
|
|
def seed(self):
|
|
|
- if self.egg == 0:
|
|
|
- self.egg = 1
|
|
|
- else:
|
|
|
- print("Il y a déjà un oeuf")
|
|
|
+ if self.world.egg == 0:
|
|
|
+ self.world.egg = 1
|
|
|
+ self.world.tiles_list[0].tiletype = "egg1"
|
|
|
+ self.world.have_egg = True
|
|
|
+
|
|
|
+
|
|
|
+ def handle_egg(self):
|
|
|
+ """Gère l'oeuf"""
|
|
|
+ if self.world.egg == 4:
|
|
|
+ self.world.tiles_list[0].type = "egg2"
|
|
|
+ self.world.tiles_list[0].tiletype = "egg2"
|
|
|
+
|
|
|
+ elif self.world.egg == 8:
|
|
|
+ self.world.tiles_list[0].type = "egg3"
|
|
|
+ self.world.tiles_list[0].tiletype = "egg3"
|
|
|
+
|
|
|
+ elif self.world.egg == 12:
|
|
|
+ self.world.tiles_list[0].type = "egg4"
|
|
|
+ self.world.tiles_list[0].tiletype = "egg4"
|
|
|
+
|
|
|
+ elif self.world.egg == 16:
|
|
|
+ self.world.tiles_list[0].type = "egg5"
|
|
|
+ self.world.tiles_list[0].tiletype = "egg5"
|
|
|
+
|
|
|
+ if self.world.egg == 20:
|
|
|
+ self.world.egg = 0
|
|
|
+ self.world.have_egg = False
|
|
|
+ self.world.tiles_list[0].tiletype = "nest"
|
|
|
+ self.piou_piou_number += 1
|
|
|
+ elif self.world.egg != 0:
|
|
|
+ self.world.egg += 1
|
|
|
+
|