예제 #1
0
    //Determine whether the player lost
    public static bool PlayerLost()
    {
        if (Time.deltaTime == 0)
        {
            return(false);
        }

        //Check if player is too low
        GameObject player = GameObject.FindGameObjectWithTag("Player");

        if (player.transform.position.y < maxDepth)
        {
            return(true);
        }

        //Any close enough
        foreach (GameObject e in enemies)
        {
            NPCMovementController movement = e.GetComponent <NPCMovementController>();
            if (movement != null)
            {
                if ((e.transform.position - goal).magnitude < maxDifference)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
예제 #2
0
    //Determine whether the player wins
    public static bool PlayerWon()
    {
        if (Time.deltaTime == 0)
        {
            return(false);
        }
        int numEnemiesStuck = 0;

        //Iterate through all the enemies. Determine if all are stuck
        foreach (GameObject e in enemies)
        {
            NPCMovementController movement = e.GetComponent <NPCMovementController>();

            if (movement != null && e.transform.position.magnitude < worldSize / 3f)
            {
                Vector3 evenYGoal  = new Vector3(movement.GetGoal().x, e.transform.position.y, movement.GetGoal().z);
                Vector3 diff       = evenYGoal - e.transform.position;
                Vector3 evenYGoal2 = new Vector3(goal.x, e.transform.position.y, goal.z);
                Vector3 diff2      = evenYGoal2 - e.transform.position;

                Vector3[] path = movement.GetPath();

                //Is this enemy not heading directly for the goal (they've been blocked)
                if (Vector3.Angle(diff.normalized, diff2.normalized) > 40 || (path == null || (path[path.Length - 1] - goal).magnitude > maxDifference * 2))
                {
                    numEnemiesStuck++;
                }
            }
        }

        return(numEnemiesStuck == enemies.Length);
    }
예제 #3
0
    public void SpawnEnemies(int numSpawn, float x, float y, float z, float range = -1)
    {
        npcs       = null;
        numToSpawn = numSpawn;
        npcs       = new NPCUnit[numToSpawn];
        for (int i = 0; i < numToSpawn; i++)
        {
            GameObject go = (GameObject)Instantiate(enemyPrefab);

            go.transform.position = new Vector3(x, y, z);

            NPCMovementController   npc  = go.GetComponent <NPCMovementController>();
            NPCAppearanceController npcA = go.GetComponent <NPCAppearanceController>();

            if (npcA != null)
            {
                npcA.Init();
            }

            if (npc != null)
            {
                //Naming for ease
                npc.gameObject.name = i.ToString("0000");                 //assuming we have less than 10,000
                npcs[i]             = npc.GetComponent <NPCUnit>();

                //Movement update
                if (range > 0)
                {
                    npc.maxDistance            = range;
                    npc.randomPositionGenerate = true;
                }
            }
        }
    }
예제 #4
0
    protected new void Start()
    {
        // Get componenets
        NPCDialogueController = GetComponent <NPCDialogueController>();
        NPCMovementController = GetComponent <NPCMovementController>();

        base.Start();

        if (startPose)
        {
            Pose(poseStr, pose);
        }
    }
예제 #5
0
    //Tries to get an NPC based on the player's current view
    public NPCMovementController TryGetSelectedNPC()
    {
        RaycastHit            hit;
        NPCMovementController npcMovement = null;

        if (Physics.Raycast(cameraTrans.position, cameraTrans.forward, out hit, _distanceOfRaycast))
        {
            if (hit.collider != null)
            {
                npcMovement = hit.collider.GetComponent <NPCMovementController>();
            }
        }
        return(npcMovement);
    }
예제 #6
0
    public void SetControlledUnit(NPCMovementController go)
    {
        if (go != null)
        {
            int index = 0;

            while (index < npcs.Length && controlledUnit == -1)
            {
                if (npcs[index] != null && go.gameObject == npcs[index].gameObject)
                {
                    controlledUnit = index;
                }

                index++;
            }
        }
    }