PreciseGameState( Dictionary<Player, PlayerPosition> playerPositions, Dictionary<Player, PlayerSpeed> playerSpeeds, BallPosition ballPosition, BallSpeed ballSpeed) { Contract.Requires<ArgumentNullException>(playerPositions != null); Contract.Requires<ArgumentNullException>(playerSpeeds != null); _playerPositions = playerPositions; _playerSpeeds = playerSpeeds; _ballPosition = ballPosition; _ballSpeed = ballSpeed; }
// Sets up initialImpulse to properly reflect the selected BallSpeed void SetSpeed(BallSpeed speed) { if (speed.Equals(BallSpeed.Slow)) { initialImpulse = new Vector3(0, 0, Random.Range(slowSpeedMin, slowSpeedMax)); } if (speed.Equals(BallSpeed.Medium)) { initialImpulse = transform.forward * Random.Range(medSpeedMin, medSpeedMax); } if (speed.Equals(BallSpeed.Fast)) { initialImpulse = transform.forward * Random.Range(fastSpeedMin, fastSpeedMax); } }
// Spawns ball with given difficulty parameters public void SpawnBall(BallSize size, BallSpeed speed, BallInitAngle initAngle, BallHorizDirection hDirect) { SetSpeed(speed); SetAngle(initAngle); SetSize(size); SetDirection(hDirect); Vector3 chosenSpawn = ChooseSpawn(); currBalls += 1; //vertDirection = Random.Range(0, 2) * 2 - 1; //initialImpulse = new Vector3(initialImpulse.x * horizDirection, initialImpulse.y, initialImpulse.z * vertDirection); ball.GetComponent <BallBehavior>().initialImpulse = initialImpulse; Instantiate(ball, chosenSpawn, Quaternion.identity); Debug.Log("Spawned ball."); ResetBallPrefab(); }