Skip to content

Commit

Permalink
Incorporación de juegos restantes (GameMenu)
Browse files Browse the repository at this point in the history
  • Loading branch information
icarito committed Jan 14, 2015
1 parent a927478 commit b25cd0d
Show file tree
Hide file tree
Showing 7 changed files with 775 additions and 42 deletions.
119 changes: 113 additions & 6 deletions GameView.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
sys.path.insert(1, os.path.join(installed_dir, "Lib/"))

import gtk
import pango

import sugargame2
import sugargame2.canvas
import spyral
Expand All @@ -34,9 +36,52 @@

import gobject

class GameMenu(gtk.VBox):
def __init__(self):
gtk.VBox.__init__(self)

self.modify_bg(gtk.STATE_NORMAL, COLORES["contenido"])
self.set_border_width(4)

self.hbox = gtk.HBox()

self.ug1 = gtk.Button("Hello Asteroids")
self.ug2 = gtk.Button("Reforestation Circuit")
self.ug3 = gtk.Button("The Chakana Cross")

index = 0
for butt in self.ug1, self.ug2, self.ug3:
butt.modify_bg(gtk.STATE_NORMAL, COLORES["toolbar"])
butt.modify_fg(gtk.STATE_NORMAL, COLORES["text"])
butt.child.modify_font(pango.FontDescription("DejaVu Sans Bold 16"))
self.hbox.pack_start(butt)
butt.connect("clicked", self.start_game, index)
index += 1

self.pack_start(self.hbox)

self.gameview = GameView()
self.pack_end(self.gameview, True, True, 0)

def stop(self):
self.gameview.stop()
self.hide()

def run(self, topic):
self.topic = topic
self.show_all()
self.gameview.hide()

def start_game(self, widget, index):
self.gameview.run(self.topic, index)
self.hbox.hide()

class GameView(gtk.EventBox):

__gsignals__ = {
"video": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, (gobject.TYPE_STRING, ))}

def __init__(self):

gtk.EventBox.__init__(self)
Expand All @@ -51,20 +96,38 @@ def __init__(self):
#self.pygamecanvas.set_flags(gtk.EXPAND)
#self.pygamecanvas.set_flags(gtk.FILL)

grupo = gtk.Alignment(0.5, 0.5, 0,0)
grupo.add(self.pygamecanvas)
grupo1 = gtk.Alignment(0.5, 0, 0,0)
butt = gtk.Button()
img = gtk.Image()
img.set_from_stock(gtk.STOCK_GO_BACK, gtk.ICON_SIZE_DIALOG)
butt.set_image(img)
butt.set_label("")
butt.modify_bg(gtk.STATE_NORMAL, COLORES["toolbar"])
butt.modify_fg(gtk.STATE_NORMAL, COLORES["text"])
butt.connect("clicked", self.__emit_video)
grupo1.add(butt)

grupo2 = gtk.Alignment(0.5, 0.5, 0,0)
grupo2.add(self.pygamecanvas)

hb = gtk.HBox()
hb.pack_start(grupo1, expand=False, fill=False)
hb.pack_end(grupo2)

self.add(grupo)
self.add(hb)

self.connect("size-allocate", self.__reescalar)
self.show_all()

def __emit_video(self, widget):
self.emit("video", self.topic)

def __reescalar(self, widget, event):
if self.game:
rect = self.get_allocation()
# FIXME: El juego debe reescalarse a: rect.width, rect.height

def __run_game(self):
def __run_game_1(self):
from Games.ug1.runme import Intro

rect = self.get_allocation()
Expand All @@ -83,6 +146,44 @@ def __run_game(self):
except pygame.error:
pass

def __run_game_2(self):
from Games.ug2.runme import Escena

rect = self.get_allocation()
self.lado = min(rect.width-8, rect.height-8)
self.pygamecanvas.set_size_request(self.lado, self.lado)
spyral.director.init((self.lado, self.lado),
fullscreen=False, max_fps=30)
self.game = Escena(self.topic)
spyral.director.push(self.game)
if self.pump:
gobject.source_remove(self.pump)
self.pump = False
self.pump = gobject.timeout_add(300, self.__pump)
try:
spyral.director.run(sugar=True)
except pygame.error:
pass

def __run_game_3(self):
from Games.ug3.runme import Escena

rect = self.get_allocation()
self.lado = min(rect.width-8, rect.height-8)
self.pygamecanvas.set_size_request(self.lado, self.lado)
spyral.director.init((self.lado, self.lado),
fullscreen=False, max_fps=30)
self.game = Escena(self.topic)
spyral.director.push(self.game)
if self.pump:
gobject.source_remove(self.pump)
self.pump = False
self.pump = gobject.timeout_add(300, self.__pump)
try:
spyral.director.run(sugar=True)
except pygame.error:
pass

def __pump(self):
pygame.event.pump()
return True
Expand All @@ -102,8 +203,14 @@ def stop(self):
self.game = False
self.hide()

def run(self, topic):
def run(self, topic, game):
if game==0:
gamestart=self.__run_game_1
elif game==1:
gamestart=self.__run_game_2
elif game==2:
gamestart=self.__run_game_3
self.topic = topic
self.pygamecanvas.run_pygame(self.__run_game)
self.pygamecanvas.run_pygame(gamestart)
self.pygamecanvas.grab_focus()
self.show()
1 change: 0 additions & 1 deletion Games/ug1/runme.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ def procesar_tecla(self, key):
self.hit_snd.play()
else:
self.blup_snd.play()


self.mostrar(self.palabra, self.acertadas)

Expand Down
48 changes: 16 additions & 32 deletions Games/ug2/runme.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ def gamedir(archivo):
SIZE = (700, 700)
TILE = (64, 64)

MAPA1 = [
[0, 0, 0, 1, 2],
[0, 1, 3, 0, 0],
[0, 0 ,0, 0, 0],
[3, 4, 0, 0, 2],
[5, 0, 5, 0, 4]]

def wrap(text, length):
"""
Sirve para cortar texto en varias lineas
Expand All @@ -65,7 +58,7 @@ def wrap(text, length):
topic_dir = gamedir("../../Topics/Topic_4/")


def obtener_palabra(topic_dir=topic_dir):
def obtener_palabra(topic_dir):
archivo = os.path.join(topic_dir, "vocabulario.csv")
tabla = csv.DictReader(file(archivo))
lista = []
Expand All @@ -83,16 +76,16 @@ def obtener_palabra(topic_dir=topic_dir):

return palabra, palabra_png

def obtener_set():
def obtener_set(topic):
conjunto = list()
while len(conjunto)<5:
nueva = obtener_palabra()
nueva = obtener_palabra(topic)
if nueva not in conjunto:
conjunto.append(nueva)
return conjunto

class Tablero(spyral.View):
def __init__(self, scene):
def __init__(self, scene, topic, mapa):
spyral.View.__init__(self, scene)

margin = (700 - (140 * 5)) / 2
Expand All @@ -101,9 +94,9 @@ def __init__(self, scene):

self.layers = ["abajo", "arriba", "primer"]

self.tablero = MAPA1
self.tablero = mapa

self.palabras = obtener_set()
self.palabras = obtener_set(topic)
self.cursor = Cursor(self)
self.camino = []

Expand Down Expand Up @@ -155,7 +148,7 @@ def match(self, primero, segundo):

def check_win(self):
bloques_rest = 0
nexos_rest = 0
nexos_rest = 0
for fila in self.tablero:
for bloque in fila:
if "Bloque" in bloque.__class__.__name__:
Expand All @@ -179,7 +172,7 @@ def get_match(self, primero):
if "Bloque" in bloque.__class__.__name__:
if bloque.COLOR==primero.COLOR and bloque is not primero:
return bloque


def movimiento(self, ubicacion):
#print "Movimiento: "+str(ubicacion)
Expand Down Expand Up @@ -613,25 +606,16 @@ def __init__(self, topic=topic_dir):

self.background = img

self.tablero = Tablero(self)

spyral.event.register("system.quit", spyral.director.pop, scene=self)
mapa1 = [
[0, 0, 0, 1, 2],
[0, 1, 3, 0, 0],
[0, 0 ,0, 0, 0],
[3, 4, 0, 0, 2],
[5, 0, 5, 0, 4]]

self.tablero = Tablero(self, topic, mapa=mapa1)

# Tomado de Spyral
class DelayAnimation(spyral.Animation):
"""
Animation which performs no actions. Useful for lining up appended
and parallel animations so that things run at the right times.
"""
def __init__(self, duration=1.0):
self.absolute = False
self.properties = set([])
self.duration = duration
self.loop = False

def evaluate(self, sprite, progress):
return {}
spyral.event.register("system.quit", spyral.director.pop, scene=self)

def QuadraticOutTuple(start=(0, 0), finish=(0, 0)):
"""
Expand Down
Empty file added Games/ug3/__init__.py
Empty file.
Binary file added Games/ug3/imagenes/Crux-20100220.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b25cd0d

Please sign in to comment.