Brick Breaker

This is my very first project for Mediaheads, called Brick Breaker.

This game is created to serve as a mini game for the bigger Suitcase full of games project. When a player completes one of the various games from the Suitcase full of games, they are rewarded by being able to play one of three minigames, one of which is Brick Breaker. Including me, three trainees got the task to develop three different mini games. Because the audience of the Suitcase full of games is children with mental disabilities, the minigames were not allowed to use score or levels. Scores and levels could cause the player to get the feeling of failure and the goal of the minigames is to give the player a rewarding feeling after completing tasks/games from the suitcase full of games. Brick Breaker is a minigame that can be played forever. If the player is not able to keep the ball in play, the player will instantly get a ball back without getting a penalty. When all the blocks are destroyed, new blocks will spawn for the player. For every block the ball hits the ball changes colour e.g. if the ball hits a red block the ball's colour will change to red.

After completing the Suitcase full of games, Mediaheads decided not to use the minigames. The Suitcase full of games outgrew its expectations and no longer needed minigames.

Even though the minigames were cancelled, I enjoyed working on it, because for the first time ever I developed a game in commission of a legitimate company.

BB1PNG

BB2PNG

*These are just some of the scripts I created for this project, I cannot post all of them*

BB_BrickBreaker.cs
using UnityEngine; using System.Collections; using UnityEngine.UI; public class BB_BrickBreaker : MonoBehaviour { public int Bricks = 36; public int BrickBreakerScore; public float ResetDelay = 1.3f; public float BallMoveSpeed; public GameObject WallLeft; public GameObject WallRight; public GameObject WallTop; public GameObject WallBottom; public GameObject Paddle; public GameObject WallBumperL;
public GameObject WallBumperR; public GameObject BumperLeftTop; public GameObject BumperRightTop; public GameObject[] Brick; public static BB_BrickBreaker Instance = null; private GameObject clonePaddle; /// <summary> /// here we check if there already is a brickbreaker instance. If so, we destroy it. /// </summary> void Awake() { if (Instance == null) Instance = this; else if (Instance != this) Destroy(gameObject); Setup(); } /// <summary> /// here we call the methods to spawn bricks, walls and the paddle. /// </summary> public void Setup() { SetWalls(); SetBricks(); SetupPaddle(); } /// <summary> /// Here we check if the player's game is over if he destroyed all the bricks. /// We will make the great job message appear, destroy the paddle and ball, spawn the ball and paddle back in for the next round /// and we will higher the ball speed wich will make the game increasingly harder. /// </summary> void CheckGameOver() { if (Bricks < 1) { Destroy(GameObject.FindGameObjectWithTag("Ball"), 0.4f); Destroy(clonePaddle, 0.7f); Invoke("SetBricks", ResetDelay); Invoke("SetupPaddle", ResetDelay); BallMoveSpeed = BallMoveSpeed + 30f; float clampedSpeed = Mathf.Clamp(BallMoveSpeed, 170f, 400f); BallMoveSpeed = clampedSpeed; } } /// <summary> /// This is where we make a clone of the paddle prefab and then spawn in in the world. /// </summary> void SetupPaddle() { Vector3 paddlePos = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, -2.5f, 0)); clonePaddle = Instantiate(Paddle, paddlePos, Quaternion.identity) as GameObject; } /// <summary> /// setting up the wallpositions and instantiating them. /// </summary> void SetWalls() { //getting the positions for the walls relative to the screen width and heigth. Vector2 WallLeftPos = Camera.main.ScreenToWorldPoint(new Vector2(0, Screen.height / 2)); Vector2 WallRightPos = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height / 2)); Vector2 WallTopPos = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width / 2, Screen.height)); Vector2 WallBottomPos = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width / 2, 0)); Vector2 WallBumperLPos = Camera.main.ScreenToWorldPoint (new Vector2 (0, Screen.height / 2)); Vector2 WallBumperRPos = Camera.main.ScreenToWorldPoint (new Vector2 (Screen.width, Screen.height / 2)); Vector2 BumperTopRPos = Camera.main.ScreenToWorldPoint (new Vector2 (Screen.width, Screen.height)); Vector2 BumperTopLPos = Camera.main.ScreenToWorldPoint (new Vector2 (0, Screen.height)); //spawning the walls on their positions. Instantiate(WallLeft, WallLeftPos, Quaternion.identity); Instantiate (WallBumperL, WallBumperLPos, Quaternion.Euler(0,0,82)); Instantiate (BumperLeftTop, BumperTopLPos, Quaternion.Euler(0,0,-123)); Instantiate(WallRight, WallRightPos, Quaternion.identity); Instantiate (WallBumperR, WallBumperRPos, Quaternion.Euler(0,0,258)); Instantiate (BumperRightTop, BumperTopRPos, Quaternion.Euler(0,0,63)); Instantiate(WallTop, WallTopPos, Quaternion.identity); Instantiate(WallBottom, WallBottomPos, Quaternion.identity); } /// <summary> /// setting the amount of bricks and then instantiating them. /// </summary> void SetBricks() { Bricks = 36; Vector2 BrickPos = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width / 2, Screen.height / 10 * 5.6f)); Instantiate(Brick[Random.Range(0, Brick.Length)], BrickPos, Quaternion.identity); } /// <summary> /// when the ball is destroyed by a bounder we destroy the paddle, spawn the paddle and ball and lower the ball speed. /// </summary> public void OnBallDestroy() { Destroy(clonePaddle, 0.5f); Invoke("SetupPaddle", ResetDelay); BallMoveSpeed = BallMoveSpeed - 10f; float clampedSpeed = Mathf.Clamp(BallMoveSpeed, 200f, 450f); BallMoveSpeed = clampedSpeed; } /// <summary> /// when a brick is destroyed we lower the total bricks, update the score and check if the brick wasn't the last brick on the field /// </summary> public void DestroyBrick() { Bricks--; CheckGameOver(); } }
BB_BallMover.cs
using UnityEngine; using System.Collections; public class BB_BallMover : MonoBehaviour { public float BallInitialVelocity; private bool changeColorRed; private bool changeColorBlue; private bool changeColorGreen;
private bool changeColorYellow; private Rigidbody rb; private BB_BrickBreaker bb; private bool ballInPlay; private float minYVelocity = 0.5f; /// <summary> /// Seting references. /// </summary> void Awake() { rb = GetComponent<Rigidbody>(); bb = GameObject.FindGameObjectWithTag("BrickBreaker").gameObject.GetComponent<BB_BrickBreaker>(); } /// <summary> /// when there is a tap on the screen or when we press the LMB we want to start the game and launch the ball. /// </summary> void Update() { if (Input.GetMouseButtonDown(0) && ballInPlay == false) { transform.parent = null; ballInPlay = true; rb.isKinematic = false; rb.AddForce(new Vector3(bb.BallMoveSpeed, bb.BallMoveSpeed, 0)); } } void FixedUpdate() { if((rb.velocity.y < minYVelocity) && (Mathf.Sign(rb.velocity.y) == 1) && (ballInPlay == true)) { rb.AddForce (new Vector2 (0, -1f)); } if((rb.velocity.y > -minYVelocity) && (Mathf.Sign(rb.velocity.y) == -1) && (ballInPlay == true)) { rb.AddForce (new Vector2 (0, -1f)); } } /// <summary> /// check which brick we hit /// </summary> /// <param name="collision"</param> void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag ("Bumper")) { collision.collider.gameObject.GetComponent<BB_BumperScaler>().Grow(); } if (collision.gameObject.CompareTag("BrickRed")) { changeColorRed = true; CheckForColorChange(); } else if (collision.gameObject.CompareTag("BrickBlue")) { changeColorBlue = true; CheckForColorChange(); } else if (collision.gameObject.CompareTag("BrickGreen")) { changeColorGreen = true; CheckForColorChange(); } else if (collision.gameObject.CompareTag("BrickYellow")) { changeColorYellow = true; CheckForColorChange(); } } /// <summary> /// check if we have to change the color of the ball. and we need to activate the dubble points if we hit another brick of the same color as /// the ball. /// </summary> void CheckForColorChange() { if (changeColorRed == true) { transform.GetComponent<Renderer>().material.color = new Color32(255,78,78,255); //Red changeColorRed = false; } else if (changeColorBlue == true) { transform.GetComponent<Renderer>().material.color = new Color32(0,102,255,255); //Blue changeColorBlue = false; } else if (changeColorGreen == true) { transform.GetComponent<Renderer>().material.color = Color.green; changeColorGreen = false; } else if (changeColorYellow == true) { transform.GetComponent<Renderer>().material.color = Color.yellow; changeColorYellow = false; } } }