main.py:
import pygame, datos
from pygame.locals import *
pygame.init()
class Menu:
def __init__(self):
self.salir= False
self.opciones = [("F1: Jugar"),("F2: Como jugar?"),("F3: Salir")]
self.font = pygame.font.Font('dejavu.ttf', 20)
self.seleccionado = False
self.mantiene_pulsado = False
self.total = len(self.opciones)
def imprimir(self,pantalla):
#Imprime texto del menu
total = self.total
indice = 0
altura_de_opcion = 30
x = 270
y = 450
for (titulo) in self.opciones:
color = (0, 0, 0)
imagen = self.font.render(titulo, 1, color)
posicion = (x, y + altura_de_opcion * indice)
indice += 1
pantalla.blit(imagen, posicion)
def run(self):
menu.imprimir(pantalla)
while not salir:
for e in pygame.event.get():
if e.type == QUIT:
salir= True
elif e.type == pygame.KEYDOWN:
if e.key == K_F1:
datos.inicializar(pantalla)
i=ImagenesMenu()
ImagenesMenu.render()
elif e.key == K_F2:
datos.opciones()
elif e.key == K_F3:
salir_juego()
#Limpiar pantalla
menu.imprimir(pantalla)
pygame.display.flip()
class Detalles:
def __init__(self,detalles):
self.detalles= detalles
self.font = pygame.font.Font('dejavu.ttf', 20)
self.jugador= detalles[0]
self.puntos= detalles[1]
self.vida= detalles[2]
self.nivel= detalles[3]
self.total = len(detalles)
def mostrar_detalles(self,pantalla):
indice= 0
ok= 0
x=530
y=25
for (titulo) in self.detalles:
indice+=1
if indice < 3:
color = (255,255,255)
imagen = self.font.render(titulo, 1, color)
posicion = (x, y)
y= y+75
pantalla.blit(imagen, posicion)
else:
if ok == 0:
color = (255,255,255)
imagen = self.font.render(titulo, 1, color)
y= y+50
posicion = (x, y)
pantalla.blit(imagen, posicion)
ok+=1
else:
color = (255,255,255)
imagen = self.font.render(titulo, 1, color)
y= y+75
posicion = (x, y)
pantalla.blit(imagen, posicion)
class ImagenesMenu():
def __init__(self):
self.fondopuntajes= pygame.image.load("textura.jpg")
self.separador= pygame.image.load("separador.jpg")
self.separador2= pygame.image.load("separador2.jpg")
self.imagen= pygame.image.load("metal.jpg")
self.x=500
self.y=0
def render(self,pantalla):
pantalla.blit(self.imagen,(self.y,self.y))
pantalla.blit(self.fondopuntajes,(self.x,self.y))
pantalla.blit(self.separador,(self.x,self.y))
pantalla.blit(self.separador2,(self.x+26,self.y))
pantalla.blit(self.separador2,(self.x+26,self.y+200))
pantalla.blit(self.separador2,(self.x+26,self.y+400))
class ImagenesInicio():
def __init__(self):
self.fondo= pygame.image.load("fondo.jpg")
self.logo= pygame.image.load("logo2.png")
def render(self):
pantalla.blit(self.fondo,(0,0))
pantalla.blit(self.logo,(200,150))
class OpcionesJuego():
def __init__(self):
self.imagen=pygame.image.load("comojugar.png")
def render(self):
pantalla.blit(self.imagen,(0,0))
def salir_juego():
import sys
sys.exit()
#Configura pantalla
VENTANAALTO= 600
VENTANAANCHO= 700
pantalla= pygame.display.set_mode ((VENTANAANCHO,VENTANAALTO),0)
pygame.display.set_caption("Aprendiendo a Contar!")
inicial= ImagenesInicio()
pygame.font.init()
menu=Menu()
salir= False
menu.imprimir(pantalla)
inicial.render()
while not salir:
for e in pygame.event.get():
if e.type == QUIT:
salir= True
elif e.type == pygame.KEYDOWN:
if e.key == K_F1:
datos.setear(pantalla)
elif e.key == K_F2:
print " ejecuta las opciones"
#datos.opciones()
elif e.key == K_F3:
salir_juego()
#Limpiar pantalla
menu.imprimir(pantalla)
pygame.display.flip()
#pygame.time.delay(5)
datos.py:
import pygame, main
from pygame.locals import *
def setear(pantalla):
imagen=pygame.image.load("previa.png")
imagen.blit(imagen,(0,0))
salir= False
while not salir:
for e in pygame.event.get():
if e.type == QUIT:
salir= True
elif e.type == pygame.KEYDOWN:
if e.key == K_F1:
print"arranca juego"
inicializar(pantalla)
elif e.key == K_F2:
print "Vovler al menu"
elif e.key == K_F2:
inicializar(pantalla)
elif e.key == K_F3:
main.salir_juego()
def inicializar(pantalla):
detalles = [("Jugador:"), ("Puntaje:"),("Vidas:"), ("Nivel:")]
img=main.ImagenesMenu()
img.render(pantalla)
d=main.Detalles(detalles)
d.mostrar_detalles(pantalla)
'''
def opciones():
o=main.OpcionesJuego()
o.opciones_juego()
salir= False
while not salir:
for e in pygame.event.get():
if e.type == QUIT:
salir= True
elif e.type == pygame.KEYDOWN:
if e.key == K_F1:
print "muestra las opciones"
elif e.key == K_F5:
print "F5"
'''