repl.it
Pygame

No description

fork
loading
Files
  • main.py
  • nohup.out
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pygame

pygame.init()

screen = pygame.display.set_mode((1000, 600))

running = 1

surfX = 0

surf = pygame.Surface((100, 100))
surf.fill((255, 0 ,255))
rect = surf.get_rect()

keys = {
	'up'   : 0,
	'down' : 0,
	'left' : 0,
	'right': 0
}

while running:
	for event in pygame.event.get():
		if event.type == pygame.KEYDOWN:
			if event.key == pygame.K_ESCAPE:
				running = 0
			if event.key == pygame.K_RIGHT:
				keys['right'] = 1
			if event.key == pygame.K_LEFT:
				keys['left'] = 1
		
		elif event.type == pygame.KEYUP:
			if event.key == pygame.K_RIGHT:
				keys['right'] = 0
			if event.key == pygame.K_LEFT:
				keys['left'] = 0
	
		elif event.type == pygame.QUIT:
			running = 0
	if keys['right']:
		surfX += 1
	if keys['left']:
		surfX -= 1
	screen.fill((255, 255, 255))
	screen.blit(surf, (surfX, 100))
	pygame.display.flip()
Fetching token
?