Esempio n. 1
0
    /*
     * Set the position for a non player snake. Does nothing if pos is not valid
     * */
    void UpdateNPSnakePosition(PositionUpdate pos)
    {
        int id = pos.id;

        if (ValidateNPID(id) && CheckUpToDate(id, pos.timestamp))
        {
            float elapsedTime = Math.Abs(GameManager.instance.gameTime - pos.timestamp);

            var expected = GlobalConsts.ClampToRange(pos.position + (pos.direction * 4 * elapsedTime / 1000), new Vector2(25f, 25f));

            lastUpdateTimes[id] = pos.timestamp;

            npTargets[id].position = expected;
            npTargets[id].up       = pos.direction;
        }
    }
Esempio n. 2
0
    // Move the segment foward
    void FixedUpdate()
    {
        //Only send update if direction has changed
        if (transform.up != lastDir && GameManager.instance.gameRunning)
        {
            MessageSystem.instance.DispatchMessage(new PositionUpdate(GameManager.instance.id, transform.position, transform.up, MessageType.SEND_PLAYER_POSITION));
            lastDir = transform.up;
        }

        FollowMouse();

        rb.velocity = transform.up * GlobalConsts.SNAKE_SPEED;
        UpdateSegments();

        transform.position = GlobalConsts.ClampToRange(transform.position, GlobalConsts.FIELD_SIZE);



        if (segments.Count > GlobalConsts.MAX_SNAKE_LENGTH)
        {
            Debug.Log("You win!");
            MessageSystem.instance.DispatchMessage(new EndGame(EndType.END_WIN, MessageType.END_GAME, "Your snake is greater then " + GlobalConsts.MAX_SNAKE_LENGTH + " segments "));
        }
    }
Esempio n. 3
0
 // Update is called once per frame
 void FixedUpdate()
 {
     rb.velocity        = transform.up * GlobalConsts.SNAKE_SPEED;
     transform.position = GlobalConsts.ClampToRange(transform.position, new Vector2(25, 25));
 }