]> git.ayabusa.dev Git - jeu-gtc.git/commitdiff
added sound
authorayabusa <lebgpub@gmail.com>
Thu, 24 Oct 2024 08:30:42 +0000 (10:30 +0200)
committerayabusa <lebgpub@gmail.com>
Thu, 24 Oct 2024 08:30:42 +0000 (10:30 +0200)
assets/RETROTECH.ttf [new file with mode: 0644]
assets/blood-splatter.mp3 [new file with mode: 0644]
assets/music.mp3 [new file with mode: 0644]
assets/upheavtt.ttf [new file with mode: 0644]
game.py

diff --git a/assets/RETROTECH.ttf b/assets/RETROTECH.ttf
new file mode 100644 (file)
index 0000000..edfbb7c
Binary files /dev/null and b/assets/RETROTECH.ttf differ
diff --git a/assets/blood-splatter.mp3 b/assets/blood-splatter.mp3
new file mode 100644 (file)
index 0000000..1f5d23d
Binary files /dev/null and b/assets/blood-splatter.mp3 differ
diff --git a/assets/music.mp3 b/assets/music.mp3
new file mode 100644 (file)
index 0000000..05184a3
Binary files /dev/null and b/assets/music.mp3 differ
diff --git a/assets/upheavtt.ttf b/assets/upheavtt.ttf
new file mode 100644 (file)
index 0000000..e374c97
Binary files /dev/null and b/assets/upheavtt.ttf differ
diff --git a/game.py b/game.py
index b7ddee7f5b9db1345897217008142ddcfd7f0711..9827214f74a71487c0d0f07defaf44248a13df19 100644 (file)
--- a/game.py
+++ b/game.py
@@ -3,6 +3,7 @@ import pygame
 import math\r
 import csv\r
 import random\r
+import datetime\r
 \r
 # pygame setup\r
 pygame.init()\r
@@ -139,6 +140,9 @@ class Pnj:
             village.final_boss()\r
         elif player.killcounter >= game.pnj_number+8:\r
             game.game_over()\r
+        # play sound effect\r
+        blood = pygame.mixer.Sound("assets/blood-splatter.mp3")\r
+        pygame.mixer.Sound.play(blood)\r
 \r
 class Village:\r
     def __init__(self, nb_pnj: int) -> None:\r
@@ -173,7 +177,6 @@ class Village:
             objective_waypoint = start_waypoint.get_new_connected()\r
             self.liste_pnj.append(Pnj(start_waypoint.x, start_waypoint.y, "assets/pnj/knight.png", start_waypoint.get_direction(start_waypoint, objective_waypoint), objective_waypoint, 10))\r
             \r
-\r
 class Player:\r
     def __init__(self)-> None:\r
         self.x = 800\r
@@ -201,9 +204,9 @@ class Player:
 class Game:\r
     def __init__(self):\r
         self.is_paused = False\r
-        self.pnj_number = 5\r
+        self.pnj_number = 20\r
         pygame.font.init()\r
-        self.font = pygame.font.SysFont('Comic Sans MS', 30)\r
+        self.font = pygame.font.Font('assets/upheavtt.ttf', 60)\r
         self.load_sprites()\r
         self.load_collisions()\r
     \r
@@ -235,6 +238,22 @@ class Game:
         screen.blit(kill_surface, (0,90))\r
         #pygame.draw.rect(screen, "blue",pygame.Rect(player.x-50, player.y-50, 100, 100))\r
 \r
+    def display_ui(self):\r
+        color = "black"\r
+        if player.killcounter < game.pnj_number:\r
+            kill_surface = self.font.render("Kills: "+str(player.killcounter)+"\\"+str(game.pnj_number), False, color)\r
+        else:\r
+            kill_surface = self.font.render("Kills: "+str(player.killcounter)+"\\"+str(game.pnj_number+8), False, color)\r
+        screen.blit(kill_surface, (10,0))\r
+        \r
+        seconds = pygame.time.get_ticks()/1000\r
+        seconds = seconds % (24 * 3600)\r
+        seconds %= 3600\r
+        minutes = seconds // 60\r
+        seconds %= 60\r
+        time_surface = self.font.render("Time: "+str(int(minutes)).zfill(2)+":"+str(int(seconds)).zfill(2), False, color)\r
+        screen.blit(time_surface, (740,0))\r
+\r
     def check_input(self):\r
         keys = pygame.key.get_pressed()\r
         if keys[pygame.K_z]:\r
@@ -264,15 +283,26 @@ class Game:
         self.draw_player()\r
 \r
         # We display it at the end so it's on top of all\r
-        self.display_debug_text()\r
+        # self.display_debug_text()\r
+\r
+        self.display_ui()\r
 \r
         # flip() the display to put your work on screen\r
         pygame.display.flip()\r
 \r
     def game_over(self)->None:\r
         screen.blit(pygame.image.load("assets/gameover.png"), (0,0))\r
+        seconds = pygame.time.get_ticks()/1000\r
+        seconds = seconds % (24 * 3600)\r
+        seconds %= 3600\r
+        minutes = seconds // 60\r
+        seconds %= 60\r
+        time_surface = self.font.render(str(int(minutes)).zfill(2)+":"+str(int(seconds)).zfill(2), False, "white")\r
+        screen.blit(time_surface, (500,500))\r
+\r
         # flip() the display to put your work on screen\r
         pygame.display.flip()\r
+\r
         while True:\r
             for event in pygame.event.get():\r
                 if event.type == pygame.QUIT:\r
@@ -283,6 +313,11 @@ game = Game()
 #pnj = Pnj(800, 900, "assets/MiniPeasant.png", "south", Waypoint("H"), 3)\r
 village = Village(game.pnj_number)\r
 \r
+# start music\r
+pygame.mixer.music.load("assets/music.mp3")\r
+pygame.mixer.music.play(-1)\r
+\r
+\r
 while running:\r
     # poll for events\r
     # pygame.QUIT event means the user clicked X to close your window\r