-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathPart-04-Jumping.py
More file actions
39 lines (33 loc) · 807 Bytes
/
Part-04-Jumping.py
File metadata and controls
39 lines (33 loc) · 807 Bytes
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
import pygame
pygame.init()
win = pygame.display.set_mode((500, 500))
x = 250
y = 250
radius = 15
vel_x = 10
vel_y = 10
jump = False
run = True
while run:
win.fill((0, 0, 0))
pygame.draw.circle(win, (255, 255, 255), (int(x), int(y)), radius)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# Movement
userInput = pygame.key.get_pressed()
if userInput[pygame.K_LEFT] and x > 0:
x -= vel_x
if userInput[pygame.K_RIGHT] and x < 500:
x += vel_x
#Jump
if jump is False and userInput[pygame.K_SPACE]:
jump = True
if jump is True:
y -= vel_y*4
vel_y -= 1
if vel_y < -10:
jump = False
vel_y = 10
pygame.time.delay(30)
pygame.display.update()