I am new to pygame. I am trying to move a polygon inside a window as the player presses the UP, DOWN, RIGHT or LEFT key.
but I do not know how to do it. Can any one guide me for this problem?
import random, pygame, sys
from pygame.locals import *
import time
BLACK = (0,0,0)
WHITE = (255,255,255)
RED = (255,0,0)
windowSurface = pygame.display.set_mode((700,700),0,32)
windowSurface.fill(WHITE)
def main():
pygame.init()
worm = pygame.draw.polygon( windowSurface, RED, ( (210,350),(220,360),(230,350),(240,360),(250,350),(260,360),(270,350),(280,360),(290,350),(300,360),(300,355),(290,345),(280,355),(270,345)
,(260,355),(250,345),(240,355),(230,345),(220,355),(210,350) ))
pygame.display.update()
time.sleep(25)
return 0
if __name__ == '__main__':
main()
You draw it in a different position each time, depending on what position it should be drawn, Which is decided on whether the user has pressed a certain key or not.