Beispiel #1
0
    // Add all explosion elements for the associated ship, and destroy the ship
    public void ExplodeShip(BaseShip Ship)
    {
        // Get ship pos
        Vector2 Pos = Ship.GetPosition();

        // Create destruction geometry / animation at the old ship position
        for(int j = 0; j < 32; j++)
        {
            float Radius = 45.0f;
            Vector2 Offset = new Vector2(UnityEngine.Random.Range(-Radius, Radius), UnityEngine.Random.Range(-Radius, Radius));
            Globals.WorldView.ProjManager.AddExplosion(Pos + Offset);
        }

        // Get the length of the ship
        float Facing = Ship.GetRotation();
        float Width = Ship.GetHullSprite().GetGeometrySize().x / 2.0f;
        float Height = Ship.GetHullSprite().GetGeometrySize().y / 2.0f;
        Vector2 ShipLength = new Vector2(Mathf.Cos(Facing), Mathf.Sin(Facing)) *  Width;
        Vector2 ShipSide = new Vector2(ShipLength.normalized.y, ShipLength.normalized.x);

        // For each chunk index
        int ChunkCount = Ship.GetChunkCount();
        for(int i = 0; i < ChunkCount * (Width / 20.0f); i++)
        {
            Vector2 Offset = ShipLength * UnityEngine.Random.Range(-1.0f, 1.0f) + ShipSide * UnityEngine.Random.Range(-Height, Height);
            float Rotation = UnityEngine.Random.Range(-Mathf.PI, Mathf.PI);
            Globals.WorldView.SceneManager.AddScenery(Ship.GetConfigFileName(), "Chunk" + (i % ChunkCount), new Vector3(Pos.x + Offset.x, Pos.y + Offset.y, 0), new Vector3(Offset.x / 100.0f, Offset.y / 100.0f, Rotation / 2.0f));
        }
    }