Exemplo n.º 1
0
    // ReSharper disable once SuggestBaseTypeForParameter
    private async Task BombDestroy(int color,
                                   Sprite bomb,
                                   ItemPos[] destroyedPos)
    {
        var bombExp = (Node2D)_animTemplate.Duplicate();
        var player  =
            bombExp.GetNode <AnimationPlayer>(new NodePath("AnimationPlayer"));

        bomb.GetParent().AddChild(bombExp);
        bombExp.Position = bomb.Position;
        var sprite =
            bombExp.GetNode <AnimatedSprite>(new NodePath("AnimatedSprite"));

        sprite.Frame = GameScene.BombAnimFirstFrame[color];
        string animName = $"Bomb_{GameScene.Colors[color]}_Explosion";

        player.GetAnimation(animName).Loop = false; // Sometimes it's true(???)
        player.Play(animName);
        bombExp.Visible = true;
        bomb.Visible    = false; // removed later in Exec

        List <Task> regularDestroyedBy = destroyedPos
                                         .Where(p => p.Item.IsRegularShape)
                                         .Select(dPos =>
        {
            GD.Print($"DestroyAct. byBomb {dPos.Pos} {dPos.Item.Dump()}");
            return(DestroyItem(dPos, 0.25f));    // With delay
        })
                                         .ToList();

        await ToSignal(player, "animation_finished");

        List <Task> bonusDestroyedBy = destroyedPos
                                       .Where(p => !p.Item.IsRegularShape)
                                       .Select(dPos =>
        {
            GD.Print($"DestroyAct. byBomb {dPos.Pos} {dPos.Item.Dump()}");
            return(DestroyItem(dPos, 0));
        })
                                       .ToList();

        foreach (Task regular in regularDestroyedBy)
        {
            await regular;
        }

        foreach (Task bonus in bonusDestroyedBy)
        {
            await bonus;
        }

        bombExp.GetParent().RemoveChild(bombExp);
        bombExp.QueueFree();
    }
Exemplo n.º 2
0
    public void AddAgent(Agent agent)
    {
        if (!_agents.ContainsKey(agent.GetUnitName()))
        {
            Node2D agentMarker = (Node2D)_agentMarker.Duplicate();
            agentMarker.Name = agent.GetUnitName() + "_marker";

            agentMarker.Modulate = Team.TeamColor[(int)agent.GetCurrentTeam()];

            AddChild(agentMarker);

            agentMarker.Show();

            // Add agent to dictonary
            _agents.Add(agent.GetUnitName(), agent);

            // Add marker to dictionary
            _agentMarkers.Add(agent.GetUnitName(), agentMarker);
        }
    }