-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdino_step2.py
More file actions
71 lines (58 loc) · 1.76 KB
/
dino_step2.py
File metadata and controls
71 lines (58 loc) · 1.76 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# jumping dino game
# python + pygame. by. BlockDMask
import pygame
import sys
# step1 : set screen, fps
# step2 : show, jump dino
pygame.init()
pygame.display.set_caption('Jumping dino')
MAX_WIDTH = 800
MAX_HEIGHT = 400
def main():
# set screen, fps
screen = pygame.display.set_mode((MAX_WIDTH, MAX_HEIGHT))
fps = pygame.time.Clock()
# dino
imgDino1 = pygame.image.load('images/dino1.png')
imgDino2 = pygame.image.load('images/dino2.png')
dino_height = imgDino1.get_size()[1]
dino_bottom = MAX_HEIGHT - dino_height
dino_x = 50
dino_y = dino_bottom
jump_top = 200
leg_swap = True
is_bottom = True
is_go_up = False
while True:
screen.fill((255, 255, 255))
# event check
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if is_bottom:
is_go_up = True
is_bottom = False
# dino move
if is_go_up:
dino_y -= 10.0
elif not is_go_up and not is_bottom:
dino_y += 10.0
# dino top and bottom check
if is_go_up and dino_y <= jump_top: # end up
is_go_up = False
if not is_bottom and dino_y >= dino_bottom:
is_bottom = True
dino_y = dino_bottom
# draw dino
if leg_swap:
screen.blit(imgDino1, (dino_x, dino_y))
leg_swap = False
else:
screen.blit(imgDino2, (dino_x, dino_y))
leg_swap = True
pygame.display.update()
fps.tick(30)
if __name__ == '__main__':
main()