diff --git a/Assets/Scripts/Bosses/EnemySpawnController.cs b/Assets/Scripts/Bosses/EnemySpawnController.cs new file mode 100644 index 0000000000000000000000000000000000000000..53e435d2c593ea020f4ed0afa41044085b3cc098 --- /dev/null +++ b/Assets/Scripts/Bosses/EnemySpawnController.cs @@ -0,0 +1,42 @@ +using UnityEngine; +using UnityEngine.Serialization; +using Random = System.Random; + +public class EnemySpawnController : MonoBehaviour{ + private Main_camera _cameraScript; + private Player _player; + private Vector3 _newPos; + + [FormerlySerializedAs("OwlPrefab")] [SerializeField] private GameObject owlPrefab; + [FormerlySerializedAs("EnemySpawningOffset")] [SerializeField] private double enemySpawningOffset; + [SerializeField] private float ySpawningOffset; + + private static readonly Random Random = new Random(); + private void Start(){ + _cameraScript = GameManager.Instance.MainCamera.GetComponent<Main_camera>(); + _player = GameManager.Instance.Player; + _cameraScript.CameraMoved += CameraMove; + _newPos = _player.transform.position; + enemySpawningOffset = _cameraScript.ColliderSize.y * enemySpawningOffset; + } + + private void CameraMove(){ + var position = _player.transform.position; + var tmpPos = new Vector3(position.x, position.y + _cameraScript.ColliderSize.y * 2, position.z); + if (tmpPos.y - _newPos.y > enemySpawningOffset){ + _newPos = tmpPos; + var tmpRoute1 = new Vector3(-GameManager.Instance.x_offset, (float) (_newPos.y + GetRandomNumber(-ySpawningOffset, ySpawningOffset)), _newPos.z); + var tmpRoute2 = new Vector3(GameManager.Instance.x_offset, (float) (_newPos.y + GetRandomNumber(-ySpawningOffset, ySpawningOffset)), _newPos.z); + var newEnemy = Instantiate(owlPrefab, _newPos, Quaternion.identity); + newEnemy.GetComponent<Owl>().AddWayponts(new []{tmpRoute1, tmpRoute2}); + } + } + + private static double GetRandomNumber(double minValue, double maxValue) + { + var next = Random.NextDouble(); + var output = minValue + (next * (maxValue - minValue)); + print(output); + return output; + } +} diff --git a/Assets/Scripts/Bosses/EnemySpawnController.cs.meta b/Assets/Scripts/Bosses/EnemySpawnController.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..391dbc276e973ec6b1911851ce3d19416ccd0e5a --- /dev/null +++ b/Assets/Scripts/Bosses/EnemySpawnController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 76e401c1083713d4891fdd07806c39d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Camera.meta b/Assets/Scripts/Camera.meta new file mode 100644 index 0000000000000000000000000000000000000000..d23a474880dd4f502632459674331bdec0ca6bfb --- /dev/null +++ b/Assets/Scripts/Camera.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ce5d65d9e579b36458d835f2d8c3fead +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Camera/BackgroundInstance.cs b/Assets/Scripts/Camera/BackgroundInstance.cs new file mode 100644 index 0000000000000000000000000000000000000000..875f7063fe57e94b7cf8b5441791a8e3a9cf5dfb --- /dev/null +++ b/Assets/Scripts/Camera/BackgroundInstance.cs @@ -0,0 +1,49 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(BoxCollider2D))] + +public class BackgroundInstance : MonoBehaviour +{ + // Start is called before the first frame update + public BackgroundRoller roller; + bool flaggedForDelete = false; + + private void OnTriggerExit2D(Collider2D collision) + { + + if (collision.gameObject.CompareTag("MainCamera")) + { + Debug.Log("whoosh"); + + if(!flaggedForDelete) + { + flaggedForDelete = true; + StartCoroutine(DestroyCountdown()); + } + + + } + } + private void OnTriggerEnter2D(Collider2D collision) + { + if(collision.gameObject.CompareTag("MainCamera")) + { + Debug.Log("meow"); + roller.SetCurrentBgInstance(this.gameObject); + flaggedForDelete = false; + } + } + + private IEnumerator DestroyCountdown() + { + yield return new WaitForSeconds(10); + if(flaggedForDelete && gameObject!=null) + { + Debug.Log("Oh no we're doomed"); + Destroy(gameObject); + + } + } +} diff --git a/Assets/Scripts/Camera/BackgroundInstance.cs.meta b/Assets/Scripts/Camera/BackgroundInstance.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..3136b39253635ff367de672da8184d8c56b6e1c2 --- /dev/null +++ b/Assets/Scripts/Camera/BackgroundInstance.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 677803316bfc6c0408bf86ba89f7cdf1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Camera/BackgroundRoller.cs b/Assets/Scripts/Camera/BackgroundRoller.cs new file mode 100644 index 0000000000000000000000000000000000000000..dfbb816a7407f45484ddbf2d474cd7ea5ea41f6d --- /dev/null +++ b/Assets/Scripts/Camera/BackgroundRoller.cs @@ -0,0 +1,70 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BackgroundRoller : MonoBehaviour +{ + //rolls with constant speed now, could be adjusted to the movement speed of the platforms or the offset of the player + + + + private Camera camera; + public List<Sprite> bgSprites; + private int currentSprite = 0; + public GameObject currentBackgroundInstance; + public GameObject upcomingBackgroundInstance; + private BoxCollider2D bgCollider; + + public GameObject backgroundInstancePrefab; + + + void Start() + { + camera = Camera.main; + bgCollider = currentBackgroundInstance.GetComponent<BoxCollider2D>(); + settUpBackgroundInstance(currentBackgroundInstance); + } + + // Update is called once per frame + void Update() + { + Debug.Log("current spire" + currentSprite); + + if (currentSprite >= bgSprites.Count - 1) + { + currentSprite = -1; //never do this at home kids + } + + //if there are sprites left & we are over half the height, we instantiate another sprite at the top + if (currentSprite < bgSprites.Count - 1 && + camera.transform.position.y > currentBackgroundInstance.transform.position.y + bgCollider.size.y / 2 - camera.orthographicSize && + upcomingBackgroundInstance == null) + { + upcomingBackgroundInstance = Instantiate(backgroundInstancePrefab); + settUpBackgroundInstance(upcomingBackgroundInstance); + upcomingBackgroundInstance.transform.position = new Vector3(0, currentBackgroundInstance.transform.position.y + bgCollider.size.y * currentBackgroundInstance.transform.localScale.y, 0.1f); + + } + + + } + + public void SetCurrentBgInstance(GameObject bg) + { + currentBackgroundInstance = bg.gameObject; + upcomingBackgroundInstance = null; + bgCollider = bg.GetComponent<BoxCollider2D>(); + + } + + public void settUpBackgroundInstance(GameObject upcomingBackgroundInstance) + { + //https://answers.unity.com/questions/890148/scale-and-place-gameobject-as-a-background-of-the.html + //source + upcomingBackgroundInstance.transform.localScale = new Vector2((Camera.main.orthographicSize * 2 * Screen.width * 0.28f) / Screen.height, Camera.main.orthographicSize * 2 * 0.28f); + upcomingBackgroundInstance.transform.SetParent(transform); + upcomingBackgroundInstance.GetComponent<SpriteRenderer>().sprite = bgSprites[currentSprite]; + upcomingBackgroundInstance.GetComponent<BackgroundInstance>().roller = this; + currentSprite++; + } +} diff --git a/Assets/Scripts/Camera/BackgroundRoller.cs.meta b/Assets/Scripts/Camera/BackgroundRoller.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..1f4421da22b844c9d3980efb763960ee5fb59433 --- /dev/null +++ b/Assets/Scripts/Camera/BackgroundRoller.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 721bec2f5f1e48d4784acc70c548e367 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Camera/CameraController.cs b/Assets/Scripts/Camera/CameraController.cs new file mode 100644 index 0000000000000000000000000000000000000000..1a417067c650b8292d26295dce703c5857f85e92 --- /dev/null +++ b/Assets/Scripts/Camera/CameraController.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(BoxCollider2D))] +public class CameraController : MonoBehaviour +{ + //this script literally just sets the camera collider size to the size of the viewport + //put here any new camera functionality + public Transform playerTransform; + private Transform cameraTransform; + private int cameraSpeed; + public Vector3 velocity = Vector3.zero; + public float smoothTime = 0.2f; + void Start() + { + GetComponent<BoxCollider2D>().size = new Vector2(Camera.main.orthographicSize * Camera.main.aspect * 2, Camera.main.orthographicSize*2); //width, height + cameraTransform = Camera.main.transform; + } + + private void FixedUpdate() + { + if(playerTransform.position.y-cameraTransform.position.y>0.01)//if the player is higher than the middle of the camera + { + Vector3 targetPosition = new Vector3(cameraTransform.position.x, playerTransform.position.y, cameraTransform.position.z); + cameraTransform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime); + } + } + +} diff --git a/Assets/Scripts/Camera/CameraController.cs.meta b/Assets/Scripts/Camera/CameraController.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..df555f8fe31962c2fee43cd1ef6168466064ffe2 --- /dev/null +++ b/Assets/Scripts/Camera/CameraController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5a4449b2421c89a42b923468217fbf76 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Camera/FellOffController.cs b/Assets/Scripts/Camera/FellOffController.cs new file mode 100644 index 0000000000000000000000000000000000000000..2820e50053add147695f33c8e4f35bcb5c9c7156 --- /dev/null +++ b/Assets/Scripts/Camera/FellOffController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FellOffController : MonoBehaviour { + private Transform mainCameraTransform; + private Collider2D mainCameraCollider2D; + private Collider2D myCollider; + private bool falled = false; + + // Start is called before the first frame update + void Start() { + mainCameraTransform = GameManager.Instance.MainCamera.transform; + mainCameraCollider2D = GameManager.Instance.MainCamera.GetComponent<Collider2D>(); + myCollider = GetComponent<Collider2D>(); + + GetComponent<BoxCollider2D>().size = new Vector2(Camera.main.orthographicSize * Camera.main.aspect * 4, 1); + Vector2 nPos = mainCameraTransform.position; + nPos.y -= (mainCameraCollider2D.bounds.size.y / 2 + myCollider.bounds.size.y / 2); + transform.position = nPos; + } + + private void OnTriggerEnter2D(Collider2D other) { + if (other.CompareTag("Player")) { + if (!falled) + GameManager.Instance.FellDown(); + } + } + + private void OnTriggerExit2D(Collider2D other) { + if (falled) + GameManager.Instance.Player.hurt(); + } + + public void Fallen() { + falled = true; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Camera/FellOffController.cs.meta b/Assets/Scripts/Camera/FellOffController.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..d1eba2a4069c9707252de526d3b3765eb83afd7c --- /dev/null +++ b/Assets/Scripts/Camera/FellOffController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2c337c71b0ca81d4cabc0efcf6a32922 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Items/ItemDestroyer.cs b/Assets/Scripts/Items/ItemDestroyer.cs new file mode 100644 index 0000000000000000000000000000000000000000..b843267770ce6e7bbfd34559ac75bb841ec749ab --- /dev/null +++ b/Assets/Scripts/Items/ItemDestroyer.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ItemDestroyer : MonoBehaviour { + private List<Collider2D> colliders = new List<Collider2D>(); + private void OnTriggerExit2D(Collider2D col) { + // Ha platformmal talazunk + if (col.gameObject.CompareTag("Coin") && !colliders.Contains(col)) { + // Toroljuk azt aki lent volt + colliders.Add(col); + col.GetComponent<ItemBaseCollision>().DestroyItem(); + ItemSpawner.Instance.DecreaseCoinNum(); + } + + if (col.gameObject.CompareTag("SpecialItem") && !colliders.Contains(col)) { + // Toroljuk azt aki lent volt + colliders.Add(col); + col.GetComponent<ItemBaseCollision>().DestroyItem(); + ItemSpawner.Instance.DecreaseSpecialNum(); + } + } + + private void Update() { + colliders.Clear(); + } +} diff --git a/Assets/Scripts/Items/ItemDestroyer.cs.meta b/Assets/Scripts/Items/ItemDestroyer.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..c97e80665bfe4cfd5a2431855fb30203a41f30e2 --- /dev/null +++ b/Assets/Scripts/Items/ItemDestroyer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 62fff5dd8f0ce9a4ea3cc2832ef5e8a3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Items/ItemSpawner.cs b/Assets/Scripts/Items/ItemSpawner.cs new file mode 100644 index 0000000000000000000000000000000000000000..25cdb040aca7d222a33cded7929d7dcf710036b0 --- /dev/null +++ b/Assets/Scripts/Items/ItemSpawner.cs @@ -0,0 +1,105 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEditorInternal; +using UnityEngine; +using Random = UnityEngine.Random; + +public class ItemSpawner : MonoBehaviour { + public static ItemSpawner Instance { get; private set; } + private float width; + private float height; + + [Header("Special")] + [SerializeField] private float chanceToSpawnSpecial = 0.4f; + [SerializeField] private int maxSpecialNum = 3; + [SerializeField] private int minSpecialNum = 0; + [SerializeField] private BaseItemEffect[] specialItems; + private int specialNum; + + [Header("Coin")] + [SerializeField] private float chanceToSpawnCoin = 0.8f; + [SerializeField] private int maxCoinNum = 5; + [SerializeField] private int minCoinNum = 1; + [SerializeField] private Coin coinPrefab; + [SerializeField] private int minCoinValue = 50; + [SerializeField] private int maxCoinValue = 500; + private int coinNum; + + private float lastY; + private float m_PlayerY; + void Start() { + if (Instance != null) + Destroy(gameObject); + else + Instance = this; + + width = Camera.main.orthographicSize * Camera.main.aspect; + height = Camera.main.orthographicSize * 2; + m_PlayerY = GameManager.Instance.Player.transform.position.y; + + coinNum = 0; + specialNum = 0; + + lastY = m_PlayerY; + + SpawnItems(); + } + void Update() { + SpawnItems(); + } + private void SpawnItems() { + if (coinNum <= minCoinNum) { + for (int i = 0; i < (maxCoinNum - coinNum); ++i) { + if (Random.Range(0.0f, 1.0f) < chanceToSpawnCoin) { + SpawnCoin(); + } + } + + while (coinNum < minCoinNum) { + SpawnCoin(); + } + + lastY += height / 2; + } + + if (specialNum <= minSpecialNum) { + for (int i = 0; i < (maxSpecialNum - specialNum); ++i) { + if (Random.Range(0.0f, 1.0f) < chanceToSpawnSpecial) { + SpawnSpecial(); + } + } + + while (specialNum < minSpecialNum) { + SpawnSpecial(); + } + + lastY += height / 2; + } + } + private void SpawnCoin() { + var tmp = GenerateNextItemPos(); + Coin coin = Instantiate(coinPrefab, tmp, Quaternion.identity); + coin.coinBonusLowerBound = minCoinValue; + coin.coinBonusUpperBound = maxCoinValue; + coinNum++; + } + private void SpawnSpecial() { + var tmp = GenerateNextItemPos(); + Instantiate(specialItems[Random.Range(0, specialItems.Length)], tmp, Quaternion.identity); + specialNum++; + } + private Vector2 GenerateNextItemPos() { + + float x = Random.Range(-width / 2, width / 2); + float y = Mathf.Max(lastY, m_PlayerY) + Random.Range(0.2f, height / 2); + Vector2 tmp = new Vector2(x, y); + lastY = y; + return tmp; + } + public void DecreaseCoinNum() { + coinNum--; + } + public void DecreaseSpecialNum() { + specialNum--; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Items/ItemSpawner.cs.meta b/Assets/Scripts/Items/ItemSpawner.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..2246c9da6736ff0949156af492ace18f71dc3979 --- /dev/null +++ b/Assets/Scripts/Items/ItemSpawner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 616440c7c868257439ec39a2ac72a4b9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Menu.meta b/Assets/Scripts/Menu.meta new file mode 100644 index 0000000000000000000000000000000000000000..0c2fd245edb71c99251f0a011a9a2172422a0828 --- /dev/null +++ b/Assets/Scripts/Menu.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 55d7353e71a6515419d853d81ebe8b74 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Menu/MenuController.cs b/Assets/Scripts/Menu/MenuController.cs new file mode 100644 index 0000000000000000000000000000000000000000..ce48b5814b7a6ed77d135f680e4150eed315cb99 --- /dev/null +++ b/Assets/Scripts/Menu/MenuController.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MenuController : MonoBehaviour { + [SerializeField] private Animator mainMenuAnimator; + [SerializeField] private Animator optionAnimator; + [SerializeField] private Animator leaderboardAnimator; + + public void OptionButton() { + mainMenuAnimator.Play("MainOut"); + optionAnimator.Play("OptionIn"); + } + + public void BackButton() { + mainMenuAnimator.Play("MenuIn"); + optionAnimator.Play("OptionOut"); + } + + public void leaderboardButton() + { + mainMenuAnimator.Play("MainOut"); + leaderboardAnimator.Play("LeaderboardIn"); + } + + public void backButtonLeaderboard() + { + mainMenuAnimator.Play("MenuIn"); + leaderboardAnimator.Play("LeaderboardOut"); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Menu/MenuController.cs.meta b/Assets/Scripts/Menu/MenuController.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..6972fd2a91581663f32d6dedf4874ca7636f5d35 --- /dev/null +++ b/Assets/Scripts/Menu/MenuController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bc687a0428b1c9249907e57f5201647e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Menu/menuButtons.cs b/Assets/Scripts/Menu/menuButtons.cs new file mode 100644 index 0000000000000000000000000000000000000000..263fafa5bdba175620c98cfd96fdd4c07111cfd1 --- /dev/null +++ b/Assets/Scripts/Menu/menuButtons.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +public class menuButtons : MonoBehaviour +{ + public void playButtonPress() + { + SceneManager.LoadScene(1); + } + public void quitButtonPress() + { + Application.Quit(); + } +} + diff --git a/Assets/Scripts/Menu/menuButtons.cs.meta b/Assets/Scripts/Menu/menuButtons.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..f83c0bd30a0a23a2533666cdbd4761e6eee4ae06 --- /dev/null +++ b/Assets/Scripts/Menu/menuButtons.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 34767b4c9fb8a964581d2cbf1e9288e8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Platforms/OnkoltsegController.cs b/Assets/Scripts/Platforms/OnkoltsegController.cs new file mode 100644 index 0000000000000000000000000000000000000000..3cf72bc920094270368747c36abba391eba04738 --- /dev/null +++ b/Assets/Scripts/Platforms/OnkoltsegController.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class OnkoltsegController : MonoBehaviour { + [SerializeField] private float waitingTime = 3; + [SerializeField] private float raisingSpeed = 2; + + public float RaisingSpeed { + get => raisingSpeed; + set { + if (value <= 0) { + throw new ArgumentException("Onkoltseg Speed Cannot be zero or less."); + } + + raisingSpeed = value; + } + } + + public float WaitingTime { + get => waitingTime; + set { + if (value <= 0) { + throw new ArgumentException("Onkoltseg Time Cannot be zero or less."); + } + + waitingTime = value; + } + } + + public bool Enable{ get; set; } + + private Rigidbody2D _rb; + private float tmpWaitingTime; + private Transform mainCameraTransform; + private Collider2D mainCameraCollider2D; + private Collider2D myCollider; + + private bool moving; + + private bool end = false; + // Start is called before the first frame update + void Start(){ + Enable = false; + tmpWaitingTime = waitingTime; + moving = false; + _rb = GetComponent<Rigidbody2D>(); + myCollider = GetComponent<Collider2D>(); + mainCameraTransform = GameManager.Instance.MainCamera.transform; + mainCameraCollider2D = GameManager.Instance.MainCamera.GetComponent<Collider2D>(); + } + + public void ResetTimer() { + tmpWaitingTime = waitingTime; + if (moving) + _rb.velocity = Vector2.zero; + + moving = false; + } + + private void StartMoving() { + if (!Enable) return; + Vector2 nPos = mainCameraTransform.position; + nPos.y -= (mainCameraCollider2D.bounds.size.y / 2 + myCollider.bounds.size.y / 2); + transform.position = nPos; + moving = true; + + _rb.velocity = Vector2.up * raisingSpeed; + } + + private void Update() { + if (!Enable) return; + if (tmpWaitingTime <= 0 && !moving && !end) + StartMoving(); + else if (!moving && !end) + tmpWaitingTime -= Time.deltaTime; + } + + private void OnTriggerEnter2D(Collider2D other) { + // Elkerjuk az utkozestol az enemyt + Player player = other.GetComponent<Player>(); + // Megnezzuk, hogy tenyleg egy ellenseggel utkoztunk e + if (player) { + player.hurt(); + } + } + + public void GameEnd() { + end = true; + Vector2 nPos = mainCameraTransform.position; + nPos.y += (mainCameraCollider2D.bounds.size.y / 2 + myCollider.bounds.size.y / 2); + transform.position = nPos; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Platforms/OnkoltsegController.cs.meta b/Assets/Scripts/Platforms/OnkoltsegController.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..48d9d780c9ec4e37e98d74bd1a83fc46e3a3ab64 --- /dev/null +++ b/Assets/Scripts/Platforms/OnkoltsegController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3bc2e633913ded64886a4669a8dc1934 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/ScoreController.cs b/Assets/Scripts/Player/ScoreController.cs new file mode 100644 index 0000000000000000000000000000000000000000..e585467722330e9f85ec1e4d89e8bfa6c3149a72 --- /dev/null +++ b/Assets/Scripts/Player/ScoreController.cs @@ -0,0 +1,52 @@ +using System; +using UnityEngine; +using UnityEngine.UI; + +public class ScoreController : MonoBehaviour{ + private Player _player; + private int _start_pos; + private Text scoreText; + public double multiplier; + private double score; + + public string ScoreText{ + set => scoreText.text = value; + get => scoreText.text; + } + + public double BoostMultiplier{ + set{ + if (value > 0) + multiplier = value; + } + + get => multiplier; + } + + [SerializeField] private int pointDiffToHarden = 50; + private double pointToHarden; + public event Action HardenTheLevel; + + void Start() { + pointToHarden = pointDiffToHarden; + _player = GameManager.Instance.Player; + _start_pos = (int)_player.gameObject.transform.position.y; + scoreText = GetComponentInChildren<Text>(); + BoostMultiplier = 1; + score = 0; + } + + void Update(){ + var position = _player.gameObject.transform.position; + var scoreTmp = (int) position.y - _start_pos; + _start_pos = Math.Max((int)position.y, _start_pos); + if (scoreTmp > 0){ + score += scoreTmp * multiplier; + if (score / pointToHarden >= 1) { + pointToHarden += pointDiffToHarden; + HardenTheLevel?.Invoke(); + } + ScoreText = score.ToString(); + } + } +} diff --git a/Assets/Scripts/Player/ScoreController.cs.meta b/Assets/Scripts/Player/ScoreController.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..3a204b696470f99c502944d8a68ddf024e9a5b30 --- /dev/null +++ b/Assets/Scripts/Player/ScoreController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d67a4f3940499a1459177d175a88673e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: