1. Arne Babenhauserheide
  2. lpc

Commits

Arne Babenhauserheide  committed 893d8a5

prepared for starting pyglet.

  • Participants
  • Parent commits 0f141b5
  • Branches default

Comments (0)

Files changed (10)

File BRivera-maleZombiesoldier.png

Removed
Old image

File BRivera-malesoldier.png

Removed
Old image

File core.py

View file
+#!/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
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  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.
+media_paths.append("@graphics")
+reindex()
+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
+        self.image_path = image_path
+        img = image(image_path)
+        super(Sprite, self).__init__(img, x=x, y=y, *args, **kwds)
+
+    def update(self):
+        pass
+
+import d6
+
+class SemiZombie(d6.char.Char):
+    """A protagonist. It can switch between zombie and non-zombie"""
+    def __init__(self, image_path, zombie_image_path, *args, **kwds):
+        super().__init__(*args, **kwds)
+        self.x = self.y = 0
+        self.zombie = True
+        self.sprite = core.Sprite(self.image_path)
+        self.zombie_sprite = Sprite(self.zombie_image_path)
+    def draw(self, *args):
+        """Show the protagonist on screen."""
+        if self.zombie:
+            self.zombie_sprite.draw()
+        else: 
+            self.sprite.draw()
+
+def run(scenefile): 
+    """Run a scene with game.py.
+
+    For use from a scene to delegate running the scene to game.py:
+    core.run(__file__)
+"""
+    from subprocess import call
+    from os.path import basename
+    from sys import argv
+    call(["./game.py", "-s", basename(scenefile)] + argv[1:])
+

File game.py

View file
+#!/usr/bin/env python2
+# encoding: utf-8
+
+"""The game starts the central event loop for all scenes."""
+
+### imports
+
+# disable pyglet gl debugging before we do anything else (2x speed hit)
+import pyglet
+pyglet.options['debug_gl'] = False
+
+from core import core, __copyright__
+
+from pyglet import app
+from pyglet.window import Window
+from pyglet.clock import schedule_once
+from sys import argv
+from optparse import OptionParser
+
+### commandline arguments
+
+def _help(mod=None):
+    """Provide help from this main module and optionally from the selected scene.
+    @param mod: module in which the selected scene is defined - this contains the second help string to use.
+    """
+    if mod is None or mod.__doc__ is None: 
+	return __doc__
+    else: 
+	return mod.__doc__
+
+### clean parsing
+parser = OptionParser(usage = "Game runner", version = "0.1")
+
+parser.add_option("-s", "--scene", type="string", dest="scene", default="scene", help="the scene to start: scene filename without extension")
+
+parser.add_option("--width", type="int", dest="width", default=800, help="width of the window")
+
+parser.add_option("--height", type="int", dest="height", default=600, help="height of the window")
+
+parser.add_option("--fullscreen",
+                  action="store_true", dest="fullscreen", default=False,
+                  help="Run the game in fullscreen")
+
+(options, args) = parser.parse_args()
+
+### preparation
+if options.fullscreen: 
+    window = Window(fullscreen=options.fullscreen)
+else: 
+    window = Window(width=options.width, height=options.height)
+core.win = window
+core.app = app
+
+# get the scene (might already need core settings)
+scene = eval("__import__('" + options.scene.split(".")[0] + "')")
+
+# activate tranparency for pngs
+from pyglet.gl import glEnable, glBlendFunc, GL_BLEND, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
+glEnable(GL_BLEND)
+glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+
+# scene running.
+schedule_once(scene.start, 0.1)
+
+core.app.run()

File graphics/BRivera-maleZombiesoldier.png

Added
New image

File graphics/BRivera-malesoldier.png

Added
New image

File graphics/lpc_home_cup.gif

Added
New image

File logic.py

View file
 
 - First level: Protect the tree lpc_full_assets/Barbara_Rivera__Concept Art for LPC Entry/fullpufftree.png. You have one character and 4 zombies attack.
 """
+# The rpg rules
 import d6
 
+# the core object for exchanging data
+import core
+
 class Logic:
     """Basic Game Logic"""
     pass
     skills: {hide: 1}
     special: {rich: 1}
     '''), 'story_text': 'You! How did you manage to get here so fast? \\n\\nYou have a strength in you the others lack. Your soul is still alive in you!\\n\\nI call on your soul. Yotek, Warrior. Do you wish for a chance to regain humanity?\\n'}
+    >>> pa = pa.command()
+    >>> print (pa.data)
+    {'story_text': 'Your soul is strong. \\n\\nThose who tried to destroy it are attacking our forest at this very moment. And when we are down, they will take the rest of the world.\\n\\nPlease help defend us.'}
     """
     def __init__(self):
         self.current = None
         self.hero.image_zombie = "BRivera-maleZombiesoldier.png"
         self.hero.image = "BRivera-malesoldier.png"
         data["show_char"] = self.hero
-        return PlayerAction("Next step", data=data, commands=[Command(self.future, "to be done")])
+        return PlayerAction("Next step", data=data, commands=[Command(self.human_again, "become human again")])
+
+    def human_again(self, *args):
+        self.hero.zombie = False
+        return PlayerAction("Next step", data={"story_text": """Your soul is strong. 
+
+Those who tried to destroy it are attacking our forest at this very moment. And when we are down, they will take the rest of the world.
+
+Please help defend us."""}, commands=[Command(self.future, "to be done")])
 
     def future(self, *args):
         pass

File lpc_home_cup.gif

Removed
Old image

File units.py

View file
+#!/usr/bin/env python3
+
+"""Basic unit classes.
+
+Units hold logic from presentation and logic, so they are hybrid classes.
+
+TODO (someday): Decouple unit logic from pyglet.
+"""
+
+import d6
+import core
+
+class SemiZombie:
+    """A protagonist. It can switch between zombie and non-zombie"""
+    def __init__(self, char, image_path, zombie_image_path, *args, **kwds):
+        super().__init__(*args, **kwds)
+        self.char = char
+        self.sprite = core.Sprite(self.image_path)
+        self.zombie_sprite = Sprite(self.zombie_image_path)
+    @property
+    def zombie(self):
+        return self.char.zombie
+    @property
+    def x(self):
+        return self.sprite.x
+    @x.setter
+    def setx(self, x):
+        self.sprite.x = x
+        self.zombie_sprite = x
+    @property
+    def y(self):
+        return self.sprite.y
+    @y.setter
+    def sety(self, y):
+        self.sprite.y = y
+        self.zombie_sprite = y
+    def draw(self, *args):
+        """Show the protagonist on screen."""
+        if self.zombie:
+            self.zombie_sprite.draw()
+        else: 
+            self.sprite.draw()