Răsfoiți Sursa

ajout personnage, du nid, et des graines. Certaines fonctions a revoir cependant (perso, nid)

louciane 3 săptămâni în urmă
părinte
comite
b4bd3586b4
10 a modificat fișierele cu 123 adăugiri și 2 ștergeri
  1. 3 0
      .vscode/settings.json
  2. BIN
      images/nest.png
  3. BIN
      images/player.png
  4. BIN
      images/seed.png
  5. 9 0
      main.py
  6. 43 0
      nest.py
  7. 47 0
      player.py
  8. 5 1
      tiles.py
  9. 8 0
      variables.py
  10. 8 1
      world.py

+ 3 - 0
.vscode/settings.json

@@ -0,0 +1,3 @@
+{
+    "python-envs.defaultEnvManager": "ms-python.python:system"
+}

BIN
images/nest.png


BIN
images/player.png


BIN
images/seed.png


+ 9 - 0
main.py

@@ -2,6 +2,9 @@ import pygame, sys
 from pygame.locals import * # Import des constantes de pygame
 from pygame.locals import * # Import des constantes de pygame
 from world import *
 from world import *
 from variables import *
 from variables import *
+from player import *
+from nest import *
+
 
 
 def main():
 def main():
     """La fonction pricipale"""
     """La fonction pricipale"""
@@ -18,6 +21,12 @@ def main():
     world = World(display, NB_COL, NB_ROW, GAP)
     world = World(display, NB_COL, NB_ROW, GAP)
     world.draw()
     world.draw()
 
 
+    player = Player(0, 0, display)
+    player.draw(world.pos_list[1])              #Le choix de la tuile a été arbitraire
+
+    nest = Nest(0, display)
+    nest.draw(world.pos_list[0], 0)
+
     ### Boucle principale ###
     ### Boucle principale ###
     while True:
     while True:
         
         

+ 43 - 0
nest.py

@@ -0,0 +1,43 @@
+import pygame
+from tiles import *
+from variables import *
+
+
+class Nest:
+    def __init__(self, eggs: int, display: pygame.display):
+        """Un joueur, avec ses coordonnées (x, y)"""
+        self.display = display
+        self.eggs: int = eggs
+
+
+    def draw(self, tile: dict, eggs: int):
+        """Affiche le nid"""
+        image = pygame.transform.scale(NEST, (self.nest_size(), self.nest_size()))
+        tile_size = self.tile_size()
+        self.display.blit(image, (tile['x'] - tile_size // 3.7, tile['y'] - tile_size // 3.7))  #la valeur ici est arbitraire mais marche. elle est la pour centrer l'affichage du joueur sur une tuile, a changer dans le futur
+
+    def nest_size(self):
+        """Renvoie la taille que fera le joueur (sa hauteur et sa largeur sont similaires)"""
+        width = (WINDOW_WIDTH - NB_COL * GAP) // NB_COL
+        height = (WINDOW_HEIGHT - NB_ROW * GAP) // NB_ROW
+
+        #Réutilisation du calcul de la taille des tuilles pour calculer la taille du joueur
+        if height < 0.86 * width:
+            width = height // 0.86
+        else:
+            height = round(width * 0.86)
+        return int(width) // 1.8
+
+
+
+    def tile_size(self):
+        """Renvoie la taille d'une tuille                       CECI EST UNE FONCTION TEST QUI POURRAS SUREMENT ETRE ENLEVEE"""
+        width = (WINDOW_WIDTH - NB_COL * GAP) // NB_COL
+        height = (WINDOW_HEIGHT - NB_ROW * GAP) // NB_ROW
+
+        #Réutilisation du calcul de la taille des tuilles pour calculer la taille du joueur
+        if height < 0.86 * width:
+            width = height // 0.86
+        else:
+            height = round(width * 0.86)
+        return int(width)

+ 47 - 0
player.py

@@ -0,0 +1,47 @@
+import pygame
+from tiles import *
+from variables import *
+
+
+class Player:
+    def __init__(self, x: int, y: int, display: pygame.display):
+        """Un joueur, avec ses coordonnées (x, y)"""
+        self.display = display
+        self.x: int = x
+        self.y: int = y
+        self.width: int = self.player_size()
+        self.height: int = self.player_size()
+        self.picture: str = "player"
+
+    def draw(self, tile: dict):
+        """Affiche le joueur"""
+        image = pygame.transform.scale(PLAYER, (self.player_size(), self.player_size()))
+        tile_size = self.tile_size()
+        self.display.blit(image, (tile['x'] - tile_size // 3.7, tile['y'] - tile_size // 3.7))  #la valeur ici est arbitraire mais marche. elle est la pour centrer l'affichage du joueur sur une tuile, a changer dans le futur
+
+    def player_size(self):
+        """Renvoie la taille que fera le joueur (sa hauteur et sa largeur sont similaires)"""
+        width = (WINDOW_WIDTH - NB_COL * GAP) // NB_COL
+        height = (WINDOW_HEIGHT - NB_ROW * GAP) // NB_ROW
+
+        #Réutilisation du calcul de la taille des tuilles pour calculer la taille du joueur
+        if height < 0.86 * width:
+            width = height // 0.86
+        else:
+            height = round(width * 0.86)
+        return int(width) // 1.8
+
+    def tile_size(self):
+        """Renvoie la taille d'une tuille                       CECI EST UNE FONCTION TEST QUI POURRAS SUREMENT ETRE ENLEVEE"""
+        width = (WINDOW_WIDTH - NB_COL * GAP) // NB_COL
+        height = (WINDOW_HEIGHT - NB_ROW * GAP) // NB_ROW
+
+        #Réutilisation du calcul de la taille des tuilles pour calculer la taille du joueur
+        if height < 0.86 * width:
+            width = height // 0.86
+        else:
+            height = round(width * 0.86)
+        return int(width)
+
+    
+    

+ 5 - 1
tiles.py

@@ -14,7 +14,11 @@ class Tile:
 
 
     def draw(self):
     def draw(self):
         """Affiche la tuile"""
         """Affiche la tuile"""
-        image = pygame.transform.scale(HEXA, (self.width, self.height))
+        if self.tiletype == "seed" :
+            image = pygame.transform.scale(SEED, (self.width, self.height))
+        else :
+            image = pygame.transform.scale(HEXA, (self.width, self.height))
         self.display.blit(image, (self.x - self.width // 2, self.y - self.height // 2))
         self.display.blit(image, (self.x - self.width // 2, self.y - self.height // 2))
+
         
         
         
         

+ 8 - 0
variables.py

@@ -15,6 +15,14 @@ GAP = 8
 
 
 # images
 # images
 HEXA = image.load(path.join("images/hexa.png"))
 HEXA = image.load(path.join("images/hexa.png"))
+SEED = image.load(path.join("images/seed.png"))
+
+PLAYER = image.load(path.join("images/player.png"))
+
+NEST = image.load(path.join("images/nest.png"))
+
+# tuile de base pour le personnage
+ORIGIN = 0
 
 
 # couleurs
 # couleurs
 BACKGROUND_COLOR = (24, 40, 69)
 BACKGROUND_COLOR = (24, 40, 69)

+ 8 - 1
world.py

@@ -1,5 +1,6 @@
 from tiles import *
 from tiles import *
 from variables import *
 from variables import *
+from random import randint
 
 
 
 
 class World:
 class World:
@@ -16,10 +17,16 @@ class World:
     def draw(self):
     def draw(self):
         """Dessine les tuiles du monde"""
         """Dessine les tuiles du monde"""
         for pos in self.pos_list:
         for pos in self.pos_list:
-            tile = Tile(pos["x"], pos["y"], self.tile_width, self.tile_height, "green", self.display)
+            tile = Tile(pos["x"], pos["y"], self.tile_width, self.tile_height, self.tile_type(), self.display)
             tile.draw()
             tile.draw()
 
 
 
 
+    def tile_type(self) -> str:
+        """Renvoie une chaine de caractère contenant 'green' ou 'seed' avec une probabilité respective de 80% et 20%"""
+        t_type = ["green", "green", "green", "green", "seed"]
+        return t_type[randint(0, 4)]
+            
+
     def tile_size(self) -> tuple:
     def tile_size(self) -> tuple:
         """Renvoie un tuple contenant la largeur et la hauteur d'une tuile en fonction du nombre de lignes, de colonnes, et de l'espacement entre le tuiles"""
         """Renvoie un tuple contenant la largeur et la hauteur d'une tuile en fonction du nombre de lignes, de colonnes, et de l'espacement entre le tuiles"""
         width = (WINDOW_WIDTH - self.nb_col * self.gap) // self.nb_col
         width = (WINDOW_WIDTH - self.nb_col * self.gap) // self.nb_col