private void CreateSnakes() { // Delete any existing snakes first. // Cache the length of the player's snake? int playerSnakeLength = SerpentConsts.GetStartingSnakeLength(Side.Player, this.levelNum); if (this.playerSnake != null && this.playerSnake.Dead == false) { playerSnakeLength = this.playerSnake.Length; } DestroySnakes(); this.playerSnakeConf = this.playerSnakeConfig.GetComponent <SnakeConfig>(); CreatePlayerSnake(playerSnakeLength); this.enemySnakeConf = this.theme.EnemySnakeConfig; List <Snake> enemySnakes = GetEnemySnakes(); int currNumEnemySnakes = enemySnakes.Count; int snakeLength = SerpentConsts.GetStartingSnakeLength(Side.Enemy, this.levelNum); for (int i = 0; i < (this.maxNumEnemySnakes - currNumEnemySnakes); ++i) { CreateEnemySnake(snakeLength); } }
private Vector3 InterpolateFacing(SnakeSegment segment, SnakeTrail.SnakePosition lastCorner, float interpolation) { Vector3 firstDirectionVector = lastCorner.UnitVectorToPreviousPosition * -1.0f; Direction firstDirection = SerpentConsts.GetDirectionForVector(firstDirectionVector); Direction secondDirection = segment.CurrentDirection; Vector3 firstEulerAngles = SerpentConsts.RotationVector3[(int)firstDirection]; Vector3 secondEulerAngles = SerpentConsts.RotationVector3[(int)secondDirection]; // Compare the sign of the angles and make sure they are both positive or both negative to account for the circle. if (firstEulerAngles.z * secondEulerAngles.z < 0.0f) { // sign problem to do with west (90) and south (-180) if (firstEulerAngles.z < -90.0f) { firstEulerAngles *= -1.0f; } else { secondEulerAngles *= -1.0f; } } Vector3 currentEulerAngles = firstEulerAngles * (1.0f - interpolation) + secondEulerAngles * interpolation; return(currentEulerAngles); }
private void SetSegmentRotation(SnakeSegment bodySegment, SnakePosition position) { Direction dir = SerpentConsts.GetDirectionForVector(position.UnitVectorToPreviousPosition); if (dir == Direction.None) { return; } Direction oppositeDir = SerpentConsts.OppositeDirection[(int)dir]; bodySegment.CurrentDirection = oppositeDir; }