Beispiel #1
0
 private void Awake()
 {
     _tailGenerator = GetComponent <TailGenerator>();
     _input         = GetComponent <SnakeInput>();
     _tail          = _tailGenerator.Generate(_tailSize);
     SizeUpdated?.Invoke(_tail.Count);
 }
Beispiel #2
0
        private void Render(object sender, EventArgs e)
        {
            if (worldController.GetIsGameOver())
            {
                StartGame();
            }
            else
            {
#if player
                if (SnakeInput.KeyPressed(Keys.Right) && snakeSettings.headDirection != SnakeDirection.LEFT)
                {
                    snakeSettings.headDirection = SnakeDirection.RIGHT;
                }
                else if (SnakeInput.KeyPressed(Keys.Left) && snakeSettings.headDirection != SnakeDirection.RIGHT)
                {
                    snakeSettings.headDirection = SnakeDirection.LEFT;
                }
                else if (SnakeInput.KeyPressed(Keys.Up) && snakeSettings.headDirection != SnakeDirection.DOWN)
                {
                    snakeSettings.headDirection = SnakeDirection.UP;
                }
                else if (SnakeInput.KeyPressed(Keys.Down) && snakeSettings.headDirection != SnakeDirection.UP)
                {
                    snakeSettings.headDirection = SnakeDirection.DOWN;
                }
                else
                {
                    snakeSettings.headDirection = SnakeDirection.NULL;
                }
#else
                selfBrain.feed(worldController.Self.X, worldController.Self.Y, worldController.Target.X, worldController.Target.Y);
                worldController.Self.Direction = selfBrain.decide();
#endif
            }

            worldController.UpdateWorld();
            InputController.ClearTable();
            pbCanvas.Invalidate();
        }
    int snakeMoveDistance = 1; // the amount of units the snake travels per move. must be at one for this grid based game

    // Start is called before the first frame update
    void Start()
    {
        gmScript = GameObject.Find("GameManager").GetComponent<GameManager>(); // references GameManager script
        snakeInput = this.GetComponent<SnakeInput>();
        snakeGridPosition = new Vector2Int(10, 0);
    }
Beispiel #4
0
 private void Awake()
 {
     _tailGenerator = GetComponent <TailGenerator>();
     _snakeInput    = GetComponent <SnakeInput>();
     _tail          = _tailGenerator.GenerateStartTail(_tailSize, transform.position);
 }
 private void Start()
 {
     Input = gameObject.GetComponent <SnakeInput>();
 }