-
Notifications
You must be signed in to change notification settings - Fork 1
/
billboard.py
190 lines (153 loc) · 6.67 KB
/
billboard.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
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
190
#!/usr/bin/env python
import util
import pygame
import gameobject
import animation
class GuiTimerBar():
def __init__(self,pos,finish_time,time_until_play = 0.0):
self.map_time = finish_time
self.draw_pos = pos
self.empty_timer = util.load_image("data/timer_empty0.png")
self.blue_timer = util.load_image("data/timer_blue0.png")
self.green_timer = util.load_image("data/timer_green0.png")
self.red_timer = util.load_image("data/timer_red0.png")
self.stopwatch = util.load_image("data/stopwatch0.png")
self.red_animation = animation.new_animation("data/timer_red","png",1,8,[0,1])
self.timer_finish = finish_time
self.time_until_finish = self.map_time
self.time_until_play = time_until_play
self.timer_on = False
self.has_stopped = False
self.rect = self.empty_timer.get_rect()
self.wait_until_play = False
self._show = True
def start(self):
self.timer_on = True
self.time_until_finish = self.map_time
def stop(self):
self.timer_on = False
self.has_stopped = True
def hide(self):
self._show = False
def show(self):
self._show = True
def reset(self,time_until_play = 0.0, play = True):
self.has_stopped = False
if time_until_play > 0.0:
self.wait_until_play = True
self.time_until_play = time_until_play
if play:
self.start()
def update(self,dt):
if self.timer_on:
if self.wait_until_play:
if self.time_until_play <= 0:
self.wait_until_play = False
else:
self.time_until_play -= dt * 0.001
else:
if self.time_until_finish <= 0:
self.timer_on = False
self.has_stopped = True
else:
if self.time_until_finish <= 0.25*self.map_time:
self.red_animation.update(dt)
self.time_until_finish -= dt*0.001
def draw(self,canvas):
if self._show:
draw_rect = self.rect.copy()
draw_rect.width -= draw_rect.width * (1-(self.time_until_finish/self.map_time))
canvas.blit(self.empty_timer, self.draw_pos.get(), None)
canvas.blit(self.stopwatch, (self.draw_pos.x+self.rect.width,self.draw_pos.y), None)
if (self.time_until_finish <= 0.7*self.map_time) and (self.time_until_finish >= 0.25*self.map_time):
canvas.blit(self.green_timer, self.draw_pos.get(), draw_rect)
elif self.time_until_finish <= 0.25*self.map_time:
self.red_animation.play()
self.red_animation.draw(canvas,self.draw_pos.get(),True,draw_rect)
else:
canvas.blit(self.blue_timer, self.draw_pos.get(), draw_rect)
class GuiKeys():
def __init__(self,pos,offset = 16):
#load imgs
self._default = util.load_image("data/bw_key0.png")
self._red = util.load_image("data/red_key0.png")
self._green = util.load_image("data/green_key0.png")
self._blue = util.load_image("data/blue_key0.png")
self.red = self._default
self.green = self._default
self.blue = self._default
self.offset = offset
self.draw_pos = pos
def draw(self,canvas):
# draw keys at relative positions
canvas.blit(self.red, self.draw_pos.get(), None)
canvas.blit(self.green, (self.draw_pos.x+self.offset,self.draw_pos.y), None)
canvas.blit(self.blue, (self.draw_pos.x+self.offset*2,self.draw_pos.y), None)
def update(self,toggle_key):
# only call update when a key has been picked up
if toggle_key == gameobject.OBJECT_TYPE_KEY_RED:
self.red = self._red
elif toggle_key == gameobject.OBJECT_TYPE_KEY_GREEN:
self.green = self._green
elif toggle_key == gameobject.OBJECT_TYPE_KEY_BLUE:
self.blue = self._blue
else:
print "unknown key type"
def reset(self):
self.red = self._default
self.green = self._default
self.blue = self._default
class Billboard:
def __init__(self,name,pos,speed,repeat = False,animated = False,blend = False):
self.image = util.load_image(name)
self.rect = self.image.get_rect()
self.width = self.rect.width
self.height = self.rect.height
self.is_animated = animated
self.pos = pos
self.draw_pos = util.vec2(0,0)
self.speed = speed
self.inv_speed = speed/100.
self.repeat = repeat
self.offset = 320
self.last_frame_pos = 0
self.blend = blend
def draw(self,canvas):
if not self.is_animated:
if self.repeat:
if self.draw_pos.x < -320:
self.draw_pos.x += 320
for x in range(0, 6):
if self.blend:
canvas.blit(self.image, (-1000 + self.draw_pos.x + 320*x,self.draw_pos.y), None,pygame.BLEND_MAX)
else:
canvas.blit(self.image, (-1000 + self.draw_pos.x + 320*x,self.draw_pos.y), None)
"""
if self.outside(self.draw_pos):
self.draw_pos.x -= 320
canvas.blit(self.image, (self.draw_pos.x,self.draw_pos.y), None)
#canvas.blit(self.image, (self.draw_pos.x,self.draw_pos.y), None)
print self.draw_pos.get()
else:
canvas.blit(self.image, (self.draw_pos.x,self.draw_pos.y), None)
#canvas.blit(self.image, (self.draw_pos.x,self.draw_pos.y), None)
"""
#canvas.blit(self.image, self.draw_pos.get(), None)
#canvas.blit(self.image, (self.draw_pos.x+self.offset,self.draw_pos.y), None)
pass
def update(self,cam_pos,dt):
self.draw_pos.set(self.pos.x-cam_pos.x*self.inv_speed,
self.pos.y-cam_pos.y*self.inv_speed*0.2)
self.draw_pos.x * dt
self.draw_pos.y * dt
self.draw_pos.set(int(self.draw_pos.x),int(self.draw_pos.y))
if self.draw_pos.y <= 240-self.height:
self.draw_pos.y = self.pos.y
#print self.pos.y,self.draw_pos.y,self.height
#print self.draw_pos
outside = self.outside(self.draw_pos)
def outside(self,pos):
if pos.x < -self.width:
return True
if pos.x > self.width:
return True