public void InitMovement(DirectionHelper.Directions direction) { head.speed = speed; head.InitMovement(direction); ClientInitMovement(direction); }
public void ChangeDirection(DirectionHelper.Directions direction) { if (!isServer) { HandleFiller(direction); } if (!isMoving) { InitMovement(direction); StartMoving(); return; } //If the tail is newly created then start moving transform.position = new Vector3(nextLoc.x, transform.position.y, nextLoc.y); if (nextTail != null) { nextTail.ChangeDirection(movementDirection); } movementDirection = direction; SetNewNextLoc(); }
public void InitMovement(DirectionHelper.Directions direction) { movementDirection = direction; nextLoc = new Vector2(transform.position.x, transform.position.z); prevLoc = nextLoc; SetNewNextLoc(); if (nextTail != null) { nextTail.InitMovement(direction); } }
public void HeadReachedNextLoc() { movementDirection = nextDirection; head.ChangeDirection(movementDirection); ClientChangeHeadDirection(movementDirection); if (pendingTailCount > 0) { SpawnTail(pendingTailCount, false); } }
void Update() { if (!isLocal) { return; } HandleMovementInput(); CheckDirectionChange(); if (directionChange) { directionChange = false; inputDirection = tempInputDirection; SerndInputDirectionToServer(tempInputDirection); } }
public void HandleFiller(DirectionHelper.Directions direction) { // Checking For filler needs if (hasFiller) { Destroy(filler); hasFiller = false; } if (movementDirection != direction && !isEnd) { // Instantiate filler filler = Instantiate(fillerPrefab, new Vector3(nextLoc.x, transform.position.y, nextLoc.y), Quaternion.identity); hasFiller = true; } }
void HandleMovementInput() { Vector2 input = playerAction.Main.Move.ReadValue <Vector2>(); if (Mathf.Abs(input.x) > Mathf.Abs(input.y)) { tempInputDirection = input.x > 0 ? DirectionHelper.Directions.Right : DirectionHelper.Directions.Left; } else if (Mathf.Abs(input.y) > 0) { tempInputDirection = input.y > 0 ? DirectionHelper.Directions.Forward : DirectionHelper.Directions.Back; } else { //Do noting } }
public Snake SpawnSnake(Vector3 loc, DirectionHelper.Directions movementDirection) { Debug.Log("SPAWN SNAKE : PLAYER INDEX : " + playerIndex + " MATCH ID: " + networkMatchChecker.matchId); GameObject localSnakeObj = Instantiate(snakePrefab); localSnakeObj.transform.position = loc; localSnake = localSnakeObj.GetComponent <Snake>(); localSnake.SetMatchId(networkMatchChecker.matchId); localSnake.playerIndex = playerIndex; NetworkServer.Spawn(localSnakeObj); TargetAddInputHandler(); localSnake.InitMovement(movementDirection); localSnake.StartMoving(); localSnake.SpawnInitTail(); return(localSnake); }
public void ChangeNextDirection(DirectionHelper.Directions direction) { // check if the next direction can be in the provided direction switch (direction) { case DirectionHelper.Directions.Forward: if (movementDirection == DirectionHelper.Directions.Back) { return; } break; case DirectionHelper.Directions.Back: if (movementDirection == DirectionHelper.Directions.Forward) { return; } break; case DirectionHelper.Directions.Right: if (movementDirection == DirectionHelper.Directions.Left) { return; } break; case DirectionHelper.Directions.Left: if (movementDirection == DirectionHelper.Directions.Right) { return; } break; } nextDirection = direction; }
public void SerndInputDirectionToServer(DirectionHelper.Directions direction) { GetComponent <Player>().localSnake.ChangeNextDirection(direction); }
public void ClientInitMovement(DirectionHelper.Directions direction) { head.InitMovement(direction); }
public void ClientChangeHeadDirection(DirectionHelper.Directions direction) { movementDirection = direction; head.ChangeDirection(movementDirection); }