def moveWall (paddleWall, paddleWallDirY):
paddleWall.y+=paddleWallDirY
return paddleWall
def main():
pygame.init()
global DISPLAYSURF
##Font information
global BASICFONT, BASICFONTSIZE
BASICFONTSIZE = 20
BASICFONT = pygame.font.Font('freesansbold.ttf', BASICFONTSIZE)
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT))
pygame.display.set_caption('Pong')
#Initiate variable and set starting positions
#any future changes made within rectangles
WallX = WINDOWWIDTH/2 - LINETHICKNESS/2
WallY = (WINDOWHEIGHT)/2 - LINETHICKNESS/2
ballX = WINDOWWIDTH/2 - LINETHICKNESS/2
ballY = WINDOWHEIGHT/2 - LINETHICKNESS/2
playerOnePosition = (WINDOWHEIGHT - PADDLESIZE) /2
playerTwoPosition = (WINDOWHEIGHT - PADDLESIZE) /2
score = 0
#Keeps track of ball direction
ballDirX = -1 ## -1 = left 1 = right
ballDirY = -1 ## -1 = up 1 = down
paddleWallDirX = 0
paddleWallDirY = 1
#Creates Rectangles for ball and paddles.
paddle1 = pygame.Rect(PADDLEOFFSET,playerOnePosition, LINETHICKNESS,PADDLESIZE)
paddle2 = pygame.Rect(WINDOWWIDTH - PADDLEOFFSET - LINETHICKNESS, playerTwoPosition, LINETHICKNESS,PADDLESIZE)
paddle3 = pygame.Rect(PADDLEOFFSET,playerOnePosition, LINETHICKNESS,PADDLESIZE)
paddleWall = pygame.Rect(WallX, WallY, LINETHICKNESS, 100)
ball = pygame.Rect(ballX, ballY, LINETHICKNESS, LINETHICKNESS)
#Draws the starting position of the Arena
drawArena()
drawPaddle(paddle1)
drawPaddle(paddle2)
drawPaddle(paddle3)
drawPaddle(paddleWall)
drawBall(ball)
pygame.mouse.set_visible(0) # make cursor invisible
while True: #main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
# mouse movement commands
elif event.type == MOUSEMOTION:
mousex, mousey = event.pos
paddle1.y = mousey
paddle3.y = mousey - 100
drawArena()
drawPaddle(paddle1)
drawPaddle(paddle2)
drawPaddle(paddle3)
drawPaddle(paddleWall)
drawBall(ball)
paddleWall = moveWall(paddleWall, paddleWallDirY)
ball = moveBall(ball, ballDirX, ballDirY)
ballDirX, ballDirY = checkEdgeCollision(ball, ballDirX, ballDirY)
paddleWallDirY = checkEdgeCollisionWall(paddleWall, paddleWallDirY)
score = checkPointScored(paddle1, paddle3, ball, score, ballDirX)
ballDirX = ballDirX * checkHitBall(ball, paddle1, paddle2, paddle3, paddleWall, ballDirX)
paddle2 = artificialIntelligence (ball, ballDirX, paddle2)
I can't fix this and i did give paddleWallDirY the value of 1 in the main method
Your second parameter is None either directly:
or indirectly:
Please note that the
None
value can be a result of a function call, for example.