]> git.ayabusa.dev Git - jeu-gtc.git/commitdiff
added some pnj walking around
authorayabusa <lebgpub@gmail.com>
Wed, 23 Oct 2024 09:58:57 +0000 (11:58 +0200)
committerayabusa <lebgpub@gmail.com>
Wed, 23 Oct 2024 09:58:57 +0000 (11:58 +0200)
game.py

diff --git a/game.py b/game.py
index aeeef07e7c78e89273568260860d36ab5dda367a..7efc497ca7b48c95baa15d197ab6353a351be291 100644 (file)
--- a/game.py
+++ b/game.py
@@ -69,15 +69,14 @@ class Waypoint:
         else:\r
             raise Exception("crash: POINT A and B impossible")\r
                 \r
-\r
 class Pnj:\r
-    def __init__(self, x: int, y: int, sprite_path: str, direction: str, objectif: Waypoint) -> None:\r
+    def __init__(self, x: int, y: int, sprite_path: str, direction: str, objectif: Waypoint, speed: int) -> None:\r
         self.x = x\r
         self.y = y\r
         self.sprite = pygame.transform.scale_by(pygame.image.load(sprite_path), 3.0)\r
         self.direction = direction\r
         self.objectif = objectif\r
-        self.speed = 6\r
+        self.speed = speed\r
     \r
     def avance(self):\r
         '''\r
@@ -129,6 +128,27 @@ class Pnj:
                     return True\r
         return False\r
 \r
+class Village:\r
+    def __init__(self, nb_pnj: int) -> None:\r
+        self.liste_pnj = []\r
+        for i in range(nb_pnj):\r
+            start_waypoint = Waypoint(random.choice(("A", "B", "C", "D", "E", "F", "G", "H")))\r
+            objective_waypoint = start_waypoint.get_new_connected()\r
+            self.liste_pnj.append(Pnj(start_waypoint.x, start_waypoint.y, "assets/MiniPeasant.png", start_waypoint.get_direction(start_waypoint, objective_waypoint), objective_waypoint, random.randint(1, 4)))\r
+\r
+    def ajouter_pnj_random(self)-> None:\r
+        pass\r
+\r
+    def update_pnj(self)-> None:\r
+        for p in self.liste_pnj:\r
+            p.avance()\r
+\r
+    def get_village_sprites(self)->list:\r
+        village_sprites = []\r
+        for p in self.liste_pnj:\r
+            village_sprites.append((p.x, p.y, p.sprite))\r
+        return village_sprites\r
+\r
 class Player:\r
     def __init__(self)-> None:\r
         self.x = 800\r
@@ -197,15 +217,16 @@ class Game:
         img = pygame.transform.rotozoom(self.perso_sprite, -player.angle-90, 0.2)\r
         screen.blit(img, (540-img.get_rect().centerx, 360-img.get_rect().centery))\r
 \r
-    def draw_villager(self):\r
-        screen.blit(pnj.sprite, (540-player.x + pnj.x - pnj.sprite.get_rect().centerx, 360-player.y + pnj.y - pnj.sprite.get_rect().centery))\r
+    def draw_village(self):\r
+        for s in village.get_village_sprites():\r
+            screen.blit(s[2], (540-player.x + s[0] - s[2].get_rect().centerx, 360-player.y + s[1] - s[2].get_rect().centery))\r
 \r
     def display_all(self):\r
         # fill the screen with a color to wipe away anything from last frame\r
         screen.fill("purple")\r
         screen.blit(self.map_sprite, (540-player.x, 360-player.y))\r
 \r
-        self.draw_villager()\r
+        self.draw_village()\r
         self.draw_player()\r
 \r
         # We display it at the end so it's on top of all\r
@@ -214,11 +235,10 @@ class Game:
         # flip() the display to put your work on screen\r
         pygame.display.flip()\r
 \r
-\r
-\r
 player = Player()\r
 game = Game()\r
-pnj = Pnj(800, 900, "assets/MiniPeasant.png", "south", Waypoint("H"))\r
+#pnj = Pnj(800, 900, "assets/MiniPeasant.png", "south", Waypoint("H"), 3)\r
+village = Village(20)\r
 \r
 while running:\r
     # poll for events\r
@@ -226,7 +246,8 @@ while running:
     for event in pygame.event.get():\r
         if event.type == pygame.QUIT:\r
             running = False\r
-    pnj.avance()\r
+    # make all the pnj move and do their pnj stuff\r
+    village.update_pnj()\r
 \r
     game.check_input()\r
     \r