Things can now be shared globally by maps.

This commit is contained in:
Patrick Marsee 2019-10-15 18:40:50 -04:00
parent aba0014e27
commit 963c77f77c
3 changed files with 73 additions and 35 deletions

View file

@ -44,7 +44,7 @@ class GameBase(object):
self.eventQueue = []
self.gameTime = 0.0
self.skipLoop = True
self.nextThing = 0
self.nextThing = 1
# player info
self.playerName = 'You'
@ -363,9 +363,9 @@ Object can be the name of the object, or its coordinates."""
# load the new level
if len(args) == 2:
self.level, self.nextThing = _gm.GameMap.read(args[0], int(args[1]), preLoaded, self.nextThing)
self.level, self.nextThing = _gm.GameMap.read(args[0], int(args[1]), self.singletons, preLoaded, self.nextThing)
else:
self.level, self.nextThing = _gm.GameMap.read(args[0], None, preLoaded, self.nextThing)
self.level, self.nextThing = _gm.GameMap.read(args[0], None, self.singletons, preLoaded, self.nextThing)
if self.level == None:
raise GameError("Map could not be loaded.")
@ -388,7 +388,7 @@ Object can be the name of the object, or its coordinates."""
inventory = {}, customValues = {}, name = self.playerName)
#print("Player created.")
else:
self.player.x, self.player.y = x, y
self.player.x, self.player.y = mx, my
#print("Player moved.")
self.player.prevx, self.player.prevy = self.player.x, self.player.y
self.nextThing = self.level.addThing(self.player, self.nextThing) # The player needs to be added to the new level.
@ -559,6 +559,7 @@ Object can be the name of the object, or its coordinates."""
# any map. This is useful for when you have major characters who will
# show up in many scenes, and their inventory must stay the same, for
# example.
self.singletons = {}
if 'singletons' in data:
for thing in data['singletons']:
#thing = data['singletons'][datum]
@ -576,7 +577,7 @@ Object can be the name of the object, or its coordinates."""
self.nextThing = _gm.GameMap.addThingRecursive(i.customValues, self.nextThing + 1)
thing.addThing(i)
del thing.tempInventory
self.singletons = list(data['singletons'])
self.singletons[thing.name] = thing
return data
def gameEventLoop(self):