1. Arne Babenhauserheide
  2. hexbattle


hexbattle / core.py

#!/usr/bin/env python
# encoding: utf-8

"""The core, shared data by all scenes."""

__copyright__ = """ 
  Fungus - Simple game framework building on fungus.
© 2008 - 2010 Copyright by Arne Babenhauserheide

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  MA 02110-1301 USA


from pyglet.clock import schedule, schedule_once, schedule_interval
from pyglet.resource import path as media_paths
from pyglet.resource import reindex
# adapt the media paths: add the graphics folder.
from pyglet.resource import image

### The core object: The basic carrier for persistent data between scenes.

class Core(object):
    """The basic data exchange object between scenes.

    This gets instantiated in this module, so core.core is a singleton,
    shared by all scenes."""
    def __init__(self):
        #: Scenes which are inactive. If a scene stops, pop the previous resume function.
        self.paused_scene_resume_functions = []

core = Core()

### Helper functions

from pyglet.sprite import Sprite as pyglet_sprite

class Sprite(pyglet_sprite):
    def __init__(self, image_path, x = 212, y = 208, update_func=None, *args, **kwds):
        """Create a simple sprite. 
It is a more conveniently callable version of the pyglet_sprite which loads its image itself.
-> For pyglet sprite usage see: http://www.pyglet.org/doc/api/pyglet.sprite.Sprite-class.html

@param image_path: the path to the image, relative to the graphics folder. 
@param x: horizontal position. 
@param y: vertical position. 
@param update_func: A function to update the Sprite position. If defined, it has to take x, y and return new x, y. 
	## Sprite image
	img = image(image_path)
	super(Sprite, self).__init__(img, x=x, y=y, *args, **kwds)

    def update(self):

def run(scenefile): 
    """Run a scene with game.py.

    For use from a scene to delegate running the scene to game.py:
    from subprocess import call
    from os.path import basename
    from sys import argv
    call(["./game.py", "-s", basename(scenefile)] + argv[1:])