-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2_4.py
52 lines (50 loc) · 1.21 KB
/
day2_4.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
48
49
50
51
52
import pygame
pygame.init()
window= pygame.display.set_mode((500,500))
pygame.display.set_caption("game1")
x = 250
y = 250
width = 50
height = 50
velocity = 20
jump = False
JUMP_COUNT_MAX = 10
jumpcount = JUMP_COUNT_MAX
run = True
while run :
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
print("left")
x -= velocity
elif keys[pygame.K_RIGHT]:
print("right")
x += velocity
elif keys[pygame.K_UP]:
print("up")
y -= velocity
elif keys[pygame.K_DOWN]:
print("down")
y += velocity
elif keys[pygame.K_SPACE]:
jump = True
elif keys[pygame.K_SPACE]:
jump = True
if jump:
if jumpcount >= -JUMP_COUNT_MAX:
if jumpcount < 0:
sign = -1
else:
sign = 1
y -= sign * jumpcount**2
jumpcount -=1
else:
jump = False
jumpcount =JUMP_COUNT_MAX
print(x,y)
window.fill("black")
pygame.draw.rect(window,(238,189,34),(x,y,width,height))
pygame.display.update()
pygame.quit()