############################################################################ #Module to set the game board and control the game ball #################### ############################################################################ import pygame, os, sys from pygame.locals import * import GlobVar, random class game(): def Start(self): #set up the game board and load all images, including changing the game board background# GlobVar.screen.fill ((0,0,0)) GlobVar.screen.blit(GlobVar.GameBall,(GlobVar.GBallX,GlobVar.GBallY)) GlobVar.screen.blit(GlobVar.Pad,(GlobVar.PlayerX,GlobVar.PlayerY)) GlobVar.screen.blit(GlobVar.Pad,(GlobVar.CompX,GlobVar.CompY)) #set the random number for ball to start with# self.x = 0 self.x = GlobVar.RandChoice self.Xmove = 1 #draw and control the ball# def Ball(self): if GlobVar.BallSpace == "GameBoard": GlobVar.screen.blit(GlobVar.EBall,(GlobVar.GBallX,GlobVar.GBallY)) GlobVar.GBallX = GlobVar.GBallX + self.Xmove GlobVar.screen.blit(GlobVar.GameBall,(GlobVar.GBallX,GlobVar.GBallY)) #control the player# def Player(self): #input# for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == K_ESCAPE: exit() if event.key == K_UP and GlobVar.PlayerY > 20: GlobVar.screen.blit(GlobVar.ErasePad,(GlobVar.PlayerX,GlobVar.PlayerY)) GlobVar.PlayerY = GlobVar.PlayerY - 10 GlobVar.screen.blit(GlobVar.Pad,(GlobVar.PlayerX,GlobVar.PlayerY)) if event.key == K_DOWN and GlobVar.PlayerY < 530: GlobVar.screen.blit(GlobVar.ErasePad,(GlobVar.PlayerX,GlobVar.PlayerY)) GlobVar.PlayerY = GlobVar.PlayerY + 10 GlobVar.screen.blit(GlobVar.Pad,(GlobVar.PlayerX,GlobVar.PlayerY)) #draw and control the computer# def Computer(self): GlobVar.screen.blit(GlobVar.Pad,(GlobVar.CompX,GlobVar.CompY)) def Collide(self): if GlobVar.GBallY == GlobVar.PlayerY: self.Xmove = -2 #################################################################################### #Every variable that a module needs to share with another module will be found here# #################################################################################### import pygame, os, sys, random from pygame.locals import* #the screen global# global screen screen = pygame.display.set_mode ((800,600)) pygame.display.set_caption ("!!!PONG!!!") #background image# global BackGround BackGround = pygame.image.load (os.path.join ("Data","menubackground.jpeg")) BackGround = BackGround.convert() #ball image# global Ball Ball = pygame.image.load (os.path.join ("Data", "ball.jpeg")) Ball = Ball.convert() #eraseball image# global EBall EBall = pygame.image.load (os.path.join ("Data","eraseball.jpeg")) EBall= EBall.convert() #Menu Select variable to keep track of choice at main menu# global MenuSel MenuSel = "none" #Game Ball And position variables# global GameBall global GBallX global GBallY global BallSpace GameBall = pygame.image.load (os.path.join("Data", "ball.jpeg")) GBallX = 400 GBallY = 300 BallSpace = "GameBoard" #set the random number for ball to start with# global RandChoice RandChoice = random.choice([0,1,2,3,4,5]) #paddles and possition variables# global Pad global ErasePad global PlayerX global PlayerY global CompX global CompY global PlayerCspace ErasePad = pygame.image.load (os.path.join ("Data", "erasepaddle.jpeg")) Pad = pygame.image.load (os.path.join ("Data","paddle.jpeg")) PlayerX = 780 PlayerY = 280 CompX = 10 CompY = 280 #player collision space PlayerCspace = PlayerX - 50 #################################################################################### #Every variable that a module needs to share with another module will be found here# #################################################################################### import pygame, os, sys, random from pygame.locals import* #the screen global# global screen screen = pygame.display.set_mode ((800,600)) pygame.display.set_caption ("!!!PONG!!!") #background image# global BackGround BackGround = pygame.image.load (os.path.join ("Data","menubackground.jpeg")) BackGround = BackGround.convert() #ball image# global Ball Ball = pygame.image.load (os.path.join ("Data", "ball.jpeg")) Ball = Ball.convert() #eraseball image# global EBall EBall = pygame.image.load (os.path.join ("Data","eraseball.jpeg")) EBall= EBall.convert() #Menu Select variable to keep track of choice at main menu# global MenuSel MenuSel = "none" #Game Ball And position variables# global GameBall global GBallX global GBallY global BallSpace GameBall = pygame.image.load (os.path.join("Data", "ball.jpeg")) GBallX = 400 GBallY = 300 BallSpace = "GameBoard" #set the random number for ball to start with# global RandChoice RandChoice = random.choice([0,1,2,3,4,5]) #paddles and possition variables# global Pad global ErasePad global PlayerX global PlayerY global CompX global CompY global PlayerCspace ErasePad = pygame.image.load (os.path.join ("Data", "erasepaddle.jpeg")) Pad = pygame.image.load (os.path.join ("Data","paddle.jpeg")) PlayerX = 780 PlayerY = 280 CompX = 10 CompY = 280 #player collision space PlayerCspace = PlayerX - 50 #################################################################################### #Every variable that a module needs to share with another module will be found here# #################################################################################### import pygame, os, sys, random from pygame.locals import* #the screen global# global screen screen = pygame.display.set_mode ((800,600)) pygame.display.set_caption ("!!!PONG!!!") #background image# global BackGround BackGround = pygame.image.load (os.path.join ("Data","menubackground.jpeg")) BackGround = BackGround.convert() #ball image# global Ball Ball = pygame.image.load (os.path.join ("Data", "ball.jpeg")) Ball = Ball.convert() #eraseball image# global EBall EBall = pygame.image.load (os.path.join ("Data","eraseball.jpeg")) EBall= EBall.convert() #Menu Select variable to keep track of choice at main menu# global MenuSel MenuSel = "none" #Game Ball And position variables# global GameBall global GBallX global GBallY global BallSpace GameBall = pygame.image.load (os.path.join("Data", "ball.jpeg")) GBallX = 400 GBallY = 300 BallSpace = "GameBoard" #set the random number for ball to start with# global RandChoice RandChoice = random.choice([0,1,2,3,4,5]) #paddles and possition variables# global Pad global ErasePad global PlayerX global PlayerY global CompX global CompY global PlayerCspace ErasePad = pygame.image.load (os.path.join ("Data", "erasepaddle.jpeg")) Pad = pygame.image.load (os.path.join ("Data","paddle.jpeg")) PlayerX = 780 PlayerY = 280 CompX = 10 CompY = 280 #player collision space PlayerCspace = PlayerX - 50