-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuttons.py
214 lines (177 loc) · 6.96 KB
/
buttons.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import sprites as sp
import defaults as df
import var as var
import pygame
import time
import text as txg
class Button(sp.Sprite2):
def __init__(self, filename, x, y, w, h):
sp.Sprite2.__init__(self)
self.file = filename
self.w = w
self.h = h
self.set_image()
self.rect.x = x
self.rect.y = y
self.hover_text = 'Back / Zurück/ Atras'
self.click_text = 'Loading/ Laden/ Caragando'
# self.font = "monospace"
# self.font_size = 30
self.txt_w = df.display_width
self.txt_h = 30
self.txt_x = df.display_width*0.1
self.txt_y = df.display_height - self.txt_h*2
self.txt_color= df.gray
self.hover_color = df.white
self.click_color = df.red
self.shadow_w = df.display_width
self.shadow_h = 50
self.shadow_x = 0
self.shadow_y = self.txt_y
self.shadow_color = df.white
self.index = 0
self.highlighted = False
self.clicked = False
self.max_frame = 10
self.animating = False
self.txt_x_d = self.txt_x
self.txt_y_d = self.txt_y
self.shadow_x_d = self.shadow_x
self.shadow_y_d = self.shadow_y
self.shadow_color = df.white
self.font_btn = txg.TextGame()
self.font_btn.font_size = 50
self.font_btn.set_font()
self.font_btn.center = (self.txt_x, self.txt_y)
self.font_btn.color = df.white
# self.font = pygame.font.Font("assets/fonts/horrendo.ttf", self.font_size)
def draw_sprite2(self):
var.gameDisplay.blit(self.image, (self.rect.x, self.rect.y))
def highlight(self, color):
s = pygame.Surface((self.rect.w, self.rect.h))
s.set_alpha(50)
s.fill(color)
pygame.draw.rect(var.gameDisplay, color, [self.rect.x, self.rect.y, self.rect.w, 1])
pygame.draw.rect(var.gameDisplay, color, [self.rect.x, self.rect.y, 1, self.rect.h])
pygame.draw.rect(var.gameDisplay, color, [self.rect.x, self.rect.y + self.rect.h, self.rect.w, 1])
pygame.draw.rect(var.gameDisplay, color, [self.rect.x+self.rect.w, self.rect.y, 1, self.rect.h])
var.gameDisplay.blit(s, (self.rect.x, self.rect.y))
def new_shadow(self, color):
s = pygame.Surface((self.txt_w, self.shadow_h))
s.set_alpha(50)
s.fill(color)
var.gameDisplay.blit(s, (self.shadow_x, self.shadow_y))
def new_msg(self, text):
self.new_shadow(self.shadow_color)
self.font_btn.display_text(text)
# myfont = pygame.font.SysFont(self.font, self.font_size)
# label = self.font.render(text, 1, color2)
# var.gameDisplay.blit(label, (self.txt_x, self.txt_y))
def onClick(self, mouse):
if self.rect.collidepoint(mouse.get_pos()) == 1:
self.highlight(self.hover_color)
self.new_msg(self.hover_text)
# self.highlighted = True
if mouse.get_pressed()[0]:
self.animating = True
self.clicked = True
print('button clicked', self.file)
self.index = 0
time.sleep(0.5)
else:
self.highlight_color = self.hover_color
if self.animating:self.animate()
self.draw_sprite2()
if self.animating or not self.clicked:
return False #continue running
else:
self.clicked = False
return True #clicken event is true
def animate(self):
self.index +=1
if self.index < self.max_frame:
self.highlight(self.click_color)
# self.new_msg('Nuevo', self.click_color, self.click_color)
# self.new_msg(self.hover_text, self.click_color, self.click_color)
self.txt_x += 100
#self.txt_y += 1
self.shadow_x += 100
#self.shadow_y += 1
self.animating = True
else:
self.animating = False
self.txt_x = self.txt_x_d
self.txt_y = self.txt_y_d
self.shadow_x = self.shadow_x_d
self.shadow_y = self.shadow_y_d
class Imap(Button):
def __init__(self,filename, x, y, level, gap, blocked, total_enemies):
w = 50
h = 50
Button.__init__(self, filename, x, y, w, h)
self.level = level
self.blocked = blocked
self.total = total_enemies
self.gap = gap
self.map_name = ""
self.filename = ""
self.bfilename = var.assetsDir + "icons8-lock-100.png"
self.lockpad = sp.Sprite2()
self.lockpad.file = self.bfilename
self.lockpad.w = int(w*0.5)
self.lockpad.h = int(h*0.5)
self.lockpad.set_image()
self.lockpad.rect.x = x
self.lockpad.rect.y = y
self.hover_text = 'Level ' + str(level) + ' / ' + str(total_enemies) + ' Zombies'
self.font_btn.color = df.red
def set_map(self):
if self.level ==1 :
self.map_name = 'classic_city.jpg'
self.gap = df.display_height * 0.1437
if self.level ==2 :
self.map_name = 'china.jpg'
self.gap = df.display_height * 0.181
if self.level ==3 :
self.map_name = 'parallax background for nature tileset.jpg'
self.gap = df.display_height * 0.195
if self.level ==4 :
self.map_name = 'forest.jpg'
self.gap = df.display_height * 0.0762
if self.level ==5 :
self.map_name = 'classic1.jpg'
self.gap = df.display_height * 0.2063
if self.level ==6 :
self.map_name = 'classic2.jpg'
self.gap = df.display_height * 0.185
if self.level ==7 :
self.map_name = 'night_lanterns.jpg'
self.gap = df.display_height * 0.183
if self.level ==8 :
self.map_name = 'mountain_valley.jpg'
self.gap = df.display_height * 0.05
if self.level ==9 :
self.map_name = 'snow1.jpg'
self.gap = df.display_height * 0.17
if self.level ==10 :
self.map_name = 'snow2.jpg'
self.gap = df.display_height * 0.176
if self.level ==11 :
self.map_name = 'horror2.jpg'
self.gap = df.display_height * 0.195
if self.level ==12 :
self.map_name = 'horror1.jpg'
self.gap = df.display_height * 0.1775
if self.level ==13 :
self.map_name = 'volcanoes.jpg'
self.gap = df.display_height * 0.171
if self.level ==14 :
self.map_name = 'volcanoes.jpg'
self.gap = df.display_height * 0.171
# self.map_name = self.file.split("_", 1)[1]
# self.map_name = self.map_name.split(".", 1)[0]
self.filename = var.assetsDir + "backgrounds/" + self.map_name
def draw_block(self):
# var.gameDisplay.blit(self.image, (self.rect.x, self.rect.y))
if self.blocked:
var.gameDisplay.blit(self.lockpad.image, (self.rect.x, self.rect.y))