Esempio n. 1
0
    public FOBJ CheckCollision(Ray inp)
    {
        baseplane = new Plane(-Vector3.forward, Vector3.zero);
        float d;

        baseplane.Raycast(InputRay, out d);
        GameManager.InputPos = InputRay.GetPoint(d);
        Debug.DrawRay(InputRay.origin, InputRay.direction * 500);
        if (Physics.Raycast(InputRay, out InputRay_hit, Mathf.Infinity))
        {
            WorldPosition = InputRay_hit.point;
            if (Target != InputRay_hit.transform)
            {
                Target = InputRay_hit.transform;
                FOBJ fin = InputRay_hit.transform.GetComponent <FOBJ>();

                Transform p = Target;
                while (fin == null && p.parent != null)
                {
                    p   = p.parent;
                    fin = p.GetComponent <FOBJ>();
                }
                return(fin);
            }
            else
            {
                return(TObj);
            }
        }
        return(null);
    }
Esempio n. 2
0
    public void SetupTable(int n)
    {
        if (TableUI == TableObjects[n])
        {
            return;
        }

        for (int i = 0; i < TableObjects.Length; i++)
        {
            if (i != n)
            {
                TableObjects[i].SetActive(false);
            }
        }
        TableUI = TableObjects[n];

        TableObj = TableUI.Child[0].transform.gameObject;
        //TableObj.transform.SetParent(GameManager.Module.transform);
        Seat = new _Seat[TableUI.Child.Length - 1];
        List <Vector2> splinepoints = new List <Vector2>();

        for (int i = 0; i < Seat.Length; i++)
        {
            Seat[i]        = new _Seat();
            Seat[i].Index  = i;
            Seat[i].Object = TableUI.Child[i + 1].transform.gameObject;
            Vector3 p = TableUI.Child[i + 1].transform.position + TableUI.Child[i + 1].transform.forward * 1.7F;
            splinepoints.Add(new Vector2(p.x, p.y));
        }
        VectorLine.Destroy(ref Movement);

        Movement = new VectorLine("Movement Path", new List <Vector2>(mvmt_segments + 1), 4.0F, LineType.Continuous);
        Movement.MakeSpline(splinepoints.ToArray(), mvmt_segments, 0, true);
        //Movement.Draw();
    }
Esempio n. 3
0
    public void CreateDinner(int d = 0)
    {
        Running = false;

        FOBJ fparent = MOB["faceparent"];

        Difficulty = d;
        Grands     = new GreatGrand[GGNum];

        _TableManager.SetupTable(Difficulty);
        Faces = new Face[GGNum];

        List <GrandData> hungry = GameManager.Data.SortResidentsBy(AlertType.Hunger);

        Guests = new List <GreatGrand>();
        for (int i = 0; i < GGNum; i++)
        {
            if (i < hungry.Count && hungry[i].Hunger.Current < 95)
            {
                Grands[i] = hungry[i].GrandObj;
            }
            else
            {
                GreatGrand g = GameManager.Generator.GenerateGuest();
                Guests.Add(g);
                g.transform.SetParent(GameManager.Data.GuestParent.transform);
                Grands[i] = g;
            }

            Faces[i] = GameManager.Generator.GenerateNewFace(Grands[i].Data);
            fparent.AddChild(Faces[i]);

            Grands[i].Data.TargetFace = (Faces[i]);
            SetupFace(Faces[i], Grands[i]);
        }

        for (int i = 0; i < GGNum; i++)
        {
            SitImmediate(Grands[i], _TableManager.Seat[i]);
        }

        for (int i = 0; i < GGNum; i++)
        {
            int gnum = 1 + Random.Range(0, Difficulty);
            //if(Random.value > 0.8F) gnum ++;
            GenerateGrumpsReal(Grands[i], gnum);
        }

        GG_Indexes = new int[0];
        while (NumberHappy > GGNum / 2)
        {
            GG_Indexes = ShuffleGG();
        }

        for (int i = 0; i < GGNum; i++)
        {
            Faces[i].SetActive(false);
        }
    }
Esempio n. 4
0
 public void SendCorrectAlert(FOBJ u, Transform t)
 {
     u.transform.DOScale(Vector3.one * 0.4F, 0.18F);
     u.transform.DOMove(t.position, 0.25F).OnComplete(() => {
         FinalScore++;
         u.PoolDestroy();
     });
 }
Esempio n. 5
0
    public override void InitUI()
    {
        Pathway      = MOB["pathway"];
        Pathway_init = Pathway.transform.position;

        EndButton = MUI["reset"];
        EndButton.ClearActions();
        EndButton.AddAction(UIAction.MouseUp, () =>
        {
            Clear();
            StartCoroutine(Reload());
        });

        EndInfo    = MUI["endcond"];
        FitnessObj = MUI["fitobj"];
    }
Esempio n. 6
0
    public void CheckInput()
    {
        if (Input.GetMouseButtonUp(0))
        {
            HasInput = false;
            GameManager.OnRelease();
            if (TObj != null)
            {
                TObj.OnUp();
            }
            TObj   = null;
            Target = null;
        }

        if (Input.GetMouseButton(0))
        {
            HasInput = true;
            InputRay = Camera.main.ScreenPointToRay(Position);
            TObj     = CheckCollision(InputRay);
            if (TObj != null)
            {
                TObj.OnStay();
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            HasInput = true;
            InputRay = Camera.main.ScreenPointToRay(Position);
            TObj     = CheckCollision(InputRay);
            if (TObj != null)
            {
                TObj.OnDown();
            }
            GameManager.OnTouch();
        }
    }
Esempio n. 7
0
    IEnumerator EndGame()
    {
        while (!AllSeated)
        {
            yield return(null);
        }

        UIObj endgame = MUI["endgame"];

        Running = false;
        GameManager.IgnoreInput = true;
        timerobj.Txt[0].text    = "";
        timerobj.Txt[1].text    = "";

        if (!GameManager.WorldRes.Funds.Charge(DinnerCost))
        {
            endgame[0].TweenActive(true);
            endgame[1].SetActive(false);
            endgame[2].SetActive(false);

            endgame[0].Txt[0].text = "No Funds!";

            FinalScore = 0;

            yield return(new WaitForSeconds(0.8F));

            endgame[0].TweenActive(false);

            yield return(StartCoroutine(FinishDinner()));

            yield break;
        }

        endgame[0].TweenActive(true);
        endgame[1].SetActive(false);
        endgame[2].SetActive(false);

        endgame[0].Txt[0].text = "Let's Eat!";

        FinalScore = 0;

        yield return(new WaitForSeconds(0.85F));

        endgame[0].TweenActive(false);

        List <FOBJ> correct = new List <FOBJ>();
        List <FOBJ> wrong   = new List <FOBJ>();

        for (int i = 0; i < _TableManager.Seat.Length; i++)
        {
            GreatGrand grand = _TableManager.Seat[i].Target;

            if (grand == null)
            {
                continue;
            }

            int targ_grumps = grand.GetGrumps(false);
            yield return(new WaitForSeconds(Time.deltaTime * 5));

            Sprite s = targ_grumps >= 0 ? Alert_Right :  Alert_Wrong;

            FOBJ a = Instantiate(GameManager.UI.Prefabs.GetObject("FOBJ_Default") as GameObject).GetComponent <FOBJ>();
            (a as FIRL).IMG[0].sprite = s;
            a.SetActive(false);
            a.transform.position   = grand.TargetFace.pos - Vector3.forward * 1;
            a.transform.localScale = Vector3.one * 1.8F;
            a.TweenActive(true);

            if (targ_grumps >= 0)
            {
                correct.Add(a);
            }
            else
            {
                wrong.Add(a);
            }

            yield return(new WaitForSeconds(0.12F));
        }

        UIObj info = MUI["kitchen"];

        info.Txt[1].text = "HAPPY\nGRANDS";
        info.Txt[0].text = FinalScore + "";

        Tweens.Bounce(info.transform);
        info.TweenActive(true);
        yield return(new WaitForSeconds(0.5F));

        bool isCounting = true;

        for (int i = 0; i < correct.Count; i++)
        {
            SendCorrectAlert(correct[i], info.transform);
        }

        for (int i = 0; i < wrong.Count; i++)
        {
            wrong[i].transform.DOScale(Vector3.zero, 0.3F).OnComplete(() => {});
        }

        while (isCounting)
        {
            info.Txt[0].text = FinalScore + "";
            bool complete = true;
            for (int i = 0; i < correct.Count; i++)
            {
                if (correct[i] != null)
                {
                    complete = false;
                    break;
                }
            }
            if (complete)
            {
                isCounting = false;
            }
            yield return(null);
        }

        int rep = (int)((FinalScore * 5) * (1.0F + (Difficulty * Bonus_DifficultyMultiplier)));

        info.Txt[0].text = rep + "";

        if (GameTime < Timer)
        {
            yield return(new WaitForSeconds(0.4F));

            float mult = 1.0F - (GameTime / Timer * Bonus_TimerDecay);
            mult              = Mathf.Clamp(1.0F + mult, 1.0F, Bonus_TimerMax);
            rep               = (int)((float)rep * mult);
            info.Txt[0].text  = rep + "";
            info.Txt[1].text  = "TIME\nBONUS";
            info.Txt[1].color = Color.green;

            Tweens.Bounce(info.transform);
            yield return(null);
        }

        if (FinalScore == GGNum)
        {
            yield return(new WaitForSeconds(0.4F));

            rep = (int)((float)rep * Bonus_Perfect);
            info.Txt[0].text  = rep + "";
            info.Txt[1].text  = "PERFECT!";
            info.Txt[1].color = Color.blue;

            Tweens.Bounce(info.transform);
            yield return(null);
        }

        yield return(new WaitForSeconds(0.4F));

        StartCoroutine(GameManager.UI.ResourceAlert(GameManager.WorldRes.Rep, rep));

        List <FIRL> alerts = new List <FIRL>();

        for (int i = 0; i < _TableManager.Seat.Length; i++)
        {
            GrandData g = _TableManager.Seat[i].Target.Data;
            FIRL      a = GameManager.UI.MeterAlert(g, AlertType.Hunger);
            alerts.Add(a);
            Tweens.Bounce(a.transform);
            yield return(null);
        }

        //FUTURE ANIMATION OF GRANDS EATING
        yield return(new WaitForSeconds(0.3F));

//$$$$$$$
        int   hungerticks = 10 + FinalScore * 10;
        int   ticks       = 0;
        float tickrate    = 1;

        while (true)
        {
            for (int i = 0; i < _TableManager.Seat.Length; i++)
            {
                GrandData g = _TableManager.Seat[i].Target.Data;
                g.Hunger.Add((int)tickrate);
                alerts[i][0].transform.localScale = new Vector3(g.Hunger.Ratio, 1.0F, 1.0f);
            }
            ticks    += (int)tickrate;
            tickrate *= 1.1F;
            if (ticks >= hungerticks)
            {
                break;
            }
            yield return(null);
        }
        yield return(new WaitForSeconds(0.3F));

        for (int i = 0; i < alerts.Count; i++)
        {
            alerts[i].PoolDestroy();
        }

        yield return(new WaitForSeconds(0.5F));

        yield return(StartCoroutine(FinishDinner()));
    }