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(); + } + } +} 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; + } + } +} 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]; + } + } + + + +} 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"); + } +} 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; + } +} diff --git a/README.md b/README.md index b0bc48e..8bc58ca 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # UnityPublic -C#Scripts +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 +}