SHOW:
|
|
- or go back to the newest paste.
| 1 | import pygame, sys, time | |
| 2 | from pygame.locals import * | |
| 3 | ||
| 4 | pygame.init() | |
| 5 | ||
| 6 | black=0,0,0 | |
| 7 | pygame.display.init() | |
| 8 | screen=pygame.display.set_mode ((800,600)) | |
| 9 | clock=pygame.time.Clock() | |
| 10 | image = 'image.png' | |
| 11 | ||
| 12 | Image = pygame.image.load(image).convert_alpha() | |
| 13 | ||
| 14 | x,y=0,0 | |
| 15 | movex, movey,=0,0 | |
| 16 | ||
| 17 | while True: | |
| 18 | screen.fill(black) | |
| 19 | for event in pygame.event.get(): | |
| 20 | if event.type == QUIT: | |
| 21 | pygame.quit() | |
| 22 | sys.exit() | |
| 23 | ||
| 24 | if event.type == KEYDOWN: | |
| 25 | if event.key==K_LEFT: | |
| 26 | movex=-1 | |
| 27 | elif event.key==K_RIGHT: | |
| 28 | movex=1 | |
| 29 | elif event.key==K_UP: | |
| 30 | movey=-1 | |
| 31 | elif event.key==K_DOWN: | |
| 32 | movey=1 | |
| 33 | ||
| 34 | if event.type == KEYUP: | |
| 35 | if event.key==K_LEFT: | |
| 36 | movex=0 | |
| 37 | elif event.key==K_RIGHT: | |
| 38 | movex=0 | |
| 39 | elif event.key==K_UP: | |
| 40 | movey=0 | |
| 41 | elif event.key==K_DOWN: | |
| 42 | movey=0 | |
| 43 | ||
| 44 | ||
| 45 | x = x+movex | |
| 46 | y = y+movey | |
| 47 | ||
| 48 | screen.blit(Image,(x,y)) | |
| 49 | ||
| 50 | pygame.display.update() |