while messing with pygame.draw.polygon
I found out polygon can be move by using for point in points. so I came up with a idea to move polygon shape as a player. but I can't keep the player in side the screen when it touch border
import pygame
win = pygame.display.set_mode((500, 400))
trang = (255,255,255)
p1 = pygame.Rect(50, 200, 50, 50)
a = 95
points = [ [100, 50], [180, a], [320, a], [400, 50], [250,35] ]
x,y = 0,1
def trongluc(y,a):
if a < 400:
for point in points:
point[1] += y
def move(key, x):
if key[pygame.K_d]:
x += 20
if key[pygame.K_a]:
x -= 20
for point in points:
point[0] += x
def draw():
win.fill((0,0,0))
pygame.draw.polygon(win,trang,points)
pygame.display.update()
def main():
clock = pygame.time.Clock()
run = True
while run :
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()
#key_board_input
key = pygame.key.get_pressed()
#functions
trongluc(y)
move(key, x)
draw()
if __name__ == "__main__":
main()
I try to replace a < 400 to
y = 1 for point in points: if point[1] > 400: y = 0 point[1] += y
but the output still the same