Exemplo n.º 1
0
    public static void SetSpawnLocation(string start, string end)
    {
        int startScene = SpawnLocations.ParseString(start).GetHashCode();
        int endScene   = SpawnLocations.ParseString(end).GetHashCode();

        playerTransform.position = SpawnLocations.ReturnSpawnVector(startScene, endScene);
    }
 void Start()
 {
     if (SpawnLocationsObj == null)
     {
         SpawnLocationsObj = FindObjectOfType <SpawnLocations>();
     }
 }
Exemplo n.º 3
0
    /// <summary>
    /// NOTE: This will modify the internal spawn list for the GameWallHolder this
    /// is associated with
    /// </summary>
    /// <returns></returns>
    public SpawnLocations GetValidSpawnLocations()
    {
        wallHolder.GetWalls();
        SpawnLocations spawnLocations = new SpawnLocations();
        float          xCheck         = minPosition.x;
        float          yCheck         = maxPosition.y;
        Collider2D     pointCollider  = point.Collider;

        while (yCheck >= minPosition.y)
        {
            Vector3 newPos = new Vector3(xCheck, yCheck, 0);
            point.transform.position = newPos;

            if (!PointTooCloseToWall(newPos))
            {
                spawnLocations.Add(new SpawnLocation(newPos));
            }

            xCheck += increments;
            if (xCheck > maxPosition.x)
            {
                xCheck  = minPosition.x;
                yCheck -= increments;
            }
        }

        return(spawnLocations);
    }
Exemplo n.º 4
0
    private void AddSpawnPoint(Vector3 location)
    {
        SpawnLocations SpawnLocations = target as SpawnLocations;

        Vector3 pos = location;

        pos.y += SpawnLocations.Offset / 2;

        SpawnLocations.Locations.Add(pos);
    }
Exemplo n.º 5
0
    public void RunTest()
    {
        SpawnLocations spawnLocations = GetValidSpawnLocations();

        Debug.Log("Valid Locations: " + spawnLocations.Count);
        if (spawnLocations.Count != 0)
        {
            SaveXml(spawnLocations);
        }
    }
Exemplo n.º 6
0
    void ParsePoints()
    {
        pointsReceived = true;

        XmlSerializer serializer = new XmlSerializer(typeof(SpawnLocations));

        using (StringReader reader = new StringReader(pointXml.text))
        {
            locations = (SpawnLocations)serializer.Deserialize(reader);
        }
    }
Exemplo n.º 7
0
 public LevelInfo(GameWallHolder holder)
 {
     Name        = holder.LevelName;
     PointSpawns = holder.Locations;
     GameWalls   = new Walls(holder.Walls.Length);
     for (int i = 0; i < holder.Walls.Length; i++)
     {
         GameWalls.Add(new Wall(holder.Walls[i]));
     }
     PlayerSpawn = holder.PlayerSpawn;
 }
Exemplo n.º 8
0
    Vector3 GetRandomLocation()
    {
        // float x = UnityEngine.Random.Range(minSpawnLocation.x, maxSpawnLocation.x);
        // float y = UnityEngine.Random.Range(minSpawnLocation.y, maxSpawnLocation.y);

        // return new Vector2(x, y);

        SpawnLocations locations = LevelParser.Parser.LevelDictionary[LevelParser.Parser.ChosenLevel].PointSpawns;

        return(locations[UnityEngine.Random.Range(0, locations.Count)]);
    }
Exemplo n.º 9
0
    public void CreateLevel()
    {
        SpawnLocations spawnLocations = GetValidSpawnLocations();

        wallHolder.Locations   = spawnLocations;
        wallHolder.PlayerSpawn = GetPlayerSpawnLocation();

        LevelInfo info = new LevelInfo(wallHolder);

        SaveXml(info);
    }
Exemplo n.º 10
0
    private void OnSceneGUI()
    {
        // Handle stuff
        SpawnLocations SpawnLocations  = target as SpawnLocations;
        Transform      handleTransform = SpawnLocations.transform;
        Quaternion     handleRotation  = handleTransform.rotation;

        Handles.color = Color.white;

        for (int i = 0; i < SpawnLocations.Locations.Count; i++)
        {
            Vector3 p = SpawnLocations.Locations[i];//handleTransform.TransformPoint(SpawnLocations.Locations[i]);

            EditorGUI.BeginChangeCheck();
            p = Handles.DoPositionHandle(p, handleRotation);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(SpawnLocations, "Move Point");
                EditorUtility.SetDirty(SpawnLocations);
                SpawnLocations.Locations[i] = handleTransform.InverseTransformPoint(p);
            }
        }

        // Spawn objects
        if (m_EditMode)
        {
            Event e = Event.current;

            // We use hotControl to lock focus onto the editor (to prevent deselection)
            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            switch (Event.current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                GUIUtility.hotControl = controlID;

                Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                {
                    AddSpawnPoint(hit.point);
                }

                Event.current.Use();
                break;

            case EventType.MouseUp:
                GUIUtility.hotControl = 0;
                Event.current.Use();
                break;
            }
        }
    }
Exemplo n.º 11
0
    // Use this for initialization
    void Start()
    {
        leadermovement = leader.GetComponent <LeadVehicleMovement>();
        spawns         = spawnArea.GetComponent <SpawnLocations>();

        for (int i = 0; i < numberToSpawnAtStart; i++)
        {
            Vector3    pos     = spawns.getSpawnLocation();
            Quaternion rot     = transform.rotation;        //new Quaternion(0f,0f,0f,0f);
            GameObject tempobj = Instantiate(Resources.Load("prefabs/pickup"), pos, rot) as GameObject;
        }
    }
Exemplo n.º 12
0
    void SaveXml(SpawnLocations locations)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(SpawnLocations));

        string filename = GetFileName();

        using (TextWriter tw = new StreamWriter(filename))
        {
            serializer.Serialize(tw, locations);
            Debug.LogWarning("Spawns Saved to file: \"" + filename + "\"");
        }
    }
Exemplo n.º 13
0
 public void CreateLevel(LevelInfo level)
 {
     foreach (Wall wall in level.GameWalls)
     {
         GameWall childWall = Instantiate(wallPrefab, transform);
         childWall.SetParameters(wall);
     }
     levelName = level.Name;
     locations = new SpawnLocations(level.PointSpawns.Count);
     foreach (SpawnLocation location in level.PointSpawns)
     {
         locations.Add(location);
     }
     GetWalls();
 }
Exemplo n.º 14
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Player"))
     {
         convoylist1.increaseLength();
         //spawn another pickup
         SpawnLocations spawns  = GameObject.FindObjectOfType(typeof(SpawnLocations)) as SpawnLocations;
         Vector3        pos     = spawns.getSpawnLocation();
         Quaternion     rot     = transform.rotation;    //new Quaternion(0f,0f,0f,0f);
         GameObject     tempobj = Instantiate(Resources.Load("prefabs/pickup"), pos, rot) as GameObject;
         so.GetComponent <AudioSource>().Play();
         ScoreInfo.Score += 1;
         Destroy(this.gameObject);
     }
 }
Exemplo n.º 15
0
    public LevelInfo CreateLevel(string path, string levelName)
    {
        SpawnLocations spawnLocations = GetValidSpawnLocations();

        wallHolder.Locations   = spawnLocations;
        wallHolder.PlayerSpawn = GetPlayerSpawnLocation();

        LevelInfo info = new LevelInfo(wallHolder);

        info.Name = levelName;

        SaveXml(info, path);

        return(info);
    }
Exemplo n.º 16
0
        private SpawnLocation FindLocation()
        {
            var locations = SpawnLocations.Where(s => !s.InUse).ToArray();

            if (locations.Length == 0)
            {
                return(new SpawnLocation
                {
                    Position = Transform.Position,
                    Rotation = Transform.Rotation
                });
            }

            var location = locations[_random.Next(locations.Length)];

            return(location);
        }
Exemplo n.º 17
0
    public override void OnInspectorGUI()
    {
        SpawnLocations SpawnLocations = target as SpawnLocations;

        m_EditMode = GUILayout.Toggle(m_EditMode, "Edit Mode");

        if (GUILayout.Button("Remove Location") && SpawnLocations.Locations.Count > 0)
        {
            SpawnLocations.Locations.RemoveAt(SpawnLocations.Locations.Count - 1);
        }

        if (GUILayout.Button("Reset All"))
        {
            SpawnLocations.Locations = new List <Vector3>();
        }

        DrawDefaultInspector();
    }
Exemplo n.º 18
0
    public static void CreateNewSave()
    {
        Debug.Log("Creating New Save in Slot: " + currentSaveSlot);
        BinaryFormatter data = new BinaryFormatter();

        if (!Directory.Exists(Application.persistentDataPath + folderPath + currentSaveSlot + saveSlotStrings[currentSaveSlot - 1]))
        {
            Directory.CreateDirectory(Application.persistentDataPath + folderPath + currentSaveSlot);
        }

        FileStream file = File.Create(Application.persistentDataPath + folderPath + currentSaveSlot + saveSlotStrings[currentSaveSlot - 1]);

        SaveableData saveData = new SaveableData();

        //-----------------------Setting Save Data---------------------------------------------
        saveData.ownedTools = new List <Tool>()
        {
            new Tool(ToolName.EMPTY_HANDS),
            new Tool(ToolName.FELLING_AXE),
            new Tool(ToolName.CROSSCUT_SAW),
            new Tool(ToolName.SPLITTING_AXE)
        };

        saveData.efficiencySkill        = new EfficiencySkill();
        saveData.contractsSkill         = new ActiveContractsSkill();
        saveData.currencySkill          = new CurrencySkill();
        saveData.energySkill            = new EnergySkill();
        saveData.buildingMaterialsSkill = new BuildingMaterialsSkill();
        saveData.toolPartsSkill         = new ToolPartsSkill();
        saveData.bookPagesSkill         = new BookPagesSkill();
        saveData.lumberTreesSkill       = new LumberTreesSkill();
        saveData.lumberLogsSkill        = new LumberLogsSkill();
        saveData.lumberFirewoodSkill    = new LumberFirewoodSkill();

        saveData.bedRoom      = new BedRoom();
        saveData.kitchenRoom  = new KitchenRoom();
        saveData.officeRoom   = new OfficeRoom();
        saveData.studyRoom    = new StudyRoom();
        saveData.workshopRoom = new WorkshopRoom();

        saveData.coffeeMakerAddition      = new CoffeeMakerAddition();
        saveData.fireplaceAddition        = new FireplaceAddition();
        saveData.frontPorchAddition       = new FrontPorchAddition();
        saveData.woodworkingBenchAddition = new WoodworkingBenchAddition();

        saveData.activeContracts            = new List <LumberContract>();
        saveData.availableContracts         = new List <LumberContract>();
        saveData.availableContractsToRemove = new List <int>();

        saveData.didDailyGeneration                = false;
        saveData.averageContractDifficulty         = 2.5f;
        saveData.pastGeneratedContractDifficulties = new List <int>()
        {
            2, 3
        };

        saveData.currentEnergy         = PlayerSkills.GetMaxEnergyValue();
        saveData.currentlyEquippedTool = new Tool(ToolName.EMPTY_HANDS);
        ToolManager.EquipTool(0);

        saveData.currentCurrency          = 0;
        saveData.currentBuildingMaterials = 0;
        saveData.currentToolParts         = 0;
        saveData.currentBookPages         = 0;

        saveData.homesteadTreesCount = new int[5] {
            0, 0, 0, 0, 0
        };
        saveData.homesteadLogsCount = new int[5] {
            0, 0, 0, 0, 0
        };
        saveData.homesteadFirewoodCount = new int[5] {
            0, 0, 0, 0, 0
        };

        saveData.currentTime = 480f;

        saveData.lastSceneName = "MainCabin";
        Vector3 spawnHolder = SpawnLocations.GetSpawnForLoad("MainMenu");

        saveData.lastSceneSpawnLocation = new float[3] {
            spawnHolder.x, spawnHolder.y, spawnHolder.z
        };
        //-----------------------Done Setting Data---------------------------------------------
        data.Serialize(file, saveData);
        file.Close();
        Debug.Log("Finished Saving");
    }
 private Vector2 GetSpawnLoc(Arrangement arrangement)
 {
     return(SpawnLocations.GetSpawnLocation(arrangement, spawnMagnitude));
 }
Exemplo n.º 20
0
    public static void Save()
    {
        Debug.Log("Save Slot: " + currentSaveSlot);
        BinaryFormatter data = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + folderPath + currentSaveSlot + saveSlotStrings[currentSaveSlot - 1]);

        SaveableData saveData = new SaveableData();

        //-----------------------Setting Save Data---------------------------------------------
        saveData.activeContracts            = PlayerContracts.GetActiveContractsList();
        saveData.availableContracts         = AvailableContracts.GetAvailableContracts();
        saveData.availableContractsToRemove = AvailableContracts.GetContractsToRemove();

        saveData.didDailyGeneration                = TimeManager.GetDidDailyGeneration();
        saveData.averageContractDifficulty         = AvailableContracts.GetAverageContractDifficulty();
        saveData.pastGeneratedContractDifficulties = AvailableContracts.GetPastGeneratedContractDifficuties();

        saveData.currentEnergy = PlayerEnergy.GetCurrentEnergyValue();

        saveData.currentCurrency          = PlayerResources.GetCurrentCurrencyValue();
        saveData.currentBuildingMaterials = PlayerResources.GetCurrentBuildingMaterialsValue();
        saveData.currentToolParts         = PlayerResources.GetCurrentToolPartsValue();
        saveData.currentBookPages         = PlayerResources.GetCurrentBookPagesValue();

        saveData.homesteadTreesCount    = HomesteadStockpile.GetAllTreesCount();
        saveData.homesteadLogsCount     = HomesteadStockpile.GetAllLogsCount();
        saveData.homesteadFirewoodCount = HomesteadStockpile.GetAllFirewoodCount();

        saveData.ownedTools            = PlayerTools.GetOwnedToolsList();
        saveData.currentlyEquippedTool = PlayerTools.GetCurrentlyEquippedTool();

        saveData.efficiencySkill        = PlayerSkills.GetEfficiencySkill();
        saveData.contractsSkill         = PlayerSkills.GetContractsSkill();
        saveData.currencySkill          = PlayerSkills.GetCurrencySkill();
        saveData.energySkill            = PlayerSkills.GetEnergySkill();
        saveData.buildingMaterialsSkill = PlayerSkills.GetBuildingMaterialsSkill();
        saveData.toolPartsSkill         = PlayerSkills.GetToolPartsSkill();
        saveData.bookPagesSkill         = PlayerSkills.GetBookPagesSkill();
        saveData.lumberTreesSkill       = PlayerSkills.GetLumberTreesSkill();
        saveData.lumberLogsSkill        = PlayerSkills.GetLumberLogsSkill();
        saveData.lumberFirewoodSkill    = PlayerSkills.GetLumberFirewoodSkill();

        saveData.bedRoom      = PlayerRooms.GetBedRoom();
        saveData.kitchenRoom  = PlayerRooms.GetKitchenRoom();
        saveData.officeRoom   = PlayerRooms.GetOfficeRoom();
        saveData.studyRoom    = PlayerRooms.GetStudyRoom();
        saveData.workshopRoom = PlayerRooms.GetWorkshopRoom();

        saveData.coffeeMakerAddition      = PlayerAdditions.GetCoffeeMakerAddition();
        saveData.fireplaceAddition        = PlayerAdditions.GetFireplaceAddition();
        saveData.frontPorchAddition       = PlayerAdditions.GetFrontPorchAddition();
        saveData.woodworkingBenchAddition = PlayerAdditions.GetWoodworkingBenchAddition();

        saveData.currentTime = TimeManager.GetCurrentTime();

        saveData.lastSceneName = SceneManager.GetActiveScene().name;
        Vector3 spawnHolder = SpawnLocations.GetSpawnForLoad(SceneManager.GetActiveScene().name);

        saveData.lastSceneSpawnLocation = new float[3] {
            spawnHolder.x, spawnHolder.y, spawnHolder.z
        };
        //-----------------------Done Setting Data---------------------------------------------
        data.Serialize(file, saveData);
        file.Close();
        Debug.Log("Saved here: " + Application.persistentDataPath);
    }
Exemplo n.º 21
0
    private void Start()
    {
        m_SpawnLocations = GetComponentInChildren <SpawnLocations>();

        InitalizeGame();
    }
Exemplo n.º 22
0
 public static void SetSpawnLocation(int start, int destination)
 {
     playerTransform.position = SpawnLocations.ReturnSpawnVector(start, destination);
 }