underware-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Underware-devel] Game scripting


From: Loic Dachary
Subject: [Underware-devel] Game scripting
Date: Sun, 25 Jan 2004 19:03:03 +0100

        Hi,

        Following the rough ideas exposed earlier this week
(http://mail.gnu.org/archive/html/underware-devel/2004-01/msg00007.html),
I implemented the logic that is used to launch and script the game.

        The pong example is now run from examples/pong/pongclient.py
which does nothing more than asking the ScriptGame class to run 
client.game.gpy.

        The logic is then driven by the interpretation of all *.gpy 
files which are built on the same fashion:

        . A set of parameters embedded in a XML stored at the beggining
          of the file.
        . A python script that uses these parameters to implement the
          gameplay.

        For instance, pong.game.gpy looks like this:

----------------------------------------------------------------------
from underware.script import ScriptGame

HEADER = """\
<?xml version='1.0'  encoding='iso-8859-1' ?>

  <game xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:noNamespaceSchemaLocation="game.xsd">
    <mode style="versus" players="2" network="yes" />
    <settings>file:pong.settings.gpy</settings>
<!--
    <sequence url="file:pong.intro.sequence.gpy" /> 
    <sequence url="file:pong.lobby.sequence.gpy" />
-->
    <sequence url="file:pong.versus.sequence.gpy" />
<!--
    <sequence url="file:pong.finish.sequence.gpy" />
-->
  </game>
"""

class PongGame(ScriptGame):
    "Pong example"

    def __init__(self):
        self.setHeader(HEADER)


def run():
    return PongGame().run()

----------------------------------------------------------------------

        The ScriptGame logic (running each <sequence> element in turn)
is used but could be modified by adding methods to the PongGame class.
Such a modification is done in the pong.versus.sequence.gpy script that
implements the network part of the gameplay. 

        Because it seems unappropriate to expose the CGI interface at
the moment (who knows what the CGI interface is ? ;-), part of the
gameplay is in C++. I doubt we will attempt to have a pure python 
gameplay shortly: it is more convenient to wait for the CGI interface
to stabilize.

        In order to separate the gameplay from CGI, I moved the network
classes into underware/{protocol,server,client}.py and implemented the
pong example specific parts in examples/pong/pong.versus.sequence.gpy and
examples/pong/pongserver.gpy. Thanks to twisted I did not have to worry
about anything but the actual implementation of the protocol specific
to underware.

        I hope to discuss the idealistic code we need this week. I
plan to apply the ideas described above to get a gameplay code that
can be recognized as such. I'll add gameplay features to the example
pong (counting points, animated characters that move their paddle,
splash screen and minimal game settings screen) to improve the state
of things.

        Cheers,

-- 
Donate to FSF France online : http://rate.affero.net/fsffrance/
Loic Dachary, 12 bd Magenta, 75010 Paris. Tel: 33 1 42 45 07 97      
http://www.fsffrance.org/   http://www.dachary.org/loic/gpg.txt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]