Skip to content

Commit

Permalink
Ajustes al juego para correr mejor en la XO 1.5 - F11
Browse files Browse the repository at this point in the history
  • Loading branch information
icarito committed Dec 9, 2014
1 parent f5194eb commit 83d75e8
Show file tree
Hide file tree
Showing 46 changed files with 235 additions and 11,732 deletions.
26 changes: 17 additions & 9 deletions GameView.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
sys.path.insert(1, "Lib/")

import gtk

from Globales import COLORES

import gobject
import sugargame2
import sugargame2.canvas
import spyral
import pygame
from Games.ug1.runme import Escena

from Globales import COLORES

import gobject


class GameView(gtk.EventBox):
Expand Down Expand Up @@ -64,6 +63,8 @@ def __reescalar(self, widget, event):
# FIXME: El juego debe reescalarse a: rect.width, rect.height

def __run_game(self):
from Games.ug1.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)
Expand All @@ -75,7 +76,10 @@ def __run_game(self):
gobject.source_remove(self.pump)
self.pump = False
self.pump = gobject.timeout_add(300, self.__pump)
spyral.director.run(sugar=True)
try:
spyral.director.run(sugar=True)
except spyral.exceptions.GameEndException, pygame.error:
pass

def __pump(self):
pygame.event.pump()
Expand All @@ -86,9 +90,13 @@ def stop(self):
gobject.source_remove(self.pump)
self.pump = False
if self.game:
spyral.quit()
del(self.game)
self.game = False
try:
spyral.quit()
del(self.game)
except spyral.exceptions.GameEndException, pygame.error:
pass
finally:
self.game = False
self.hide()

def run(self, topic):
Expand Down
137 changes: 137 additions & 0 deletions Games/ug1/dev_launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
### CISC374 Test Launcher

__author__ = "Robert Deaton"
__version__ = "0.3"
__license__ = "MIT"

import sys
sys.path.insert(1, "../../Lib/")

import gettext
import sys
import os
#import libraries
#libraries.setup_path()
from optparse import OptionParser
import spyral
try:
import json
except ImportError:
import simplejson as json

def format_columns(message, data):
first_width = max([len(x[0]) for x in data])
second_width = max([len(x[1]) for x in data])
total_width = first_width + second_width + 8

# calculate a format string for the output lines
format_str = "%%-%ds %%-%ds" % (first_width, second_width)

print message
print "=" * max(total_width, len(message))
for x in data:
print format_str % x

if __name__ == '__main__':
parser = OptionParser()
parser.add_option("-f", "--fullscreen", action="store_true", dest="fullscreen", default=False, help="Run in fullscreen mode. Default is windowed mode.")
parser.add_option("-r", "--resolution", type="int", nargs=2, dest="res", help="Specify the resolution. Default is 0 0, which uses the screen's resolution.", metavar="WIDTH HEIGHT", default=(0,0))
parser.add_option("-s", "--fps", type="int", dest="fps", help="Specify the fps cap. Default is 30", metavar="FPS", default=30)
parser.add_option("-l", "--locale", type="str", dest="locale", help="Specify the locale to launch the game with. Default uses the system's locale settings.", default="default")
parser.add_option("-t", "--list-translations", action="store_true", dest="list", default=False, help="List the available translations.")
parser.add_option("-p", "--profile", action="store_true", dest="profile", default=False,help="Enable profiling via cProfile. Individual profiles for each scene will be output. If graphviz is installed on your system, callgrind style output images will be created.")
parser.add_option("-o", "--output", type="string", dest="profile_output", default=None, help="Specify an output directory for profiling data. By default, output will be placed in profiles/%d-%m-%Y %H-%M-%S/")
parser.add_option("-g", "--graphviz", action="store_true", dest="graphviz", default=False, help="Use graphviz if available to generate png callgraphs if profiling is enabled.")
(options, args) = parser.parse_args()

languages = None
if os.path.exists('./locale'):
languages = [file for file in os.listdir('./locale') if os.path.isdir('./locale/%s' % file) and os.path.isfile('./locale/%s/activity.linfo' % file)]

if options.list:
if languages:
print 'Available translations: %s' % ', '.join(languages)
else:
print 'No available translations'
sys.exit()

if options.graphviz and not options.profile:
print 'Graphiz option '

if options.locale != 'default':
lang = gettext.translation("org.laptop.community.cisc374.mathadder", "./locale", languages=[options.locale])
lang.install()
else:
gettext.install("org.laptop.community.cisc374.mathadder", "./locale")

if options.profile_output is not None:
output_dir = options.profile_output
elif options.profile:
import time
d = time.strftime("%d-%m-%Y %H-%M-%S")
output_dir = os.path.join('profiles', d)

def launch():
import runme
runme.main()

## Let's output some friendly information at the top
output = [
("launcher version:", __version__),
("spyral version:", spyral.__version__),
("resolution:", "Autodetect" if options.res == (0,0) else str(options.res[0]) + " x " + str(options.res[1])),
("fullscreen:", "True" if options.fullscreen else "False"),
("Max FPS:", str(options.fps)),
("Locale:", options.locale),
("Profiling:", "Enabled" if options.profile else "Disabled")
]
if options.profile:
output.append(("Profile output:", output_dir))
format_columns("CISC374 Launcher", output)

if not options.profile:
try:
spyral.director.init(options.res, fullscreen = options.fullscreen, max_fps = options.fps)
launch()
spyral.director.run()
except KeyboardInterrupt:
spyral.quit()
spyral.quit()
sys.exit()

# We now handle if profiling is enabled.
import cProfile
import envoy
from collections import defaultdict
scenes = defaultdict(lambda: 0)
files = []

try:
os.mkdir(output_dir)
except OSError:
pass

spyral.director.init(options.res, fullscreen = options.fullscreen, max_fps = options.fps)
launch()

def run():
spyral.director.run(profiling = True)

while spyral.director.get_scene():
scene = spyral.director.get_scene().__class__.__name__
scenes[scene] += 1
output = '%s/%s-%d' % (output_dir, scene, scenes[scene])
try:
cProfile.run('run()', '%s.pstats' % (output,))
except KeyboardInterrupt:
spyral.quit()
files.append(output)
spyral.quit()

try:
for file in files:
r = envoy.run('python libraries/gprof2dot.py -f pstats "%s.pstats" | dot -Tpng -o "%s.png"' % (file, file))

except Exception:
print 'Could not generate image outputs from profiling. Is graphviz installed?'
sys.exit()
22 changes: 14 additions & 8 deletions Games/ug1/runme.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def gamedir(archivo):


font_path = gamedir("fonts/SourceCodePro-Regular.ttf")
topic_dir = gamedir("../../Topics/Topic_5/")
topic_dir = gamedir("../../Topics/Topic_2/")


def obtener_palabra(topic_dir=topic_dir):
Expand Down Expand Up @@ -85,13 +85,14 @@ def __init__(self, window=None, topic=topic_dir):
self.v = Visualizador(self)

spyral.event.register("system.quit", spyral.director.pop)
spyral.event.register("director.scene.enter", self.entrar)
#spyral.event.register("director.scene.enter", self.entrar)
spyral.event.register("director.scene.enter", self.l.llover)

#spyral.event.register("director.update", self.chequea)

def entrar(self):
self.j.set_caminar(self.scene.width / 2)
#No funcionó en la XO Fedora 11
#def entrar(self):
# self.j.set_caminar(self.scene.width / 2)


class Terraza(spyral.Sprite):
Expand Down Expand Up @@ -252,7 +253,7 @@ def __init__(self, scene):
self.scale = 2

def reset(self):
self.x = self.scene.width / 2 + random.randint(0, 300) - 150
self.x = self.scene.width / 2 + random.randint(0, 600) - 300
self.stop_all_animations()
self.stop_all_animations()
self.stop_all_animations()
Expand All @@ -263,8 +264,8 @@ def reset(self):

def llover(self):
p = spyral.Animation("y",
spyral.easing.QuadraticIn(0, self.scene.height - 75),
duration=2 * len(self.scene.tablero.palabra))
spyral.easing.CubicIn(0, self.scene.height - 75),
duration=2 * len(self.scene.tablero.palabra) + 3)
self.animate(p)

def finalizar(self):
Expand Down Expand Up @@ -314,6 +315,7 @@ def set_text(self, text):
position=(0, 0), anchor="midleft")

def reset(self):
self.stop_all_animations()
self.text = self.scene.tablero.palabra
self.palabra_png = self.scene.tablero.archivo_img

Expand Down Expand Up @@ -381,6 +383,7 @@ def __init__(self, scene):
self.full_image = spyral.Image(filename=gamedir("images/user2.png"))
self.estado = "nuevo"
self.y = scene.height - 138
self.x = scene.width / 2
self.velocidad = 90
self.anchor = "midtop"
self.layer = "arriba"
Expand Down Expand Up @@ -475,7 +478,10 @@ def set_caminar(self, x, disparar=False):
self.estado = "caminando"
return tiempo

def main():
spyral.director.push(Escena())

if __name__ == "__main__":
spyral.director.init(SIZE, fullscreen=False)
spyral.director.run(scene=Escena())
main()
spyral.director.run(profiling=True)
Empty file removed Lib/ometa/__init__.py
Empty file.
Empty file removed Lib/ometa/_generated/__init__.py
Empty file.
Loading

0 comments on commit 83d75e8

Please sign in to comment.