Example #1
0
 void FirstPath()
 {
     pathfind.FindPath(transform.position, star.transform.position);
     path       = grid.path;
     unitStates = _states.star;
     go         = true;
 }
Example #2
0
 // Use this for initialization
 void Start()
 {
     grassStates = _states.growing;
     grid        = FindObjectOfType <GridGenerator>();
     sheep       = FindObjectOfType <Sheep>();
     hp          = Random.Range(2, 4);
 }
Example #3
0
 void states()
 {
     if (unitStates == _states.ship)
     {
         pathfind.FindPath(transform.position, ship.transform.position);
         path          = grid.path;
         waypointCount = 0;
         return;
     }
     if (unitStates == _states.star)
     {
         pathfind.FindPath(transform.position, tradingpost.transform.position);
         path          = grid.path;
         unitStates    = _states.tradingpost;
         starTaken     = true;
         waypointCount = 0;
         return;
     }
     if (unitStates == _states.tradingpost)
     {
         pathfind.FindPath(transform.position, star.transform.position);
         path          = grid.path;
         unitStates    = _states.star;
         starTaken     = false;
         waypointCount = 0;
         return;
     }
 }
Example #4
0
    void Startimus()
    {
        if (grid.WolfSearching(this) == false)
        {
            WolfnewPos = grid.ClosestSheep(this);
        }
        else
        {
            WolfnewPos.x = Random.Range(0, 20);
            WolfnewPos.y = Random.Range(0, 20);
        }
        if (grid.SheepTargeted(WolfnewPos, this) == false)
        {
            WolfoldPos     = currentWolfPos;
            currentWolfPos = WolfnewPos;
        }
        else
        {
            WolfnewPos = new Vector2(Random.Range(0, 20), Random.Range(0, 20));

            WolfoldPos     = currentWolfPos;
            currentWolfPos = WolfnewPos;
        }
        wolfStates = _states.hunting;
    }
Example #5
0
    void Retrace()
    {
        if (unitStates == _states.ship)
        {
            pathfind.FindPath(transform.position, ship.transform.position);
            path               = grid.path;
            unitStates         = _states.ship;
            transform.position = gridgen.ClosestTile(this);
            waypointCount      = 0;
            return;
        }

        if (unitStates == _states.star)
        {
            pathfind.FindPath(transform.position, star.transform.position);
            path               = grid.path;
            unitStates         = _states.star;
            transform.position = gridgen.ClosestTile(this);
            waypointCount      = 0;
            return;
        }

        if (unitStates == _states.tradingpost)
        {
            pathfind.FindPath(transform.position, tradingpost.transform.position);
            path               = grid.path;
            unitStates         = _states.tradingpost;
            transform.position = gridgen.ClosestTile(this);
            waypointCount      = 0;
            return;
        }
    }
Example #6
0
    // Update is called once per frame
    void Startimus()
    {
        currentSheepPos = grid.ClosestTile(this);

        if (grid.SheepSearching(this) == false)
        {
            currentSheepPos = grid.ClosestTile(this);
            newPos          = grid.ClosestGrass(this);
        }
        else
        {
            newPos = new Vector2(Random.Range(0, 20), Random.Range(0, 20));
        }
        if (grid.grassTaken(newPos, this) == false)
        {
            currentSheepPos = grid.ClosestTile(this);
            oldPos          = currentSheepPos;
            currentSheepPos = newPos;
        }
        else
        {
            currentSheepPos = grid.ClosestTile(this);
            newPos          = new Vector2(Random.Range(0, 20), Random.Range(0, 20));
            oldPos          = currentSheepPos;
            currentSheepPos = newPos;
        }
        sheepStates = _states.moving;
        run         = false;
    }
Example #7
0
    void Start()
    {
        pathfind = FindObjectOfType <Pathfinding>();
        grid     = FindObjectOfType <Grid>();
        gridgen  = FindObjectOfType <Gridgenerator>();

        unitStates = _states.star;
        Invoke("FirstPath", 0.5f);
    }
Example #8
0
 void Decide()
 {
     if (hp >= 5)
     {
         if (Random.value < 0.1)
         {
             grassStates = _states.spreading;
         }
     }
 }
Example #9
0
 void state_sheets_0()
 {
     text.text = "You can't believe you are sleeping in these things " +
                 "surely it is time someone changed them.  The pleasures of prison life I Guess! \n \n" +
                 "Press R to return to roaming your cell.";
     if (Input.GetKeyDown(KeyCode.R))
     {
         _myState = _states.cell;
     }
 }
Example #10
0
 void state_lock_0()
 {
     text.text = "This is one of those button locks.  You have no idea what the combination is " +
                 "You wish you could somehow see what the dirty buttons are. \n \n" +
                 "Press R to return to roaming your cell.";
     if (Input.GetKeyDown(KeyCode.R))
     {
         _myState = _states.cell;
     }
 }
Example #11
0
 void Sense()
 {
     if (grid.GrassTrampled(this) == true)
     {
         trampled = true;
         Invoke("Normal", 1);
     }
     if (grid.SheepEating(this, currentGrassPos) == true)
     {
         grassStates = _states.eaten;
     }
 }
Example #12
0
    // Update is called once per frame
    void Update()
    {
        switch (_state)
        {
        case _states.Init:
            deck.shuffle();
            initializeCards();
            _state = _states.First_Flip;
            break;

        case _states.First_Flip:
            enableButtons("player");
            break;

        case _states.Init_Draw:
            //refreshCards();
            disableButtons("player");
            enableButtons("draw");
            enableButtons("discard");
            _state = _states.Draw;
            break;

        case _states.Draw:
            break;

        case _states.Init_Place:
            enableButtons("player");
            disableButtons("draw");
            enableButtons("discard");
            _state = _states.Place;
            break;

        case _states.Place:
            break;

        case _states.Init_Swap:
            enableButtons("player");
            disableButtons("draw");
            disableButtons("discard");
            _state = _states.Swap;
            break;

        case _states.Swap:
            break;

        case _states.End:
            disableButtons("player");
            disableButtons("draw");
            disableButtons("discard");
            break;
        }
        checkComplete();
    }
Example #13
0
 // Board functions
 public void checkComplete()
 {
     foreach (GameObject card in cardsPlayer)
     {
         if (card.GetComponent <Card>().state == 0)
         {
             return;
         }
     }
     updateScore();
     _state = _states.End;
 }
Example #14
0
    public void buttonCard(string type, Card card)
    {
        switch (type)
        {
        case "player":
            switch (_state)
            {
            case _states.First_Flip:
                card.GetComponent <Card>().flipCard();
                refreshCards();
                _state = _states.Init_Draw;
                break;

            case _states.Place:
            case _states.Swap:
                cardDraw.GetComponent <Card>().setFaceDown();
                card.GetComponent <Card>().setFaceUp();
                placeCard(card);
                _state = _states.Init_Draw;
                break;
            }
            break;

        case "draw":
            switch (_state)
            {
            case _states.Draw:
                currentCard = card;
                card.GetComponent <Card>().flipCard();
                _state = _states.Init_Place;
                break;
            }
            break;

        case "discard":
            switch (_state)
            {
            case _states.Draw:
                currentCard = card;
                _state      = _states.Init_Swap;
                break;

            case GameManager._states.Place:
                cardDraw.GetComponent <Card>().setFaceDown();
                discardCard(card);
                _state = _states.Init_Draw;
                break;
            }
            break;
        }
    }
Example #15
0
 void state_lock_1()
 {
     text.text = "You are using the mirror and it allows you to see what the combinaiton is.  " +
                 "You punch in the combination, the door beeps and opens up. Will you leave? \n \n" +
                 "Press R to return to roaming your cell. Press F to escape to freedom.";
     if (Input.GetKeyDown(KeyCode.R))
     {
         _myState = _states.cell;
     }
     else if (Input.GetKeyDown(KeyCode.F))
     {
         _myState = _states.freedom;
     }
 }
Example #16
0
 void state_mirror()
 {
     text.text = "You hae found a mirror on the wall.  You can now use it to come back and see what the  " +
                 "dirty buttons are to try to figure out the combination. \n \n" +
                 "Press R to return to roaming your cell. Press M to use the mirror.";
     if (Input.GetKeyDown(KeyCode.R))
     {
         _myState = _states.cell;
     }
     else if (Input.GetKeyDown(KeyCode.M))
     {
         _myState = _states.lock_1;
     }
 }
Example #17
0
 public BugObject(Texture2D texture, Vector2 position, float rotation = 0f)
 {
     _texture = texture;
     _position = position;
     _rotation = rotation;
     _origin.X = _texture.Width / 2;
     _origin.Y = _texture.Height / 2;
     _longestSide = _texture.Width > _texture.Height ? _texture.Width : _texture.Height;
     _state = _states.wander;
     _wanderTimer = 0;
     _backupTimer = 0;
     _turnTimer = 0;
     _restTimer = 0;
     _stamina += _random.Next(0, 2501);
     _life += _random.Next(0, 25001);
 }
Example #18
0
 public BugObject(Texture2D texture, Vector2 position, float rotation = 0f)
 {
     _texture     = texture;
     _position    = position;
     _rotation    = rotation;
     _origin.X    = _texture.Width / 2;
     _origin.Y    = _texture.Height / 2;
     _longestSide = _texture.Width > _texture.Height ? _texture.Width : _texture.Height;
     _state       = _states.wander;
     _wanderTimer = 0;
     _backupTimer = 0;
     _turnTimer   = 0;
     _restTimer   = 0;
     _stamina    += _random.Next(0, 2501);
     _life       += _random.Next(0, 25001);
 }
Example #19
0
 public void Decide()
 {
     if (ActSelect == 1)
     {
         //transform.position = newPos;
         sheepStates = _states.eating;
         eating      = true;
         ActSelect   = 0;
     }
     else if (ActSelect == 2)
     {
         this.GetComponent <SpriteRenderer>().color = EscapingColor;
         run = true;
         Escape();
         ActSelect = 0;
     }
 }
Example #20
0
 void state_cell()
 {
     text.text = "You are in a prison cell and are trying to escape. There are some dirty " +
                 "Sheets on the bed, a mirror on the wall and the door is locked from the outside \n \n" +
                 "Press S to view Sheets, M to view Mirror and L to view lock.";
     if (Input.GetKeyDown(KeyCode.S))
     {
         _myState = _states.sheets_0;
     }
     else if (Input.GetKeyDown(KeyCode.M))
     {
         _myState = _states.mirror;
     }
     else if (Input.GetKeyDown(KeyCode.L))
     {
         _myState = _states.lock_0;
     }
 }
Example #21
0
        private void Move(GameTime gameTime)
        {
            float  x, y;
            Matrix m;

            if (--_life == 0)
            {
                _state = _states.dead;
            }
            else if (_stamina < 1)
            {
                _state = _states.rest;
            }

            switch (_state)
            {
            case _states.wander:
                if (_stuckCounter > 0)
                {
                    _stuckCounter--;
                }
                if (_wanderTimer++ >= _wanderTimerMax)
                {
                    double d = _random.NextDouble();
                    if (d > 0.5)
                    {
                        _rotation -= (float)gameTime.ElapsedGameTime.TotalSeconds * _rotationStep;
                    }
                    else
                    {
                        _rotation += (float)gameTime.ElapsedGameTime.TotalSeconds * _rotationStep;
                    }
                    _wanderTimer = (int)(d * 10) + 10;
                }
                x         = _position.X;
                y         = _position.Y;
                m         = Matrix.CreateRotationZ(_rotation);
                x        += m.M12 * (float)gameTime.ElapsedGameTime.TotalSeconds * _speed;
                y        -= m.M11 * (float)gameTime.ElapsedGameTime.TotalSeconds * _speed;
                _position = new Vector2(x, y);
                _stamina--;
                break;

            case _states.backup:
                if (_backupTimer++ < _backupTimerMax)
                {
                    x         = _position.X;
                    y         = _position.Y;
                    m         = Matrix.CreateRotationZ(_rotation);
                    x        -= m.M12 * (float)gameTime.ElapsedGameTime.TotalSeconds * _speed;
                    y        += m.M11 * (float)gameTime.ElapsedGameTime.TotalSeconds * _speed;
                    _position = new Vector2(x, y);
                }
                else
                {
                    _backupTimer = 0;
                    _state       = _states.turn;
                }
                _stamina--;
                if (_stuckCounter++ > _stuckCounterMax)
                {
                    _state = _states.stuck;
                }
                break;

            case _states.turn:
                if (_turnTimer++ < _turnTimerMax)
                {
                    _rotation -= (float)gameTime.ElapsedGameTime.TotalSeconds * _rotationStep * _turnLeft;
                }
                else
                {
                    _turnTimer = 0;
                    _state     = _states.wander;
                }
                break;

            case _states.stuck:
                if (_turnTimer++ < _turnTimerMax * 2)
                {
                    _rotation -= (float)gameTime.ElapsedGameTime.TotalSeconds * _rotationStep;
                }
                else
                {
                    _turnTimer = 0;
                    _state     = _states.wander;
                }
                break;

            case _states.rest:
                if (_restTimer++ < _restTimerMax)
                {
                    _stamina += 10;
                }
                else
                {
                    _restTimer = 0;
                    _state     = _states.wander;
                }
                break;

            case _states.dead:
                break;
            }
        }
Example #22
0
        private void CheckBoundaryCollision(GameTime gameTime, Rectangle limits)
        {
            int    MaxX  = limits.Width - (_longestSide / 2);
            int    MinX  = _longestSide / 2;
            int    MaxY  = limits.Height - (_longestSide / 2);
            int    MinY  = _longestSide / 2;
            double angle = RadianToDegree(_rotation);

            if (_position.X > MaxX)
            {
                _position.X = MaxX;
                _state      = _states.backup;
                if (angle > 0 && angle <= 90)
                {
                    _turnLeft = 1;
                }
                else
                {
                    _turnLeft = -1;
                }
            }
            else if (_position.X < MinX)
            {
                _position.X = MinX;
                _state      = _states.backup;
                if (angle > 180 && angle <= 270)
                {
                    _turnLeft = 1;
                }
                else
                {
                    _turnLeft = -1;
                }
            }

            if (_position.Y > MaxY)
            {
                _position.Y = MaxY;
                _state      = _states.backup;
                if (angle > 90 && angle <= 180)
                {
                    _turnLeft = 1;
                }
                else
                {
                    _turnLeft = -1;
                }
            }
            else if (_position.Y < MinY)
            {
                _position.Y = MinY;
                _state      = _states.backup;
                if (angle > 270 && angle <= 360)
                {
                    _turnLeft = 1;
                }
                else
                {
                    _turnLeft = -1;
                }
            }
        }
Example #23
0
 // Use this for initialization
 void Start()
 {
     _myState = _states.cell;
 }
Example #24
0
    void Update()
    {
        if (go == true)
        {
            Vector3[] WaypointArray = Paths(path);

            if (transform.position == waypoint)
            {
                waypointCount++;
            }

            if (Input.GetMouseButtonUp(0))
            {
                Invoke("Retrace", 0.1f);
            }

            if (fatigueBool == false)
            {
                fatigueCounter += Time.deltaTime * 0.5f;
            }
            if (fatigueCounter >= 10)
            {
                fatigueBool = true;
                unitStates  = _states.ship;
                states();
                fatigueCounter = 0;
            }
            if (timer == false)
            {
                count += Time.deltaTime;
            }
            if (count > 1)
            {
                count = 0;
                timer = true;
            }

            float minX = transform.position.x - 0.3f;
            float maxX = transform.position.x + 0.3f;
            float minY = transform.position.y - 0.3f;
            float maxY = transform.position.y + 0.3f;

            if (minX < ship.transform.position.x && maxX > ship.transform.position.x && minY < ship.transform.position.y && maxY > ship.transform.position.y && fatigueBool == true)
            {
                transform.position = ship.transform.position;
                fatigueBool        = false;
                if (starTaken == false)
                {
                    unitStates = _states.tradingpost;
                    states();
                }
                else if (starTaken == true)
                {
                    unitStates = _states.star;
                    states();
                }
            }

            if (minX < star.transform.position.x && maxX > star.transform.position.x && minY < star.transform.position.y && maxY > star.transform.position.y && timer == true && unitStates == _states.star)
            {
                transform.position = star.transform.position;
                states();

                timer = false;
            }
            else if (minX < tradingpost.transform.position.x && maxX > tradingpost.transform.position.x && minY < tradingpost.transform.position.y && maxY > tradingpost.transform.position.y && timer == true && unitStates == _states.tradingpost)
            {
                transform.position = tradingpost.transform.position;
                states();

                timer = false;
            }
            if (path != null)
            {
                waypoint = WaypointArray[waypointCount];
            }
            if (!Input.GetMouseButton(0) && path != null)
            {
                transform.position = Vector3.MoveTowards(transform.position, WaypointArray[waypointCount], speed * Time.deltaTime);
            }
        }
    }
 set => SetProperty(ref _states, value);
Example #26
0
        private void Move(GameTime gameTime)
        {
            float x, y;
            Matrix m;

            if (--_life == 0)
            {
                _state = _states.dead;
            }
            else if (_stamina < 1)
            {
                _state = _states.rest;
            }

            switch (_state)
            {
                case _states.wander:
                    if (_stuckCounter > 0) { _stuckCounter--; }
                    if (_wanderTimer++ >= _wanderTimerMax)
                    {
                        double d = _random.NextDouble();
                        if (d > 0.5)
                        {
                            _rotation -= (float)gameTime.ElapsedGameTime.TotalSeconds * _rotationStep;
                        }
                        else
                        {
                            _rotation += (float)gameTime.ElapsedGameTime.TotalSeconds * _rotationStep;
                        }
                        _wanderTimer = (int)(d * 10) + 10;
                    }
                    x = _position.X;
                    y = _position.Y;
                    m = Matrix.CreateRotationZ(_rotation);
                    x += m.M12 * (float)gameTime.ElapsedGameTime.TotalSeconds * _speed;
                    y -= m.M11 * (float)gameTime.ElapsedGameTime.TotalSeconds * _speed;
                    _position = new Vector2(x, y);
                    _stamina--;
                    break;
                case _states.backup:
                    if (_backupTimer++ < _backupTimerMax)
                    {
                        x = _position.X;
                        y = _position.Y;
                        m = Matrix.CreateRotationZ(_rotation);
                        x -= m.M12 * (float)gameTime.ElapsedGameTime.TotalSeconds * _speed;
                        y += m.M11 * (float)gameTime.ElapsedGameTime.TotalSeconds * _speed;
                        _position = new Vector2(x, y);
                    }
                    else
                    {
                        _backupTimer = 0;
                        _state = _states.turn;
                    }
                    _stamina--;
                    if (_stuckCounter++ > _stuckCounterMax)
                    {
                        _state = _states.stuck;
                    }
                    break;
                case _states.turn:
                    if (_turnTimer++ < _turnTimerMax)
                    {
                        _rotation -= (float)gameTime.ElapsedGameTime.TotalSeconds * _rotationStep * _turnLeft;
                    }
                    else
                    {
                        _turnTimer = 0;
                        _state = _states.wander;
                    }
                    break;
                case _states.stuck:
                    if (_turnTimer++ < _turnTimerMax*2)
                    {
                        _rotation -= (float)gameTime.ElapsedGameTime.TotalSeconds * _rotationStep;
                    }
                    else
                    {
                        _turnTimer = 0;
                        _state = _states.wander;
                    }
                    break;
                case _states.rest:
                    if (_restTimer++ < _restTimerMax)
                    {
                        _stamina += 10;
                    }
                    else
                    {
                        _restTimer = 0;
                        _state = _states.wander;
                    }
                    break;
                case _states.dead:
                    break;
            }
        }
Example #27
0
        private void CheckBoundaryCollision(GameTime gameTime, Rectangle limits)
        {
            int MaxX = limits.Width - (_longestSide / 2);
            int MinX = _longestSide / 2;
            int MaxY = limits.Height - (_longestSide / 2);
            int MinY = _longestSide / 2;
            double angle = RadianToDegree(_rotation);

            if (_position.X > MaxX)
            {
                _position.X = MaxX;
                _state = _states.backup;
                if (angle > 0 && angle <= 90)
                {
                    _turnLeft = 1;
                }
                else
                {
                    _turnLeft = -1;
                }
            }
            else if (_position.X < MinX)
            {
                _position.X = MinX;
                _state = _states.backup;
                if (angle > 180 && angle <= 270)
                {
                    _turnLeft = 1;
                }
                else
                {
                    _turnLeft = -1;
                }
            }

            if (_position.Y > MaxY)
            {
                _position.Y = MaxY;
                _state = _states.backup;
                if (angle > 90 && angle <= 180)
                {
                    _turnLeft = 1;
                }
                else
                {
                    _turnLeft = -1;
                }
            }
            else if (_position.Y < MinY)
            {
                _position.Y = MinY;
                _state = _states.backup;
                if (angle > 270 && angle <= 360)
                {
                    _turnLeft = 1;
                }
                else
                {
                    _turnLeft = -1;
                }
            }
        }