예제 #1
0
 private void Start()
 {
     audio            = GetComponent <AudioSource>();
     gameManager      = Object.FindObjectOfType <GameManager>();
     congaLine        = Object.FindObjectOfType <CongaLineController>();
     animalSpawner    = Object.FindObjectOfType <AnimalSpawner>();
     alltimeVariables = Object.FindObjectOfType <AlltimeVariables>();
 }
예제 #2
0
 // Start is called before the first frame update
 void Start()
 {
     instance         = this;
     counter          = 0;
     alltimeVariables = Object.FindObjectOfType <AlltimeVariables>();
     animalMax        = alltimeVariables.spawnRate;
     if (alltimeVariables.boostChecker[4] == true)
     {
         animalMax *= 2;
     }
 }
    // called when patience reaches zero, ending the game
    public void GameOver()
    {
        if (isPlaying)
        {
            backgroundMusic.SetActive(false);
            forestAudioSnapshot.TransitionTo(1f);

            // TODO reset the game
            // i.e. reset flags, reset score, music, etc.

            score            = 0;
            lastSignalChange = 0;
            // reset patience level
            patienceRef.ResetPatience();
            roundNumber = 0;
            // delete human and create a new one
            SpawnHuman();
            // delete animals
            AnimalSpawner.ClearAllAnimals();
            signal.transform.position = signalStartPosition;

            isPlaying = false;
            startUI.SetActive(false);
            gameUI.SetActive(false);
            endUI.SetActive(true);
            // TODO some sort of transition


            //END
            float totalTime = Time.time - startTime;
            int   numLess   = 0;
            for (int i = 0; i < scores.Count; i++)
            {
                if (scores[i] < totalTime)
                {
                    numLess++;
                }
            }
            yourScore.text = "(" + Mathf.RoundToInt(totalTime) + " seconds)";
            if (scores.Count == 0)
            {
                relativeScore.text = "and he was the only candidate.";
            }
            else
            {
                relativeScore.text = "but he stayed on the phone longer than " + Mathf.RoundToInt(100 * numLess / scores.Count) + "% of candidates.";
            }

            //add score
            PlayerPrefs.SetFloat("Score" + scores.Count, totalTime);
            scores.Add(totalTime);
            PlayerPrefs.SetInt("Scores", scores.Count);
        }
    }
예제 #4
0
    private void Start()
    {
        if (GameObject.Find("AnimalSpawner") == null)
        {
            return;
        }
        animalSpawner = GameObject.Find("AnimalSpawner").GetComponent <AnimalSpawner>();

        foreach (GameObject hole in HoleList)
        {
            animalSpawner.HoleList.Add(hole);
        }
    }
    // called in GameManager's Update() function when the player presses space
    public void StartNextRound()
    {
        waitingToStartRound = false;

        AnimalSpawner.HideStack();
        roundPrompt.SetActive(false);
        nextAnimalPanel.Retract();
        humanInstance.GetComponent <Human>().DisableCameraFocus();

        // start next round
        AnimalSpawner.SpawnAnimal();
        roundNumber += 1;
    }
    // called by the actively controlled Animal when the player freezes it
    public void CurrentAnimalFrozen()
    {
        waitingToStartRound = true;

        // show the stack
        AnimalSpawner.ShowStack();
        roundPrompt.SetActive(true);
        nextAnimalPanel.PopOut();
        humanInstance.GetComponent <Human>().EnableCameraFocus();

        //Combined Freeze + Next round button press into one
        //StartNextRound();
    }
    private void Update()
    {
        // debug controls
        if (Input.GetKeyDown(KeyCode.F1))
        {
            debugControlsUI.SetActive(!debugControlsUI.activeSelf);
        }
        if (Input.GetKeyDown(KeyCode.F8))
        {
            GameOver();
        }
        if (Input.GetKeyDown(KeyCode.F12))
        {
            ResetHighScores();
        }

        // next round control
        if (Input.GetKeyDown(KeyCode.Return))
        {
            if (waitingToStartRound)
            {
                StartNextRound();
            }
            else if (introRoutine != null)
            {
                StopCoroutine(introRoutine);
                humanInstance.GetComponentInChildren <Phone>().SubtractSignal(true);
                humanInstance.GetComponentInChildren <Phone>().SubtractSignal(true);
                humanInstance.GetComponentInChildren <Phone>().SubtractSignal(true);
                humanInstance.GetComponentInChildren <Phone>().rotateBar = true;
                humanInstance.GetComponentInChildren <Human>().cinematic = false;
                AnimalSpawner.SpawnAnimal();
                introRoutine = null;
                skipPrompt.SetActive(false);
                backgroundMusic.SetActive(true);
                humanInstance.GetComponentInChildren <Human>().ShowTooltip(true);
                StartCoroutine(TurnOffTooltip());
                startTime = Time.time;
            }
        }
        // if (waitingToStartRound && Input.GetKeyDown(KeyCode.Return))
        // {
        //     StartNextRound();
        // }

        if (score - lastSignalChange >= signalChangeFrequency)
        {
            lastSignalChange = score;
            ChangeSignalLocation();
        }
    }
예제 #8
0
        public virtual void SpawnOffspring()
        {
            for (int i = 0; i < UnityEngine.Random.Range(1, 4); i++)
            {
                Animal newAnimal = AnimalSpawner.GetNewInstance().GetComponent <Animal>();

                newAnimal.SetTraits(moveSpeed, senseRadius); //overwrite awake SetTraits
                adultMoveSpeed = moveSpeed;

                newAnimal.AnimalIsYoung();
                newAnimal.transform.position += Vector3.forward * UnityEngine.Random.Range(-1f, 1f) +
                                                Vector3.right * UnityEngine.Random.Range(-1f, 1f);
                newAnimal.transform.SetParent(transform.parent);
                newAnimal.gameObject.name = "Rabbit (born)";
            }
        }
예제 #9
0
    public void GenerateMap()
    {
        var startTime = DateTime.Now;
        var points    = GetPoints();

        var time    = DateTime.Now;
        var voronoi = new Delaunay.Voronoi(points, null, new Rect(0, 0, meshSize, meshSize));

        Debug.Log(string.Format("Voronoi Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        heightMapSettings.noiseSettings.seed = seed;
        var heightMap = HeightMapGenerator.GenerateHeightMap(meshSize, meshSize, heightMapSettings, Vector2.zero);

        Debug.Log(string.Format("Heightmap Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        var mapGraph = new MapGraph(voronoi, heightMap, snapDistance);

        Debug.Log(string.Format("Finished Generating Map Graph: {0:n0}ms with {1} nodes", DateTime.Now.Subtract(time).TotalMilliseconds, mapGraph.nodesByCenterPosition.Count));

        time = DateTime.Now;
        MapGenerator.GenerateMap(mapGraph);
        Debug.Log(string.Format("Map Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        OnMeshDataReceived(MapMeshGenerator.GenerateMesh(mapGraph, meshSize));
        Debug.Log(string.Format("Mesh Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        var texture = MapTextureGenerator.GenerateTexture(mapGraph, meshSize, textureSize, colours, drawNodeBoundries, drawDelaunayTriangles);

        Debug.Log(string.Format("Texture Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        UpdateTexture(texture);

        time = DateTime.Now;
        EnvironmentSpawner.Spawn(mapGraph, GameObject.Find("Environment").transform, environmentSettings, seed);
        Debug.Log(string.Format("Environment Spawned: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        AnimalSpawner.Spawn(mapGraph, GameObject.Find("Animals").transform, animalSettings, seed);
        Debug.Log(string.Format("Animals Spawned: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        Debug.Log(string.Format("Finished Generating World: {0:n0}ms with {1} nodes", DateTime.Now.Subtract(startTime).TotalMilliseconds, mapGraph.nodesByCenterPosition.Count));
    }
예제 #10
0
    private IEnumerator IntroSequence()
    {
        skipPrompt.SetActive(true);
        // TODO start dialogue
        yield return(new WaitForSeconds(1));

        humanInstance.GetComponentInChildren <Phone>().AddSignal(true);
        yield return(new WaitForSeconds(0.5f));

        humanInstance.GetComponentInChildren <Phone>().AddSignal(true);
        yield return(new WaitForSeconds(0.5f));

        humanInstance.GetComponentInChildren <Phone>().AddSignal(true);
        yield return(new WaitForSeconds(0.5f));

        humanInstance.GetComponent <Human>().ShowTextBubble("I see you're applying for a job...");
        yield return(new WaitForSeconds(5));

        humanInstance.GetComponent <Human>().ShowTextBubble("Hello? Are you there?");
        yield return(new WaitForSeconds(5));

        humanInstance.GetComponentInChildren <Phone>().SubtractSignal(true);
        yield return(new WaitForSeconds(1f));

        humanInstance.GetComponentInChildren <Phone>().SubtractSignal(true);
        yield return(new WaitForSeconds(1f));

        humanInstance.GetComponentInChildren <Phone>().SubtractSignal(true);
        yield return(new WaitForSeconds(1f));

        humanInstance.GetComponentInChildren <Phone>().rotateBar = true;
        humanInstance.GetComponentInChildren <Human>().cinematic = false;

        humanInstance.GetComponentInChildren <Human>().ShowTooltip(true);
        StartCoroutine(TurnOffTooltip());

        // load in initial animal
        AnimalSpawner.SpawnAnimal();
        backgroundMusic.SetActive(true);

        introRoutine = null;
        skipPrompt.SetActive(false);

        startTime = Time.time;
    }
예제 #11
0
    private void Awake()
    {
        Instance = this;

        if (PlayerPrefs.HasKey("Scores"))
        {
            int numScores = PlayerPrefs.GetInt("Scores");
            for (int i = 0; i < numScores; i++)
            {
                Debug.Log("Score " + i + ": " + PlayerPrefs.GetFloat("Score" + i));
                scores.Add(PlayerPrefs.GetFloat("Score" + i));
            }
        }
        else
        {
            PlayerPrefs.SetInt("Scores", 0);
        }

        // TODO intro sequence?

        startUI.SetActive(true);
        endUI.SetActive(false);
        gameUI.SetActive(false);
        freezePrompt.SetActive(false);
        grabPrompt.SetActive(false);
        movePrompt.SetActive(false);
        roundPrompt.SetActive(false);
        abilityPrompt.SetActive(false);
        skipPrompt.SetActive(false);
        unstickPrompt.SetActive(false);
#if UNITY_EDITOR
        debugControlsUI.SetActive(debugControlsStartShowing);
#else
        debugControlsUI.SetActive(false);
#endif

        AnimalSpawner = GetComponent <AnimalSpawner>();

        signalStartPosition = signal.transform.position;

        // create a human initially
        SpawnHuman();
    }
예제 #12
0
        public override void Spawn()
        {
            base.Spawn();
            FSM = GetComponent <FiniteStateMachine>();
            InitializeFSM();

            _energy = MaxEnergy;

            adultMoveSpeed = moveSpeed;

            AdultScale = Vector3.one;
            YoungScale = 0.5f * AdultScale;

            GroundYPos = 0.5f; // HARDCODED

            AnimalSpawner = GetComponent <AnimalFactory>();
            AnimalSpawner.SetInstance(gameObject);

            FoodIgnored = null;
        }
예제 #13
0
    // ----------------

    // called by UI to start the game
    public void StartPlay(bool cinematic)
    {
        if (!isPlaying)
        {
            if (cinematic)
            {
                // start the game with intro sequence
                introRoutine = StartCoroutine(IntroSequence());
            }
            else
            {
                humanInstance.GetComponentInChildren <Phone>().rotateBar = true;
                humanInstance.GetComponentInChildren <Human>().cinematic = false;
                AnimalSpawner.SpawnAnimal();
            }

            waitingToStartRound = false;
            isPlaying           = true;
            startUI.SetActive(false);
            gameUI.SetActive(true);
            endUI.SetActive(false);
            // TODO fade out UI instead of immediately hiding, animate in game UI
        }
    }
예제 #14
0
 // Start is called before the first frame update
 void Start()
 {
     audio         = GetComponent <AudioSource>();
     animalSpawner = Object.FindObjectOfType <AnimalSpawner>();
     congaLine     = Object.FindObjectOfType <CongaLineController>();
 }
예제 #15
0
 public static bool loadData(string name)
 {
     try{
         string[] players = null, machines = null, stumps = null, rocks = null, animals = null, crates = null, structures = null;
         string   time    = "";
         using (StreamReader sR = new StreamReader(path + "/" + name + ".txt")){
             WorldData.sType = decrypt(sR.ReadLine());
             players         = decrypt(sR.ReadLine()).Split('!');
             machines        = decrypt(sR.ReadLine()).Split('!');
             stumps          = decrypt(sR.ReadLine()).Split('!');
             rocks           = decrypt(sR.ReadLine()).Split('!');
             animals         = decrypt(sR.ReadLine()).Split('!');
             crates          = decrypt(sR.ReadLine()).Split('!');
             structures      = decrypt(sR.ReadLine()).Split('!');
             time            = decrypt(sR.ReadLine());
         }
         string[]   data;
         GameObject player  = GameObject.Find("Player");
         Player     playerS = player.GetComponent <Player>();
         foreach (string p in players)
         {
             if (p.Split('@')[0] == "player")
             {
                 data = p.Split('@')[1].Split('#');
                 player.transform.position = new Vector3((float)Convert.ToDouble(data[0]), (float)Convert.ToDouble(data[1]), (float)Convert.ToDouble(data[2]));
                 data              = p.Split('@');
                 playerS.health    = Convert.ToInt16(data[2]);
                 playerS.nutrition = Convert.ToInt16(data[3]);
                 data              = p.Split('@')[4].Split('#');
                 for (int i = 0; i < data.Length; i++)
                 {
                     playerS.inv[i] = new Vector2((float)Convert.ToDouble(data[i].Split('$')[0]), (float)Convert.ToDouble(data[i].Split('$')[1]));
                 }
                 data = p.Split('@')[5].Split('#');
                 for (int i = 0; i < data.Length; i++)
                 {
                     playerS.toolbar[i] = new Vector2((float)Convert.ToDouble(data[i].Split('$')[0]), (float)Convert.ToDouble(data[i].Split('$')[1]));
                 }
                 data = p.Split('@')[6].Split('#');
                 for (int i = 0; i < data.Length; i++)
                 {
                     playerS.armor[i] = new Vector2((float)Convert.ToDouble(data[i].Split('$')[0]), (float)Convert.ToDouble(data[i].Split('$')[1]));
                 }
                 data = p.Split('@')[7].Split('#');
                 playerS.spawnPoint = new Vector3((float)Convert.ToDouble(data[0]), (float)Convert.ToDouble(data[1]), (float)Convert.ToDouble(data[2]));
             }
         }
         foreach (string m in machines)
         {
             foreach (GameObject g in playerS.machines)
             {
                 if (g.name == m.Split('@')[0])
                 {
                     Vector3 pos, rot;
                     data = m.Split('@')[1].Split('#');
                     pos  = new Vector3((float)Convert.ToDouble(data[0]), (float)Convert.ToDouble(data[1]), (float)Convert.ToDouble(data[2]));
                     rot  = new Vector3(0f, (float)Convert.ToDouble(m.Split('@')[2]), 0f);
                     GameObject newM = Instantiate(g, pos, player.transform.rotation) as GameObject;
                     newM.name = newM.name.Split('(')[0];
                     newM.transform.eulerAngles = rot;
                     if (m.Split('@').Length == 4)
                     {
                         MonoBehaviour mScript = null;
                         if (g.name == "Iron Furnace" || g.name == "Stone Furnace")
                         {
                             mScript = newM.GetComponent <Furnace>();
                         }
                         else if (g.name == "Oven" || g.name == "Campfire")
                         {
                             mScript = newM.GetComponent <Oven>();
                         }
                         else if (g.name == "Chest")
                         {
                             mScript = newM.GetComponent <Chest>();
                         }
                         data = m.Split('@')[3].Split('#');
                         Vector2[] mInv = new Vector2[data.Length];
                         for (int i = 0; i < data.Length; i++)
                         {
                             mInv[i] = new Vector2((float)Convert.ToDouble(data[i].Split('$')[0]), (float)Convert.ToDouble(data[i].Split('$')[1]));
                         }
                         mScript.SendMessage("loadInv", mInv);
                     }
                 }
             }
         }
         foreach (string s in stumps)
         {
             if (s != "")
             {
                 foreach (GameObject t in GameObject.FindGameObjectsWithTag("tree"))
                 {
                     if (Vector3.Distance(t.transform.position, new Vector3((float)Convert.ToDouble(s.Split('@')[0]), (float)Convert.ToDouble(s.Split('@')[1]), (float)Convert.ToDouble(s.Split('@')[2]))) < 1f)
                     {
                         t.GetComponent <Tree>().loadStump();
                     }
                 }
             }
         }
         RockSpawner rockSpawner = GameObject.Find("RockSpawner").GetComponent <RockSpawner>();
         foreach (string r in rocks)
         {
             if (r != "")
             {
                 rockSpawner.loadRock(Convert.ToInt16(r.Split('@')[0]), Convert.ToInt16(r.Split('@')[1]));
             }
         }
         rockSpawner.loadComplete = true;
         AnimalSpawner animalSpawner = GameObject.Find("AnimalSpawner").GetComponent <AnimalSpawner>();
         foreach (string a in animals)
         {
             if (a != "")
             {
                 GameObject animal = null;
                 if (a.Split('@')[0] == "Ra")
                 {
                     animal = animalSpawner.rabbit;
                 }
                 else if (a.Split('@')[0] == "De")
                 {
                     animal = animalSpawner.deer;
                 }
                 else if (a.Split('@')[0] == "Bo")
                 {
                     animal = animalSpawner.boar;
                 }
                 else if (a.Split('@')[0] == "Be")
                 {
                     animal = animalSpawner.bear;
                 }
                 else if (a.Split('@')[0] == "Ch")
                 {
                     animal = animalSpawner.chicken;
                 }
                 Vector3 pos, rot;
                 data = a.Split('@')[1].Split('#');
                 pos  = new Vector3((float)Convert.ToDouble(data[0]), (float)Convert.ToDouble(data[1]), (float)Convert.ToDouble(data[2]));
                 rot  = new Vector3(0f, (float)Convert.ToDouble(a.Split('@')[2]), 0f);
                 GameObject newA = Instantiate(animal, pos, player.transform.rotation) as GameObject;
                 newA.transform.eulerAngles = rot;
                 newA.SendMessage("loadHealth", Convert.ToInt16(a.Split('@')[3]));
                 AnimalSpawner.animals++;
             }
         }
         animalSpawner.loadComplete = true;
         GameObject crate = GameObject.Find("Player").GetComponent <Player>().crateGO;
         foreach (string c in crates)
         {
             if (c != "")
             {
                 data = c.Split('@')[0].Split('#');
                 Vector3 pos = new Vector3((float)Convert.ToDouble(data[0]), (float)Convert.ToDouble(data[1]), (float)Convert.ToDouble(data[2]));
                 data = c.Split('@')[1].Split('#');
                 GameObject newC = Instantiate(crate, pos, new Quaternion(0, 0, 0, 0)) as GameObject;
                 newC.GetComponent <Crate>().spawn(new Vector2((float)Convert.ToDouble(data[0]), (float)Convert.ToDouble(data[1])));
             }
         }
         foreach (string s in structures)
         {
             if (s != "")
             {
                 data = s.Split('@')[1].Split('#');
                 Vector3    pos  = new Vector3((float)Convert.ToDouble(data[0]), (float)Convert.ToDouble(data[1]), (float)Convert.ToDouble(data[2]));
                 GameObject newS = Instantiate(playerS.structures[Convert.ToInt16(s.Split('@')[0])], pos, new Quaternion(0, 0, 0, 0)) as GameObject;
                 newS.transform.eulerAngles = new Vector3(0f, (float)Convert.ToDouble(s.Split('@')[2]), 0f);
                 data = s.Split('@');
                 newS.GetComponent <Structure>().load(Convert.ToInt16(data[0]), data[3], Convert.ToInt16(data[4]));
                 if (Convert.ToInt16(data[0]) % 8 == 7)
                 {
                     newS.GetComponent <Door>().creator = data[3];
                 }
                 else if (Convert.ToInt16(data[0]) % 8 == 5 && data[5] == "1")
                 {
                     foreach (Transform t in newS.GetComponentsInChildren <Transform>())
                     {
                         t.localPosition = new Vector3(t.localPosition.x, t.localPosition.y, 0f);
                     }
                     newS.transform.position = pos;
                 }
             }
         }
         Clock clock = GameObject.Find("Clock").GetComponent <Clock>();
         clock.hour   = Convert.ToInt16(time.Split('!')[0]);
         clock.second = (float)Convert.ToInt16(time.Split('!')[1]);
         return(true);
     }catch { return(false); }
 }