private Point3[] GetOcclusionMapping(Dominant dominant, XDir xDir, YDir yDir, ZDir zDir) { if (dominant == Dominant.X) { return(new[] { new Point3((int)xDir, 0, (int)zDir), new Point3((int)xDir, (int)yDir, 0), new Point3((int)xDir, (int)yDir, (int)zDir), }); } if (dominant == Dominant.Y) { return(new[] { new Point3(0, (int)yDir, (int)zDir), new Point3((int)xDir, (int)yDir, 0), new Point3((int)xDir, (int)yDir, (int)zDir), }); } if (dominant == Dominant.Z) { return(new[] { new Point3(0, (int)yDir, (int)zDir), new Point3((int)xDir, 0, (int)zDir), new Point3((int)xDir, (int)yDir, (int)zDir), }); } throw new NotSupportedException(); }
private void Update() { if (GameControl.playerID == 1) { if (transform.position.y < BoardManager.ballBounds.min.y) { MatchManager.playerScore += 1; } else if (transform.position.y > BoardManager.ballBounds.max.y) { MatchManager.computerScore += 1; } } else if (GameControl.playerID == 2) { if (transform.position.y < BoardManager.ballBounds.min.y) { MatchManager.computerScore += 1; } else if (transform.position.y > BoardManager.ballBounds.max.y) { MatchManager.playerScore += 1; } } if ((transform.position.y < BoardManager.ballBounds.min.y) || (transform.position.y > BoardManager.ballBounds.max.y)) { for (int i = 0; i < paddles.Length; i++) { paddles[i].GetComponent <PaddleController>().ResetPaddle(); } if (MatchManager.playerScore + MatchManager.computerScore != 0 && (MatchManager.playerScore + MatchManager.computerScore) % 5 == 0) { MatchManager.ChangeServer(); MatchManager.displayText = true; MatchManager.changingServer = true; } gradient = 3f; SetBall(MatchManager.server); MatchManager.serve = false; } if (MatchManager.serve && !MatchManager.paused) { if (xDir == XDir.LEFT && transform.position.x < BoardManager.ballBounds.min.x) { BoardManager.collideSound.Play(); xDir = XDir.RIGHT; } else if (xDir == XDir.RIGHT && transform.position.x > BoardManager.ballBounds.max.x) { BoardManager.collideSound.Play(); xDir = XDir.LEFT; } MoveBall(); } }
public void SetBall(int server) { if (server == 1) { xDir = XDir.RIGHT; yDir = YDir.DOWN; transform.position = paddles[0].transform.position - ballPaddleOffset; } else if (server == 2) { xDir = XDir.LEFT; yDir = YDir.UP; transform.position = paddles[1].transform.position + ballPaddleOffset; } }
private void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.CompareTag("Paddle1") || other.gameObject.CompareTag("Paddle2")) { collideSound.Play(); PaddleState paddleState = other.gameObject.GetComponent <PaddleController>().paddleState; if (paddleState == PaddleState.PLAYER) { gradient = Random.Range(3, 6); } else if (paddleState == PaddleState.COMPUTER) { if (GameControl.difficulty == Difficulty.EASY) { gradient = Random.Range(4, 6); } else if (GameControl.difficulty == Difficulty.MEDIUM) { gradient = Random.Range(3, 6); } else if (GameControl.difficulty == Difficulty.HARD) { gradient = Random.Range(2, 6); } } contact = other.contacts[0].point; if (other.gameObject.CompareTag("Paddle1")) { if ((contact.x - paddles[0].transform.position.x) < 0f) { xDir = XDir.LEFT; } else if ((contact.x - paddles[0].transform.position.x) > 0f) { xDir = XDir.RIGHT; } } else if (other.gameObject.CompareTag("Paddle2")) { if ((contact.x - paddles[1].transform.position.x) < 0f) { xDir = XDir.LEFT; } else if ((contact.x - paddles[1].transform.position.x) > 0f) { xDir = XDir.RIGHT; } } if (yDir == YDir.UP) { yDir = YDir.DOWN; } else if (yDir == YDir.DOWN) { yDir = YDir.UP; } } }
public void MoveLeft() { x = XDir.Left; }
public void MoveRight() { x = XDir.Right; }
public void ResetMovement() { x = 0; y = 0; }
private int GetOcclusion(Dominant dominant, XDir xDir, YDir yDir, ZDir zDir) { return(CalculateOcclusion(GetOcclusionValues(GetOcclusionMapping(dominant, xDir, yDir, zDir)))); }