-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdinosaur.py
91 lines (75 loc) · 2.49 KB
/
dinosaur.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
class Dinosaur:
X_POS = 80
JUMP_VEL = 7.25
score = 0
def __init__(self, Y_POS, DUCKING, RUNNING, JUMPING):
self.duck_img = DUCKING
self.run_img = RUNNING
self.jump_img = JUMPING
self.dino_duck = False
self.dino_run = True
self.dino_jump = False
self.step_index = 0
self.jump_vel = self.JUMP_VEL
self.image = self.run_img[0]
self.dino_rect = self.image.get_rect()
self.dino_rect.x = self.X_POS
self.dino_rect.y = Y_POS
self.Y_POS = Y_POS
self.Y_POS_DUCK = Y_POS+30
self.DUCKING = DUCKING
self.RUNNING = RUNNING
self.JUMPING = JUMPING
# updates what the dino is doing
def update(self, userInput):
if self.dino_duck:
self.duck()
if self.dino_run:
self.run()
if self.dino_jump:
self.jump()
if self.step_index >= 10:
self.step_index = 0
if userInput==0 and not self.dino_jump:
self.dino_duck = False
self.dino_run = False
self.dino_jump = True
elif userInput==1 and not self.dino_jump:
self.dino_duck = False
self.dino_run = True
self.dino_jump = False
elif userInput==2 and not self.dino_jump:
self.dino_duck = True
self.dino_run = False
self.dino_jump = False
self.score += 0.25
def duck(self):
self.image = self.duck_img[self.step_index // 5]
self.dino_rect = self.image.get_rect()
self.dino_rect.x = self.X_POS
self.dino_rect.y = self.Y_POS_DUCK
self.step_index += 1
def run(self):
self.image = self.run_img[self.step_index // 5]
self.dino_rect = self.image.get_rect()
self.dino_rect.x = self.X_POS
self.dino_rect.y = self.Y_POS
self.step_index += 1
def jump(self):
self.image = self.jump_img
if self.dino_jump:
self.dino_rect.y -= self.jump_vel * 4
self.jump_vel -= 0.8
if self.jump_vel < - self.JUMP_VEL:
self.dino_jump = False
self.jump_vel = self.JUMP_VEL
def draw(self, SCREEN):
SCREEN.blit(self.image, (self.dino_rect.x, self.dino_rect.y))
def getY(self):
return self.dino_rect.y
def getV(self):
return self.jump_vel
def changeScore(self, num):
self.score = num
def getScore(self):
return self.score