Answered step by step
Verified Expert Solution
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
SCRWID, SCRHEI
#Audio, Sound, Music
load pygame.mixer.music.loadsynthaudiomp
pygame.mixer.music.play
def MusicSynthload:
musicPlaying True
def crowdNoiseplayer:
if player.score or player.score:
channel pygame.mixer.Channel
sound pygame.mixer.Soundcrowdnoisemp
channel.playsound
channel.setvolume
elif player.score or player.score:
channel pygame.mixer.Channel
sound pygame.mixer.Soundcrowdnoisemp
channel.playsound
channel.setvolume
class Player:
counter
def initself x num:
Player.counter
self.id Player.counter
self.num num
self.x self.y x SCRHEI
self.speed
self.padWid, self.padHei
self.score
self.score
print Playercounter
def movementself:
keys pygame.key.getpressed
if self.num :
if keyspygameKw:
self.y self.speed
elif keyspygameKs:
self.y self.speed
if self.y :
self.y
elif self.y SCRHEI:
self.y SCRHEI
if self.num :
if keyspygameKUP:
self.y self.speed
elif keyspygameKDOWN:
self.y self.speed
if self.y :
self.y
elif self.y SCRHEI:
self.y SCRHEI
def drawself:
pygame.draw.rectscreenselfx self.y self.padWid, self.padHei
class Ball:
def initself:
self.x self.y SCRWID SCRHEI
self.speedx
self.speedy
self.size
def movementself:
self.x self.speedx
self.y self.speedy
if self.y :
self.speedy
elif self.y SCRHEIself.size:
self.speedy
if self.x :
self.init
player.score
elif self.x SCRWIDself.size:
self.init
self.speedx
player.score
for n in rangeself.size, player.padHei:
if self.y player.y n:
if self.x player.x player.padWid:
self.speedx
break
n
for n in rangeself.size, enemy.padHei:
if self.y enemy.y n:
if self.x enemy.x enemy.padWid:
self.speedx
break
n
def drawself:
pygame.draw.rectscreenselfx self.y
SCRWID, SCRHEI
screen pygame.display.setmodeSCRWID, SCRHEI
pygame.display.setcaptionPong
pygame.font.init
clock pygame.time.Clock
FPS
player Player
ball Ball
enemy Player
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
Backgroundsynthimage
crowdNoiseplayer
screen.fill
ball.draw
player.draw
enemy.draw
pygame.display.flip
clock.tickFPS
main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started