2

I am making a game in pygame and i am trying to have the ship point towards the mouse and change the scrollx and scrolly values to make it look like its moving how would i do that. But right now it moves wird and i cant understand what is going wrong

These are the needed functions from the game


def getAngle(x1, y1, x2, y2):

    # Return value is 0 for right, 90 for up, 180 for left, and 270 for down (and all values between 0 and 360)
    rise = y1 - y2
    run = x1 - x2
    angle = math.atan2(run, rise) # get the angle in radians
    angle = angle * (180 / math.pi) # convert to degrees
    angle = (angle + 90) % 360 # adjust for a right-facing sprite
    return angle

def player_calc():

    x, y = pygame.mouse.get_pos()

    degrees = getAngle(400, 350, scrollx + x, scrolly + y)
    player_copy = pygame.transform.rotate(player, degrees)

    #gameDisplay.blit(rotatedSurf,(HEIGHT / 2,WIDTH / 2))
    gameDisplay.blit(player_copy, (WIDTH / 2 - int(player_copy.get_width() / 2), HEIGHT / 2 - 
    int(player_copy.get_height() / 2)))
    pygame.display.update()

And for the scrolling i have

scrollx += math.sin(degrees) * 3
scrolly += math.cos(degrees) * 3

And it updates the player and moves the stars to the there position plus the scroll y position

Luke
  • 33
  • 4

0 Answers0