def resize(self): self.lw,self.lh = pygame.display.get_surface().get_size() self.SURFACE = pygame.surface.Surface((pygame.display.get_surface().get_size()[0], 100),pygame.SRCALPHA,32) background = pygame.surface.Surface(self.SURFACE.get_size()) background.fill(op("bar","color",(0,0,0))) background.set_alpha(op("bar","transparencia")) self.SURFACE.blit(background,(0,0)) pf.add_border(self.SURFACE, 1 , 1 , 1 ,1 , (0,0,0) )
def __init__(self, name, ub, color, cant_bot, tamY): tam = pfunctions.ubuntu_bold_graph.render(name, 1, (0, 0, 0)).get_size() tam = (tam[0] + 30, tamY) self.Tbot_men = (160, 26) self.color = color self.name = name self.ubic = ub self.Tbot = tam self.pos = (self.ubic, 0) self.hover = False self.pressed = False self.nbot = 0 self.menu = pygame.Surface( (self.Tbot_men[0], self.Tbot_men[1] * cant_bot)) self.Tmenu = (self.Tbot_men[0] + 8, self.Tbot_men[1] * cant_bot + 8) self.Pmenu = (self.pos[0], self.Tbot[1]) self.menu.fill((211, 211, 211)) self.menu = pfunctions.add_border(self.menu, 2, 2, 2, 2, (150, 150, 150)) self.Pbotones = [] self.Nbotones = [] self.Cbotones = [] self.hover_menu = [] self.cant_bot = cant_bot self.LM = 0 self.LM2 = 0 self.enviado = False
def checkbox(self, surface, mouse, global_pos, x, y, titulo, ubicacion=1): title = self.font1.render(str(titulo), 1, (0, 0, 0)) pos_title = (2, 2 + title.get_size()[1] * ubicacion + 5 * ubicacion - self.disferencia_barra) surface.blit(title, pos_title) size_checkbox = (title.get_size()[1] + 4, title.get_size()[1] + 4) checkbox = pygame.Surface(size_checkbox) checkbox.fill((255, 255, 255)) checkbox = pf.add_border(checkbox, 4, 4, 4, 4, (0, 0, 0)) pos_checkbox = (2 + title.get_size()[0] + 5, pos_title[1] - 4) x_checkbox = self.font1.render("X", 1, (255, 0, 0)) if self.checkbox_selected: checkbox.blit( x_checkbox, (size_checkbox[0] / 2 - x_checkbox.get_size()[0] / 2, size_checkbox[1] / 2 - x_checkbox.get_size()[1] / 2)) surface.blit(checkbox, pos_checkbox) if mouse.get_pressed()[0] and pygame.time.get_ticks() > self.LP1 + 100: self.LP1 = pygame.time.get_ticks() if x > global_pos[0] + pos_checkbox[0] and x < global_pos[ 0] + pos_checkbox[0] + size_checkbox[0] and y > global_pos[ 1] + pos_checkbox[1] and y < global_pos[ 1] + pos_checkbox[1] + size_checkbox[1]: if self.checkbox_selected: self.checkbox_selected = False else: self.checkbox_selected = True
def __init__(self, X, Y, cx, cy, name, type): img = pygame.Surface((50, 50)) self.speed = 5 self.danino = False if type == 1: img.fill((0, 133, 255)) img = add_border(img, 2, 2, 2, 2, (0, 0, 0)) self.speed = 5 elif type == 2: img.fill((255, 222, 0)) for q in range(50): for w in range(50): if random.randrange(0, 6) == 2: img.blit(pygame.Surface((1, 1)), (q, w)) self.speed = 2 elif type == 3: img.fill((231, 231, 231)) self.speed = 10 elif type == 4: self.danino = 4 img.fill((226, 36, 48)) for q in range(50): for w in range(50): if random.randrange(0, 12) == 5: img.blit(pygame.Surface((1, 1)), (q, w)) img = generate.generate_background(img, cx, cy) self._cx = cx self._cy = cy self._type = type self.element(X, Y, name, "background", [], img)
def graphic_update(self, pantalla): self.boton = img.boton_configuracion self.Pboton = (pantalla.get_size()[0] - self.boton.get_size()[0] - 5, 5) pantalla.blit(self.boton, self.Pboton) if self.activo: self.Sfondo = [300, 10] for q in self.configs: test = self.font.render(q, 1, (0, 0, 0)) if test.get_size()[0] > self.Sfondo[0]: self.Sfondo[0] = test.get_size()[0] self.Sfondo[1] += test.get_size()[1] + 10 self.fondo = pygame.Surface(self.Sfondo) self.fondo.fill((215, 211, 211)) self.fondo = pf.add_border(self.fondo, 4, 4, 4, 4, (170, 170, 170)) self.Pfondo = [ pantalla.get_size()[0] - 5 - self.Sfondo[0], 5 + self.boton.get_size()[1] ] y_act = 10 barra = pygame.Surface((self.Sfondo[0] - 10, 2)) for q in range(len(self.configs)): render = self.font.render(self.configs[q], 1, (0, 0, 0)) self.fondo.blit(render, (10, y_act)) if y_act != 10: self.fondo.blit(barra, (5, y_act - 6)) pos_boton = (self.Sfondo[0] - 10 - self.botones[q][0].get_size()[0], y_act + render.get_size()[1] / 2 - self.botones[q][0].get_size()[1] / 2) self.botones[q][1] = pos_boton self.fondo.blit(self.botones[q][0], pos_boton) y_act += render.get_size()[1] + 10 pantalla.blit(self.fondo, self.Pfondo)
def Mgraphic_update(self, pantalla): self.menu = pygame.Surface( (self.Tbot_men[0] + 8, self.Tbot_men[1] * self.cant_bot + 8)) self.menu.fill((211, 211, 211)) self.menu = pfunctions.add_border(self.menu, 2, 2, 2, 2, (150, 150, 150)) for q in range(len(self.Nbotones)): texto = self.Nbotones[q] pos = self.Pbotones[q] color = self.Cbotones[q] hover_menu = self.hover_menu[q] if hover_menu: self.bot_men = pfunctions.boton(self.Tbot_men, texto, False, [1, 1, 1, 1], (211, 211, 211), (0, 0, 0), (0, 0, 0), 18) else: self.bot_men = pfunctions.boton(self.Tbot_men, texto, False, [0, 0, 0, 0], (211, 211, 211), (0, 0, 0), (0, 0, 0), 18) self.menu.blit(self.bot_men, pos) pantalla.blit(self.menu, (self.pos[0], self.pos[1] + self.Tbot[1]))
def graphic_update(self, pantalla): self.pantalla = pantalla if not self.seleccionando_nombre and not self.terminado: self.posicion_act(pantalla) self.phi.graphic_update(pantalla) self.bar_size = (pantalla.get_size()[0], 120) self.bar_pos = (0, pantalla.get_size()[1] - self.bar_size[1]) self.bar = pygame.Surface(self.bar_size) self.bar.fill((0, 192, 255)) self.font1 = pygame.font.Font(fonts.font3, 20) seleccione_objeto = self.font1.render("Seleccione objeto:", 1, (0, 0, 0)) self.bar.blit(seleccione_objeto, (5, 2)) x_act = 10 for q in range(len(self.objetos)): self.objetos[q][1] = pygame.transform.scale( self.objetos[q][1], self.size_buttons) if self.selected == self.objetos[q][0]: self.objetos[q][1] = pf.add_border(self.objetos[q][1], 4, 4, 4, 4, (255, 0, 0)) else: self.objetos[q][1] = pf.add_border(self.objetos[q][1], 4, 4, 4, 4, (0, 0, 0)) pos_act_obj = (x_act, 2 + seleccione_objeto.get_size()[1] + 20) self.bar.blit(self.objetos[q][1], pos_act_obj) self.ayuda[q + 1].cambiar_valores( (self.bar_pos[0] + pos_act_obj[0], self.bar_pos[1] + pos_act_obj[1]), self.size_buttons) if len(self.objetos[q]) > 3: del self.objetos[q][3] self.objetos[q].append( (self.bar_pos[0] + x_act, self.bar_pos[1] + 30)) x_act += self.objetos[q][1].get_size()[0] + 10 self.pos_propiedades = (x_act + 10, 5) self.propiedades = pygame.Surface( (self.bar_size[0] - x_act - 20, self.bar_size[1] - 10)) self.propiedades.fill((0, 255, 255)) self.title_propiedades = self.font1.render("Propiedades:", 1, (0, 0, 255)) self.propiedades.blit(self.title_propiedades, (2, 2 - self.disferencia_barra)) self.propiedades = self.analizar_propiedades(self.propiedades) if self.objetos_propiedades > 3: self.barra_activa = True self.barra.set_scale(1.0 / float(self.objetos_propiedades)) self.barra.set_position( (self.propiedades.get_size()[0] - 32, 2)) self.barra.global_position = (self.bar_pos[0] + self.pos_propiedades[0], self.bar_pos[1] + self.pos_propiedades[1]) self.barra.graphic_update(self.propiedades) self.disferencia_barra = int(self.barra.position * self.propiedades.get_size()[1]) else: self.barra_activa = False self.bar.blit(self.propiedades, self.pos_propiedades) if not self.borrando: borrar = self.font1.render("Borrar", 1, (0, 0, 0)) else: borrar = self.font1.render("Borrar", 1, (255, 0, 0)) self.pos_borrar = (seleccione_objeto.get_size()[0] + 40, 2) self.size_borrar = borrar.get_size() self.bar.blit(borrar, self.pos_borrar) if self.selected == "NO": vaciar = self.font1.render("Nada", 1, (255, 0, 0)) else: vaciar = self.font1.render("Nada", 1, (0, 0, 0)) self.pos_vaciar = (seleccione_objeto.get_size()[0] + 40 + borrar.get_size()[0] + 40, 2) self.size_vaciar = vaciar.get_size() self.bar.blit(vaciar, self.pos_vaciar) self.size_enviar = (100, 100) self.pos_enviar = (pantalla.get_size()[0] - self.size_enviar[0], 0) self.enviar = pf.boton_redondo(pantalla, self.pos_enviar, self.size_enviar, self.size_enviar[0] / 2, "Guardar", True, 4, (255, 0, 0), (0, 0, 255), (0, 255, 0)) pantalla.blit(self.bar, self.bar_pos) self.ayuda[0].cambiar_valores(self.pos_enviar, self.size_enviar) for q in self.ayuda: q.graphic_update(pantalla) self.iniciado = True if self.seleccionando_nombre: self.nombre_nivel.graphic_update(pantalla) if self.terminado: self.game_over.graphic_update(pantalla)
import utils.pfunctions as pf ruta = "data/images/" tux_world = pygame.image.load(ruta + "tux_world.png") fondo_menu = pygame.image.load(ruta + "fondo_menu.png") test_enemigo = pygame.image.load(ruta + "enemigos/windows.png") test_enemigo = pygame.transform.scale(test_enemigo, (50, 50)) enemigo2 = pygame.image.load(ruta + "enemigos/enemigo_x4.png") moneda = pygame.image.load(ruta + "moneda.png") caja = pygame.image.load(ruta + "Box/caja_cerrada.png") caja = pygame.transform.scale(caja, (50, 50)) disco = pygame.image.load(ruta + "disco3.png") disco = pygame.transform.scale(disco, (50, 50)) test_background = pygame.Surface((50, 50)) test_background.fill((0, 133, 255, 0.98)) test_background = pf.add_border(test_background, 2, 2, 2, 2, (0, 0, 0)) test_bomba = pygame.image.load(ruta + "bombas/tnt_0.png") def load_backgrounds(): bks = glob.glob(ruta + "background/*.png") backgrounds = [] for x in range(len(bks)): backgrounds.append(pygame.image.load(bks[x])) return backgrounds def cargar_bombas(): dmt = glob.glob(ruta + "bombas/*.png") dmt = sorted(dmt)
def graphic_update(self,Pantalla): self.Render_boton = self.Font.render("Aceptar",1,(0,0,0)) self.Tboton = [self.Render_boton.get_size()[0] + 40, self.Render_boton.get_size()[1] + 10] self.Boton = pygame.Surface((self.Tboton[0] + 4, self.Tboton[1] + 4)) self.Surface_boton = pygame.Surface(self.Tboton) self.Surface_boton.fill(self.Color_boton) self.Boton.blit(self.Surface_boton,(2,2)) self.Boton.blit(self.Render_boton,(self.Boton.get_size()[0]/2-self.Render_boton.get_size()[0]/2,self.Boton.get_size()[1]/2-self.Render_boton.get_size()[1]/2)) self.Talert = [300,10] lineas = [] palabras = [] palabra = "" for q in self.Text: if q == " ": palabras.append(palabra) palabra = "" else: palabra += q if palabra != "": palabras.append(palabra) end = False while not end: for q in range(len(palabras)): test = "" for w in range(q): test += palabras[w] + " " #if q != len(palabras) - 1: test2 = "" for w in range(q+1): test2 += palabras[w] + " " n1 = self.Font.render(test,1,(0,0,0)) n2 = self.Font.render(test2,1,(0,0,0)) if n1.get_size()[0] < self.Talert[0] and n2.get_size()[0] >= self.Talert[0]: lineas.append(test) for w in range(q): del palabras[0] break if q == len(palabras)-1: if len(palabras) > 0: test = "" for w in palabras: test += w + " " lineas.append(test) end = True for q in range(len(lineas)): self.Talert[1] += self.Font.render(lineas[q],1,(0,0,0)).get_size()[1] + 10 if lineas[q][len(lineas[q])-1] == " ": lineas[q] = lineas[q][:len(lineas[q])-1] self.Talert[1] += self.Tboton[1] + 10 self.Position = [Pantalla.get_size()[0]/2-self.Talert[0]/2,Pantalla.get_size()[1]/2-self.Talert[1]/2] self.Alert = pygame.Surface(self.Talert) self.Alert.fill((255,255,255)) self.Alert = pf.add_border(self.Alert, 2, 2, 2, 2, (0,0,0)) pos_y = 10 for q in range(len(lineas)): rendered = self.Font.render(lineas[q],1,(0,0,0)) self.Alert.blit(rendered,(self.Talert[0]/2-rendered.get_size()[0]/2,pos_y)) pos_y += rendered.get_size()[1] + 10 pos_boton = (self.Talert[0]/2-self.Tboton[0]/2,pos_y) self.Position_boton = (self.Position[0] + pos_boton[0], self.Position[1] + pos_boton[1]) self.Alert.blit(self.Boton,pos_boton) Pantalla.blit(self.Alert,self.Position)