Beispiel #1
0
        /// <summary>
        /// reads in data from a json file. will have to update it so components are stored in an array on the JSON file to save the
        /// if statement
        /// </summary>
        private void CreateEntities()
        {
            Entity newEntity;

            using (StreamReader r = new StreamReader("Managers/SceneData.json"))
            {
                string json = r.ReadToEnd();
                List <SceneManager> gameData = JsonConvert.DeserializeObject <List <SceneManager> >(json);

                for (int i = 0; i < gameData.Count; i++)
                {
                    string  name = gameData[i].Name;
                    string  mat  = gameData[i].Mat;
                    Vector3 pos  = gameData[i].ConvertToVector(gameData[i].Location);
                    Vector3 rot  = gameData[i].ConvertToVector(gameData[i].Rotation);

                    newEntity = new Entity(name);
                    if (name.Contains("SmallSphere"))
                    {
                        newEntity.AddComponent(new ComponentTransform(pos, new Vector3(1, 1, 1), rot, .3f));
                    }
                    else if (name.Contains("BigSphere"))
                    {
                        newEntity.AddComponent(new ComponentTransform(pos, new Vector3(1, 1, 1), rot, .5f));
                    }
                    else if (name.Contains("DoomSphere"))
                    {
                        newEntity.AddComponent(new ComponentTransform(pos, new Vector3(1, 1, 1), rot, .8f));
                    }
                    else
                    {
                        newEntity.AddComponent(new ComponentTransform(pos, new Vector3(1, 1, 1), rot, 1));
                    }
                    newEntity.AddComponent(new ComponentModel(modelManager.FindModel(name)));
                    newEntity.AddComponent(new ComponentMaterial(matManager.FindMaterial(mat)));

                    if (name.Contains("Cylinder"))
                    {
                        newEntity.AddComponent(new ComponentCollsion());
                    }
                    else if (name.Contains("Doom"))
                    {
                        newEntity.AddComponent(new ComponentDoomSphere());
                    }
                    else if (name.Contains("Sphere"))
                    {
                        if (!name.StartsWith("Doom"))
                        {
                            if (name.Contains("SmallSphere"))
                            {
                                newEntity.AddComponent(new ComponentPhysics(new Vector3(1, -1, 0), 4.8f, .3f));
                            }
                            else if (name.Contains("BigSphere"))
                            {
                                newEntity.AddComponent(new ComponentPhysics(new Vector3(1, -1, 0), 7.8f, .5f));
                            }
                            newEntity.AddComponent(new ComponentPhysicsCollision());
                            newEntity.AddComponent(new ComponentWorldCollsion());
                            newEntity.AddComponent(new ComponentCylinderCollsion());
                            newEntity.AddComponent(new ComponentDoomCollsion());
                        }
                    }
                    if (name.Contains("Tower"))
                    {
                        newEntity.AddComponent(new ComponentBoxCollison());
                    }

                    entityManager.AddEntity(newEntity);
                }
            }
        }