0

I am currently trying to develop a minigolf game but that is the main problem. The error that is displaying is: TypeError: invalid position for blit

power = 0
angle = 0
ballPos = (width//2 - golfBallWidth//2, 550)
ballVel = [0, 0]  # x and y velocity components of the ball
ballAcc = [0, 0]  # x and y acceleration components of the ball
ballMass = 0.0459  # mass of the golf ball in kg
frictionCoeff = 0.15  # coefficient of friction between ball and ground
holePos = (holePosX, holePosY)

def friction():
    global ballVel, ballAcc
    frictionalForce = frictionCoeff * ballMass * 9.81 #Calculates frictional force
    frictionalDirection = math.atan2(-ballVel[1], -ballVel[0]) #Direction of friction
    frictionalX = frictionalForce * math.cos(frictionalDirection) #components of frictional force
    frictionalY = frictionalForce * math.sin(frictionalDirection)
    ballAcc[0] += frictionalX/ballMass #applying fric force to ball
    ballAcc[1] += frictionalY/ballMass

def setBallVelocity(power, angle, ballVel):
    ballVel[0] = power * math.cos(angle)
    ballVel[1] = power * math.sin(angle)


def ballPositioning():
    global ballPos
    ballPos = list(ballPos)
    ballPos[0] += ballVel[0] * oneFrame
    ballPos[1] += ballVel[1] * oneFrame
    ballPos = tuple(ballPos)

def drawLevelOne(ballPos)
    friction()
    setBallVelocity(power, angle, ballVel)
    ballPositioning()
    WIN.blit(levelBackground, (0,0))
    WIN.blit(courseHole, (holePosX, holePosY))
    WIN.blit(golfBall, (ballPos))
    pygame.display.update()`

I tried to print the variable ballPos at two different places. One right after the line ballPos = tuple(ballPos)

and once right before the line

WIN.blit(golfBall, (ballPos))

I thought that both would have a tuple value but only the one that prints after the ballPos = tuple(ballPos) line is printing and actually has a value within it. Im honestly not too sure whats wrong. The output after the 2nd line is simply just '()'

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
cookietsu
  • 11
  • 3
  • What do you get when you do `print(ballPos)` (before `WIN.blit(golfBall, (ballPos))`)? – Rabbid76 Feb 21 '23 at 14:41
  • @Rabbid76 the output when I try to print(ballPos) before WIN.blit(golfBall, (ballPos)) is simply '()' which probably means there isnt a value assigned to that variable or something of that sort – cookietsu Feb 21 '23 at 15:43
  • 1
    So what do you pass to `drawLevelOne` when you call it? `ballPos` is the argument of that function. – Rabbid76 Feb 21 '23 at 15:57

0 Answers0