-
Notifications
You must be signed in to change notification settings - Fork 1
/
stage3.py
66 lines (49 loc) · 1.99 KB
/
stage3.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
# Chrome game
import pygame
import pyganim
from .stage import Stage, Text
class Stage3(Stage):
def __init__(self, resolution):
super().__init__(resolution)
self.texts = [Text("JUMP", (255, 255, 255), self._center_text)]
self.run_anim = pyganim.PygAnimation([("images/dinosaur.png", 10),])
self.jump_anim = pyganim.PygAnimation([("images/dinosaur.png", 10),])
self.run_anim.play()
self.jump_anim.play()
self.obstacle = pyganim.PygAnimation([("images/button1.png", 10),
("images/button 2.png", 10)])
self.obstacle.play()
self.reset()
def reset(self):
self.player_x = 200
self.ground_y = 300
self.state = "run"
self.jump_power = 0
self.jump_tick = 0
self.obstacle_pos = [self.player_x + 1000, self.ground_y + 50]
def update(self, input, tick):
if input.button:
if self.state == "run":
self.state = "jump"
self.jump_power = self.obstacle.getMaxSize()[1] + 50
self.jump_tick += tick
if self.jump_tick > 100:
self.jump_power -= 10
if self.jump_power < 0:
self.jump_power = 0
self.state = "run"
self.obstacle_pos[0] -= 13
if self.obstacle_pos[0] < -100:
return True
if (self.state == "run" and
(self.obstacle_pos[0] <= self.player_x + (self.run_anim.getMaxSize()[0] * .60) and
self.obstacle_pos[0] >= self.player_x - (self.obstacle.getMaxSize()[0] * .30))):
self.reset()
def draw(self, screen):
super().draw(screen)
if self.state == "run":
self.run_anim.blit(screen, [self.player_x, self.ground_y])
else:
y = self.ground_y - min(self.jump_power, 100)
self.run_anim.blit(screen, [self.player_x, y])
self.obstacle.blit(screen, self.obstacle_pos)