forked from reddit-pygame/snowboard-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobstacles.py
More file actions
189 lines (143 loc) · 6.45 KB
/
Copy pathobstacles.py
File metadata and controls
189 lines (143 loc) · 6.45 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from random import randint, choice
import pygame as pg
import prepare, tools
class Obstacle(pg.sprite.Sprite):
"""Base class for course objects."""
def __init__(self, name, midbottom, collider_tl, collider_size, *groups):
super(Obstacle, self).__init__(*groups)
self.name = name
self.image = prepare.GFX[self.name]
self.pos = midbottom
self.rect = self.image.get_rect(midbottom=midbottom)
x, y = collider_tl
self.collider = pg.Rect((self.rect.left + x, self.rect.top + y),
collider_size)
def collide_with_boarder(self, boarder):
"""
Called when player collides with an obstacle. Obstacles that
should cause a crash when collided with should call boarder.crash
from this method.
"""
pass
def update(self, boarder):
pass
def draw(self, surface, offset):
surface.blit(self.image, self.rect.move(offset))
#pg.draw.rect(surface, pg.Color("red"), self.collider.move(offset))
#pg.draw.rect(surface, pg.Color("blue"), self.rect.move(offset), 2)
#try:
# pg.draw.rect(surface, pg.Color("green"), self.goal_rect.move(offset), 2)
#except:
# pass
class Tree(Obstacle):
"""A pine tree for crashing into."""
def __init__(self, midbottom, *groups):
super(Tree, self).__init__("tree", midbottom, (11, 27), (3, 4), *groups)
def collide_with_boarder(self, boarder):
boarder.crash()
class Rock(Obstacle):
"""A rock for crashing into."""
def __init__(self, midbottom, *groups):
super(Rock, self).__init__("rock", midbottom, (0, 24), (23, 8), *groups)
def collide_with_boarder(self, boarder):
boarder.crash()
class Gate(Obstacle):
"""
Base class for slalom gates. Passing a gate on the correct side changes the gate's
image and plays a boing sound.
"""
def __init__(self, image_name, midbottom, *groups):
super(Gate, self).__init__(image_name, midbottom, (16, 32), (6, 6), *groups)
self.unpassed_image = self.image
self.goal_rect = pg.Rect(0, 0, 250, self.collider.height)
self.passed = False
def reset(self):
self.passed = False
self.image = self.unpassed_image
def update(self, boarder):
if not self.passed:
if self.goal_rect.collidepoint(boarder.collider.midbottom):
self.image = self.passed_image
self.sound.play()
self.passed = True
def collide_with_boarder(self, boarder):
boarder.crash()
class LeftGate(Gate):
def __init__(self, midbottom, *groups):
super(LeftGate, self).__init__("leftgate", midbottom, *groups)
self.passed_image = prepare.GFX["passedgate"]
self.sound = prepare.SFX["boing1"]
self.goal_rect.topright = self.collider.topleft
class RightGate(Gate):
def __init__(self, midbottom, *groups):
super(RightGate, self).__init__("rightgate", midbottom, *groups)
self.passed_image = prepare.GFX["passedgate"]
self.sound = prepare.SFX["boing2"]
self.goal_rect.topleft = self.collider.topright
class Jump(Obstacle):
"""Currently unimplemented, a jump for catching some air."""
def __init__(self, midbottom, *groups):
self.entrance = "down"
super(Jump, self).__init__("jump", midbottom, (0, 6), (29, 15), *groups)
self.hit = False
class GreenSign(Obstacle):
"""A trail marker for relatively easy trails."""
def __init__(self, midbottom, *groups):
super(GreenSign, self).__init__("greensign", midbottom, (16, 32), (6, 6), *groups)
class BlueSign(Obstacle):
"""A trail marker for moderately difficult trails."""
def __init__(self, midbottom, *groups):
super(BlueSign, self).__init__("bluesign", midbottom, (16, 32), (6, 6), *groups)
class BlackSign(Obstacle):
"""A trail marker for difficult trails."""
def __init__(self, midbottom, *groups):
super(BlackSign, self).__init__("blacksign", midbottom, (16, 32), (6, 6), *groups)
class Chair(pg.sprite.Sprite):
"""Base class for chairlift chairs."""
def __init__(self, name, midbottom, *groups):
super(Chair, self).__init__(*groups)
self.name = name
self.xpos, self.ypos = midbottom
if name == "upchair":
if not randint(0, 4):
self.image = prepare.GFX["upchair0"]
else:
self.image = choice(prepare.CHAIRS)
else:
self.image = prepare.GFX[self.name]
self.rect = self.image.get_rect(midbottom=midbottom)
self.collider = pg.Rect(self.rect.center, (2, 2))
def draw(self, surface, offset):
surface.blit(self.image, self.rect.move(offset))
class DownChair(Chair):
"""An empty chairlift chair travelling down the mountain."""
def __init__(self, midbottom, *groups):
super(DownChair, self).__init__("downchair", midbottom, *groups)
class UpChair(Chair):
"""
A chairlift chair travelling up the mountain with a random
number of randomly colored elves riding it.
"""
def __init__(self, midbottom, *groups):
super(UpChair, self).__init__("upchair", midbottom, *groups)
class TopLiftHut(Obstacle):
"""Where elves get off the chairlift."""
def __init__(self, midbottom, *groups):
super(TopLiftHut, self).__init__("toplifthut", midbottom, (0, 0), (2, 2), *groups)
class BottomLiftHut(Obstacle):
"""
Where elves get on the chairlift. Snowboarding inbto this building will return the
player to the top of the mountain for another run.
"""
def __init__(self, midbottom, *groups):
super(BottomLiftHut, self).__init__("bottomlifthut", midbottom, (0, 0), (2, 2), *groups)
class Pylon(Obstacle):
"""A pole that supoorts the chairlift cables."""
def __init__(self, midbottom, *groups):
super(Pylon, self).__init__("pylon", midbottom, (0, 35), (4, 5), *groups)
def collide_with_boarder(self, boarder):
boarder.crash()
class Cable(Obstacle):
"""The cables that chairlift chairs are suspended from."""
def __init__(self, midbottom, *groups):
super(Cable, self).__init__("cables", midbottom, (0, 0), (2, 2), *groups)