Esempio n. 1
0
    def move_to_attack( self, explo, chara, target, redraw=None ):
        result = None
        if not redraw:
            redraw = explo.view
        explo.view.overlays.clear()
        if self.scene.on_the_map( *target.pos ):
            attack_positions = pfov.AttackReach( self.scene, target.pos[0], target.pos[1], chara.get_attack_reach() ).tiles
            # Remove the positions of models from the goal tiles, so they will be avoided.
            for m in self.scene.contents:
                if self.scene.is_model(m) and m.pos in attack_positions and m is not chara:
                    attack_positions.remove( m.pos )
            hmap = hotmaps.HotMap( self.scene, attack_positions, avoid_models=True )

            while self.ap_spent[ chara ] < chara.get_move():
                result = self.step( explo, chara, hmap )
                if chara in self.camp.party:
                    self.scene.update_party_position( explo.camp.party )
                if result:
                    break

                redraw( explo.screen )
                pygame.display.flip()
                pygwrap.anim_delay()

            if chara.pos in attack_positions:
                # Close enough to attack. Make it so.
                self.attack( explo, chara, target, redraw )

        return result
Esempio n. 2
0
    def move_to_attack( self, explo, chara, target, redraw=None ):
        result = None
        if not redraw:
            redraw = explo.view
        explo.view.overlays.clear()
        if self.scene.on_the_map( *target.pos ):
            attack_positions = pfov.AttackReach( self.scene, target.pos[0], target.pos[1], chara.get_attack_reach() ).tiles
            # Remove the positions of models from the goal tiles, so they will be avoided.
            for m in self.scene.contents:
                if self.scene.is_model(m) and m.pos in attack_positions and m is not chara:
                    attack_positions.remove( m.pos )
            hmap = hotmaps.HotMap( self.scene, attack_positions, avoid_models=True )

            while self.ap_spent[ chara ] < chara.get_move():
                result = self.step( explo, chara, hmap )
                if chara in self.camp.party:
                    self.scene.update_party_position( explo.camp.party )
                if result:
                    break

                redraw( explo.screen )
                pygame.display.flip()
                pygwrap.anim_delay()

            if chara.pos in attack_positions:
                # Close enough to attack. Make it so.
                self.attack( explo, chara, target, redraw )

        return result
Esempio n. 3
0
def handle_anim_sequence(screen, view, anims, record_anim=False):
    tick = 0
    if record_anim:
        view.anims.clear()
        view(screen, show_quick_stats=False)
        pygame.display.flip()
        pygame.image.save(screen,
                          util.user_dir("anim_{:0>3}.png".format(tick)))
        tick += 1

    while anims:
        view.anims.clear()
        for a in anims[:]:
            if a.needs_deletion:
                anims.remove(a)
                anims += a.children
            else:
                view.anims[a.pos].append(a)
                a.update()
        view(screen, show_quick_stats=False)
        pygame.display.flip()
        if record_anim:
            pygame.image.save(screen,
                              util.user_dir("anim_{:0>3}.png".format(tick)))

        pygwrap.anim_delay()
        tick += 1
    view.anims.clear()
Esempio n. 4
0
def handle_anim_sequence( screen, view, anims, record_anim=False ):
    tick = 0
    if record_anim:
        view.anims.clear()
        view( screen, show_quick_stats=False )
        pygame.display.flip()
        pygame.image.save( screen, util.user_dir( "anim_{:0>3}.png".format(tick) ) )
        tick += 1

    while anims:
        view.anims.clear()
        for a in anims[:]:
            if a.needs_deletion:
                anims.remove( a )
                anims += a.children
            else:
                view.anims[a.pos].append( a )
                a.update()
        view( screen, show_quick_stats=False )
        pygame.display.flip()
        if record_anim:
            pygame.image.save( screen, util.user_dir( "anim_{:0>3}.png".format(tick) ) )

        pygwrap.anim_delay()
        tick += 1
    view.anims.clear()
Esempio n. 5
0
def handle_anim_sequence( screen, view, anims ):
    while anims:
        view.anims.clear()
        for a in anims[:]:
            if a.needs_deletion:
                anims.remove( a )
                anims += a.children
            else:
                view.anims[a.pos].append( a )
                a.update()
        view( screen, show_quick_stats=False )
        pygame.display.flip()
        pygwrap.anim_delay()
    view.anims.clear()
Esempio n. 6
0
 def move_for_action( self, explo, chara, action, act_positions, hmap, redraw=None ):
     # Just move towards nearest enemy and try to use the provided action.
     comba = explo.camp.fight
     redraw = redraw or explo.view
     did_action = False
     explo.view.overlays.clear()
     while comba.ap_spent[ chara ] < chara.get_move() and chara.is_alright():
         result = comba.step( explo, chara, hmap )
         if result or ( chara.pos in act_positions and comba.ap_spent[ chara ] >= chara.get_move() ):
             if chara.is_alright():
                 did_action = action( explo, comba, chara, redraw )
             break
         redraw( explo.screen )
         pygame.display.flip()
         pygwrap.anim_delay()
     return did_action
Esempio n. 7
0
    def move_player_to_spot( self, explo, chara, pos, redraw=None ):
        result = None
        if not redraw:
            redraw = explo.view
        explo.view.overlays.clear()
        if self.scene.on_the_map( *pos ):
            hmap = hotmaps.PointMap( self.scene, pos, avoid_models=True )

            while self.ap_spent[ chara ] < chara.get_move():
                result = self.step( explo, chara, hmap, do_bump=True )
                self.scene.update_party_position( explo.camp.party )
                if result:
                    break

                redraw( explo.screen )
                pygame.display.flip()
                pygwrap.anim_delay()

        return result
Esempio n. 8
0
    def move_player_to_spot( self, explo, chara, pos, redraw=None ):
        result = None
        if not redraw:
            redraw = explo.view
        explo.view.overlays.clear()
        if self.scene.on_the_map( *pos ) and not self.scene.map[pos[0]][pos[1]].blocks_walking():
            hmap = hotmaps.PointMap( self.scene, pos, avoid_models=True )

            while self.ap_spent[ chara ] < chara.get_move():
                result = self.step( explo, chara, hmap )
                self.scene.update_party_position( explo.camp.party )
                if result:
                    break

                redraw( explo.screen )
                pygame.display.flip()
                pygwrap.anim_delay()

        return result
 def move_for_action(self,
                     explo,
                     chara,
                     action,
                     act_positions,
                     hmap,
                     redraw=None):
     # Just move towards nearest enemy and try to use the provided action.
     comba = explo.camp.fight
     redraw = redraw or explo.view
     did_action = False
     explo.view.overlays.clear()
     while comba.ap_spent[chara] < chara.get_move() and chara.is_alright():
         result = comba.step(explo, chara, hmap)
         if result:
             if chara.is_alright():
                 did_action = action(explo, comba, chara, redraw)
             break
         redraw(explo.screen)
         pygame.display.flip()
         pygwrap.anim_delay()
     return did_action