Exemple #1
0
    //Determines if a ghost has captured the kid
    public void check_collisions()
    {
        GameController gc = GameObject.Find("ScriptObject").GetComponent <GameController>(); //Grabs GameController script data
        GhostUtilities gu = GameObject.Find("ScriptObject").GetComponent <GhostUtilities>();

        for (int k = 0; k < gc.kid_list.Count; k++)       //For each kid
        {
            for (int i = 0; i < gc.ghost_list.Count; i++) //Calculate Euclidean distance between each ghost and kid
            {
                float euclidean = Mathf.Sqrt(Mathf.Pow((gc.kid_list[k].kid_object.transform.position.x - gc.ghost_list[i].ghost_object.transform.position.x), 2f) + Mathf.Pow((gc.kid_list[k].kid_object.transform.position.z - gc.ghost_list[i].ghost_object.transform.position.z), 2f));

                //If ghost leaves Duncan's aura, then remove the slow effects
                if (gc.kid_list[k].character_number == 1 && euclidean >= 5f && gc.ghost_list[i].speed_multiplier < 1f)
                {
                    gc.ghost_list[i].speed_multiplier = 1f; //If out of Duncan aura -> reset speed
                    gc.ghost_list[i].slowed           = false;
                    gu.destroy_slow_symbol(i);              //Destroy slow symbol
                }

                //If ghost within Duncan slow aura, reduce the speed multiplier
                if (gc.kid_list[k].character_number == 1 && euclidean < 5f && gc.ghost_list[i].speed_multiplier >= 1)
                {
                    gc.ghost_list[i].speed_multiplier = 0.83334f - (0.005f * (float)gc.kid_list[k].power_upgrades); //If in Duncan aura -> slow speed

                    if (!gc.ghost_list[i].slowed)                                                                   //If slow symbol not there, then add it to Ghost
                    {
                        gc.ghost_list[i].slowed = true;

                        //Make slow symbol over ghost and remove unwanted properties
                        GameObject     slow_symbol = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                        SphereCollider sc          = slow_symbol.GetComponent <SphereCollider>();
                        sc.enabled = false;

                        //Define position properties for slow symbol
                        Vector3 pos = gc.ghost_list[i].ghost_object.transform.position;
                        pos.y += 1.5f;
                        Quaternion rot = new Quaternion(); rot.Set(0f, 0f, 0f, 1f);
                        slow_symbol.transform.position = pos;
                        slow_symbol.transform.rotation = rot;

                        //Scale and place material on slow symbol
                        slow_symbol.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
                        slow_symbol.GetComponent <Renderer>().material = gc.slow_symbol_material;

                        //Add the slowed ghost to list
                        gc.slowed_ghost_list.Add((gc.ghost_list[i].ghost_object.name, slow_symbol));
                    }
                }

                if (gc.kid_list[k].region.safe_zone == false && euclidean < 0.715f)
                {
                    respawn(k);                                                                //Respawn when hit in non-safe area
                }
            }
        }
    }
Exemple #2
0
    //Cleans up level one once completed
    public void end_level()
    {
        if (Scene_Switch_Data.level == 0)
        {
            return;                                                                          //Do nothing if in tutorial mode
        }
        GameController gc = GameObject.Find("ScriptObject").GetComponent <GameController>(); //Grabs GameController script data
        GhostUtilities gu = GameObject.Find("ScriptObject").GetComponent <GhostUtilities>();
        KidUtilities   ku = GameObject.Find("ScriptObject").GetComponent <KidUtilities>();

        if (gc.level + 1 >= 4)
        {
            onMainMenuClick();                   //Sends player back to main screen when current levels completed
        }
        //Delete all ghost from ghost_list and and destroy the objects of every ghost in all regions
        for (int i = 0; i < gc.ghost_list.Count; i++)
        {
            gu.destroy_slow_symbol(i);
            Destroy(gc.ghost_list[i].ghost_object);
        }
        gc.ghost_list.Clear();
        gc.region_list.Clear();

        gc.level += 1;
        setup_level_enemies();

        for (int k = 0; k < gc.kid_list.Count; k++) //For each kid in kid_list
        {
            gc.kid_list[k].region_index = 0;
            gc.kid_list[k].region       = gc.region_list[0];
            gc.kid_list[k].region_flags_list.Clear();

            //Fill region flag list of every kid
            for (int j = 0; j < gc.region_list.Count; j++)
            {
                gc.kid_list[k].region_flags_list.Add(false);
            }

            ku.respawn(k);
        }
        gc.level_end_timer = 2.0f;
        gc.level_complete  = false;
    }
    //Populates Regions with orange ghost
    public void fill_regions()
    {
        GameController gc = GameObject.Find("ScriptObject").GetComponent <GameController>(); //Grabs GameController script data
        GhostUtilities gu = GameObject.Find("ScriptObject").GetComponent <GhostUtilities>(); //Grabs GameUtilities script data

        for (int i = 0; i < gc.region_list.Count; i++)
        {
            if (gc.region_list[i].safe_zone == false)
            {
                for (int j = 0; j < gc.region_list[i].ghost_number; j++) //Creates j number of ghost
                {
                    float[] boundaries = gc.region_list[i].boundary_coordinates;

                    Vector3 pos            = new Vector3(Random.Range(boundaries[0] + 0.1f, boundaries[1] - 0.1f), 0f, Random.Range(boundaries[2] + 0.1f, boundaries[3] - 0.1f)); //Defines initial position of ghost by picking random point in the region boundary (with a small error)
                    Vector3 rotationVector = new Vector3(0f, Random.Range(0, 360), 0f);                                                                                           //Rotate ghost randomly

                    gu.make_ghost_oj(pos, rotationVector, gc.region_list[i]);                                                                                                     //Make new ghost at specified location
                }
            }
        }
    }
Exemple #4
0
    //Respawns kid (kid_list[k]) at last checkpoint
    public void respawn(int k)
    {
        GameController gc = GameObject.Find("ScriptObject").GetComponent <GameController>(); //Grabs GameController script data
        GhostUtilities gu = GameObject.Find("ScriptObject").GetComponent <GhostUtilities>();

        if (gc.kid_list[k].region_index % 2 != 0) //If not in safe zone, then set the kid_region to the last safe zone
        {
            gc.kid_list[k].region        = gc.region_list[gc.kid_list[k].region_index - 1];
            gc.kid_list[k].region_index -= 1;
        }

        //Place kid in middle of last safe zone
        gc.kid_list[k].kid_object.transform.position = new Vector3(gc.kid_list[k].region.boundary_coordinates[1] - (gc.kid_list[k].region.boundary_coordinates[1] - gc.kid_list[k].region.boundary_coordinates[0]) / 2f, 0,
                                                                   gc.kid_list[k].region.boundary_coordinates[3] - ((gc.kid_list[k].region.boundary_coordinates[3] - gc.kid_list[k].region.boundary_coordinates[2]) / 2f) - 2 * k);

        Vector3 rotationVector; //Rotate kid

        if (gc.kid_list[k].region.region_up == 0)
        {
            rotationVector = new Vector3(0f, 270f, 0f);
        }
        else if (gc.kid_list[k].region.region_up == 1)
        {
            rotationVector = new Vector3(0f, 90f, 0f);
        }
        else if (gc.kid_list[k].region.region_up == 2)
        {
            rotationVector = new Vector3(0f, 180f, 0f);
        }
        else
        {
            rotationVector = new Vector3(0f, 0f, 0f);
        }
        gc.kid_list[k].kid_object.transform.eulerAngles = rotationVector;

        gc.kid_list[k].animator.SetBool("isRunning", false);
        gc.kid_list[k].animator.SetBool("isBackingUp", false);

        gc.kid_list[k].falling = false;
    }