示例#1
0
    private void RunToWaypoint()
    {
        Vector3 targetPos = Vector3.zero;

        try
        {
            targetPos = _nextTile.transform.position + new Vector3(0, 1, 0);
        }
        catch
        {
            LevelManager.Points++;
            Destroy(this.gameObject);
        }
        float step = this.Speed * Time.deltaTime * (_speedBonus ? 1.5f : 1.0f);

        transform.position = Vector3.MoveTowards(transform.position, targetPos, step);

        Vector3 relativePos = targetPos - this.gameObject.transform.position;

        if (relativePos != Vector3.zero)
        {
            //relativePos.y = 0;
            Quaternion rotation = Quaternion.LookRotation(relativePos);
            this.gameObject.transform.rotation = rotation;// Quaternion.Slerp(rotation, this.gameObject.transform.rotation, 0.1f);
        }

        if (transform.position == targetPos)
        {
            _state = LemmingState.WaypointReached;
        }
    }
示例#2
0
    private void FindNextWaypoint(bool ignoreLast = false)
    {
        if (!ignoreLast)
        {
            if (Random.value < 0.33f)
            {
                ignoreLast = true;
            }
        }

        if (CanRunTo(_lastRunDirection) && !ignoreLast)
        {
            SetNextWayPoint(_lastRunDirection);
        }
        else
        {
            RunDirection[] possibleDirection = (RunDirection[])Enum.GetValues(typeof(RunDirection));
            RunDirection   nextDirection;

            do
            {
                int next;
                do
                {
                    next = UnityEngine.Random.Range((int)possibleDirection[0], (int)possibleDirection[possibleDirection.Length - 1] + 3);
                } while (next > (int)possibleDirection[possibleDirection.Length - 1]);
                nextDirection = (RunDirection)next;
            }while (!CanRunTo(nextDirection));

            SetNextWayPoint(nextDirection);
            _lastRunDirection = nextDirection;
        }

        _state = LemmingState.RunningToWaypoint;
    }
示例#3
0
    private void HandleFireAlarmButton()
    {
        LevelManager.FireAlarmTriggered = true;

        _placeableUseTimer -= Time.deltaTime;
        if (_placeableUseTimer <= 0)
        {
            _state = LemmingState.Idle;
        }
    }
示例#4
0
    private void CheckForObjectInteraction()
    {
        Transform[] x = _currentTile.gameObject.GetComponentsInChildren <Transform>();
        if (_currentTile.Placeable.transform.childCount != 0)
        {
            Transform placeable = _currentTile.Placeable.transform.GetChild(0);

            switch (placeable.name)
            {
            case "Placeable_Fire_Extinguisher":
                _placeableUseTimer = 3.0f;
                _state             = LemmingState.UsingFireExtinguisher;
                Destroy(placeable.gameObject);
                return;

            case "Placeable_Fire_Alarm_Button":
                _placeableUseTimer = 1.0f;
                _state             = LemmingState.UsingFireAlarmButton;
                return;

            case "Placeable_EXIT_Right":
                _placeableUseTimer = 0.5f;
                _state             = LemmingState.UsingExitRight;
                return;

            case "Placeable_EXIT_Left":
                _placeableUseTimer = 0.5f;
                _state             = LemmingState.UsingExitLeft;
                return;

            case "Placeable_Firealarm":
                _placeableUseTimer = 0.0f;
                if (LevelManager.FireAlarmTriggered)
                {
                    _speedBonus = true;
                }
                break;
            }
        }

        _state = LemmingState.Idle;
    }
示例#5
0
    private void HandleFireExtinguisher()
    {
        for (int x = (int)_currentTile.transform.position.z - 1; x <= (int)_currentTile.transform.position.z + 1; x++)
        {
            for (int y = (int)_currentTile.transform.position.x - 1; y <= (int)_currentTile.transform.position.x + 1; y++)
            {
                Tile t = LevelModel.Instance.TryGetTile(x, y);
                if (t != null)
                {
                    t.onFire -= Time.deltaTime;
                    if (t.onFire < 0)
                    {
                        t.onFire = 0;
                    }
                }
            }
        }

        _placeableUseTimer -= Time.deltaTime;
        if (_placeableUseTimer <= 0)
        {
            _state = LemmingState.Idle;
        }
    }
示例#6
0
    private void Update()
    {
        if (LevelModel.Instance == null)
        {
            return;
        }

        float shortestDistance = float.MaxValue;

        //Find the tile we are currently standing on
        foreach (Tile[] innerTiles in LevelModel.Instance.Tiles)
        {
            foreach (Tile tile in innerTiles)
            {
                if (tile != null)
                {
                    float distance = Vector3.Distance(tile.gameObject.transform.position, this.gameObject.transform.position);
                    if (distance < shortestDistance)
                    {
                        shortestDistance = distance;
                        _currentTile     = tile;
                    }
                }
            }
        }

        if (_state == LemmingState.NotLaunched)
        {
            return;
        }
        if (health <= 0)
        {
            _removeTimer -= Time.deltaTime;
            _state        = LemmingState.Dead;
        }
        if (_removeTimer <= 0)
        {
            Destroy(this.gameObject);
        }

        if (_tiles.Length == 0)
        {
            _tiles = FindObjectsOfType <Tile>();
            return;
        }
        if (_currentTile.IsOnFire)
        {
            health -= Time.deltaTime / 100 * 70;
        }

        GetComponent <Animator>().SetBool("onFire", _currentTile.IsOnFire);
        GetComponent <Animator>().SetFloat("life", health);
        GetComponent <Animator>().SetBool("extinguishing", _state == LemmingState.UsingFireExtinguisher);


        switch (_state)
        {
        case LemmingState.Idle:
            FindNextWaypoint();
            break;

        case LemmingState.WaypointReached:
            CheckForObjectInteraction();
            break;

        case LemmingState.RunningToWaypoint:
            RunToWaypoint();
            break;

        case LemmingState.UsingFireExtinguisher:
            HandleFireExtinguisher();
            break;

        case LemmingState.UsingFireAlarmButton:
            HandleFireAlarmButton();
            break;

        case LemmingState.UsingExitLeft:
            HandleExitSign(true);
            break;

        case LemmingState.UsingExitRight:
            HandleExitSign(false);
            break;
        }
    }
示例#7
0
 public void StartAI()
 {
     _state = LemmingState.Idle;
     GetComponent <Animator>().Play("Lemming_Walking", -1, Random.Range(0.0f, 1.0f));
 }
示例#8
0
    private void HandleExitSign(bool left)
    {
        _placeableUseTimer -= Time.deltaTime;
        if (_placeableUseTimer > 0)
        {
            return;
        }

        Transform    placeable = _currentTile.Placeable.transform.GetChild(0);
        RunDirection direction;

        RunDirectionHelper.ToDirection(placeable.transform.localEulerAngles.y, out direction);
        if (left)
        {
            switch (direction)
            {
            case RunDirection.North:
                direction = RunDirection.West;
                break;

            case RunDirection.West:
                direction = RunDirection.South;
                break;

            case RunDirection.South:
                direction = RunDirection.East;
                break;

            case RunDirection.East:
                direction = RunDirection.North;
                break;
            }
        }
        else
        {
            switch (direction)
            {
            case RunDirection.North:
                direction = RunDirection.East;
                break;

            case RunDirection.West:
                direction = RunDirection.North;
                break;

            case RunDirection.South:
                direction = RunDirection.West;
                break;

            case RunDirection.East:
                direction = RunDirection.South;
                break;
            }
        }

        if (CanRunTo(direction))
        {
            _lastRunDirection = direction;
            SetNextWayPoint(direction);
        }
        _state = LemmingState.RunningToWaypoint;
    }