using DiscordRPC; using UnityEngine; public class Game : MonoBehaviour { public float spawnRate = 1f; private float nextSpawnTime; private bool gameRunning = true; private int score; private float boostLeft; public float screenWidth; private void Start() { screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect; GameObject obj = new GameObject("Bird"); obj.AddComponent(); obj.AddComponent(); obj.GetComponent().gravityScale = 0f; obj.GetComponent().velocity = new Vector2(0f, 0f); obj.transform.position = new Vector3(0f, -4.5f, 0f); obj.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f); obj.GetComponent().sprite = Resources.Load("bird"); GameObject obj2 = new GameObject("ScoreText"); obj2.AddComponent(); obj2.GetComponent().text = "Score: 0"; obj2.GetComponent().characterSize = 0.1f; obj2.GetComponent().fontSize = 100; obj2.GetComponent().color = Color.white; obj2.GetComponent().anchor = TextAnchor.MiddleCenter; obj2.transform.position = new Vector3(0f, 4f, 0f); GameObject obj3 = new GameObject("BoostText"); obj3.AddComponent(); obj3.GetComponent().text = ""; obj3.GetComponent().characterSize = 0.1f; obj3.GetComponent().fontSize = 50; obj3.GetComponent().color = Color.white; obj3.GetComponent().anchor = TextAnchor.MiddleCenter; obj3.transform.position = new Vector3(0f, 3f, 0f); if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.LinuxPlayer || Application.platform == RuntimePlatform.OSXPlayer) { DiscordRpcClient discordRpcClient = new DiscordRpcClient("1216934858182361148"); discordRpcClient.Initialize(); discordRpcClient.SetPresence(new RichPresence { Details = "Playing Foodie Dash", State = "Eating Berries", Assets = new Assets { LargeImageKey = "https://foodiedash.xytriza.com/assets/bird.png", LargeImageText = "Foodie Dash", SmallImageKey = "https://xytriza.com/assets/icon.png", SmallImageText = "Made by Xytriza!" }, Timestamps = Timestamps.Now }); } if (Application.isMobilePlatform) { GameObject gameObject = new GameObject("LeftArrow"); GameObject gameObject2 = new GameObject("RightArrow"); GameObject obj4 = new GameObject("RestartButton"); gameObject.AddComponent(); gameObject2.AddComponent(); obj4.AddComponent(); gameObject.GetComponent().sprite = Resources.Load("left"); gameObject2.GetComponent().sprite = Resources.Load("right"); obj4.GetComponent().sprite = Resources.Load("restart"); gameObject.transform.position = new Vector3((0f - screenWidth) / 2.5f, -4f, 0f); gameObject2.transform.position = new Vector3(screenWidth / 2.5f, -4f, 0f); obj4.transform.position = new Vector3(screenWidth / 2.17f, Camera.main.orthographicSize - 1f, 0f); } if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { Screen.orientation = ScreenOrientation.LandscapeLeft; } } private void MoveBird() { if (!gameRunning) { return; } GameObject gameObject = GameObject.Find("Bird"); float num = Camera.main.orthographicSize * 2f * Camera.main.aspect; float num2 = 0.18f; if (boostLeft > 0f) { num2 = 0.25f + 0.002f * (float)(int)boostLeft; } if (!Application.isMobilePlatform) { if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { gameObject.transform.position += new Vector3(0f - num2, 0f, 0f); ClampPosition(num, gameObject); gameObject.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f); } if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { gameObject.transform.position += new Vector3(num2, 0f, 0f); ClampPosition(num, gameObject); gameObject.transform.localScale = new Vector3(-1.35f, 1.35f, 1.35f); } if (Input.GetKey(KeyCode.R)) { gameObject.transform.position = new Vector3(0f, -4.5f, 0f); gameObject.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f); score = 0; boostLeft = 0f; UpdateScore(score); GameObject[] array = GameObject.FindGameObjectsWithTag("Berry"); GameObject[] array2 = GameObject.FindGameObjectsWithTag("PoisonBerry"); GameObject[] array3 = GameObject.FindGameObjectsWithTag("UltraBerry"); GameObject[] array4 = array; for (int i = 0; i < array4.Length; i++) { Object.Destroy(array4[i]); } array4 = array2; for (int i = 0; i < array4.Length; i++) { Object.Destroy(array4[i]); } array4 = array3; for (int i = 0; i < array4.Length; i++) { Object.Destroy(array4[i]); } } return; } GameObject gameObject2 = GameObject.Find("LeftArrow"); GameObject gameObject3 = GameObject.Find("RightArrow"); GameObject gameObject4 = GameObject.Find("RestartButton"); if (Input.touchCount <= 0) { return; } Touch touch = Input.GetTouch(0); Vector3 point = Camera.main.ScreenToWorldPoint(touch.position); point.z = 0f; if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) { if (gameObject2.GetComponent().bounds.Contains(point)) { gameObject.transform.position += new Vector3(0f - num2, 0f, 0f); ClampPosition(num, gameObject); gameObject.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f); } if (gameObject3.GetComponent().bounds.Contains(point)) { gameObject.transform.position += new Vector3(num2, 0f, 0f); ClampPosition(num, gameObject); gameObject.transform.localScale = new Vector3(-1.35f, 1.35f, 1.35f); } } if (touch.phase == TouchPhase.Began && gameObject4.GetComponent().bounds.Contains(point)) { gameObject.transform.position = new Vector3(0f, -4.5f, 0f); gameObject.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f); score = 0; boostLeft = 0f; UpdateScore(score); GameObject[] array5 = GameObject.FindGameObjectsWithTag("Berry"); GameObject[] array6 = GameObject.FindGameObjectsWithTag("PoisonBerry"); GameObject[] array7 = GameObject.FindGameObjectsWithTag("UltraBerry"); GameObject[] array4 = array5; for (int i = 0; i < array4.Length; i++) { Object.Destroy(array4[i]); } array4 = array6; for (int i = 0; i < array4.Length; i++) { Object.Destroy(array4[i]); } array4 = array7; for (int i = 0; i < array4.Length; i++) { Object.Destroy(array4[i]); } } } private void ClampPosition(float screenWidth, GameObject bird) { float num = screenWidth / 2.17f; float x = Mathf.Clamp(bird.transform.position.x, 0f - num, num); bird.transform.position = new Vector3(x, bird.transform.position.y, bird.transform.position.z); } private void FixedUpdate() { MoveBird(); SpawnBerries(); if (boostLeft > 0f) { boostLeft -= Time.deltaTime; GameObject.Find("BoostText").GetComponent().text = "Boost expires in " + $"{boostLeft:0.00}" + "s"; } else { GameObject.Find("BoostText").GetComponent().text = ""; } if (Application.platform == RuntimePlatform.WindowsPlayer && Input.GetKey(KeyCode.Escape)) { Application.Quit(); } } private void SpawnBerries() { if (Time.time >= nextSpawnTime && gameRunning) { nextSpawnTime = Time.time + 1f / spawnRate; float value = Random.value; GameObject gameObject; if (value <= 0.7f) { gameObject = new GameObject("Berry"); gameObject.AddComponent().sprite = Resources.Load("Berry"); gameObject.tag = "Berry"; } else if (value <= 0.9f) { gameObject = new GameObject("PoisonBerry"); gameObject.AddComponent().sprite = Resources.Load("PoisonBerry"); gameObject.tag = "PoisonBerry"; } else { gameObject = new GameObject("UltraBerry"); gameObject.AddComponent().sprite = Resources.Load("UltraBerry"); gameObject.tag = "UltraBerry"; } float num = Camera.main.orthographicSize * 2f * Camera.main.aspect; float x = Random.Range((0f - num) / 2.17f, num / 2.17f); gameObject.transform.position = new Vector3(x, Camera.main.orthographicSize + 1f, 0f); Rigidbody2D rigidbody2D = gameObject.AddComponent(); rigidbody2D.gravityScale = 0f; rigidbody2D.velocity = new Vector2(0f, -3f); } } private void Update() { if (screenWidth != Camera.main.orthographicSize * 2f * Camera.main.aspect) { screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect; if (Application.isMobilePlatform) { GameObject obj = GameObject.Find("LeftArrow"); GameObject gameObject = GameObject.Find("RightArrow"); GameObject gameObject2 = GameObject.Find("RestartButton"); obj.transform.position = new Vector3((0f - screenWidth) / 2.5f, -4f, 0f); gameObject.transform.position = new Vector3(screenWidth / 2.5f, -4f, 0f); gameObject2.transform.position = new Vector3(screenWidth / 2.17f, Camera.main.orthographicSize - 1f, 0f); } } GameObject[] array = GameObject.FindGameObjectsWithTag("Berry"); GameObject[] array2 = GameObject.FindGameObjectsWithTag("PoisonBerry"); GameObject[] array3 = GameObject.FindGameObjectsWithTag("UltraBerry"); GameObject gameObject3 = GameObject.Find("Bird"); GameObject[] array4 = array; foreach (GameObject gameObject4 in array4) { if (gameObject4.transform.position.y < 0f - Camera.main.orthographicSize - 1f) { Object.Destroy(gameObject4); } else if (Vector3.Distance(gameObject3.transform.position, gameObject4.transform.position) < 1.5f) { AudioSource.PlayClipAtPoint(Resources.Load("eat"), Camera.main.transform.position); Object.Destroy(gameObject4); score++; UpdateScore(score); } } array4 = array2; foreach (GameObject gameObject5 in array4) { if (gameObject5.transform.position.y < 0f - Camera.main.orthographicSize - 1f) { Object.Destroy(gameObject5); } else if (Vector3.Distance(gameObject3.transform.position, gameObject5.transform.position) < 1.5f) { AudioSource.PlayClipAtPoint(Resources.Load("death"), Camera.main.transform.position); GameObject[] array5 = array; for (int j = 0; j < array5.Length; j++) { Object.Destroy(array5[j]); } array5 = array2; for (int j = 0; j < array5.Length; j++) { Object.Destroy(array5[j]); } array5 = array3; for (int j = 0; j < array5.Length; j++) { Object.Destroy(array5[j]); } gameObject3.transform.position = new Vector3(0f, -4.5f, 0f); gameObject3.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f); score = 0; boostLeft = 0f; UpdateScore(score); } } array4 = array3; foreach (GameObject gameObject6 in array4) { if (gameObject6.transform.position.y < 0f - Camera.main.orthographicSize - 1f) { Object.Destroy(gameObject6); } else if (Vector3.Distance(gameObject3.transform.position, gameObject6.transform.position) < 1.5f) { AudioSource.PlayClipAtPoint(Resources.Load("eat"), Camera.main.transform.position); Object.Destroy(gameObject6); score += 5; UpdateScore(score); boostLeft += 10f; } } if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { Screen.orientation = ScreenOrientation.LandscapeLeft; } } private void UpdateScore(int score) { GameObject.Find("ScoreText").GetComponent().text = "Score: " + score; } }