Exemple #1
0
        public void Load()
        {
            LevelToSave = GeneralManager.Singleton.CurrentLevel;

            Connections = new RawConnection[LevelToSave.ConnectionsCount];
            Vertex = new RawVertex[LevelToSave.VertexCount];

            int iV = 0;
            int iC = 0;
            foreach (GameComponent c in LevelToSave.Components)
            {
                if (c is Connection)
                {
                    Connections[iC] = GetRawFromConnection(c as Connection);
                    iC++;
                }
                else if (c is Vertex)
                {
                    Vertex[iV] = GetRawFromVertex(c as Vertex);
                    iV++;
                }

            }
        }
        public static Level GenerateLevel(Game Game)
        {
            GeneratingLevel = new Level(Renderer.Singleton.Game);

            int VertexNumber = 50 - GeneralManager.Singleton.GetRandom() % 20;
            List<int> AbleToConnect = new List<int>();

            List<VertexScreen> Ver = new List<VertexScreen>();

            for (int i = 0; i < VertexNumber; i++)
            {
                // Vertex generation

                VertexScreen v = CreateVertex(Renderer.Singleton.Game, new Vector2(GeneralManager.Singleton.GetRandom() % 500 + 10.0f, GeneralManager.Singleton.GetRandom() % 500 + 10.0f), Renderer.Singleton.Content.Load<Texture2D>("indicator"));

                //========================

                if (i == 0)
                {
                    GeneralManager.Players["test"].Ship.Position = new Vector2(2000, 2000);
                    GeneralManager.Players["test"].Ship.State = Ship.ShipState.InVertex;
                    GeneralManager.Singleton.CurrentPlayer = GeneralManager.Players["test"];
                    v.Ships.Add(GeneralManager.Players["test"].Ship);
                    GeneralManager.Singleton.CurrentPlayer.Ship.CurrentVertex = v;
                }
                bool IsGood = true;

                AbleToConnect.Clear();
                for (int j = 0; j < i; j++)
                {
                    float Lenght = v.Vertex.GetLenghtFrom(Ver[j].Vertex);
                    if (Lenght < 60)
                    {
                        IsGood = false;
                    }

                    if (Lenght < 120)
                    {
                        if (AbleToConnect.Count < 4)
                        {
                            AbleToConnect.Add(j);
                        }
                    }
                }

                if (AbleToConnect.Count == 0 && i != 0)
                {
                    IsGood = false;
                }

                if (IsGood)
                {
                    GeneratingLevel.VertexCount++;
                    Ver.Add(v);
                    GeneratingLevel.Components.Add(v.Vertex);
                }
                else
                {
                    i--;
                    continue;
                }

                foreach (int Able in AbleToConnect)
                {
                    AddConnection(i, Able, v.Vertex.Position, Ver[Able].Vertex.Position);
                    v.Vertex.Connections.Add(Ver[Able].Vertex);
                    Ver[Able].Vertex.Connections.Add(v.Vertex);
                }
            }

            foreach (VertexScreen v in Ver)
            {
                GeneratingLevel.Components.Add(v);
            }

            CreateUserInventory(Game);
            GenerateNPC(Game);

            //GeneralManager.Singleton.IsLevelInitalized = true;
            //GeneralManager.Singleton.CurrentLevel = GeneratingLevel;
            return GeneratingLevel;
        }