예제 #1
0
    // public void _on_Node2D_body_entered(Node area)
    // {
    //     //if(area.GetType() != typeof(Area2D))
    //     //{
    //     //Get
    //     GD.Print("Hello");
    //     this.Split();
    //     GetCollidingBodies();
    //     //}
    // }

    public DescructibleTerrain[] Split()
    {
        if (size <= this.MIN_SIZE)
        {
            this.QueueFree();
            return(null);
        }

        this.size /= 2;

        DescructibleTerrain[] newNodes = new DescructibleTerrain[4];

        int iNewNode = 0;

        for (int i = -1; i <= 1; i += 2)
        {
            for (int j = -1; j <= 1; j += 2)
            {
                var newNode = this.MakeNewNode();
                newNode.size = this.size;
                float position = this.size / 2.0f;

                Vector2 relativePosition = new Vector2(position * i, position * j);
                newNode.SetPosition(GetPosition() + relativePosition);
                newNodes[iNewNode] = newNode;
                iNewNode++;
            }
        }

        this.QueueFree();

        return(newNodes);
    }
예제 #2
0
    /// <summary>
    /// Check collision and split terrain if necessary
    /// </summary>
    /// <param name="body"></param>
    public void CollidTerrain(PhysicsBody2D body)
    {
        DescructibleTerrain terrain = body as DescructibleTerrain;

        if (terrain != null)
        {
            terrain.Split();
        }
    }
예제 #3
0
    public DescructibleTerrain MakeNewNode()
    {
        DescructibleTerrain newNode = Duplicate() as DescructibleTerrain;

        //GetParent().CallDeferred("add_child", newNode);
        GetParent().AddChild(newNode);
        newNode.SetScale(GetScale() / 2.0f);

        return(newNode);
    }