How to convert a PNG image to boundries (for circle) [pygame]?

Viewed 1085

How can I convert a PNG file that I load in my code (for pygame) convert to boundaries for circle?

I have the following image (png):

Maze

And I am using jpeg file as a white background.

I mean, how can I prevent the circle from going in the PNG image? The circle moves left, right, up, down with arrows keys.

My code:

import pygame

def main1():
    width, height = 600, 600
    posx, posy = 300, 300
    screen = pygame.display.set_mode((width, height))
    clock = pygame.time.Clock()
    velocity = (0, 0)
    done = False
    pygame.display.update()
    bg = pygame.image.load("maze1.png")
    bg1 = pygame.image.load("maze2.jpeg")
    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

        keys = pygame.key.get_pressed()
        screen.blit(bg1, (0, 0))
        screen.blit(bg, (0, 0))
        if keys[pygame.K_RIGHT]:
            posx += 3
        if keys[pygame.K_UP]:
            posy -= 3
        if keys[pygame.K_LEFT]:
            posx -= 3
        if keys[pygame.K_DOWN]:
            posy += 3
        cir = pygame.draw.circle(screen, (255, 200, 240), (posx,posy), 10)
        pygame.display.flip()
        clock.tick(30)

if __name__ == '__main__':
   pygame.init()
   main1()
   pygame.quit()
1 Answers
Related