Пример #1
0
def hook(mod):

    import pygame_sdl2
    pygame_sdl2.import_as_pygame()

    import _renpy

    base = os.path.dirname(_renpy.__file__)
    moddir = mod.__name__.replace(".", "/")
    modpath = os.path.join(base, moddir)
    mod.__path__.append(modpath)

    return mod
Пример #2
0
    def __init__(self, filename):
        super(RenpyReporter, self).__init__(filename)

        global renpy_import_all

        if not renpy_import_all:
            import pygame_sdl2

            pygame_sdl2.import_as_pygame()

            renpy.import_all()

            renpy_import_all = True

            renpy.config.basedir = "/"
            renpy.config.renpy_base = "/"

            # renpy.game.contexts = [ renpy.execution.Context(False) ]
            renpy.game.script = renpy.script.Script()

        # stmts = renpy.parser.parse(filename)

        with open(filename + "c", "rb") as f:
            data = renpy.game.script.read_rpyc_data(f, 1)

        try:
            stmts = cPickle.loads(data)[1]
        except:
            stmts = []
            print(filename + "c", "failed")

        all_stmts = []
        for i in stmts:
            i.get_children(all_stmts.append)

        self._lines = set()
        for i in all_stmts:
            if not isinstance(i, renpy.ast.Init):
                self._lines.add(i.linenumber)

        for i in renpy.game.script.all_pycode:
            self.pycode_lines(i)

        renpy.game.script.all_pycode = []
Пример #3
0
    def __init__(self, filename):
        super(RenpyReporter, self).__init__(filename)

        global renpy_import_all

        if not renpy_import_all:
            import pygame_sdl2
            pygame_sdl2.import_as_pygame()

            renpy.import_all()

            renpy_import_all = True

            renpy.config.basedir = '/'
            renpy.config.renpy_base = '/'

            # renpy.game.contexts = [ renpy.execution.Context(False) ]
            renpy.game.script = renpy.script.Script()

        # stmts = renpy.parser.parse(filename)

        with open(filename + "c", "rb") as f:
            data = renpy.game.script.read_rpyc_data(f, 1)

        try:
            stmts = cPickle.loads(data)[1]
        except:
            stmts = []
            print(filename + "c", "failed")

        all_stmts = []
        for i in stmts:
            i.get_children(all_stmts.append)

        self._lines = set()
        for i in all_stmts:
            if not isinstance(i, renpy.ast.Init):
                self._lines.add(i.linenumber)

        for i in renpy.game.script.all_pycode:
            self.pycode_lines(i)

        renpy.game.script.all_pycode = []
Пример #4
0
from __future__ import unicode_literals

__version__ = "1.5a0"

import sys
import os

try:
    import pygame
except ImportError as e:
    try:
        import pygame_sdl2
    except ImportError:
        raise e
    else:
        pygame_sdl2.import_as_pygame()
        import pygame

# Constants
IMPLEMENTATION = "Pygame SGE"
SCALE_METHODS = ["scale2x"]

BLEND_NORMAL = None
BLEND_ALPHA = 1
BLEND_RGB_ADD = 2
BLEND_RGB_SUBTRACT = 4
BLEND_RGB_MULTIPLY = 6
BLEND_RGB_SCREEN = 8
BLEND_RGB_MINIMUM = 10
BLEND_RGB_MAXIMUM = 12
Пример #5
0
import os
import json
import uuid
import sys
import math
import queue
from PIL import Image
import pygame_sdl2
pygame_sdl2.import_as_pygame()
import pygame
from pygame.locals import *
from gardenbotnn import Garden_Bot_NN
from gardenbotnn import mutate_dna
from garden import Garden
from customer import Customer
from graphics_geometor import Graphics_Geometor

def load_pygame_img(file_name):
    """Load img is a function that uses PIL to load a pygame image"""

    img = Image.open(file_name)
    mode = img.mode
    size = img.size
    data = img.tostring()
    #pygame_img = pygame.image.fromstring(data, size, mode) #Load the sheet
    pygame_img = pygame.image.load(file_name)
    return pygame_img

class Robot_Sprite:
    """A singleton sprite loader that caches the robot sprites at various angles"""
    class _Robot_Sprite:
Пример #6
0
def bootstrap(renpy_base):

    global renpy  # W0602

    import renpy.log  # @UnusedImport

    # Remove a legacy environment setting.
    if os.environ.get(b"SDL_VIDEODRIVER", "") == "windib":
        del os.environ[b"SDL_VIDEODRIVER"]

    renpy_base = unicode(renpy_base, FSENCODING, "replace")

    # If environment.txt exists, load it into the os.environ dictionary.
    if os.path.exists(renpy_base + "/environment.txt"):
        evars = { }
        execfile(renpy_base + "/environment.txt", evars)
        for k, v in evars.iteritems():
            if k not in os.environ:
                os.environ[k] = str(v)

    # Also look for it in an alternate path (the path that contains the
    # .app file.), if on a mac.
    alt_path = os.path.abspath("renpy_base")
    if ".app" in alt_path:
        alt_path = alt_path[:alt_path.find(".app")+4]

        if os.path.exists(alt_path + "/environment.txt"):
            evars = { }
            execfile(alt_path + "/environment.txt", evars)
            for k, v in evars.iteritems():
                if k not in os.environ:
                    os.environ[k] = str(v)

    # Get a working name for the game.
    name = os.path.basename(sys.argv[0])

    if name.find(".") != -1:
        name = name[:name.find(".")]

    # Parse the arguments.
    import renpy.arguments
    args = renpy.arguments.bootstrap()

    if args.trace:
        enable_trace(args.trace)

    if args.basedir:
        basedir = os.path.abspath(args.basedir).decode(FSENCODING)
    else:
        basedir = renpy_base

    if not os.path.exists(basedir):
        sys.stderr.write("Base directory %r does not exist. Giving up.\n" % (basedir,))
        sys.exit(1)

    gamedirs = [ name ]
    game_name = name

    while game_name:
        prefix = game_name[0]
        game_name = game_name[1:]

        if prefix == ' ' or prefix == '_':
            gamedirs.append(game_name)

    gamedirs.extend([ 'game', 'data', 'launcher/game' ])

    for i in gamedirs:

        if i == "renpy":
            continue

        gamedir = basedir + "/" + i
        if os.path.isdir(gamedir):
            break
    else:
        gamedir = basedir

    sys.path.insert(0, basedir)

    if renpy.macintosh:
        # If we're on a mac, install our own os.start.
        os.startfile = mac_start

        # Are we starting from inside a mac app resources directory?
        if basedir.endswith("Contents/Resources/autorun"):
            renpy.macapp = True

    # Check that we have installed pygame properly. This also deals with
    # weird cases on Windows and Linux where we can't import modules. (On
    # windows ";" is a directory separator in PATH, so if it's in a parent
    # directory, we won't get the libraries in the PATH, and hence pygame
    # won't import.)
    try:
        import pygame_sdl2
        pygame_sdl2.import_as_pygame()
    except:
        print("""\
Could not import pygame_sdl2. Please ensure that this program has been built
and unpacked properly. Also, make sure that the directories containing
this program do not contain : or ; in their names.

You may be using a system install of python. Please run {0}.sh,
{0}.exe, or {0}.app instead.
""".format(name), file=sys.stderr)

        raise

    # If we're not given a command, show the presplash.
    if args.command == "run" and not renpy.mobile:
        import renpy.display.presplash  # @Reimport
        renpy.display.presplash.start(basedir, gamedir)

    # Ditto for the Ren'Py module.
    try:
        import _renpy; _renpy
    except:
        print("""\
Could not import _renpy. Please ensure that this program has been built
and unpacked properly.

You may be using a system install of python. Please run {0}.sh,
{0}.exe, or {0}.app instead.
""".format(name), file=sys.stderr)
        raise

    # Load up all of Ren'Py, in the right order.

    import renpy  # @Reimport
    renpy.import_all()

    renpy.loader.init_importer()

    exit_status = None

    try:
        while exit_status is None:
            exit_status = 1

            try:
                renpy.game.args = args
                renpy.config.renpy_base = renpy_base
                renpy.config.basedir = basedir
                renpy.config.gamedir = gamedir
                renpy.config.args = [ ]

                if renpy.android:
                    renpy.config.logdir = os.environ['ANDROID_PUBLIC']
                else:
                    renpy.config.logdir = basedir

                if not os.path.exists(renpy.config.logdir):
                    os.makedirs(renpy.config.logdir, 0o777)

                renpy.main.main()

                exit_status = 0

            except KeyboardInterrupt:
                raise

            except renpy.game.UtterRestartException:

                # On an UtterRestart, reload Ren'Py.
                renpy.reload_all()

                exit_status = None

            except renpy.game.QuitException as e:
                exit_status = e.status

                if e.relaunch:
                    if hasattr(sys, "renpy_executable"):
                        subprocess.Popen([sys.renpy_executable] + sys.argv[1:])
                    else:
                        subprocess.Popen([sys.executable, "-EO"] + sys.argv)

            except renpy.game.ParseErrorException:
                pass

            except Exception as e:
                renpy.error.report_exception(e)
                pass

        sys.exit(exit_status)

    finally:

        if "RENPY_SHUTDOWN_TRACE" in os.environ:
            enable_trace(int(os.environ["RENPY_SHUTDOWN_TRACE"]))

        renpy.display.im.cache.quit()

        if renpy.display.draw:
            renpy.display.draw.quit()

        # Prevent subprocess from throwing errors while trying to run it's
        # __del__ method during shutdown.
        subprocess.Popen.__del__ = popen_del
Пример #7
0
def bootstrap(renpy_base):

    global renpy  # W0602

    import renpy.log  # @UnusedImport

    # Remove a legacy environment setting.
    if os.environ.get(b"SDL_VIDEODRIVER", "") == "windib":
        del os.environ[b"SDL_VIDEODRIVER"]

    renpy_base = str(renpy_base, FSENCODING, "replace")

    # If environment.txt exists, load it into the os.environ dictionary.
    if os.path.exists(renpy_base + "/environment.txt"):
        evars = {}
        exec(
            compile(
                open(renpy_base + "/environment.txt").read(),
                renpy_base + "/environment.txt", 'exec'), evars)
        for k, v in evars.items():
            if k not in os.environ:
                os.environ[k] = str(v)

    # Also look for it in an alternate path (the path that contains the
    # .app file.), if on a mac.
    alt_path = os.path.abspath("renpy_base")
    if ".app" in alt_path:
        alt_path = alt_path[:alt_path.find(".app") + 4]

        if os.path.exists(alt_path + "/environment.txt"):
            evars = {}
            exec(
                compile(
                    open(alt_path + "/environment.txt").read(),
                    alt_path + "/environment.txt", 'exec'), evars)
            for k, v in evars.items():
                if k not in os.environ:
                    os.environ[k] = str(v)

    # Get a working name for the game.
    name = os.path.basename(sys.argv[0])

    if name.find(".") != -1:
        name = name[:name.find(".")]

    # Parse the arguments.
    import renpy.arguments
    args = renpy.arguments.bootstrap()

    if args.trace:
        enable_trace(args.trace)

    if args.basedir:
        basedir = os.path.abspath(args.basedir).decode(FSENCODING)
    else:
        basedir = renpy_base

    if not os.path.exists(basedir):
        sys.stderr.write("Base directory %r does not exist. Giving up.\n" %
                         (basedir, ))
        sys.exit(1)

    gamedirs = [name]
    game_name = name

    while game_name:
        prefix = game_name[0]
        game_name = game_name[1:]

        if prefix == ' ' or prefix == '_':
            gamedirs.append(game_name)

    gamedirs.extend(['game', 'data', 'launcher/game'])

    for i in gamedirs:

        if i == "renpy":
            continue

        gamedir = basedir + "/" + i
        if os.path.isdir(gamedir):
            break
    else:
        gamedir = basedir

    sys.path.insert(0, basedir)

    if renpy.macintosh:
        # If we're on a mac, install our own os.start.
        os.startfile = mac_start

        # Are we starting from inside a mac app resources directory?
        if basedir.endswith("Contents/Resources/autorun"):
            renpy.macapp = True

    # Check that we have installed pygame properly. This also deals with
    # weird cases on Windows and Linux where we can't import modules. (On
    # windows ";" is a directory separator in PATH, so if it's in a parent
    # directory, we won't get the libraries in the PATH, and hence pygame
    # won't import.)
    try:
        import pygame_sdl2
        if not ("pygame" in sys.modules):
            pygame_sdl2.import_as_pygame()
    except:
        print("""\
Could not import pygame_sdl2. Please ensure that this program has been built
and unpacked properly. Also, make sure that the directories containing
this program do not contain : or ; in their names.

You may be using a system install of python. Please run {0}.sh,
{0}.exe, or {0}.app instead.
""".format(name),
              file=sys.stderr)

        raise

    # If we're not given a command, show the presplash.
    if args.command == "run" and not renpy.mobile:
        import renpy.display.presplash  # @Reimport
        renpy.display.presplash.start(basedir, gamedir)

    # Ditto for the Ren'Py module.
    try:
        import _renpy
        _renpy
    except:
        print("""\
Could not import _renpy. Please ensure that this program has been built
and unpacked properly.

You may be using a system install of python. Please run {0}.sh,
{0}.exe, or {0}.app instead.
""".format(name),
              file=sys.stderr)
        raise

    # Load up all of Ren'Py, in the right order.

    import renpy  # @Reimport
    renpy.import_all()

    renpy.loader.init_importer()

    exit_status = None

    try:
        while exit_status is None:
            exit_status = 1

            try:
                renpy.game.args = args
                renpy.config.renpy_base = renpy_base
                renpy.config.basedir = basedir
                renpy.config.gamedir = gamedir
                renpy.config.args = []

                if renpy.android:
                    renpy.config.logdir = os.environ['ANDROID_PUBLIC']
                else:
                    renpy.config.logdir = basedir

                if not os.path.exists(renpy.config.logdir):
                    os.makedirs(renpy.config.logdir, 0o777)

                renpy.main.main()

                exit_status = 0

            except KeyboardInterrupt:
                raise

            except renpy.game.UtterRestartException:

                # On an UtterRestart, reload Ren'Py.
                renpy.reload_all()

                exit_status = None

            except renpy.game.QuitException as e:
                exit_status = e.status

                if e.relaunch:
                    if hasattr(sys, "renpy_executable"):
                        subprocess.Popen([sys.renpy_executable] + sys.argv[1:])
                    else:
                        subprocess.Popen([sys.executable, "-EO"] + sys.argv)

            except renpy.game.ParseErrorException:
                pass

            except Exception as e:
                renpy.error.report_exception(e)
                pass

        sys.exit(exit_status)

    finally:

        if "RENPY_SHUTDOWN_TRACE" in os.environ:
            enable_trace(int(os.environ["RENPY_SHUTDOWN_TRACE"]))

        renpy.display.im.cache.quit()

        if renpy.display.draw:
            renpy.display.draw.quit()

        # Prevent subprocess from throwing errors while trying to run it's
        # __del__ method during shutdown.
        subprocess.Popen.__del__ = popen_del
Пример #8
0
import pygame_sdl2; pygame_sdl2.import_as_pygame()
import sys, os
import pygame

if len(sys.argv) < 2:
    print "Usage: %s <filename>" % sys.argv[0]
    sys.exit(0)

print pygame.mixer.get_init()
pygame.mixer.pre_init(frequency=44100)
pygame.init()
print pygame.mixer.get_init()

pygame.mixer.music.load(sys.argv[1])
pygame.mixer.music.play()
pygame.mixer.music.fadeout(2000)

snd = pygame.mixer.Sound(sys.argv[1])
print snd.get_length()
channel = snd.play()

pygame.time.wait(1000)
channel.set_volume(0.0, 1.0)
channel.fadeout(1000)
pygame.time.wait(1000)
Пример #9
0
import pygame_sdl2; pygame_sdl2.import_as_pygame()
import sys, os
import pygame

if len(sys.argv) < 2:
    print("Usage: %s <filename>" % sys.argv[0])
    sys.exit(0)

print(pygame.mixer.get_init())
pygame.mixer.pre_init(frequency=44100)
pygame.init()
print(pygame.mixer.get_init())
#
# pygame.mixer.music.load(sys.argv[1])
# pygame.mixer.music.play()
# pygame.mixer.music.fadeout(2000)

snd = pygame.mixer.Sound(sys.argv[1])
print(snd.get_length())
channel = snd.play()
channel.queue(snd)

channel.set_volume(.1)
print(channel.get_volume())

pygame.time.wait(3000)
# channel.set_volume(0.0, 1.0)
# channel.fadeout(1000)
# pygame.time.wait(1000)
# coding:utf-8

import pygame_sdl2 as pg
pg.import_as_pygame()

from asteroid import *
from bullet import *
from ship import *
from star_field import *
from controller import *
from touch_buttons import *


def main():
    print('pg.get_sdl_version()', pg.get_sdl_version())

    FPS = 60
    SIZE = (800, 600)
    # screen = pg.display.set_mode(SIZE, pg.FULLSCREEN)
    screen = pg.display.set_mode(SIZE, pg.RESIZABLE)
    icon = pg.image.load('img/icon.png')
    pg.display.set_caption("AsteroidsPresentation", icon)

    background = pg.surface.Surface(SIZE)

    font = pg.font.Font('font/hyperspace.ttf', 40)
    text = font.render("by Humberto Lino", 1, Color.WHITE)

    star_field = StarField(screen)
    ship = Ship('img/ship.png', angle=0)
    asteroids = Asteroid.create_asteroids()
# coding:utf-8

import pygame_sdl2 as pg
pg.import_as_pygame()

from asteroid import *
from bullet import *
from ship import *
from star_field import *
from controller import *
from touch_buttons import *

def main():
    print('pg.get_sdl_version()', pg.get_sdl_version())

    FPS = 60
    SIZE = (800,600)
    # screen = pg.display.set_mode(SIZE, pg.FULLSCREEN)
    screen = pg.display.set_mode(SIZE, pg.RESIZABLE)
    icon =  pg.image.load('img/icon.png')
    pg.display.set_caption("AsteroidsPresentation", icon)

    background = pg.surface.Surface(SIZE)

    font = pg.font.Font('font/hyperspace.ttf', 40)
    text = font.render("by Humberto Lino", 1, Color.WHITE)

    star_field = StarField(screen)
    ship = Ship('img/ship.png', angle=0)
    asteroids = Asteroid.create_asteroids()
Пример #12
0
def bootstrap(renpy_base):

    global renpy  # W0602

    import renpy.log  #@UnusedImport

    os.environ["RENPY_BASE"] = os.path.abspath(renpy_base)

    renpy_base = unicode(renpy_base, FSENCODING, "replace")

    # If environment.txt exists, load it into the os.environ dictionary.
    if os.path.exists(renpy_base + "/environment.txt"):
        evars = {}
        execfile(renpy_base + "/environment.txt", evars)
        for k, v in evars.iteritems():
            if k not in os.environ:
                os.environ[k] = str(v)

    # Also look for it in an alternate path (the path that contains the
    # .app file.), if on a mac.
    alt_path = os.path.abspath("renpy_base")
    if ".app" in alt_path:
        alt_path = alt_path[:alt_path.find(".app") + 4]

        if os.path.exists(alt_path + "/environment.txt"):
            evars = {}
            execfile(alt_path + "/environment.txt", evars)
            for k, v in evars.iteritems():
                if k not in os.environ:
                    os.environ[k] = str(v)

    # Get a working name for the game.
    name = os.path.basename(sys.argv[0])

    if name.find(".") != -1:
        name = name[:name.find(".")]

    # Parse the arguments.
    import renpy.arguments
    args = renpy.arguments.bootstrap()

    # Since we don't have time to fully initialize before running the presplash
    # command, handle it specially.
    if args.command == "presplash":
        import renpy.display.presplash
        renpy.display.presplash.show(sys.argv[3])

    if args.trace:
        enable_trace(args.trace)

    if args.basedir:
        basedir = os.path.abspath(args.basedir).decode(FSENCODING)
    else:
        basedir = renpy_base

    if not os.path.exists(basedir):
        sys.stderr.write("Base directory %r does not exist. Giving up.\n" %
                         (basedir, ))
        sys.exit(1)

    gamedirs = [name]
    game_name = name

    while game_name:
        prefix = game_name[0]
        game_name = game_name[1:]

        if prefix == ' ' or prefix == '_':
            gamedirs.append(game_name)

    gamedirs.extend(['game', 'data', 'launcher/game'])

    for i in gamedirs:

        if i == "renpy":
            continue

        gamedir = basedir + "/" + i
        if os.path.isdir(gamedir):
            break
    else:
        gamedir = basedir

    sys.path.insert(0, basedir)

    # If we're not given a command, show the presplash.
    if args.command == "run":
        import renpy.display.presplash  #@Reimport
        renpy.display.presplash.start(basedir, gamedir)

    # If we're on a mac, install our own os.start.
    if renpy.macintosh:
        os.startfile = mac_start

    # Check that we have installed pygame properly. This also deals with
    # weird cases on Windows and Linux where we can't import modules. (On
    # windows ";" is a directory separator in PATH, so if it's in a parent
    # directory, we won't get the libraries in the PATH, and hence pygame
    # won't import.)
    try:
        import pygame_sdl2
        pygame_sdl2.import_as_pygame()
    except:
        print >> sys.stderr, """\
Could not import pygame_sdl2. Please ensure that this program has been built
and unpacked properly. Also, make sure that the directories containing
this program do not contain : or ; in their names.

You may be using a system install of python. Please run {0}.sh,
{0}.exe, or {0}.app instead.
""".format(name)

        raise

    # Ditto for the Ren'Py module.
    try:
        import _renpy
        _renpy
    except:
        print >> sys.stderr, """\
Could not import _renpy. Please ensure that this program has been built
and unpacked properly.

You may be using a system install of python. Please run {0}.sh,
{0}.exe, or {0}.app instead.
""".format(name)
        raise

    # Load up all of Ren'Py, in the right order.

    import renpy  #@Reimport
    renpy.import_all()

    renpy.loader.init_importer()

    exit_status = None

    try:
        while exit_status is None:
            exit_status = 1

            try:
                renpy.game.args = args
                renpy.config.renpy_base = renpy_base
                renpy.config.basedir = basedir
                renpy.config.gamedir = gamedir
                renpy.config.args = []

                if renpy.android:
                    renpy.config.logdir = os.environ['ANDROID_PUBLIC']
                else:
                    renpy.config.logdir = basedir

                if not os.path.exists(renpy.config.logdir):
                    os.makedirs(renpy.config.logdir, 0777)

                renpy.main.main()

                exit_status = 0

            except KeyboardInterrupt:
                raise

            except renpy.game.UtterRestartException:

                # On an UtterRestart, reload Ren'Py.
                renpy.reload_all()

                exit_status = None

            except renpy.game.QuitException as e:
                exit_status = e.status

                if e.relaunch:
                    subprocess.Popen([sys.executable, "-EO"] + sys.argv)

            except renpy.game.ParseErrorException:
                pass

            except Exception, e:
                renpy.error.report_exception(e)
                pass

        sys.exit(exit_status)