Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

crowdnoise file will not load but code seems correct, the synthaudio loads just fine though. Any ideas? ( NOTE: WAV files don't load either, also

crowdnoise file will not load but code seems correct, the synthaudio loads just fine though. Any ideas?
(NOTE: WAV files don't load either, also This code is shrunk to fit the question.)
Code:
import pygame
SCR_WID, SCR_HEI =640,480
#Audio, Sound, Music
load = pygame.mixer.music.load('synthaudio.mp3')
pygame.mixer.music.play(-1,0.0)
def Music_Synth(load):
musicPlaying = True
def crowdNoise(player):
if player.score >=5 or player.score2>=5:
channel = pygame.mixer.Channel(0)
sound = pygame.mixer.Sound('crowdnoise.mp3')
channel.play(sound,-1)
channel.set_volume(0.5)
elif player.score >=8 or player.score2>=8:
channel = pygame.mixer.Channel(0)
sound = pygame.mixer.Sound('crowdnoise.mp3')
channel.play(sound,-1)
channel.set_volume(1.0)
class Player():
_counter =0
def __init__(self, x, num):
Player._counter +=1
self.id = Player._counter
self.num = num
self.x, self.y = x, SCR_HEI/2
self.speed =3
self.padWid, self.padHei =8,64
self.score =0
self.score2=0
print (Player._counter)
def movement(self):
keys = pygame.key.get_pressed()
if self.num ==1:
if keys[pygame.K_w]:
self.y -= self.speed
elif keys[pygame.K_s]:
self.y += self.speed
if self.y <=0:
self.y =0
elif self.y >= SCR_HEI-64:
self.y = SCR_HEI-64
if self.num ==2:
if keys[pygame.K_UP]:
self.y -= self.speed
elif keys[pygame.K_DOWN]:
self.y += self.speed
if self.y <=0:
self.y =0
elif self.y >= SCR_HEI-64:
self.y = SCR_HEI-64
def draw(self):
pygame.draw.rect(screen,(255,255,255),(self.x, self.y, self.padWid, self.padHei))
class Ball():
def __init__(self):
self.x, self.y = SCR_WID/2, SCR_HEI/2
self.speed_x =-3
self.speed_y =3
self.size =8
def movement(self):
self.x += self.speed_x
self.y += self.speed_y
if self.y <=0:
self.speed_y *=-1
elif self.y >= SCR_HEI-self.size:
self.speed_y *=-1
if self.x <=0:
self.__init__()
player.score2+=1
elif self.x >= SCR_WID-self.size:
self.__init__()
self.speed_x =3
player.score +=1
for n in range(-self.size, player.padHei):
if self.y == player.y + n:
if self.x <= player.x + player.padWid:
self.speed_x *=-1
break
n +=1
for n in range(-self.size, enemy.padHei):
if self.y == enemy.y + n:
if self.x >= enemy.x - enemy.padWid:
self.speed_x *=-1
break
n +=1
def draw(self):
pygame.draw.rect(screen,(255,255,255),(self.x, self.y,8,8))
SCR_WID, SCR_HEI =640,480
screen = pygame.display.set_mode((SCR_WID, SCR_HEI))
pygame.display.set_caption("Pong")
pygame.font.init()
clock = pygame.time.Clock()
FPS =60
player = Player(16,1)
ball = Ball()
enemy = Player(624,2)
def main():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
print ("Game exited by user")
exit()
ball.movement()
player.movement()
enemy.movement()
Background_synth(image)
crowdNoise(player)
screen.fill((0,0,0))
ball.draw()
player.draw()
enemy.draw()
pygame.display.flip()
clock.tick(FPS)
main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

Students also viewed these Databases questions