forked from prakharsdev/ChromeDino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDino.py
142 lines (112 loc) · 3.92 KB
/
Dino.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import pygame
from pygame.locals import *
#modules initialized
x = pygame.init()
#screen height and width
screen = pygame.display.set_mode((950, 573))
#screen title
pygame.display.set_caption("Chrome Dino")
message = pygame.font.Font('freesansbold.ttf', 30)
white = (255,255,255)
orange = (255, 100, 100)
#images
cactus = pygame.image.load("cactusSmallMany0000.png")
cactus = pygame.transform.scale(cactus, (200, 110))
cactus1 = pygame.image.load("cactusBig0000.png")
cactus1 = pygame.transform.scale(cactus1, (100, 120))
cactus2 = pygame.image.load("cactusSmall0000.png")
cactus2 = pygame.transform.scale(cactus2, (100, 120))
dino = pygame.image.load("dinorun0000.png")
dino1 = pygame.image.load("dinorun0001.png")
walk = [dino,dino, dino1, dino1, dino,dino]
background = pygame.image.load("background.png")
def gameloop():
#images
cactus = pygame.image.load("cactusSmallMany0000.png")
cactus = pygame.transform.scale(cactus, (200, 110))
cactus1 = pygame.image.load("cactusBig0000.png")
cactus1 = pygame.transform.scale(cactus1, (100, 120))
cactus2 = pygame.image.load("cactusSmall0000.png")
cactus2 = pygame.transform.scale(cactus2, (100, 120))
dino = pygame.image.load("dinorun0000.png")
dino1 = pygame.image.load("dinorun0001.png")
walk = [dino,dino, dino1, dino1, dino,dino]
background = pygame.image.load("background.png")
backx = 0
backy = 0
drawx = 310
drawy = 440
cactusx = 100
cactusy = 430
backvelocity = 0
walkpoint = 0
gravity = 10
game = False
jump = False
gameover = False
jump = False
score = 0
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
if event.type == KEYDOWN:
if event.key == K_UP:
if drawy == 440:
jump = True
#Change the speed then alter the value of below backvelocity
backvelocity = 4
game = True
if event.key == K_SPACE:
gameloop()
if backx == -600:
backx = 0
if cactusx < -1600:
cactusx = 550
if 441 > drawy > 50:
if jump == True:
drawy -= 10
else:
jump = False
print(drawy)
if drawy < 440:
if jump == False:
drawy +=gravity
#collision
if cactusx < drawx + 100 < cactusx +200 and cactusy < drawy + 100 < cactusy + 100 :
backvelocity = 0
walkpoint = 0
game = False
gameover = True
if cactusx +800 < drawx + 100 < cactusx +1000 and cactusy < drawy + 100 < cactusy + 100 :
backvelocity = 0
walkpoint = 0
game = False
gameover = True
if cactusx + 1600< drawx + 100 < cactusx +1800 and cactusy < drawy + 100 < cactusy + 100 :
backvelocity = 0
walkpoint = 0
game = False
gameover = True
if game == True:
score += 1
screen.fill(white)
text = message.render("Score: "+ str(score), True, orange)
text1 = message.render("GAME OVER", True, (255,255,0))
backx -= backvelocity
cactusx -= backvelocity
screen.blit(background, [backx,backy])
screen.blit(background, [backx + 780,backy])
screen.blit(text, [700, 100])
if gameover == True:
screen.blit(text1, [400, 190])
screen.blit(walk[walkpoint], [drawx, drawy])
if game == True:
walkpoint +=1
if walkpoint > 5:
walkpoint = 0
screen.blit(cactus, [cactusx,cactusy])
screen.blit(cactus1, [cactusx + 800,cactusy - 8])
screen.blit(cactus2, [cactusx + 1600,cactusy - 10])
pygame.display.update()
gameloop()