Exemple #1
0
    def __init__(self, core, data):
        """Reset all the data."""
        self.core = core
        self.core.SetGame(self)

        # Data from the YAML file
        self.data = data

        # Create the mouse object
        self.mouse = Mouse()

        # Our map dictionary
        self.maps = {}

        #TODO(g): Make map loading dynamic
        #self.map = rpg_map.Map(self, MAP_HARDCODED)
        self.SelectMap(data['game']['initial_map'])

        # We're just getting started!
        self.quitting = False

        # For the editor-cursor: mouse
        self.cursor_map_pos = rpg_base.Position()

        # Player object goes here
        self.player = None

        # Save dialogue stuff going on.
        #TODO(g): This is cheating for having a game state stack, which I should do
        #   but will put off because it will take longer and I want NPC dialogue
        #   NOW!!!
        self.dialogue = None

        # When this list is non-null, the player and listed characters are battling
        self.combat = []
Exemple #2
0
 def __init__(self, game, data):
   """Create the actor, place it on the map."""
   self.game = game
   self.data = data
   self.name = data['name']
   
   # Create our attributes (need to make new field references)
   self.attributes = {}
   for key in self.data.get('attributes', {}):
     self.attributes[key] = self.data['attributes'][key]
   
   # Create items
   self.items = []
   for key in self.data.get('items', {}):
     item = rpg_item.Item(self.game, self, self.data['items'][key])
     self.items.append(item)
   
   # Image
   self.image = rpg_image.Load(data['image'],
                               colorkey=data.get('image_color_key',
                               game.data['game']['color_key']))
   
   starting_position = data['pos']
   self.pos = rpg_base.Position(starting_position[0], starting_position[1])
   self.pos_last = self.pos
   
   # Save any data we need to manipulate
   self.money = data.get('money', 0)
   
   
   # More stats
   self.fatigued = False
Exemple #3
0
 def ProcessPlayerTileMove(self):
   """Process anything that needs to happen now that the player is on this tile.
   """
   # If the player steps on a door
   if 'doors' in self.data:
     for key in self.data['doors']:
       door = self.data['doors'][key]
       
       if self.game.player.pos.IsSame(door['pos']):
         Log('Entering door: %s: %s' % (key, door['map']))
         self.game.SelectMap(door['map'])
         
         if 'player_pos' in door:
           (player_x, player_y) = door['player_pos']
         else:
           (player_x, player_y) = self.game.map.data['player']['starting_pos']
         
         self.game.player.pos = rpg_base.Position(player_x, player_y)
         
         # Center the player on the screen
         tiles = self.game.map.GetTilesPerScreen()
         self.game.map.offset[0] = self.game.player.pos.x - tiles[0] / 2
         self.game.map.offset[1] = self.game.player.pos.y - tiles[1] / 2
   
   # Check if we have stepped next to an actor
   for name in self.actors:
     actor = self.actors[name]
     if self.game.player.pos.GetDistance(actor.pos) <= 1.0:
       self.game.dialogue = rpg_dialogue.Dialogue(self.game, actor)
       break
Exemple #4
0
    def __init__(self, game, name):
        """Create the player, place it on the map."""
        self.game = game
        self.name = name

        starting_position = game.map.data['player']['starting_pos']
        self.pos = rpg_base.Position(starting_position[0],
                                     starting_position[1])
        self.pos_last = self.pos
        #TODO(g): Unhard-code the default player
        self.data = yaml.load(YamlOpen(DATA_FILE))['default']

        # Image
        self.image = rpg_image.Load(self.data['image'],
                                    colorkey=self.data.get(
                                        'image_color_key',
                                        game.data['game']['color_key']))

        # Save any attributes we want specifically out of our data
        self.money = self.data.get('money', 0)

        # Create our attributes (need to make new field references)
        self.attributes = {}
        for key in self.data.get('attributes', {}):
            self.attributes[key] = self.data['attributes'][key]

        # Create our items
        self.items = []
        for key in self.data.get('items', {}):
            item = rpg_item.Item(self.game, self, self.data['items'][key])
            self.items.append(item)

        # Save the current health of the player
        if 'heath' in self.attributes:
            self.health_current = self.attributes['health']
        else:
            #NOTE(g): This makes the player alive.  Apparently health isnt important
            #   in this game...
            self.health_current = 1

        # Get the quests we start with
        #TODO(g): Make this a deep copy, so we arent changing the data we loaded
        self.quests = dict(self.data['quests'])

        # Save the current health of the player
        if 'mana' in self.attributes:
            self.mana_current = self.attributes['mana']
        else:
            #NOTE(g): Mana is not necessary, like health i
            self.mana_current = 0

        # More stats
        self.fatigued = False

        # Achievements
        self.achievements = {}
Exemple #5
0
 def Move(self, x, y):
   """x and y should be values between -1 and 1."""
   
   new_x = self.pos.x + x
   new_y = self.pos.y + y
   
   # Bound the position by the map size
   if new_x < 0:
     new_x = 0
   
   if new_y < 0:
     new_y = 0
   
   if new_x >= self.game.map.width:
     new_x = self.game.map.width - 1
   
   if new_y >= self.game.map.height:
     new_y = self.game.map.height - 1
   
   # See if we can actually move to this new position
   is_blocked = self.game.map.IsTileBlocked(new_x, new_y, self)
   
   if not is_blocked:
     # Save our last position
     self.pos_last = rpg_base.Position(self.pos.x, self.pos.y)
     
     # Update our new position
     self.pos.x = new_x
     self.pos.y = new_y
     
     # If this is the player, then do these
     if self == self.game.player:
       # Check for Map features of this tile
       self.game.map.ProcessPlayerTileMove()
       
       # After a move, ensure the map is positioned properly
       self.PostMove()
       
       # Update the visibility map
       self.game.map.UpdateVisibility()