Example #1
0
    private static void CreateWorkerAnt(Transform target, Transform source)
    {
        GameObject go = new GameObject("Worker", typeof(WorkerAnt));

        WorkerAnt ant = go.GetComponent <WorkerAnt>();

        ant.Target = target;
        ant.Source = source;
    }
Example #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        WorkerAnt worker = collision.gameObject.GetComponent <WorkerAnt>();

        if (worker != null)
        {
            HandleIncomingWorker(worker);
            return;
        }

        CarrierAnt carrier = collision.gameObject.GetComponent <CarrierAnt>();

        if (carrier != null)
        {
            HandleIncomingCarrier(carrier);
            return;
        }
    }
Example #3
0
    private void HandleIncomingWorker(WorkerAnt worker)
    {
        if (worker.Target != transform)
        {
            return;
        }

        lock (_Sync)
        {
            if (WorkerAnts == MaxWorkerAnts)
            {
                AntDispatcher.ToBase(worker);
            }
            else
            {
                WorkerAnts++;
                AntDispatcher.Destroy(worker);
            }
        }
    }
Example #4
0
    public static void BuildNest(Player player)
    {
        // Find player cursor position
        Cursor playerCursor = null;

        foreach (Cursor cursor in CursorManager.Cursors)
        {
            if (cursor.Player == player)
            {
                playerCursor = cursor;
                break;
            }
        }
        Vector2 cursorPosition = playerCursor.CursorGameObject.transform.position;

        WorkerAnt closestWorkerAnt = null;
        float     minDistance      = float.MaxValue;

        foreach (Ant workerAnt in ants)
        {
            if (workerAnt.GetType().Equals(typeof(WorkerAnt)))
            {
                if (workerAnt.Nest.Player == player)
                {
                    Vector2 workerAntPosition = workerAnt.AntGameObject.transform.position;
                    float   distanceToCursor  = Vector2.Distance(workerAntPosition, cursorPosition);
                    if (distanceToCursor < minDistance)
                    {
                        minDistance      = distanceToCursor;
                        closestWorkerAnt = (WorkerAnt)workerAnt;
                    }
                }
            }
        }

        closestWorkerAnt.OrderNestBuild(cursorPosition);
    }
Example #5
0
    public static void SpawnWorkerAnt(Nest nest)
    {
        WorkerAnt newWorkerAnt = new WorkerAnt(nest);

        ants.Add(newWorkerAnt);
    }
Example #6
0
    public static void SpawnWorkerAnt(Player player)
    {
        WorkerAnt newWorkerAnt = new WorkerAnt(player.SelectedNest);

        ants.Add(newWorkerAnt);
    }