python - unsupported operand type(s) for +=: 'int' and 'NoneType' -
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 , 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 = 1 = down paddlewalldirx = 0 paddlewalldiry = 1 #creates rectangles ball , 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 starting position of 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 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 , did give paddlewalldiry value of 1 in main method
your second parameter none either directly:
movewall(pw, none)
or indirectly:
x = none ... movewall(pw, x)
please note none
value can result of function call, example.
Comments
Post a Comment