예제 #1
0
    def update(self, up):
        if isinstance(up, Update):
            if is_living(up.enttype):
                entity = self.map.layers[2].getById(up.idnum)
                if entity is not None:
                    entity.stats = up.stats

        else:
            if up.name != "":
                self.map.addPlayer(up)
예제 #2
0
    def handleUpdate(self, update):
        if update.idnum == 0 or (self.map is None and self.player.stats.hp <= 0):
            return
        entity = None
        if is_living(update.enttype):
            entity = self.map.layers[2].getById(update.idnum)
            if entity is None:
                entity = Entity(update.stats, update.enttype,
                                True, update.name, update.idnum)
                self.map.layers[2].add(entity)
            # the monster's not dead, so it's attacking. arrrgh
            if update.stats.hp > 0 and self.player:
                self.monster_attack(entity)

        elif is_player(update.enttype):
            entity = self.map.layers[2].getById(update.idnum)
            if entity is None:
                entity = Entity(update.stats, update.enttype,
                                       True, update.name, update.idnum)
                if self.player is None:
                    self.player = entity

                    x = pygame.display.get_surface().get_width()
                    y = pygame.display.get_surface().get_height()
                    self.hud = hud.HUD(self.player, x, y)
                    self.viewport = viewport.Viewport(self.player, int(x/32), int(y/32))
                self.map.layers[2].add(entity)

        elif is_item(update.enttype):
            entity = self.map.layers[1].getById(update.idnum)
            if entity is None:
                entity = Entity(update.stats, update.enttype,
                                       False, update.name, update.idnum)
                self.map.layers[1].add(entity)
        elif is_terrain(update.enttype):
            entity = self.map.layers[0].getById(update.idnum)
            if entity is None:
                entity = Entity(update.stats, update.enttype,
                                       is_solid_terrain(update.enttype),
                                       update.name, update.idnum)
                self.map.layers[0].add(entity)
        entity.stats = update.stats