Pygame buttons functions

Viewed 15

I have troubles with buttons in pygame.

I don't know what is next I created rectangles that must be buttons (black) and red rectangle that must move when you touch black rectangles

That's my code What I have to do? ↓

import pygame
pygame.init()

width=800
height=400

win=pygame.display.set_mode((width,height))

#colors
white=(255,255,255)
red=(255,0,0)
green=(0,255,0)
blue=(0,0,255)
black=(0,0,0)


x1=width/2
y1=height/2

x_change=0
y_change=0

clock=pygame.time.Clock()
while True:
    
    win.fill(white)
    pygame.draw.rect(win,red,[x1,y1,100,100])
    
    #buttons
    pygame.draw.rect(win,black,[700,1500,150,150])
    pygame.draw.rect(win,black,[500,1700,150,150])
    pygame.draw.rect(win,black,[900,1700,150,150])
    pygame.draw.rect(win,black,[700,1700,150,150])
    
    x1+=x_change
    y1+=y_change
    
    clock.tick(30)
    
    pygame.display.update()
0 Answers
Related