From 0bb435e223cb43125bef943f281dca00b743501b Mon Sep 17 00:00:00 2001 From: ZevilLacer <51844240+ZevilLacer@users.noreply.github.com> Date: Sat, 27 Jul 2019 17:59:05 +0530 Subject: [PATCH 1/8] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b0bc48e..38894d8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # UnityPublic -C#Scripts +C#Scripts used to make a copy of a 2D game "ARKANOID" + From 4e17e45b59971f695224b786809995bfa5300487 Mon Sep 17 00:00:00 2001 From: ZevilLacer <51844240+ZevilLacer@users.noreply.github.com> Date: Sat, 27 Jul 2019 18:05:10 +0530 Subject: [PATCH 2/8] Create BlockBreaker(ball_script) --- BlockBreaker(ball_script) | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 BlockBreaker(ball_script) diff --git a/BlockBreaker(ball_script) b/BlockBreaker(ball_script) new file mode 100644 index 0000000..ff7719f --- /dev/null +++ b/BlockBreaker(ball_script) @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ball : MonoBehaviour +{ + public paddle paddle; + private bool hasStarted = false; + + private Vector3 paddleToBallVector; + // Start is called before the first frame update + void Start() + { + paddle = GameObject.FindObjectOfType(); + paddleToBallVector = this.transform.position - paddle.transform.position; + } + + // Update is called once per frame + void Update() + { + if(!hasStarted) + { + this.transform.position = paddle.transform.position + paddleToBallVector; + if(Input.GetMouseButtonDown(0)) + { + print("button pressed"); + hasStarted = true; + GetComponent().velocity = new Vector2(Random.Range(1f,2f),Random.Range(7f,9f)); + } + } + } + + void OnCollisionEnter2D (Collision2D collsion) + { + Vector2 tweak = new Vector2 (Random.Range(0f,0.2f),Random.Range(0f,0.2f)); + if (hasStarted) + { + GetComponent().velocity += tweak; + } + } +} From f79ffb34b10c1ba8fe7e66e28042348c1caba77e Mon Sep 17 00:00:00 2001 From: ZevilLacer <51844240+ZevilLacer@users.noreply.github.com> Date: Sat, 27 Jul 2019 18:07:39 +0530 Subject: [PATCH 3/8] Create BlockBreaker(block_script) --- BlockBreaker(block_script) | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 BlockBreaker(block_script) diff --git a/BlockBreaker(block_script) b/BlockBreaker(block_script) new file mode 100644 index 0000000..54c8ecc --- /dev/null +++ b/BlockBreaker(block_script) @@ -0,0 +1,67 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class block : MonoBehaviour +{ + public AudioClip crack; + public Sprite[] hitSprites; + public static int breakableCount = 0; + public GameObject smoke; + private int timesHit; + private LevelManager levelManager; + private bool isBreakable; + // Start is called before the first frame update + void Start() + { + isBreakable = (this.tag=="Breakable"); + if(isBreakable) + { + breakableCount++; + print("breakableCount "+breakableCount); + } + timesHit=0; + levelManager = GameObject.FindObjectOfType(); + } + + // Update is called once per frame + void Update() + { + } + void OnCollisionEnter2D (Collision2D Col) + { + + if (isBreakable) + HandleHits(); + } + + void HandleHits() + { + timesHit++; + int maxHits = hitSprites.Length+1; + + if(timesHit>=maxHits) + { + breakableCount--; + print("breakableCount "+breakableCount); + levelManager.BrickDestroyed(); + Destroy(gameObject); + AudioSource.PlayClipAtPoint(crack,transform.position); + + } + else { + loadSprites(); + } + } + void loadSprites() + { + int spriteIndex = timesHit-1; + if (hitSprites[spriteIndex]) + { + this.GetComponent().sprite =hitSprites[spriteIndex]; + } + } + + + +} From 62acc5aa217e0b6c5ef4069b8abb1e8df91c9f6f Mon Sep 17 00:00:00 2001 From: ZevilLacer <51844240+ZevilLacer@users.noreply.github.com> Date: Sat, 27 Jul 2019 18:12:10 +0530 Subject: [PATCH 4/8] Create BlockBreaker(LevelManager_script) script used to change scenes of the game --- BlockBreaker(LevelManager_script) | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 BlockBreaker(LevelManager_script) diff --git a/BlockBreaker(LevelManager_script) b/BlockBreaker(LevelManager_script) new file mode 100644 index 0000000..2b87eb6 --- /dev/null +++ b/BlockBreaker(LevelManager_script) @@ -0,0 +1,36 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + + +public class LevelManager : MonoBehaviour +{ + public void LoadLevel(string name) + { + Debug.Log("Level load requested for "+name); + block.breakableCount=0; + Application.LoadLevel(name); + } + + + public void QuitRequest() + { + Debug.Log("I wanna quit!"); + Application.Quit(); + } + + public void LoadNextLevel() + { + block.breakableCount=0; + Application.LoadLevel(Application.loadedLevel+1); + } + + public void BrickDestroyed() + { + if(block.breakableCount <=0) + { + LoadNextLevel(); + } + } +} From b3afdb3e94d7d1f825e71933464cd53906445911 Mon Sep 17 00:00:00 2001 From: ZevilLacer <51844240+ZevilLacer@users.noreply.github.com> Date: Sat, 27 Jul 2019 18:16:05 +0530 Subject: [PATCH 5/8] Create BlockBreaker(losecollider_script) --- BlockBreaker(losecollider_script) | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 BlockBreaker(losecollider_script) diff --git a/BlockBreaker(losecollider_script) b/BlockBreaker(losecollider_script) new file mode 100644 index 0000000..17a76cf --- /dev/null +++ b/BlockBreaker(losecollider_script) @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class losecollider : MonoBehaviour +{ + public LevelManager LevelManager; + void OnTriggerEnter2D (Collider2D trigger) + { + print("Trigger"); + } + + void OnCollisionEnter2D (Collision2D collision) + { + print("collision"); + LevelManager.LoadLevel("lose"); + } +} From 562997e2d33dfb0c67117b32d119e4db795fabb9 Mon Sep 17 00:00:00 2001 From: ZevilLacer <51844240+ZevilLacer@users.noreply.github.com> Date: Sat, 27 Jul 2019 18:20:37 +0530 Subject: [PATCH 6/8] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 38894d8..c3e8c8f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # UnityPublic C#Scripts used to make a copy of a 2D game "ARKANOID" +{ +ball_script = script used to move ball +block_script = script for blocks + +levelmanager_script = used for changing scenes + +losecollider_script = used for making you lose a game if ball doesnt hits paddle + +paddle_script = used for moving paddle +} From 978ed4dbead5b91c0bdf9782938f8550fe825dfd Mon Sep 17 00:00:00 2001 From: ZevilLacer <51844240+ZevilLacer@users.noreply.github.com> Date: Sat, 27 Jul 2019 18:24:32 +0530 Subject: [PATCH 7/8] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c3e8c8f..8bc58ca 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # UnityPublic C#Scripts used to make a copy of a 2D game "ARKANOID" + + + + { ball_script = script used to move ball From 88358ecb8379c1a2de319000f82788cd5a3e7477 Mon Sep 17 00:00:00 2001 From: ZevilLacer <51844240+ZevilLacer@users.noreply.github.com> Date: Sat, 27 Jul 2019 18:25:45 +0530 Subject: [PATCH 8/8] Create BlockBreaker(paddle_script) --- BlockBreaker(paddle_script) | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 BlockBreaker(paddle_script) diff --git a/BlockBreaker(paddle_script) b/BlockBreaker(paddle_script) new file mode 100644 index 0000000..79865b3 --- /dev/null +++ b/BlockBreaker(paddle_script) @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class paddle : MonoBehaviour +{ + public bool autoPlay = false; + void Update() + { + MoveWithMouse(); + } + + void MoveWithMouse() + { + Vector3 paddlePos = new Vector3(0.5f,this.transform.position.y,0f); + float mousePosInBlocks = Input.mousePosition.x / Screen.width * 16; + paddlePos.x = Mathf.Clamp(mousePosInBlocks,1.09f,15.09f); + this.transform.position = paddlePos; + } +}