Repository navigation
Expand file tree
/
Copy pathstep0.py
More file actions
50 lines (40 loc) · 1.44 KB
/
Copy pathstep0.py
File metadata and controls
50 lines (40 loc) · 1.44 KB
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
48
49
50
import pygame
# init MUST be included before pygame can do anything
pygame.init()
# creates a window that's 1280 pixels wide and 720 pixels tall
# display.setmode takes in a parameter of a tuple.
screen = pygame.display.set_mode((1280, 720))
# creates a clock that keeps track of time for us
clock = pygame.time.Clock()
running = True
# we want these outside of the loop, since we don't want to reset them every frame
x = 0
y = 0
# all code within the while loop is run over and over as long as running is true
while running:
# iterates through every new event since the last time get() was called
for event in pygame.event.get():
# if one of those events is QUIT, set running to false
if event.type == pygame.QUIT:
running = False
# keys is a list of 1s and 0s
# if a key is pressed, it's position in the list will be a 1
keys = pygame.key.get_pressed()
# print(keys)
# update position based on pressed keys
if keys[pygame.K_w]:
y -= 5
if keys[pygame.K_s]:
y += 5
if keys[pygame.K_d]:
x += 5
if keys[pygame.K_a]:
x -= 5
# clears everything that was on screen
screen.fill("grey")
# draws a circle on the screen that's "red" at (x,y) with radius 50
pygame.draw.circle(screen, "red", (x,y), 50)
# flip() updates the display to show everything that has been drawn
pygame.display.flip()
clock.tick(60) # limits FPS to 60
pygame.quit()