Ejemplo n.º 1
0
   def __init__(self, screen, node):
      """
      Set up the screen - load any images and play any music.

      screen - the screen to blit to.
      node - the <screen> node.
      """

      #store the screen for later
      self.screen = screen

      #set up the timer
      #time of -1 means no time limit
      self.time = data.getAttr(node, "time", data.D_INT)
      self.count = 0
      self.trackTime = (self.time != -1)
      
      #find out the background color
      #use american spelling of color by convention
      self.bgColor = data.getAttr(node, "bgcolor", data.D_INT3LIST)

      #find the music to play if any
      self.music = None
      for track in data.getChildren(node, "music"):
         self.music = os.path.join(settings.path, "data", data.getAttr(track, "file", data.D_STRING))

      #load all images
      self.images = []
      for image in data.getChildren(node, "image"):
         self.images.append(IntroImage(self.screen, image))
Ejemplo n.º 2
0
    def __init__(self, screen, node):
        """
      Set up the screen - load any images and play any music.

      screen - the screen to blit to.
      node - the <screen> node.
      """

        #store the screen for later
        self.screen = screen

        #set up the timer
        #time of -1 means no time limit
        self.time = data.getAttr(node, "time", data.D_INT)
        self.count = 0
        self.trackTime = (self.time != -1)

        #find out the background color
        #use american spelling of color by convention
        self.bgColor = data.getAttr(node, "bgcolor", data.D_INT3LIST)

        #find the music to play if any
        self.music = None
        for track in data.getChildren(node, "music"):
            self.music = os.path.join(
                settings.path, "data",
                data.getAttr(track, "file", data.D_STRING))

        #load all images
        self.images = []
        for image in data.getChildren(node, "image"):
            self.images.append(IntroImage(self.screen, image))
Ejemplo n.º 3
0
    def setup(self):
        """Initialize pygame, find the main game file and parse it."""

        #initialise pygame
        pygame.init()

        #find the main game file and parse it
        if settings.path is not None:
            fn = os.path.join(settings.path, "data", "game.xml")
        else:
            raise error.DittoInvalidResourceException("settings.py", "path")
        root = data.getTreeRoot(fn, "Ditto Main")
        for p in data.getChildren(root, "property"):
            if data.getAttr(p, "name", data.D_STRING) == "tilesize":
                globs.TILESIZE = data.getAttr(p, "value", data.D_INT2LIST)
            elif data.getAttr(p, "name", data.D_STRING) == "font":
                globs.FONT = data.getAttr(p, "value", data.D_STRING)
            elif data.getAttr(p, "name", data.D_STRING) == "dialog":
                globs.DIALOG = data.getAttr(p, "value", data.D_STRING)
            elif data.getAttr(p, "name", data.D_STRING) == "pokemon":
                globs.POKEMON = data.getAttr(p, "value", data.D_STRING)
            elif data.getAttr(p, "name", data.D_STRING) == "soundeffects":
                soundPath = os.path.join(
                    settings.path, "data",
                    data.getAttr(p, "value", data.D_STRING))
            elif data.getAttr(p, "name", data.D_STRING) == "moves":
                globs.MOVES = os.path.join(
                    settings.path, "data",
                    data.getAttr(p, "value", data.D_STRING))
            elif data.getAttr(p, "name", data.D_STRING) == "behaviours":
                globs.BEHAVIOURS = os.path.join(
                    settings.path, "data",
                    data.getAttr(p, "value", data.D_STRING))

        #if there's an icon specified, use it
        if len(data.getChildren(root, "icon")) > 0:
            node = data.getChild(root, "icon")
            iconPath = os.path.join(settings.path, "data",
                                    data.getAttr(node, "file", data.D_STRING))
            icon = data.getImage(iconPath, fn)
            pygame.display.set_icon(icon)

        #set up the main window
        windowSize = settings.screenSize[0] * globs.TILESIZE[
            0], settings.screenSize[1] * globs.TILESIZE[1]
        self.screen = pygame.display.set_mode(windowSize)
        pygame.display.set_caption("%s --- Ditto Engine" %
                                   data.getAttr(root, "title", data.D_STRING))

        #create a clock object
        self.clock = pygame.time.Clock()

        #initialise sound
        sound.init(soundPath)

        #set up the initial scene, the intro
        self.activeScene = intro.Intro(self.screen)
Ejemplo n.º 4
0
    def __init__(self, node, mMap, position=None, level=None):
        """
      Initialise the sprite, and set up movement and scripts.

      node - the <npc> node.
      mMap - the map to start on.
      position - the position to start in. If unspecified gets taken from the <npc> node.
      level - the level to start on. If unspecified gets taken from the <npc> node.
      """

        #initialize the sprite
        sprite.Sprite.__init__(self, node, mMap, position, level)

        self.initialPosition = self.position  #store initial position anchor

        #determine what auto movements to do
        #use the first <movement> node if one exists, otherwise no movement
        self.move = MT_NONE
        movements = data.getChildren(node, "movement")
        if movements:
            movementNode = movements[0]
            movementType = data.getAttr(movementNode, "type", data.D_STRING)

            #if asked to wander, set movement and get wander radius
            #note this uses taxicab distance, and a taxicab circle is a diamond like this:
            #  X
            # XXX
            #XX.XX
            # XXX
            #  X
            #maybe change this due to the possibility to easily block an npc on the diamond points
            if movementType == "wander":
                self.move = MT_WANDER
                self.wanderRadius = data.getAttr(movementNode, "radius",
                                                 data.D_INT)

            #if asked to follow a track , set the movement and parse for the course
            elif movementType == "track":
                self.move = MT_TRACK
                self.course = []
                self.stepCycle = 0
                for op in data.getAttr(movementNode, "course",
                                       data.D_STRING).split(","):
                    try:
                        self.course.append(INSTRUCTIONS[op])
                    except KeyError:
                        raise error.DUnsupportedError("Unknown NPC file",
                                                      "NPC movement step", op)

        #create any event scripts
        self.scripts = {}
        for s in data.getChildren(node, "script"):
            if data.getAttr(s, "trigger", data.D_STRING) == "investigate":
                self.scripts[events.EV_INVESTIGATE] = script_engine.Script(s)
Ejemplo n.º 5
0
   def __init__(self, node, mMap, position=None, level=None):
      """
      Initialise the sprite, and set up movement and scripts.

      node - the <npc> node.
      mMap - the map to start on.
      position - the position to start in. If unspecified gets taken from the <npc> node.
      level - the level to start on. If unspecified gets taken from the <npc> node.
      """

      #initialize the sprite
      sprite.Sprite.__init__(self, node, mMap, position, level)

      self.initialPosition = self.position #store initial position anchor

      #determine what auto movements to do
      #use the first <movement> node if one exists, otherwise no movement
      self.move = MT_NONE
      movements = data.getChildren(node, "movement")
      if movements:
         movementNode = movements[0]
         movementType = data.getAttr(movementNode, "type", data.D_STRING)

         #if asked to wander, set movement and get wander radius
         #note this uses taxicab distance, and a taxicab circle is a diamond like this:
         #  X
         # XXX
         #XX.XX
         # XXX
         #  X
         #maybe change this due to the possibility to easily block an npc on the diamond points
         if movementType == "wander":
            self.move = MT_WANDER
            self.wanderRadius = data.getAttr(movementNode, "radius", data.D_INT)

         #if asked to follow a track , set the movement and parse for the course  
         elif movementType == "track":
            self.move = MT_TRACK
            self.course = []
            self.stepCycle = 0
            for op in data.getAttr(movementNode, "course", data.D_STRING).split(","):
               try:
                  self.course.append(INSTRUCTIONS[op])
               except KeyError:
                  raise error.DUnsupportedError("Unknown NPC file", "NPC movement step", op)

      #create any event scripts
      self.scripts = {}
      for s in data.getChildren(node, "script"):
         if data.getAttr(s, "trigger", data.D_STRING) == "investigate":
            self.scripts[events.EV_INVESTIGATE] = script_engine.Script(s)
Ejemplo n.º 6
0
   def setup(self):
      """Initialize pygame, find the main game file and parse it."""

      #initialise pygame
      pygame.init()

      #find the main game file and parse it
      if settings.path is not None:
         fn = os.path.join(settings.path, "data", "game.xml")
      else:
         raise error.DittoInvalidResourceException("settings.py", "path")
      root = data.getTreeRoot(fn, "Ditto Main")
      for p in data.getChildren(root, "property"):
         if data.getAttr(p, "name", data.D_STRING) == "tilesize":
            globs.TILESIZE = data.getAttr(p, "value", data.D_INT2LIST)
         elif data.getAttr(p, "name", data.D_STRING) == "font":
            globs.FONT = data.getAttr(p, "value", data.D_STRING)
         elif data.getAttr(p, "name", data.D_STRING) == "dialog":
            globs.DIALOG = data.getAttr(p, "value", data.D_STRING)
         elif data.getAttr(p, "name", data.D_STRING) == "pokemon":
            globs.POKEMON = data.getAttr(p, "value", data.D_STRING)
         elif data.getAttr(p, "name", data.D_STRING) == "soundeffects":
            soundPath = os.path.join(settings.path, "data", data.getAttr(p, "value", data.D_STRING))
         elif data.getAttr(p, "name", data.D_STRING) == "moves":
            globs.MOVES = os.path.join(settings.path, "data", data.getAttr(p, "value", data.D_STRING))
         elif data.getAttr(p, "name", data.D_STRING) == "behaviours":
            globs.BEHAVIOURS = os.path.join(settings.path, "data", data.getAttr(p, "value", data.D_STRING))

      #if there's an icon specified, use it      
      if len(data.getChildren(root, "icon")) > 0:
         node = data.getChild(root, "icon")
         iconPath = os.path.join(settings.path, "data", data.getAttr(node, "file", data.D_STRING))
         icon = data.getImage(iconPath, fn)
         pygame.display.set_icon(icon)

      #set up the main window
      windowSize = settings.screenSize[0]*globs.TILESIZE[0], settings.screenSize[1]*globs.TILESIZE[1]   
      self.screen = pygame.display.set_mode(windowSize)
      pygame.display.set_caption("%s --- Ditto Engine" % data.getAttr(root, "title", data.D_STRING))

      #create a clock object
      self.clock = pygame.time.Clock()

      #initialise sound
      sound.init(soundPath)

      #set up the initial scene, the intro
      self.activeScene = intro.Intro(self.screen)
Ejemplo n.º 7
0
   def __init__(self, node, mMap, position, level):
      """
      Set up the player.

      node - the <player> node.
      mMap - the map to start on.
      position - the position to start at.
      level - the level to start on.
      """

      #init the sprite
      sprite.Sprite.__init__(self, node, mMap, position, level)

      #create status tilesets
      self.statusTilesets = {}
      self.statusTilesets[sprite.S_WALK] = self.tileset
      for statusNode in data.getChildren(node, "status"):
         try:
            status = STATUSNAMES[data.getAttr(statusNode, "name", data.D_STRING)]
         except KeyError:
            raise data.DInvalidAttributeError(statusNode, "name")
         tsPath = os.path.join(settings.path, "data", data.getAttr(statusNode, "tileset", data.D_STRING))
         ts = tileset.Tileset(tsPath)
         self.statusTilesets[status] = ts

      #create an empty party
      #overridden with unpickled party if restoring from a save
      self.party = pokemon.Party()

      #set up scripting
      self.scriptCommands["addToParty"] = self.command_addToParty
Ejemplo n.º 8
0
   def setup(self, game):
      """
      Get the script engine ready to run scripts.

      game - the Game object to run scripts on.
      """

      #store game object
      self.game = game


      self.font = font.Font(os.path.join(settings.path, "data", globs.FONT)) #create the font

      #initialise variables needed to run
      self.running = False
      self.queue = []
      self.currentCommand = 0
      self.waiting = False
      self.waitingFor = None
      self.countDown = 0

      #initialise script variables
      self.variables = {}
      self.result = None

      #determine behaviour scripts
      tree = data.getTree(globs.BEHAVIOURS)
      root = tree.getroot()
      self.behaviours = {}
      for behaviourNode in data.getChildren(root, "behaviour", globs.BEHAVIOURS):
         i = data.getAttr(behaviourNode, "index", data.D_INT, globs.BEHAVIOURS)
         s = data.getChild(behaviourNode, "script", globs.BEHAVIOURS)
         self.behaviours[i] = Script(s, False)
Ejemplo n.º 9
0
    def __init__(self, fn):
        """
      Load the image and cut out the individual characters.

      fn - the font XML file.
      """

        #parse the XML file
        root = data.getTreeRoot(fn)
        path = os.path.join(settings.path, "data",
                            data.getAttr(root, "file", data.D_STRING))
        self.height = data.getAttr(root, "height", data.D_INT)
        transparency = data.getAttr(root, "transparency", data.D_INT3LIST)

        #load the image
        image = data.getImage(path, fn)
        image.set_colorkey(transparency)

        #cut out the tiles and store them in a dictionary
        self.characters = {}
        for c in data.getChildren(root, "character"):
            char = data.getAttr(c, "char", data.D_STRING)
            width = data.getAttr(c, "width", data.D_INT)
            location = data.getAttr(c, "location", data.D_INT2LIST)
            self.characters[char] = image.subsurface(location[0], location[1],
                                                     width, self.height)
Ejemplo n.º 10
0
    def setup(self, game):
        """
      Get the script engine ready to run scripts.

      game - the Game object to run scripts on.
      """

        #store game object
        self.game = game

        self.font = font.Font(os.path.join(settings.path, "data",
                                           globs.FONT))  #create the font

        #initialise variables needed to run
        self.running = False
        self.queue = []
        self.currentCommand = 0
        self.waiting = False
        self.waitingFor = None
        self.countDown = 0

        #initialise script variables
        self.variables = {}
        self.result = None

        #determine behaviour scripts
        tree = data.getTree(globs.BEHAVIOURS)
        root = tree.getroot()
        self.behaviours = {}
        for behaviourNode in data.getChildren(root, "behaviour",
                                              globs.BEHAVIOURS):
            i = data.getAttr(behaviourNode, "index", data.D_INT,
                             globs.BEHAVIOURS)
            s = data.getChild(behaviourNode, "script", globs.BEHAVIOURS)
            self.behaviours[i] = Script(s, False)
Ejemplo n.º 11
0
def init(fn):
   """
   Initialise the pygame mixer and parse XML file for sound effect locations.

   fn - the path to the XML file.
   """

   #initialise the pygame mixer
   pygame.mixer.init()

   #parse the XML file
   root = data.getTreeRoot(fn)
   for effect in data.getChildren(root, "soundeffect"):
      e = SOUNDEFFECTS[data.getAttr(effect, "name", data.D_STRING)]
      effects[e] = os.path.join(settings.path, "data", data.getAttr(effect, "file", data.D_STRING))
Ejemplo n.º 12
0
   def __init__(self, moveId):
      self.moveId = moveId
      
      fn = os.path.join(settings.path, "data", globs.MOVES)
      root = data.getTreeRoot(fn)

      self.moveNode = None
      for m in data.getChildren(root, "move"):
         if data.getAttr(m, "id", data.D_STRING) == moveId:
            self.moveNode = m
            break
      if self.moveNode is None:
         raise error.DittoInvalidResourceException(fn, "MOVE %s" % self.moveId)

      self.name = data.getAttr(self.moveNode, "name", data.D_STRING)
      self.maxPP = data.getAttr(self.moveNode, "pp", data.D_INT)
      self.currPP = self.maxPP
Ejemplo n.º 13
0
   def setup(self, game):
      self.symbols = symbols.Symbols(game, self)

      self.script = None
      self.result = False
      self.currentCmd = 0

      self.caller = None

      self.waitingFor = None

      #determine behaviour scripts
      root = data.getTreeRoot(globs.BEHAVIOURS)
      self.behaviours = {}
      for behaviourNode in data.getChildren(root, "behaviour"):
         i = data.getAttr(behaviourNode, "index", data.D_INT)
         s = data.getChild(behaviourNode, "script")
         self.behaviours[i] = script.Script(s, False)
Ejemplo n.º 14
0
    def __init__(self, moveId):
        self.moveId = moveId

        fn = os.path.join(settings.path, "data", globs.MOVES)
        root = data.getTreeRoot(fn)

        self.moveNode = None
        for m in data.getChildren(root, "move"):
            if data.getAttr(m, "id", data.D_STRING) == moveId:
                self.moveNode = m
                break
        if self.moveNode is None:
            raise error.DittoInvalidResourceException(fn,
                                                      "MOVE %s" % self.moveId)

        self.name = data.getAttr(self.moveNode, "name", data.D_STRING)
        self.maxPP = data.getAttr(self.moveNode, "pp", data.D_INT)
        self.currPP = self.maxPP
Ejemplo n.º 15
0
    def setup(self, game):
        self.symbols = symbols.Symbols(game, self)

        self.script = None
        self.result = False
        self.currentCmd = 0

        self.caller = None

        self.waitingFor = None

        #determine behaviour scripts
        root = data.getTreeRoot(globs.BEHAVIOURS)
        self.behaviours = {}
        for behaviourNode in data.getChildren(root, "behaviour"):
            i = data.getAttr(behaviourNode, "index", data.D_INT)
            s = data.getChild(behaviourNode, "script")
            self.behaviours[i] = script.Script(s, False)
Ejemplo n.º 16
0
    def __init__(self, screen, savegame=None):
        """
      Open the save file (or make a new one) and create camera and script engine.

      screen - the screen to render to.
      sound - the sound manager.
      savegame - path to the save file to open, or None to start a new game.
      """

        #store variables for use later
        self.screen = screen

        #parse the game XML file
        fn = os.path.join(settings.path, "data", "game.xml")
        root = data.getTreeRoot(fn, "Ditto main")
        for p in data.getChildren(root, "property"):
            if data.getAttr(p, "name", data.D_STRING) == "menu":
                self.menuPath = data.getAttr(p, "value", data.D_STRING)

        #create script engine and initialise variables
        self.scriptEngine = script_engine.ScriptEngine()
        self.scriptEngine.setup(self)
        self.paused = False
        self.foregroundObject = None

        #if there's a save, open it
        #else start a new game
        if savegame is not None:
            self.openSave(savegame, root)
        else:
            self.newGame(os.path.join(settings.path, "saves", "ditto.sav"),
                         root)

        #put the player onto the map and play music
        self.map.sprites["PLAYER"] = self.player
        sound.playMusic(self.player.map.music)

        #create a camera and attach to the player
        self.camera = camera.Camera(screen)
        self.camera.attachTo(self.player)
Ejemplo n.º 17
0
    def __init__(self, screen, savegame=None):
        """
      Open the save file (or make a new one) and create camera and script engine.

      screen - the screen to render to.
      sound - the sound manager.
      savegame - path to the save file to open, or None to start a new game.
      """

        # store variables for use later
        self.screen = screen

        # parse the game XML file
        fn = os.path.join(settings.path, "data", "game.xml")
        root = data.getTreeRoot(fn, "Ditto main")
        for p in data.getChildren(root, "property"):
            if data.getAttr(p, "name", data.D_STRING) == "menu":
                self.menuPath = data.getAttr(p, "value", data.D_STRING)

        # create script engine and initialise variables
        self.scriptEngine = script_engine.ScriptEngine()
        self.scriptEngine.setup(self)
        self.paused = False
        self.foregroundObject = None

        # if there's a save, open it
        # else start a new game
        if savegame is not None:
            self.openSave(savegame, root)
        else:
            self.newGame(os.path.join(settings.path, "saves", "ditto.sav"), root)

        # put the player onto the map and play music
        self.map.sprites["PLAYER"] = self.player
        sound.playMusic(self.player.map.music)

        # create a camera and attach to the player
        self.camera = camera.Camera(screen)
        self.camera.attachTo(self.player)
Ejemplo n.º 18
0
    def __init__(self, screen):
        """
      Load all intro screens and start the first.

      screen - the screen to blit to.
      """

        #store screen for use later
        self.screen = screen

        #parse the intro XML file
        fn = os.path.join(settings.path, "data", "intro.xml")
        root = data.getTreeRoot(fn, "Ditto main")

        #create each intro screen
        self.introScreens = []
        for s in data.getChildren(root, "screen"):
            self.introScreens.append(IntroScreen(screen, s))

        #set the first screen active
        self.current = 0
        self.activeScreen = self.introScreens[self.current]
        self.activeScreen.onShow()
Ejemplo n.º 19
0
   def __init__(self, screen):
      """
      Load all intro screens and start the first.

      screen - the screen to blit to.
      """

      #store screen for use later
      self.screen = screen

      #parse the intro XML file
      fn = os.path.join(settings.path, "data", "intro.xml")
      root = data.getTreeRoot(fn, "Ditto main")

      #create each intro screen
      self.introScreens = []
      for s in data.getChildren(root, "screen"):
         self.introScreens.append(IntroScreen(screen, s))

      #set the first screen active
      self.current = 0
      self.activeScreen = self.introScreens[self.current]
      self.activeScreen.onShow()
Ejemplo n.º 20
0
   def __init__(self, fn):
      """
      Load the image and cut out the individual characters.

      fn - the font XML file.
      """

      #parse the XML file
      root = data.getTreeRoot(fn)
      path = os.path.join(settings.path, "data", data.getAttr(root, "file", data.D_STRING))
      self.height = data.getAttr(root, "height", data.D_INT)
      transparency = data.getAttr(root, "transparency", data.D_INT3LIST)

      #load the image
      image = data.getImage(path, fn)
      image.set_colorkey(transparency)

      #cut out the tiles and store them in a dictionary
      self.characters = {}
      for c in data.getChildren(root, "character"):
         char = data.getAttr(c, "char", data.D_STRING)
         width = data.getAttr(c, "width", data.D_INT)
         location = data.getAttr(c, "location", data.D_INT2LIST)
         self.characters[char] = image.subsurface(location[0], location[1], width, self.height)
Ejemplo n.º 21
0
    def __init__(self, species, level):
        self.species = species

        fn = os.path.join(settings.path, "data", globs.POKEMON)
        root = data.getTreeRoot(fn, "Ditto main")

        for sp in data.getChildren(root, "species"):
            if data.getAttr(sp, "id", data.D_STRING) == self.species:
                self.speciesNode = sp
                break

        self.nickname = None

        self.level = level
        self.exp = 0

        typeNode = data.getChild(self.speciesNode, "type")
        self.type1 = data.getAttr(typeNode, "primary", data.D_STRING)
        self.type2 = data.getOptionalAttr(typeNode, "secondary", data.D_STRING,
                                          None)

        self.PID = random.randint(0, 4294967295)
        self.trainer = None
        self.trainerID = None

        self.ability = None

        self.gender = G_MALE
        self.nature = 0
        self.shiny = False

        self.form = 0
        self.happiness = 0
        self.pokerus = False

        self.EVs = {
            ST_HP: 0,
            ST_ATTACK: 0,
            ST_DEFENSE: 0,
            ST_SPEED: 0,
            ST_SPATTACK: 0,
            ST_SPDEFENSE: 0
        }

        self.IVs = {
            ST_HP: random.randint(0, 31),
            ST_ATTACK: random.randint(0, 31),
            ST_DEFENSE: random.randint(0, 31),
            ST_SPEED: random.randint(0, 31),
            ST_SPATTACK: random.randint(0, 31),
            ST_SPDEFENSE: random.randint(0, 31)
        }

        self.stats = {}
        self.calcStats()

        self.currentHP = self.stats[ST_HP]
        self.status = None

        self.moves = [None, None, None, None]
        movesNode = data.getChild(self.speciesNode, "attacks")
        moveNodes = sorted(data.getChildren(movesNode, "move"),
                           key=lambda n: int(n.attrib["level"]))
        i = 0
        for node in moveNodes[-4:]:
            self.moves[i] = moves.Move(data.getAttr(node, "id", data.D_STRING))
            i += 1

        self.ballCaughtIn = 0

        self.heldItem = None
Ejemplo n.º 22
0
    def __init__(self, fn):
        """
      Open the map data file, set border tiles and connections, and add NPCs and other events.

      fn - the filename of the map XML file.
      """

        #for the scripting engine
        script_engine.ScriptableObject.__init__(self)

        #store variables we'll need later
        self.fn = fn

        #get a script engine (singleton)
        self.scriptEngine = script_engine.ScriptEngine()

        #parse the XML file
        root = data.getTreeRoot(fn)
        self.music = os.path.join(settings.path, "data",
                                  data.getAttr(root, "music", data.D_STRING))

        #open the actual map data file to create the map tile data
        mapPath = os.path.join(settings.path, "data",
                               data.getAttr(root, "file", data.D_STRING))
        self.openMap(mapPath)

        #create the tileset
        tilesetPath = os.path.join(
            settings.path, "data", data.getAttr(root, "tileset",
                                                data.D_STRING))
        self.tileset = tileset.Tileset(tilesetPath)

        #set the border tiles
        self.borderTiles = {}
        borderNode = data.getChild(root, "border")

        #set each border node with the correct tile indexes, subtracting 1 because the tileset starts at 1 not 0
        self.borderTiles[BD_NW] = data.getAttr(borderNode, "nw",
                                               data.D_INT) - 1
        self.borderTiles[BD_NE] = data.getAttr(borderNode, "ne",
                                               data.D_INT) - 1
        self.borderTiles[BD_SW] = data.getAttr(borderNode, "sw",
                                               data.D_INT) - 1
        self.borderTiles[BD_SE] = data.getAttr(borderNode, "se",
                                               data.D_INT) - 1

        #create any connections from the map
        #connected maps will not be loaded until the map becomes the main game map
        #connections are stored as {direction: (filename, offset)}
        self.connections = {}
        self.connectedMaps = {}
        for c in data.getChildren(root, "connection"):
            side = data.getAttr(c, "side", data.D_STRING)
            fp = os.path.join(settings.path, "data",
                              data.getAttr(c, "map", data.D_STRING))
            offset = data.getAttr(c, "offset", data.D_INT)

            if side == "left":
                self.connections[sprite.DIR_LEFT] = (fp, offset)
            elif side == "right":
                self.connections[sprite.DIR_RIGHT] = (fp, offset)
            elif side == "up":
                self.connections[sprite.DIR_UP] = (fp, offset)
            elif side == "down":
                self.connections[sprite.DIR_DOWN] = (fp, offset)

        #create any NPCs, adding them to the sprite dictionary
        self.sprites = {}
        for n in data.getChildren(root, "npc"):
            spr = npc.NPC(n, self)
            self.sprites[spr.id] = spr

        #create a dictionary to hold positions reserved by moving sprites
        self.reservedPositions = {}

        #create script and warp events, adding them to the events dictionary
        #if a load script is defined, create it
        self.events = {}
        loadScript = None
        for s in data.getChildren(root, "script"):
            trigger = data.getAttr(s, "trigger", data.D_STRING)
            if trigger == "load":
                loadScript = script_engine.Script(s)
            else:
                position = tuple(data.getAttr(s, "position", data.D_INT2LIST))
                self.events[position] = events.ScriptEvent(s, self)

        for w in root.findall("warp"):
            position = tuple(data.getAttr(w, "position", data.D_INT2LIST))
            self.events[position] = events.Warp(w, self)

        #if there is a load script, run it
        if loadScript is not None:
            self.scriptEngine.run(loadScript, self)
Ejemplo n.º 23
0
   def __init__(self, fn):
      """
      Open the map data file, set border tiles and connections, and add NPCs and other events.

      fn - the filename of the map XML file.
      """

      #for the scripting engine
      script_engine.ScriptableObject.__init__(self)

      #store variables we'll need later
      self.fn = fn

      #get a script engine (singleton)
      self.scriptEngine = script_engine.ScriptEngine()

      #parse the XML file
      root = data.getTreeRoot(fn)
      self.music = os.path.join(settings.path, "data", data.getAttr(root, "music", data.D_STRING))

      #open the actual map data file to create the map tile data
      mapPath = os.path.join(settings.path, "data", data.getAttr(root, "file", data.D_STRING))
      self.openMap(mapPath)

      #create the tileset
      tilesetPath = os.path.join(settings.path, "data", data.getAttr(root, "tileset", data.D_STRING))
      self.tileset = tileset.Tileset(tilesetPath)

      #set the border tiles
      self.borderTiles = {}
      borderNode = data.getChild(root, "border")

      #set each border node with the correct tile indexes, subtracting 1 because the tileset starts at 1 not 0
      self.borderTiles[BD_NW] = data.getAttr(borderNode, "nw", data.D_INT)-1
      self.borderTiles[BD_NE] = data.getAttr(borderNode, "ne", data.D_INT)-1
      self.borderTiles[BD_SW] = data.getAttr(borderNode, "sw", data.D_INT)-1
      self.borderTiles[BD_SE] = data.getAttr(borderNode, "se", data.D_INT)-1
      
      #create any connections from the map
      #connected maps will not be loaded until the map becomes the main game map
      #connections are stored as {direction: (filename, offset)}
      self.connections = {}
      self.connectedMaps = {}
      for c in data.getChildren(root, "connection"):
         side = data.getAttr(c, "side", data.D_STRING)
         fp = os.path.join(settings.path, "data", data.getAttr(c, "map", data.D_STRING))
         offset = data.getAttr(c, "offset", data.D_INT)
         
         if side == "left":
            self.connections[sprite.DIR_LEFT] = (fp, offset)
         elif side == "right":
            self.connections[sprite.DIR_RIGHT] = (fp, offset)
         elif side == "up":
            self.connections[sprite.DIR_UP] = (fp, offset)
         elif side == "down":
            self.connections[sprite.DIR_DOWN] = (fp, offset)

      #create any NPCs, adding them to the sprite dictionary
      self.sprites = {}
      for n in data.getChildren(root, "npc"):
         spr = npc.NPC(n, self)
         self.sprites[spr.id] = spr

      #create a dictionary to hold positions reserved by moving sprites
      self.reservedPositions = {}

      #create script and warp events, adding them to the events dictionary
      #if a load script is defined, create it
      self.events = {}
      loadScript = None
      for s in data.getChildren(root, "script"):
         trigger = data.getAttr(s, "trigger", data.D_STRING)
         if trigger == "load":
            loadScript = script_engine.Script(s)   
         else:
            position = tuple(data.getAttr(s, "position", data.D_INT2LIST)) 
            self.events[position] = events.ScriptEvent(s, self)
            
      for w in root.findall("warp"):
         position = tuple(data.getAttr(w, "position", data.D_INT2LIST))
         self.events[position] = events.Warp(w, self)

      #if there is a load script, run it
      if loadScript is not None:
         self.scriptEngine.run(loadScript, self)
Ejemplo n.º 24
0
   def __init__(self, species, level):
      self.species = species

      fn = os.path.join(settings.path, "data", globs.POKEMON)
      root = data.getTreeRoot(fn, "Ditto main")

      for sp in data.getChildren(root, "species"):
         if data.getAttr(sp, "id", data.D_STRING) == self.species:
            self.speciesNode = sp
            break                           
      
      self.nickname = None
      
      self.level = level
      self.exp = 0

      typeNode = data.getChild(self.speciesNode, "type")
      self.type1 = data.getAttr(typeNode, "primary", data.D_STRING)
      self.type2 = data.getOptionalAttr(typeNode, "secondary", data.D_STRING, None)

      self.PID = random.randint(0, 4294967295)
      self.trainer = None
      self.trainerID = None

      self.ability = None

      self.gender = G_MALE
      self.nature = 0
      self.shiny = False

      self.form = 0
      self.happiness = 0
      self.pokerus = False
      
      self.EVs = {ST_HP: 0,
                  ST_ATTACK: 0,
                  ST_DEFENSE: 0,
                  ST_SPEED: 0,
                  ST_SPATTACK: 0,
                  ST_SPDEFENSE: 0}
      
      self.IVs = {ST_HP: random.randint(0,31),
                  ST_ATTACK: random.randint(0,31),
                  ST_DEFENSE: random.randint(0,31),
                  ST_SPEED: random.randint(0,31),
                  ST_SPATTACK: random.randint(0,31),
                  ST_SPDEFENSE: random.randint(0,31)}

      self.stats = {}
      self.calcStats()

      self.currentHP = self.stats[ST_HP]
      self.status = None

      self.moves = [None, None, None, None]
      movesNode = data.getChild(self.speciesNode, "attacks")
      moveNodes = sorted(data.getChildren(movesNode, "move"), key=lambda n: int(n.attrib["level"]))
      i = 0
      for node in moveNodes[-4:]:
         self.moves[i] = moves.Move(data.getAttr(node, "id", data.D_STRING))
         i += 1
      
      self.ballCaughtIn = 0

      self.heldItem = None