Skip to content

Commit

Permalink
added first sound
Browse files Browse the repository at this point in the history
  • Loading branch information
HotHotHeissi committed Jan 27, 2024
1 parent 9ff60c4 commit 306f22d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 7 additions & 6 deletions level.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,35 @@
class Level:
startLevelTime = None

def __init__(self, question, amountOfObject=None, initialTimer=60):
def __init__(self, question, failureSound, amountOfObject=None, initialTimer=60):
self.question = question
self.amountOfObject = amountOfObject
if amountOfObject is None:
self.amountOfObject = random.randint(0, 10)
self.initialTimer = initialTimer
self.failureSound = "sounds/" + failureSound

def __str__(self):
return "question: " + self.question + "\nnumber of objects: " + str(self.amountOfObject) + "\ninitial timer(seconds): " + str(self.initialTimer)
return "question: " + self.question + "\nnumber of objects: " + str(
self.amountOfObject) + "\ninitial timer(seconds): " + str(self.initialTimer)

def start(self):
self.startLevelTime = int(time.time())
return

def isLevelFinished(self):
return int(time.time()) - self.startLevelTime >= self.initialTimer

def timeLeft(self):
return self.initialTimer - (int(time.time()) - self.startLevelTime)


levelOne = Level("what is my age",2, 5)
levelOne = Level("what is my age", "uh_you_suck.wav", 2, 5)

print(levelOne)

levelOne.start()

while levelOne.isLevelFinished() is not True:
time.sleep(1)
print("time remaining: " + str(levelOne.timeLeft()))

print("time remaining: " + str(levelOne.timeLeft()))
7 changes: 7 additions & 0 deletions main-window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import pygame as pg

from level import Level

if not pg.font:
print("Warning, fonts disabled")
if not pg.mixer:
Expand Down Expand Up @@ -59,6 +61,10 @@ def main():
background = background.convert()
background.fill((102, 204, 10))

# Load level and failure sound
currentLevel = Level("what is my age", "uh_you_suck.wav", 2, 5)
failureSound = pg.mixer.Sound(currentLevel.failureSound)

# Put Text On The Background, Centered
if pg.font:
font = pg.font.Font(None, 64)
Expand Down Expand Up @@ -90,6 +96,7 @@ def main():
going = False
elif event.type == pg.KEYDOWN:
print("A key! A key, I say!")
pg.mixer.Sound.play(failureSound)

allobjects.update()

Expand Down
Binary file added sounds/uh_you_suck.wav
Binary file not shown.

0 comments on commit 306f22d

Please sign in to comment.