// Start is called before the first frame update void Start() { gameManager = FindObjectOfType <GameManager>(); iniBallPos = this.transform.position; currentBallState = ballState.aim; gameManager.ballsScene.Add(this.gameObject); }
/// <summary> /// Sets all the variables up that are nessasary for the ball to have basic functionality /// </summary> protected virtual void Start() { forceSlider.maxValue = maxForce; forceSlider.minValue = minForce; force = minForce; rb = this.GetComponent <Rigidbody>(); state = ballState.Stationary; stokeCount.SetText("Strokes " + strokes); }
// Use this for initialization void Start() { float leftSideOfScreen = Camera.main.transform.position.x - Camera.main.orthographicSize * Screen.width / Screen.height; //Debug.Log(leftSideOfScreen); gameManager = FindObjectOfType <GameManager>(); currentBallState = ballState.aim; startY = arrow.GetComponent <LineRenderer>().GetPosition(1).y; gameManager.ballsInScene.Add(this.gameObject); }
public void ReleaseMouse() { lineRenderer.enabled = false; isClicked = false; ballVelocityX = mouseStartPosition.x - mouseEndPosition.x; ballVelocityY = Mathf.Abs(mouseStartPosition.y - mouseEndPosition.y); tempVelocity = new Vector2(-ballVelocityX, ballVelocityY).normalized; ballLaunchPosition = transform.position; StartCoroutine(gameManager.FastBall()); currentBallState = ballState.fire; }
void Start() { currentBallState = ballState.AIM; ballWaitTimeSeconds = ballWaitTime; numOfBalls = 1; extraBallPowerup = 0; numOfBallsToFire = numOfBalls; numOfBallsText.text = "" + numOfBalls; errorBallTimer = 0f; }
// Use this for initialization void Start() { brickMoveController = FindObjectOfType <BrickMoveController>(); gameManager = FindObjectOfType <GameManager>(); currentBallState = ballState.AIM; ballWaitTimeSeconds = ballWaitTime; numOfBalls = 1; extraBallPowerup = 0; numOfBallsToFire = numOfBalls; numOfBallsText.text = "" + numOfBalls; errorBallTimer = 0f; }
public void ballDown() { tempVelocity = new Vector2(0, -ballVelocityY).normalized; if (currentBallState == ballState.fire || currentBallState == ballState.wait) { stopButton.interactable = false; gameManager.ballsInScene.ForEach(c => c.GetComponent <Rigidbody2D>().velocity = constantSpeed * tempVelocity * 2); FindObjectOfType <ExtraBallManager>().numberOfBallsToFire = 0; currentBallState = BallControl.ballState.wait; ColliderChangeEnable(false); } }
void Start() { targetPositionOfStopButton = new Vector2(0f, -9f); initialPositionOfStopButton = new Vector2(0f, -13f); constantSpeed = 20.0f; isClicked = false; specialItemManager = FindObjectOfType <SpecialItemManager>(); lineRenderer = this.GetComponent <LineRenderer>(); endGameManager = FindObjectOfType <EndGameManager>(); gameManager = FindObjectOfType <GameManager>(); currentBallState = ballState.aim; lineRenderer.enabled = false; }
/// <summary> /// Checks if the ball has been hit and prevents the user from hitting the ball whilst its still moving /// </summary> protected virtual void BallHit() { if (addStroke == true) { strokes++; stokeCount.SetText("Strokes " + strokes); addStroke = false; } if (rb.velocity == Vector3.zero) { state = ballState.Stationary; } }
// Update is called once per frame void Update() { switch (currentBallState) { case ballState.aim: if (Input.GetMouseButtonDown(0)) { MouseClicked(); } if (Input.GetMouseButton(0)) { MouseDragged(); } if (Input.GetMouseButtonUp(0)) { ReleaseMouse(); } break; case ballState.fire: break; case ballState.wait: //currentBallState = ballState.endShot; Debug.Log("wait shot: " + gameManager.bricksInScene.Count); if (gameManager.ballsInScene.Count == 1) { currentBallState = ballState.endShot; } break; case ballState.endShot: Debug.Log("End shot: " + gameManager.bricksInScene.Count); for (int i = 0; i < gameManager.bricksInScene.Count; i++) { gameManager.bricksInScene[i].GetComponent <BrickMovomentController>().currentState = BrickMovomentController.brickState.move; } gameManager.PlaceBricks(); Debug.Log("Befour shot: ballState.aim"); currentBallState = ballState.aim; break; case ballState.endGame: break; default: break; } }
public void ReleaseMouse() { arrow.SetActive(false); mouseEndPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); ballVelocityX = (mouseStartPosition.x - mouseEndPosition.x); ballVelocityY = (mouseStartPosition.y - mouseEndPosition.y); tempVelocity = new Vector2(ballVelocityX, ballVelocityY).normalized; ball.velocity = constantSpeed * tempVelocity; if (ball.velocity == Vector2.zero) { return; } ballLaunchPosition = transform.position; currentBallState = ballState.fire; }
public void ReleaseMouse() { Arrow.SetActive(false); mouseEndPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //ballVelocityX = (mouseStartPos.x - mouseEndPos.x); ballVelocityY = (mouseStartPos.y - mouseEndPos.y); if (ballVelocityY <= 0) { ballVelocityY = 0.01f; } ballVelocityX = Mathf.Clamp((mouseStartPos.x - mouseEndPos.x), ballVelocityY * -Mathf.Tan(Mathf.Deg2Rad * 75), ballVelocityY * Mathf.Tan(Mathf.Deg2Rad * 75)); tmpVelocity = new Vector2(ballVelocityX, ballVelocityY).normalized; if (tmpVelocity == Vector2.zero) { return; } ballLunchPos = transform.position; currentBallState = ballState.FIRE; }
public void TouchInput2() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); Vector2 playPosition = Camera.main.ScreenToWorldPoint(touch.position); if (touch.phase == TouchPhase.Began && playArea(playPosition)) { mouseStartPosition = this.transform.position; isClicked = true; lineRenderer.enabled = true; } if (touch.phase == TouchPhase.Moved && playArea(playPosition) && isClicked) { lineRenderer.enabled = true; Vector2 tempMousePosition = Camera.main.ScreenToWorldPoint(touch.position); float diffX = mouseStartPosition.x - tempMousePosition.x; float diffY = Mathf.Abs(mouseStartPosition.y - tempMousePosition.y); RayCastGuide(diffX, diffY); } else if (touch.phase == TouchPhase.Moved && !playArea(playPosition) && isClicked) { lineRenderer.enabled = false; } if (touch.phase == TouchPhase.Ended && playArea(playPosition) && isClicked) { lineRenderer.enabled = false; isClicked = false; mouseEndPosition = Camera.main.ScreenToWorldPoint(touch.position); ballVelocityX = mouseStartPosition.x - mouseEndPosition.x; ballVelocityY = Mathf.Abs(mouseStartPosition.y - mouseEndPosition.y); tempVelocity = new Vector2(-ballVelocityX, ballVelocityY).normalized; ballLaunchPosition = transform.position; currentBallState = ballState.fire; StartCoroutine(gameManager.FastBall()); } else if (touch.phase == TouchPhase.Ended && !playArea(playPosition) && isClicked) { lineRenderer.enabled = false; } } }
// Update is called once per frame void Update() { switch (currentBallState) { case ballState.aim: if (Input.GetMouseButtonDown(0)) { MouseClicked(); } if (Input.GetMouseButton(0)) { MouseDragged(); } if (Input.GetMouseButtonUp(0)) { ReleaseMouse(); } break; case ballState.fire: break; case ballState.wait: currentBallState = ballState.endShot; break; case ballState.endShot: for (int i = 0; i < gameManager.bricksInScene.Count; i++) { gameManager.bricksInScene[i].GetComponent <BrickMovementController>().currentState = BrickMovementController.brickState.move; } gameManager.PlaceBricks(); currentBallState = ballState.aim; break; default: break; } }
public void MainReleaseMouse() { arrow.SetActive(false); reflectArrow.SetActive(false); mouseEndPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); //ballVelocityX = (mouseStartPosition.x - mouseEndPosition.x); //ballVelocityY = (mouseStartPosition.y - mouseEndPosition.y); //Vector2 tempVelocity = new Vector2(ballVelocityX, ballVelocityY).normalized; //ball.velocity = tempVelocity*constantSpeed; ballVelocityX = velosity.x; ballVelocityY = velosity.y; tempVelocity = new Vector2(ballVelocityX, ballVelocityY).normalized; ball.velocity = tempVelocity * constantSpeed; launchVelocity = ball.velocity; //Debug.Log(ball.velocity + " " + tempVelocity); if (ball.velocity == Vector2.zero) { return; } ballLounchPosition = transform.position; currentBallState = ballState.fire; }
public void ReleaseMouse() { arrow.SetActive(false); //Obtenemos la posición del mouse al momento de levantar el botón //Esta posición será con respecto a la posición de la pantalla mouseEndPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); //Ontenemos la distancia entre los puntos X y Y ballVelocityX = (iniBallPos.x - mouseEndPosition.x); ballVelocityY = (iniBallPos.y - mouseEndPosition.y); //Damos la velocidad dependiendo del vector normalizado de las distancias tempVelocity = new Vector2(ballVelocityX, ballVelocityY).normalized; //Damos la velocidad a la bola ball.GetComponent <Rigidbody2D>().velocity = -constantSpeed * tempVelocity; if (ball.GetComponent <Rigidbody2D>().velocity == Vector2.zero) { return; } ballLaunchPosition = transform.position; //Pasamos al estado fire currentBallState = ballState.fire; }
void Update() { switch (currentBallState) { case ballState.AIM: GetComponent <SpriteRenderer>().enabled = true; if (Input.GetMouseButtonDown(0)) { MouseClicked(); } if (Input.GetMouseButton(0)) { MouseDragged(); } if (Input.GetMouseButtonUp(0)) { ballinScence = new ArrayList(); ReleaseMouse(); } break; case ballState.FIRE: if (numOfBallsToFire > 0) { if (ballWaitTimeSeconds <= 0) { FireBall(); } } else { GetComponent <SpriteRenderer>().enabled = false; currentBallState = ballState.ENDSHOT; } break; case ballState.ENDSHOT: //GetComponent<SpriteRenderer>().enabled = true; errorBallTimer += Time.deltaTime; if (errorBallTimer > 10f) { errorBallTimer = 0f; if (ErrorBall() != -1) { gameManager.ErrorBouncePowerup(ErrorBall()); } } break; case ballState.NEXTLEVEL: ballinScence.Clear(); numOfBalls += extraBallPowerup; numOfBallsToFire = numOfBalls; extraBallPowerup = 0; brickMoveController.BricksMove(); currentBallState = ballState.AIM; break; case ballState.ENDGAME: break; default: break; } numOfBallsText.text = "" + numOfBallsToFire; ballWaitTimeSeconds -= Time.deltaTime; errorBallTimer += Time.deltaTime; }
public void changeBallState(ballState newState) { currentState = newState; }
// Use this for initialization void Start() { gameManager = FindObjectOfType <GameManager>(); currentBallState = ballState.aim; }
// Use this for initialization void Start() { gameManager = FindObjectOfType <GameManager>(); currentBallState = ballState.aim; gameManager.ballsInScene.Add(this.gameObject); }
void Update() { if (Input.GetKeyDown(KeyCode.Space)) { ballDown(); } switch (currentBallState) { case ballState.aim: MouseInput(); TouchInput2(); if (specialItemManager.damage == 2) { this.gameObject.GetComponent <SpriteRenderer>().color = new Color(1f, 0f, 0f); } else if (specialItemManager.damage == 1) { this.gameObject.GetComponent <SpriteRenderer>().color = new Color(0.9716981f, 0.8459923f, 0.7196066f); } stopButton.interactable = true; stopButton.transform.position = Vector2.MoveTowards(stopButton.transform.position, initialPositionOfStopButton, 20 * Time.deltaTime); specialItem.transform.position = Vector2.MoveTowards(specialItem.transform.position, new Vector2(0f, 0f), 20 * Time.deltaTime); break; case ballState.fire: stopButton.transform.position = Vector2.MoveTowards(stopButton.transform.position, targetPositionOfStopButton, 20 * Time.deltaTime); specialItem.transform.position = Vector2.MoveTowards(specialItem.transform.position, new Vector2(0f, -5.5f), 20 * Time.deltaTime); break; case ballState.wait: if (gameManager.ballsInScene.Count == 0) { StopAllCoroutines(); currentBallState = ballState.endShot; } break; case ballState.endShot: constantSpeed = 20.0f; currentBallState = ballState.aim; for (int i = 0; i < gameManager.bricksInScene.Count; i++) { gameManager.bricksInScene[i].GetComponent <BrickMovementControl>().currentState = BrickMovementControl.brickState.move; } ColliderChangeEnable(true); gameManager.PlaceBricks(); transform.position = FindObjectOfType <BallStop>().firstBalltoLand.transform.position; FindObjectOfType <BallStop>().firstBalltoLand.GetComponent <BallMovement>().firstBall = false; FindObjectOfType <BallStop>().firstBalltoLand.SetActive(false); FindObjectOfType <BallStop>().isFirstBallLanded = false; FindObjectOfType <BallStop>().firstBalltoLand = null; specialItemManager.BallsNormalize(); break; case ballState.endGame: break; case ballState.pause: if (endGameManager.isPaused == false) { currentBallState = tempBallState; } break; default: break; } }