private void ChecksAndFinMovePoint() { if (Time.time - _OldTime > _TimeAddSpeed) { _OldTime = Time.time; _Speed += _AddSpeed; } if (Input.GetKey(KeyCode.D)) { _Racket_1.transform.position += (Vector3)(Vector2.right * (Time.deltaTime * _SpeedRacket)); _Racket_2.transform.position += (Vector3)(Vector2.right * (Time.deltaTime * _SpeedRacket)); if (_Racket_1.transform.position.x + (_Length / 2) > _Point[1].x || _Racket_2.transform.position.x + (_Length / 2) > _Point[1].x) { _Racket_1.transform.position = new Vector2(_Point[1].x - (_Length / 2), _Racket_1.transform.position.y); _Racket_2.transform.position = new Vector2(_Point[1].x - (_Length / 2), _Racket_2.transform.position.y); } } if (Input.GetKey(KeyCode.A)) { _Racket_1.transform.position += (Vector3)(Vector2.left * (Time.deltaTime * _SpeedRacket)); _Racket_2.transform.position += (Vector3)(Vector2.left * (Time.deltaTime * _SpeedRacket)); if (_Racket_1.transform.position.x - (_Length / 2) < _Point[0].x || _Racket_2.transform.position.x - (_Length / 2) < _Point[0].x) { _Racket_1.transform.position = new Vector2(_Point[0].x + (_Length / 2), _Racket_1.transform.position.y); _Racket_2.transform.position = new Vector2(_Point[0].x + (_Length / 2), _Racket_2.transform.position.y); } } Vector2 nextVect = _Dir * (Time.deltaTime * _Speed); Point point = CheckRacket((Vector2)_Ball.transform.position + nextVect); if (point != null) { _Ball.transform.position = new Vector3(point.x, point.y, 0); goto m1; } if (!CheckGameOver((Vector2)_Ball.transform.position + nextVect)) { _StateSission = StateSission.EndSession; goto m1; } point = CheckLineVertical((Vector2)_Ball.transform.position + nextVect); if (point != null) { _Ball.transform.position = new Vector3(point.x, point.y, 0); goto m1; } _Ball.transform.position += (Vector3)nextVect; m1 :; }
private void EndSession() { if (_Record < _Experience) { PlayerPrefs.SetInt("Record", _Experience); } _Ball.SetActive(false); _Racket_1.SetActive(false); _Racket_2.SetActive(false); _StateSission = StateSission.None; _IsPlaySession = false; if (_EndSession != null) { _EndSession(); } }
public void StartSession() { _IsPlaySession = true; _StateSission = StateSission.Settings; }
private void RandomDir() { _Dir = Random.insideUnitCircle.normalized; _StateSission = StateSission.ChecksAndFinMovePoint; }
private void SleepStart() { _StateSission = StateSission.RandomDir; }
private void Settings() { _Speed = _StartSpeed; _R = _StartR; _Length = _StartLength; _SpeedRacket = _StartSpeedRacket; _Experience = 0; _Record = PlayerPrefs.GetInt("Record"); if (_BallObj == null) { _BallObj = (GameObject)Resources.Load("Ball"); } if (_RacketObj == null) { _RacketObj = (GameObject)Resources.Load("Racket"); } Camera.main.orthographicSize = 1; float n = 0; if (Screen.height > Screen.width) { n = 1.0f / (Screen.height / (float)Screen.width); } else { n = 1.0f * (Screen.width / (float)Screen.height); } _Point[0] = new Vector2(n * -1, -1); _Point[1] = new Vector2(n, -1); _Point[2] = new Vector2(n, 1); _Point[3] = new Vector2(n * -1, 1); if (_Ball == null) { _Ball = Instantiate(_BallObj); _Ball.transform.localScale = new Vector3(_R * 2, _R * 2, _R * 2); _Ball.name = "Ball"; _Ball.transform.parent = transform; _Ball.transform.localPosition = Vector2.zero; } else { _Ball.transform.localPosition = Vector2.zero; _Ball.SetActive(true); } _Ball.GetComponent <SpriteRenderer>().color = _ColorBall; if (_Racket_1 == null) { _Racket_1 = Instantiate(_RacketObj); _Racket_1.transform.localScale = new Vector3(_Length, 0.05f, 1); _Racket_1.name = "Racket_1"; _Racket_1.transform.parent = transform; _Racket_1.transform.localPosition = new Vector2(0, -1 + 0.05f); } else { _Racket_1.transform.localPosition = new Vector2(0, -1 + 0.05f); _Racket_1.SetActive(true); } if (_Racket_2 == null) { _Racket_2 = Instantiate(_RacketObj); _Racket_2.transform.localScale = new Vector3(_Length, 0.05f, 1); _Racket_2.name = "Racket_2"; _Racket_2.transform.parent = transform; _Racket_2.transform.localPosition = new Vector2(0, 1 - 0.05f); } else { _Racket_2.transform.localPosition = new Vector2(0, 1 - 0.05f); _Racket_2.SetActive(true); } _StateSission = StateSission.SleepStart; _IsPlaySession = true; if (_StartSession != null) { _StartSession(); } }