Beispiel #1
0
    def perform_action(self, user, technique, target=None):
        """ Do something with the thing: animated

        :param user:
        :param technique: Not a dict: a Technique or Item
        :param target:

        :returns:
        """
        result = technique.use(user, target)

        try:
            tools.load_sound(technique.sfx).play()
        except AttributeError:
            pass

        # action is performed, so now use sprites to animate it
        target_sprite = self._monster_sprite_map[target]

        hit_delay = 0
        if user:
            message = "%s used %s!" % (user.name, technique.name)

            # TODO: a real check or some params to test if should tackle, etc
            if technique in user.moves:
                hit_delay += .5
                user_sprite = self._monster_sprite_map[user]
                self.animate_sprite_tackle(user_sprite)
                self.task(
                    partial(self.animate_sprite_take_damage, target_sprite),
                    hit_delay + .2)
                self.task(partial(self.blink, target_sprite), hit_delay + .6)

            else:  # assume this was an item used
                if result:
                    message += "\nIt worked!"
                else:
                    message += "\nIt failed!"

            self.alert(message)
            self.suppress_phase_change()

        else:
            if result:
                self.suppress_phase_change()
                self.alert("{0.name} took {1.name} damage!".format(
                    target, technique))

        if result and hasattr(technique, "images"):
            tech_sprite = self.get_technique_animation(technique)
            tech_sprite.rect.center = target_sprite.rect.center
            self.task(tech_sprite.image.play, hit_delay)
            self.task(partial(self.sprites.add, tech_sprite, layer=50),
                      hit_delay)
            self.task(tech_sprite.kill, 3)
Beispiel #2
0
    def perform_action(self, user, technique, target=None):
        """ Do something with the thing: animated

        :param user:
        :param technique: Not a dict: a Technique or Item
        :param target:

        :returns:
        """
        result = technique.use(user, target)

        try:
            tools.load_sound(technique.sfx).play()
        except AttributeError:
            pass

        # action is performed, so now use sprites to animate it
        target_sprite = self._monster_sprite_map[target]

        hit_delay = 0
        if user:
            message = "%s used %s!" % (user.name, technique.name)

            # TODO: a real check or some params to test if should tackle, etc
            if technique in user.moves:
                hit_delay += 0.5
                user_sprite = self._monster_sprite_map[user]
                self.animate_sprite_tackle(user_sprite)
                self.task(partial(self.animate_sprite_take_damage, target_sprite), hit_delay + 0.2)
                self.task(partial(self.blink, target_sprite), hit_delay + 0.6)

            else:  # assume this was an item used
                if result:
                    message += "\nIt worked!"
                else:
                    message += "\nIt failed!"

            self.alert(message)
            self.suppress_phase_change()

        else:
            if result:
                self.suppress_phase_change()
                self.alert("{0.name} took {1.name} damage!".format(target, technique))

        if result and hasattr(technique, "images"):
            tech_sprite = self.get_technique_animation(technique)
            tech_sprite.rect.center = target_sprite.rect.center
            self.task(tech_sprite.image.play, hit_delay)
            self.task(partial(self.sprites.add, tech_sprite, layer=50), hit_delay)
            self.task(tech_sprite.kill, 3)
Beispiel #3
0
    def reload_sounds(self):
        """ Reload sounds

        :returns: None
        """
        self.menu_select_sound = tools.load_sound(
            self.menu_select_sound_filename)
Beispiel #4
0
    def play_sound(self, game, action):
        """Plays a sound from "resources/sounds/"

        :param game: The main game object that contains all the game's variables.
        :param action: The action (tuple) retrieved from the database that contains the action's
            parameters

        :type game: core.control.Control
        :type action: Tuple

        :rtype: None
        :returns: None

        Valid Parameters: filename

        **Examples:**

        >>> action.__dict__
        {
            "type": "play_sound",
            "parameters": [
                "interface/NenadSimic_Click.ogg"
            ]
        }

        """
        filename = str(action.parameters[0])
        sound = tools.load_sound("sounds/" + filename)
        sound.play()
Beispiel #5
0
    def play_sound(self, game, action, contexts):
        """Plays a sound from "resources/sounds/"

        :param game: The main game object that contains all the game's variables.
        :param action: The action (tuple) retrieved from the database that contains the action's
            parameters

        :type game: core.control.Control
        :type action: Tuple

        :rtype: None
        :returns: None

        Valid Parameters: filename

        **Examples:**

        >>> action.__dict__
        {
            "type": "play_sound",
            "parameters": [
                "interface/NenadSimic_Click.ogg"
            ]
        }

        """
        filename = str(action.parameters[0])
        sound = tools.load_sound("sounds/" + filename)
        sound.play()
Beispiel #6
0
    def startup(self, **kwargs):
        # this task will skip the splash screen after some time
        self.task(self.fade_out, self.default_duration)

        width, height = prepare.SCREEN_SIZE
        splash_border = prepare.SCREEN_SIZE[0] / 20     # The space between the edge of the screen

        # Set up the splash screen logos
        logo = self.load_sprite("gfx/ui/intro/pygame_logo.png")
        logo.rect.topleft = splash_border, height - splash_border - logo.rect.height

        # Set up the splash screen logos
        cc = self.load_sprite("gfx/ui/intro/creative_commons.png")
        cc.rect.topleft = width - splash_border - cc.rect.width, height - splash_border - cc.rect.height

        self.ding = tools.load_sound("sounds/ding.wav")
        self.ding.play()
Beispiel #7
0
    def startup(self, **kwargs):
        # this task will skip the splash screen after some time
        self.task(self.fade_out, self.default_duration)

        width, height = prepare.SCREEN_SIZE
        splash_border = prepare.SCREEN_SIZE[
            0] / 20  # The space between the edge of the screen

        # Set up the splash screen logos
        logo = self.load_sprite("gfx/ui/intro/pygame_logo.png")
        logo.rect.topleft = splash_border, height - splash_border - logo.rect.height

        # Set up the splash screen logos
        cc = self.load_sprite("gfx/ui/intro/creative_commons.png")
        cc.rect.topleft = width - splash_border - cc.rect.width, height - splash_border - cc.rect.height

        self.ding = tools.load_sound("sounds/ding.wav")
        self.ding.play()
Beispiel #8
0
    def reload_sounds(self):
        """ Reload sounds

        :returns: None
        """
        self.menu_select_sound = tools.load_sound(self.menu_select_sound_filename)
Beispiel #9
0
    def perform_action(self, user, technique, target=None):
        """ Do something with the thing: animated

        :param user:
        :param technique: Not a dict: a Technique or Item
        :param target:

        :returns:
        """
        technique.advance_round()

        # This is the time, in seconds, that the animation takes to finish.
        action_time = 3.0
        result = technique.use(user, target)

        try:
            tools.load_sound(technique.sfx).play()
        except AttributeError:
            pass

        # action is performed, so now use sprites to animate it
        # this value will be None if the target is off screen
        target_sprite = self._monster_sprite_map.get(target, None)

        # slightly delay the monster shake, so technique animation
        # is synchronized with the damage shake motion
        hit_delay = 0
        if user:
            message = trans('combat_used_x', {
                "user": user.name,
                "name": technique.name
            })

            # TODO: a real check or some params to test if should tackle, etc
            if result["should_tackle"]:
                hit_delay += .5
                user_sprite = self._monster_sprite_map[user]
                self.animate_sprite_tackle(user_sprite)

                if target_sprite:
                    self.task(
                        partial(self.animate_sprite_take_damage,
                                target_sprite), hit_delay + .2)
                    self.task(partial(self.blink, target_sprite),
                              hit_delay + .6)

                # Track damage
                self._damage_map[target].add(user)

            else:  # assume this was an item used
                # handle the capture device
                if result["name"] == "capture":
                    message += "\n" + trans('attempting_capture')
                    action_time = result["num_shakes"] + 1.8
                    self.animate_capture_monster(result["success"],
                                                 result["num_shakes"], target)
                    if result["success"]:  # end combat right here
                        self.task(self.end_combat, action_time +
                                  0.5)  # Display 'Gotcha!' first.
                        self.task(partial(self.alert, trans('gotcha')),
                                  action_time)
                        self._animation_in_progress = True
                        return

                # generic handling of anything else
                else:
                    if result["success"]:
                        message += "\n" + trans('item_success')
                    else:
                        message += "\n" + trans('item_failure')

            self.alert(message)
            self.suppress_phase_change(action_time)

        else:
            if result["success"]:
                self.suppress_phase_change()
                self.alert(
                    trans('combat_status_damage', {
                        "name": target.name,
                        "status": technique.name
                    }))

        if result["success"] and target_sprite and hasattr(
                technique, "images"):
            tech_sprite = self.get_technique_animation(technique)
            tech_sprite.rect.center = target_sprite.rect.center
            self.task(tech_sprite.image.play, hit_delay)
            self.task(partial(self.sprites.add, tech_sprite, layer=50),
                      hit_delay)
            self.task(tech_sprite.kill, 3)
Beispiel #10
0
 def start(self):
     filename = self.parameters.filename
     sound = tools.load_sound("sounds/" + filename)
     sound.play()
Beispiel #11
0
    def perform_action(self, user, technique, target=None):
        """ Do something with the thing: animated

        :param user:
        :param technique: Not a dict: a Technique or Item
        :param target:

        :returns:
        """
        technique.advance_round()

        # This is the time, in seconds, that the animation takes to finish.
        action_time = 3.0
        result = technique.use(user, target)

        if technique.execute_trans:
            context = {"user": getattr(user, "name", ''),
                       "name": technique.name,
                       "target": target.name}
            message = trans(technique.execute_trans, context)
        else:
            message = ''

        try:
            tools.load_sound(technique.sfx).play()
        except AttributeError:
            pass

        # action is performed, so now use sprites to animate it
        # this value will be None if the target is off screen
        target_sprite = self._monster_sprite_map.get(target, None)

        # slightly delay the monster shake, so technique animation
        # is synchronized with the damage shake motion
        hit_delay = 0
        if user:

            # TODO: a real check or some params to test if should tackle, etc
            if result["should_tackle"]:
                hit_delay += .5
                user_sprite = self._monster_sprite_map[user]
                self.animate_sprite_tackle(user_sprite)

                if target_sprite:
                    self.task(partial(self.animate_sprite_take_damage, target_sprite), hit_delay + .2)
                    self.task(partial(self.blink, target_sprite), hit_delay + .6)

                # TODO: track total damage
                # Track damage
                self._damage_map[target].add(user)

            else:  # assume this was an item used

                # handle the capture device
                if result["capture"]:
                    message += "\n" + trans('attempting_capture')
                    action_time = result["num_shakes"] + 1.8
                    self.animate_capture_monster(result["success"], result["num_shakes"], target)

                    # TODO: Don't end combat right away; only works with SP, and 1 member parties
                    # end combat right here
                    if result["success"]:
                        self.task(self.end_combat, action_time + 0.5)  # Display 'Gotcha!' first.
                        self.task(partial(self.alert, trans('gotcha')), action_time)
                        self._animation_in_progress = True
                        return

                # generic handling of anything else
                else:
                    msg_type = 'success_trans' if result['success'] else 'failure_trans'
                    template = getattr(technique, msg_type)
                    if template:
                        message += "\n" + trans(template)

            self.alert(message)
            self.suppress_phase_change(action_time)

        else:
            if result["success"]:
                self.suppress_phase_change()
                self.alert(trans('combat_status_damage', {"name": target.name, "status": technique.name}))

        if result["success"] and target_sprite and hasattr(technique, "images"):
            tech_sprite = self.get_technique_animation(technique)
            tech_sprite.rect.center = target_sprite.rect.center
            self.task(tech_sprite.image.play, hit_delay)
            self.task(partial(self.sprites.add, tech_sprite, layer=50), hit_delay)
            self.task(tech_sprite.kill, 3)