Example #1
0
 public void Activate(SwarmObject obj)
 {
     if (objectPlacer != null && obj != null)
     {
         if (behaviour == OnClickBehaviour.Ripple)
         {
             List <SwarmObject>[] neighbours = objectPlacer.GetNeighbours(obj, size);
             for (int i = 0; i < neighbours.Length; i++)
             {
                 foreach (SwarmObject item in neighbours[i])
                 {
                     if (item != null && objectPlacer == item.Parent)
                     {
                         float _amp = amplitude - distanceFalloff * i;
                         item.Wobble(objectPlacer.GetDirection(), _amp, amplitudeCutoff, speed, time, delay * i);
                     }
                 }
             }
         }
         else
         {
             print("Behavior not defined");
         }
     }
 }
Example #2
0
    /// <summary>
    /// Get the amount of alcool in the swarm + stop them to move
    /// </summary>
    void ProceedToCheck(SwarmObject swarmObject) // param current swarm
    {
        SwarmObjectCop cop = swarmObject as SwarmObjectCop;

        cop.EndAlert();
        if (cop.SwarmTarget.ComposedOfAMaya)
        {
            cop.GoesToUniqueTarget = false;
            cop.SwarmTarget.EndChecked();
        }
        else
        {
            CoroutineUtils.ExecuteWhenFinished(this, new WaitForSeconds(timeCheck), () =>
            {
                cop.GoesToUniqueTarget = false;

                float alcoholAmount = cop.SwarmTarget.TotalSwarmPollenAmount;

                if (alcoholAmount >= (FestBeeSwarm.DRUNK_POLLEN_AMOUNT))
                {
                    cop.SwarmTarget.FailedPolitest();
                }
                else
                {
                    cop.SwarmTarget.SuccessPolitest();
                }

                // send back to home if needed
                if (_countPoliTest <= 0 && state != CopState.GoToHive)
                {
                    GoToHive();
                }
            });
        }
    }
Example #3
0
    public void PlaceObjects()
    {
        Clear();
        if (objects != null && objects.Length > 0)
        {
            Vector3 _pos;
            Vector3 _rot;
            Vector3 _scale;

            Vector3 _parentPosition = transform.position;
            float   _halfSpacing    = spacing / 2;
            float   _triHeight      = Mathf.Sqrt(spacing * spacing - _halfSpacing * _halfSpacing);

            for (int y = 0; y < yCount; y++)
            {
                for (int x = 0; x < xCount; x++)
                {
                    _pos = _parentPosition;
                    if (gridCellType == GridCellType.Triangle)
                    {
                        float offset = 0;
                        if (y % 2 != 0) // shift every odd row halfway forward
                        {
                            offset = _halfSpacing;
                        }
                        _pos += new Vector3(x * spacing + offset, 0f, y * _triHeight);
                    }
                    else
                    {
                        _pos += new Vector3(x * spacing, 0f, y * spacing);
                    }

                    _pos = GetRayHitPositionOnSurface(_pos);
                    if (discardOnMiss && _pos == Vector3.zero)
                    {
                        continue;
                    }
                    _pos  += GetRandomValue(randomPositionOffset);
                    _rot   = initialRotation + GetRandomValue(randomRotationOffset);
                    _scale = initialScale + GetRandomValue(randomScaleOffset);

                    SwarmObject _obj = objects[Random.Range(0, objects.Length)];
                    if (_obj != null)
                    {
                        GameObject obj = Instantiate(_obj.gameObject, _pos, Quaternion.Euler(_rot), transform);
                        obj.transform.localScale = _scale;

                        var swarwObj = obj.GetComponent <SwarmObject>();
                        swarwObj.SetParent(this);
                        swarwObj.SetInitialPosition(_pos);
                        swarwObj.SetIndex(new Vector2Int(x, y));
                        swarmObjectArray[x, y] = swarwObj;
                    }
                }
            }
        }
    }
Example #4
0
    public List <SwarmObject>[] GetNeighbours(SwarmObject obj, int count)
    {
        var _array = new List <SwarmObject> [count];

        for (int i = 0; i < count; i++)
        {
            _array[i] = new List <SwarmObject>();
            if (i == 0)
            {
                _array[i].Add(obj);
            }
            else
            {
                foreach (SwarmObject item in _array[i - 1])
                {
                    if (item != null)
                    {
                        Vector2Int[] nIndexes;
                        var          i1 = new Vector2Int(item.Index.x + 1, item.Index.y);
                        var          i2 = new Vector2Int(item.Index.x - 1, item.Index.y);
                        var          i3 = new Vector2Int(item.Index.x, item.Index.y + 1);
                        var          i4 = new Vector2Int(item.Index.x, item.Index.y - 1);

                        if (gridCellType == GridCellType.Square)
                        {
                            nIndexes = new Vector2Int[] { i1, i2, i3, i4 };
                        }
                        else // due to the grid being shifted halfway forward in y, we get 2 additional (odd/even row-dependent) neighbors at y + 1 and y + 1
                        {
                            var i5 = new Vector2Int(item.Index.x + (item.Index.y % 2 != 0 ? 1 : -1), item.Index.y + 1);
                            var i6 = new Vector2Int(item.Index.x + (item.Index.y % 2 != 0 ? 1 : -1), item.Index.y - 1);
                            nIndexes = new Vector2Int[] { i1, i2, i3, i4, i5, i6 };
                        }

                        foreach (var index in nIndexes)
                        {
                            if (_IsIndexInRange(index))
                            {
                                SwarmObject neighbour = swarmObjectArray[index.x, index.y];
                                if (!_IsObjectCollected(neighbour, _array, i))
                                {
                                    _array[i].Add(neighbour);
                                }
                            }
                        }
                    }
                }
            }
        }
        return(_array);
    }