예제 #1
0
    public Script_Wolf(Vector3 p_position, Script_GameManager p_gameManager, Script_Grid p_grid, Quaternion p_rotation)
    {
        _wolfObject      = GameObject.CreatePrimitive(PrimitiveType.Cube);
        _wolfObject.name = "WolfObject";
        _wolfObject.transform.position = p_position;
        _wolfObject.transform.rotation = p_rotation;
        _material       = _wolfObject.GetComponent <Renderer>().material;
        _material.color = Color.black;



        _speed                   = 0.033f;
        _size                    = 0.5f;
        _movementDecay           = 0.01f;
        _actionDecay             = 0.1f;
        _sensingRange            = 2;
        _sheepBeingEaten         = null;
        _maxHealth               = 10.0f;
        _health                  = 5.0f;
        _healthNeededToReproduce = _maxHealth * 0.75f;


        _decidedAction    = DecidedAction.Wandering;
        _actDelegate      = null;
        _tilesWithinRange = new List <Script_Tile> ();
        _sheepWithinRange = new List <Script_Sheep> ();
        _surroundingTiles = new List <Script_Tile> ();
        _grid             = p_grid;

        _occupiedLocation = GetCurrentGridPosition();
        _targetLocation   = GetCurrentGridPosition();
        OccupyNewLocation(GetCurrentGridPosition());
    }
예제 #2
0
    public void Decide()
    {
        _grassBeingEaten = null;
        if (DecideToDie())
        {
            _decidedAction = DecidedAction.dying;
            _actDelegate   = new ActDelegate(Die);
        }

        if (DecideToEvade() && !DecideToDie())
        {
            if (AtTargetLocation() || _decidedAction != DecidedAction.Evading)
            {
                DecideDirectionToEvade();
            }
            _decidedAction = DecidedAction.Evading;
            _actDelegate   = new ActDelegate(EvadeToLocation);
        }

        else if (DecideToReproduce() && !DecideToDie() && !DecideToEvade())
        {
            _reproductionLocation = DecideReproductionTile();

            Script_Tile currentlyOccupiedTile = _grid.AccessGridTile(_reproductionLocation.x, _reproductionLocation.z);
            currentlyOccupiedTile.SetOccupiedBySheep(false);
            _decidedAction = DecidedAction.Reproducing;
            _actDelegate   = new ActDelegate(Reproduce);
        }
        else if (DecideToEatGrass() && !DecideToDie() && !DecideToReproduce() && !DecideToEvade())
        {
            OccupyNewLocation(GetCurrentGridPosition());
            _decidedAction = DecidedAction.Eating;
            _actDelegate   = new ActDelegate(EatGrass);
        }
        else if (DecideToSeekGrass() && !DecideToEatGrass() && !DecideToReproduce() && !DecideToDie() && !DecideToEvade())
        {
            if (AtTargetLocation() || _decidedAction != DecidedAction.Seeking)
            {
                DecideGrassToSeek();
            }
            _decidedAction = DecidedAction.Seeking;
            _actDelegate   = new ActDelegate(MoveToLocation);
        }
        else if (DecideToWander() && !DecideToSeekGrass() && !DecideToEatGrass() && !DecideToReproduce() && !DecideToDie() && !DecideToEvade())
        {
            if (AtTargetLocation() || _decidedAction != DecidedAction.Wandering)
            {
                DecideWanderingLocation();
            }
            _decidedAction = DecidedAction.Wandering;
            _actDelegate   = new ActDelegate(MoveToLocation);
        }
    }
예제 #3
0
    public Script_Tile(Script_Grid p_grid, GrassStates p_state, int p_gridXCoordinate, int p_y, int p_gridZCoordinate, Quaternion p_rotation)
    {
        _position        = new Vector3Int(p_gridXCoordinate, -1, p_gridZCoordinate);
        _tileObject      = GameObject.CreatePrimitive(PrimitiveType.Cube);
        _tileObject.name = "TileObject";
        _tileObject.transform.position = _position;
        _tileObject.transform.rotation = p_rotation;
        _material       = _tileObject.GetComponent <Renderer>().material;
        _material.color = Color.white;



        _nearbySheep       = new List <Script_Sheep> ();
        _isOccupiedBySheep = false;
        _isOccupiedByWolf  = false;
        _grid            = p_grid;
        _gridXCoordinate = p_gridXCoordinate;
        _gridZCoordinate = p_gridZCoordinate;

        _sheepSensingRange = 2;

        _isOld              = false;
        _actDelegate        = null;
        _matureTimerMax     = 5.0f;
        _matureTimerCurrent = 0.0f;
        _isMature           = false;
        _maxHealth          = 10.0f;
        _state              = p_state;

        _colorDirt          = new Color(1, 1, 0, 1);
        _colorGrass         = new Color(0, 1, 1, 1);
        _colorDecayingGrass = new Color(0.5f, 0.5f, 0, 1);

        _isTrampledUpon = false;
        _isEatenUpon    = false;

        if (_state == GrassStates.Dirt)
        {
            _health       = 0.0f;
            _colorCurrent = _colorDirt;
        }
        else if (_state == GrassStates.Grass)
        {
            _health       = 8.0f;
            _colorCurrent = Color.Lerp(_colorDecayingGrass, _colorGrass, _health / _maxHealth);
        }

        SetColor(_colorCurrent);
    }
예제 #4
0
    public void InitializeGrass()
    {
        if (_state == GrassStates.Grass)
        {
            float spawnedGrassHealth = 2.0f;

            _actDelegate        = null;
            _isEatenUpon        = false;
            _isTrampledUpon     = false;
            _isOld              = false;
            _matureTimerCurrent = 0.0f;
            _isMature           = false;
            _health             = spawnedGrassHealth;
            _colorCurrent       = Color.Lerp(_colorDecayingGrass, _colorGrass, _health / _maxHealth);
            SetColor(_colorCurrent);
        }
    }
예제 #5
0
    public void Decide()
    {
        if (_state == GrassStates.Grass)
        {
            if (!_isEatenUpon && _isMature && !_isOld)
            {
                _actDelegate += new ActDelegate(Reproduction);
            }

            if (!_isEatenUpon && !_isTrampledUpon && (!_isMature || _isOld))
            {
                _actDelegate = new ActDelegate(Growth);
            }
            if (_health <= 0.0f)
            {
                _actDelegate = new ActDelegate(Die);
            }
        }
    }