コード例 #1
0
    /// <summary>
    /// Detect collisions when rocket explode and apply damage to characters near the explosion
    /// </summary>
    /// <param name="body">Object which detect collision</param>
    private void OnBodyEnter(object body)
    {
        if (!collisionObject.Disabled)
        {
            // Look for characters and remove some health
            foreach (Node node in areaExplosion.GetOverlappingBodies())
            {
                if (node is Character)
                {
                    Character character = node as Character;
                    character.Health -= DAMAGE;
                }
            }

            // Launch the explosion animation
            ExplosionEffect explosionEffect = GameResources.GetInstance().Get <ExplosionEffect>();
            explosionEffect.SetGlobalPosition(this.GlobalPosition);
            explosionEffect.SetScale(Vector2.One * EXPLOSION_SIZE);
            explosionEffect.Damage = DAMAGE;
            this.GetTree().GetRoot().GetNode("Main").CallDeferred("add_child", explosionEffect);
            //this.GetTree().GetRoot().GetNode("Main").AddChild(explosionEffect);

            this.QueueFree();
        }
    }
コード例 #2
0
    /// <summary>
    /// Explode the grenade when the timer is over
    /// </summary>
    /// <param name="source">Source of the event</param>
    /// <param name="e">Additional information about the event</param>
    private void OnTimeOver(System.Object source, ElapsedEventArgs e)
    {
        timer.Stop();
        timer.Dispose();

        // Look for characters which are hit
        foreach (Node node in areaExplosion.GetOverlappingBodies())
        {
            if (node is Character)
            {
                Character character = node as Character;
                character.Health -= DAMAGE;
            }
        }

        // Execute explosion animation
        ExplosionEffect explosionEffect = GameResources.GetInstance().Get <ExplosionEffect>();

        explosionEffect.SetGlobalPosition(this.GlobalPosition);
        explosionEffect.SetScale(Vector2.One * EXPLOSION_SIZE);
        explosionEffect.Damage = DAMAGE;
        this.GetTree().GetRoot().GetNode("Main").AddChild(explosionEffect);

        this.QueueFree();
    }