1.2-beta2 sources
This commit is contained in:
9 files changed
+1245
No files matched your search
@@ -0,0 +1,297 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class Account : MonoBehaviour
|
||||||
|
{
|
||||||
|
private string GameSession;
|
||||||
|
|
||||||
|
public GameObject registerPanel;
|
||||||
|
|
||||||
|
public Button registerPanelSubmitBtn;
|
||||||
|
|
||||||
|
public Button registerPanelLoginBtn;
|
||||||
|
|
||||||
|
public GameObject loginPanel;
|
||||||
|
|
||||||
|
public Button loginPanelSubmitBtn;
|
||||||
|
|
||||||
|
public Button loginPanelRegisterBtn;
|
||||||
|
|
||||||
|
public GameObject accountPanel;
|
||||||
|
|
||||||
|
public Button backButton;
|
||||||
|
|
||||||
|
public Button accountPanelSyncButton;
|
||||||
|
|
||||||
|
public Button accountPanelLogoutButton;
|
||||||
|
|
||||||
|
public TMP_InputField registerPanelUsernameForm;
|
||||||
|
|
||||||
|
public TMP_InputField registerPanelEmailForm;
|
||||||
|
|
||||||
|
public TMP_InputField registerPanelEmailConfirmForm;
|
||||||
|
|
||||||
|
public TMP_InputField registerPanelPasswordForm;
|
||||||
|
|
||||||
|
public TMP_InputField registerPanelPasswordConfirmForm;
|
||||||
|
|
||||||
|
public TMP_InputField loginPanelUsernameForm;
|
||||||
|
|
||||||
|
public TMP_InputField loginPanelPasswordForm;
|
||||||
|
|
||||||
|
public TMP_Text registerPanelStatusText;
|
||||||
|
|
||||||
|
public TMP_Text loginPanelStatusText;
|
||||||
|
|
||||||
|
public TMP_Text accountPanelStatusText;
|
||||||
|
|
||||||
|
private static readonly HttpClient client;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (!client.DefaultRequestHeaders.Contains("Requester"))
|
||||||
|
{
|
||||||
|
client.DefaultRequestHeaders.Add("Requester", "BerryDashClientLegacy");
|
||||||
|
}
|
||||||
|
if (!client.DefaultRequestHeaders.Contains("ClientVersion"))
|
||||||
|
{
|
||||||
|
client.DefaultRequestHeaders.Add("ClientVersion", "1.2-beta2");
|
||||||
|
}
|
||||||
|
if (!client.DefaultRequestHeaders.Contains("ClientPlatform"))
|
||||||
|
{
|
||||||
|
client.DefaultRequestHeaders.Add("ClientPlatform", Application.platform.ToString());
|
||||||
|
}
|
||||||
|
if (PlayerPrefs.HasKey("gameSession") && PlayerPrefs.HasKey("userID"))
|
||||||
|
{
|
||||||
|
SwitchScene(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SwitchScene(1);
|
||||||
|
}
|
||||||
|
backButton.onClick.AddListener(BackToMenu);
|
||||||
|
registerPanelLoginBtn.onClick.AddListener(delegate
|
||||||
|
{
|
||||||
|
SwitchScene(2);
|
||||||
|
});
|
||||||
|
registerPanelSubmitBtn.onClick.AddListener(SubmitRegister);
|
||||||
|
loginPanelRegisterBtn.onClick.AddListener(delegate
|
||||||
|
{
|
||||||
|
SwitchScene(1);
|
||||||
|
});
|
||||||
|
loginPanelSubmitBtn.onClick.AddListener(SubmitLogin);
|
||||||
|
accountPanelSyncButton.onClick.AddListener(SyncStats);
|
||||||
|
accountPanelLogoutButton.onClick.AddListener(LogoutAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BackToMenu()
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Menu");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwitchScene(int scene)
|
||||||
|
{
|
||||||
|
ClearForms();
|
||||||
|
registerPanelStatusText.text = "";
|
||||||
|
loginPanelStatusText.text = "";
|
||||||
|
accountPanelStatusText.text = "";
|
||||||
|
switch (scene)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
accountPanel.SetActive(value: true);
|
||||||
|
registerPanel.SetActive(value: false);
|
||||||
|
loginPanel.SetActive(value: false);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
accountPanel.SetActive(value: false);
|
||||||
|
registerPanel.SetActive(value: true);
|
||||||
|
loginPanel.SetActive(value: false);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
accountPanel.SetActive(value: false);
|
||||||
|
registerPanel.SetActive(value: false);
|
||||||
|
loginPanel.SetActive(value: true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void SubmitRegister()
|
||||||
|
{
|
||||||
|
if (!registerPanelEmailForm.text.Trim().Equals(registerPanelEmailConfirmForm.text.Trim(), StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
registerPanelStatusText.text = "Email doesn't match";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!registerPanelPasswordForm.text.Trim().Equals(registerPanelPasswordConfirmForm.text.Trim(), StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
registerPanelStatusText.text = "Password doesn't match";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponseMessage obj = await client.PostAsync("https://berrydash.lncvrt.xyz/database/registerAccount.php", new FormUrlEncodedContent(new KeyValuePair<string, string>[3]
|
||||||
|
{
|
||||||
|
new KeyValuePair<string, string>("username", registerPanelUsernameForm.text),
|
||||||
|
new KeyValuePair<string, string>("email", registerPanelEmailForm.text),
|
||||||
|
new KeyValuePair<string, string>("password", registerPanelPasswordForm.text)
|
||||||
|
}));
|
||||||
|
obj.EnsureSuccessStatusCode();
|
||||||
|
string text = await obj.Content.ReadAsStringAsync();
|
||||||
|
Debug.Log(text);
|
||||||
|
switch (text)
|
||||||
|
{
|
||||||
|
case "1":
|
||||||
|
SwitchScene(2);
|
||||||
|
break;
|
||||||
|
case "-1":
|
||||||
|
registerPanelStatusText.text = "Internal login server error";
|
||||||
|
break;
|
||||||
|
case "-2":
|
||||||
|
registerPanelStatusText.text = "Incomplete form data";
|
||||||
|
break;
|
||||||
|
case "-3":
|
||||||
|
registerPanelStatusText.text = "Username not valid";
|
||||||
|
break;
|
||||||
|
case "-4":
|
||||||
|
registerPanelStatusText.text = "Email not valid";
|
||||||
|
break;
|
||||||
|
case "-5":
|
||||||
|
registerPanelStatusText.text = "Password must have 8 characters, one number and one letter";
|
||||||
|
break;
|
||||||
|
case "-6":
|
||||||
|
registerPanelStatusText.text = "Username too long or short";
|
||||||
|
break;
|
||||||
|
case "-7":
|
||||||
|
registerPanelStatusText.text = "Username or email already exists";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
registerPanelStatusText.text = "Unknown server response \"" + text + "\"";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (HttpRequestException arg)
|
||||||
|
{
|
||||||
|
Debug.LogError($"HTTP Error: {arg}");
|
||||||
|
registerPanelStatusText.text = "Failed to make HTTP request";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void SubmitLogin()
|
||||||
|
{
|
||||||
|
_ = 1;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponseMessage obj = await client.PostAsync("https://berrydash.lncvrt.xyz/database/loginAccount.php", new FormUrlEncodedContent(new KeyValuePair<string, string>[2]
|
||||||
|
{
|
||||||
|
new KeyValuePair<string, string>("username", loginPanelUsernameForm.text),
|
||||||
|
new KeyValuePair<string, string>("password", loginPanelPasswordForm.text)
|
||||||
|
}));
|
||||||
|
obj.EnsureSuccessStatusCode();
|
||||||
|
string text = await obj.Content.ReadAsStringAsync();
|
||||||
|
Debug.Log(loginPanelUsernameForm.text);
|
||||||
|
Debug.Log(loginPanelPasswordForm.text);
|
||||||
|
Debug.Log(text);
|
||||||
|
if (!(text == "-1"))
|
||||||
|
{
|
||||||
|
if (text == "-2")
|
||||||
|
{
|
||||||
|
loginPanelStatusText.text = "Incorrect username or password";
|
||||||
|
}
|
||||||
|
else if (Regex.IsMatch(text, "^[a-zA-Z0-9]+:\\d+:\\d+$"))
|
||||||
|
{
|
||||||
|
string[] array = text.Split(':');
|
||||||
|
string value = array[0];
|
||||||
|
int value2 = int.Parse(array[1]);
|
||||||
|
int value3 = int.Parse(array[2]);
|
||||||
|
PlayerPrefs.SetString("gameSession", value);
|
||||||
|
PlayerPrefs.SetInt("userID", value2);
|
||||||
|
PlayerPrefs.SetInt("HighScore", value3);
|
||||||
|
SwitchScene(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loginPanelStatusText.text = "Unknown server response \"" + text + "\"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loginPanelStatusText.text = "Internal login server error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (HttpRequestException arg)
|
||||||
|
{
|
||||||
|
Debug.LogError($"HTTP Error: {arg}");
|
||||||
|
loginPanelStatusText.text = "Failed to make HTTP request";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClearForms()
|
||||||
|
{
|
||||||
|
registerPanelUsernameForm.text = "";
|
||||||
|
registerPanelEmailForm.text = "";
|
||||||
|
registerPanelEmailConfirmForm.text = "";
|
||||||
|
registerPanelPasswordForm.text = "";
|
||||||
|
registerPanelPasswordConfirmForm.text = "";
|
||||||
|
loginPanelUsernameForm.text = "";
|
||||||
|
loginPanelPasswordForm.text = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void SyncStats()
|
||||||
|
{
|
||||||
|
_ = 1;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponseMessage obj = await client.PostAsync("https://berrydash.lncvrt.xyz/database/syncAccount.php", new FormUrlEncodedContent(new KeyValuePair<string, string>[3]
|
||||||
|
{
|
||||||
|
new KeyValuePair<string, string>("userID", PlayerPrefs.GetInt("userID", 0).ToString()),
|
||||||
|
new KeyValuePair<string, string>("gameSession", PlayerPrefs.GetString("gameSession", "")),
|
||||||
|
new KeyValuePair<string, string>("highScore", PlayerPrefs.GetInt("HighScore", 0).ToString())
|
||||||
|
}));
|
||||||
|
obj.EnsureSuccessStatusCode();
|
||||||
|
string text = await obj.Content.ReadAsStringAsync();
|
||||||
|
Debug.Log(text);
|
||||||
|
switch (text)
|
||||||
|
{
|
||||||
|
case "1":
|
||||||
|
accountPanelStatusText.text = "Updated leaderboard stats";
|
||||||
|
break;
|
||||||
|
case "-1":
|
||||||
|
accountPanelStatusText.text = "Internal login server error";
|
||||||
|
break;
|
||||||
|
case "-2":
|
||||||
|
accountPanelStatusText.text = "Stats already synced";
|
||||||
|
break;
|
||||||
|
case "-3":
|
||||||
|
accountPanelStatusText.text = "Invalid game session (re-login)";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
accountPanelStatusText.text = "Unknown server response \"" + text + "\"";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (HttpRequestException arg)
|
||||||
|
{
|
||||||
|
Debug.LogError($"HTTP Error: {arg}");
|
||||||
|
accountPanelStatusText.text = "Failed to make HTTP request";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogoutAccount()
|
||||||
|
{
|
||||||
|
PlayerPrefs.DeleteKey("userID");
|
||||||
|
PlayerPrefs.DeleteKey("gameSession");
|
||||||
|
PlayerPrefs.DeleteKey("HighScore");
|
||||||
|
SwitchScene(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Account()
|
||||||
|
{
|
||||||
|
client = new HttpClient();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,653 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using DiscordRPC;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
public class Game : MonoBehaviour
|
||||||
|
{
|
||||||
|
public float spawnRate = 1f;
|
||||||
|
|
||||||
|
private float nextSpawnTime;
|
||||||
|
|
||||||
|
private int score;
|
||||||
|
|
||||||
|
private int highscore;
|
||||||
|
|
||||||
|
private float boostLeft;
|
||||||
|
|
||||||
|
private float slownessLeft;
|
||||||
|
|
||||||
|
private float screenWidth;
|
||||||
|
|
||||||
|
private DiscordRpcClient client = new DiscordRpcClient("1216934858182361148");
|
||||||
|
|
||||||
|
private DateTime startTimestamp = DateTime.UtcNow;
|
||||||
|
|
||||||
|
private RuntimePlatform[] desktopPlatforms = new RuntimePlatform[6]
|
||||||
|
{
|
||||||
|
RuntimePlatform.WindowsPlayer,
|
||||||
|
RuntimePlatform.LinuxPlayer,
|
||||||
|
RuntimePlatform.OSXPlayer,
|
||||||
|
RuntimePlatform.WindowsEditor,
|
||||||
|
RuntimePlatform.LinuxEditor,
|
||||||
|
RuntimePlatform.OSXEditor
|
||||||
|
};
|
||||||
|
|
||||||
|
private bool isGrounded;
|
||||||
|
|
||||||
|
private float groundYPosition = -4.3f;
|
||||||
|
|
||||||
|
public TMP_Text scoreText;
|
||||||
|
|
||||||
|
public TMP_Text highScoreText;
|
||||||
|
|
||||||
|
public TMP_Text boostText;
|
||||||
|
|
||||||
|
public GameObject bird;
|
||||||
|
|
||||||
|
public Rigidbody2D rb;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
highscore = PlayerPrefs.GetInt("HighScore", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||||
|
GameObject.Find("HighScoreText").GetComponent<TMP_Text>().text = $"High Score: {highscore}";
|
||||||
|
if (desktopPlatforms.Contains(Application.platform))
|
||||||
|
{
|
||||||
|
client.Initialize();
|
||||||
|
client.SetPresence(new RichPresence
|
||||||
|
{
|
||||||
|
State = "Playing Foodie Dash",
|
||||||
|
Details = $"Score: 0, High Score: {highscore}",
|
||||||
|
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 = new Timestamps
|
||||||
|
{
|
||||||
|
Start = startTimestamp
|
||||||
|
},
|
||||||
|
Buttons = new Button[2]
|
||||||
|
{
|
||||||
|
new Button
|
||||||
|
{
|
||||||
|
Label = "Play Foodie Dash in browser",
|
||||||
|
Url = "https://foodiedash.xytriza.com/browser"
|
||||||
|
},
|
||||||
|
new Button
|
||||||
|
{
|
||||||
|
Label = "Download Foodie Dash",
|
||||||
|
Url = "https://foodiedash.xytriza.com/download"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (PlayerPrefs.GetInt("Setting2", 0) == 1 || Application.isMobilePlatform)
|
||||||
|
{
|
||||||
|
GameObject gameObject = new GameObject("LeftArrow");
|
||||||
|
GameObject gameObject2 = new GameObject("RightArrow");
|
||||||
|
GameObject gameObject3 = new GameObject("JumpArrow");
|
||||||
|
GameObject gameObject4 = new GameObject("RestartButton");
|
||||||
|
GameObject gameObject5 = new GameObject("BackButton");
|
||||||
|
gameObject.AddComponent<SpriteRenderer>();
|
||||||
|
gameObject2.AddComponent<SpriteRenderer>();
|
||||||
|
gameObject3.AddComponent<SpriteRenderer>();
|
||||||
|
gameObject4.AddComponent<SpriteRenderer>();
|
||||||
|
gameObject5.AddComponent<SpriteRenderer>();
|
||||||
|
gameObject.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Arrow");
|
||||||
|
gameObject2.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Arrow");
|
||||||
|
gameObject3.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Arrow");
|
||||||
|
gameObject4.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Restart");
|
||||||
|
gameObject5.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Arrow");
|
||||||
|
gameObject.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
|
||||||
|
gameObject2.transform.rotation = Quaternion.Euler(0f, 0f, -90f);
|
||||||
|
gameObject5.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
|
||||||
|
gameObject.transform.position = new Vector3((0f - screenWidth) / 2.5f, -4f, 0f);
|
||||||
|
gameObject2.transform.position = new Vector3(screenWidth / 2.5f, -4f, 0f);
|
||||||
|
gameObject4.transform.position = new Vector3(screenWidth / 2.3f, Camera.main.orthographicSize - 1.2f, 0f);
|
||||||
|
gameObject5.transform.position = new Vector3((0f - screenWidth) / 2.3f, Camera.main.orthographicSize - 1.2f, 0f);
|
||||||
|
if (PlayerPrefs.GetInt("Setting3", 0) == 1)
|
||||||
|
{
|
||||||
|
gameObject.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject2.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject3.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject4.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject5.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject3.transform.position = new Vector3(screenWidth / 2.5f, -1f, 0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameObject.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject2.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject3.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject4.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject5.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject3.transform.position = new Vector3(screenWidth / 2.5f, -2f, 0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MoveBird()
|
||||||
|
{
|
||||||
|
float num = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||||
|
float num2 = 0.18f * (num / 20.19257f);
|
||||||
|
bool flag = false;
|
||||||
|
bool flag2 = false;
|
||||||
|
bool flag3 = false;
|
||||||
|
float num3 = num2;
|
||||||
|
if (boostLeft > 0f)
|
||||||
|
{
|
||||||
|
num3 = num2 * 1.39f;
|
||||||
|
}
|
||||||
|
else if (slownessLeft > 0f)
|
||||||
|
{
|
||||||
|
num3 = num2 * 0.56f;
|
||||||
|
}
|
||||||
|
CheckIfGrounded();
|
||||||
|
float axisRaw = Input.GetAxisRaw("Horizontal");
|
||||||
|
if (!Application.isMobilePlatform)
|
||||||
|
{
|
||||||
|
if (axisRaw < 0f || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
|
||||||
|
{
|
||||||
|
flag2 = true;
|
||||||
|
}
|
||||||
|
if (axisRaw > 0f || Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
|
||||||
|
{
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.UpArrow) || (Input.GetMouseButton(0) && PlayerPrefs.GetInt("Setting2", 0) == 0) || Input.GetKey(KeyCode.JoystickButton0))
|
||||||
|
{
|
||||||
|
flag3 = true;
|
||||||
|
}
|
||||||
|
if (Input.GetKey(KeyCode.R))
|
||||||
|
{
|
||||||
|
Respawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (PlayerPrefs.GetInt("Setting2", 0) != 0 || Application.isMobilePlatform)
|
||||||
|
{
|
||||||
|
GameObject gameObject = GameObject.Find("LeftArrow");
|
||||||
|
GameObject gameObject2 = GameObject.Find("RightArrow");
|
||||||
|
GameObject gameObject3 = GameObject.Find("JumpArrow");
|
||||||
|
GameObject gameObject4 = GameObject.Find("RestartButton");
|
||||||
|
GameObject gameObject5 = GameObject.Find("BackButton");
|
||||||
|
if (Application.isMobilePlatform)
|
||||||
|
{
|
||||||
|
Touch[] touches = Input.touches;
|
||||||
|
for (int i = 0; i < touches.Length; i++)
|
||||||
|
{
|
||||||
|
Touch touch = touches[i];
|
||||||
|
Vector3 point = Camera.main.ScreenToWorldPoint(touch.position);
|
||||||
|
point.z = 0f;
|
||||||
|
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
|
||||||
|
{
|
||||||
|
if (gameObject.GetComponent<SpriteRenderer>().bounds.Contains(point))
|
||||||
|
{
|
||||||
|
flag2 = true;
|
||||||
|
}
|
||||||
|
else if (gameObject2.GetComponent<SpriteRenderer>().bounds.Contains(point))
|
||||||
|
{
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
else if (gameObject3.GetComponent<SpriteRenderer>().bounds.Contains(point))
|
||||||
|
{
|
||||||
|
flag3 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (touch.phase == TouchPhase.Began)
|
||||||
|
{
|
||||||
|
if (gameObject4.GetComponent<SpriteRenderer>().bounds.Contains(point))
|
||||||
|
{
|
||||||
|
Respawn();
|
||||||
|
}
|
||||||
|
else if (gameObject5.GetComponent<SpriteRenderer>().bounds.Contains(point))
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Menu");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Input.GetMouseButton(0))
|
||||||
|
{
|
||||||
|
Vector3 point2 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||||
|
point2.z = 0f;
|
||||||
|
if (gameObject.GetComponent<SpriteRenderer>().bounds.Contains(point2))
|
||||||
|
{
|
||||||
|
flag2 = true;
|
||||||
|
}
|
||||||
|
if (gameObject2.GetComponent<SpriteRenderer>().bounds.Contains(point2))
|
||||||
|
{
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
if (gameObject3.GetComponent<SpriteRenderer>().bounds.Contains(point2))
|
||||||
|
{
|
||||||
|
flag3 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Input.GetMouseButtonDown(0))
|
||||||
|
{
|
||||||
|
Vector3 point3 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||||
|
point3.z = 0f;
|
||||||
|
if (gameObject4.GetComponent<SpriteRenderer>().bounds.Contains(point3))
|
||||||
|
{
|
||||||
|
Respawn();
|
||||||
|
}
|
||||||
|
if (gameObject5.GetComponent<SpriteRenderer>().bounds.Contains(point3))
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Menu");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flag2 && !flag)
|
||||||
|
{
|
||||||
|
bird.transform.position += new Vector3(0f - num3, 0f, 0f);
|
||||||
|
ClampPosition(num, bird);
|
||||||
|
bird.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f);
|
||||||
|
}
|
||||||
|
if (flag && !flag2)
|
||||||
|
{
|
||||||
|
bird.transform.position += new Vector3(num3, 0f, 0f);
|
||||||
|
ClampPosition(num, bird);
|
||||||
|
bird.transform.localScale = new Vector3(-1.35f, 1.35f, 1.35f);
|
||||||
|
}
|
||||||
|
if (flag3 && isGrounded)
|
||||||
|
{
|
||||||
|
if (boostLeft > 0f)
|
||||||
|
{
|
||||||
|
rb.velocity = Vector2.up * 12f;
|
||||||
|
}
|
||||||
|
else if (slownessLeft > 0f)
|
||||||
|
{
|
||||||
|
rb.velocity = Vector2.up * 6f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rb.velocity = Vector2.up * 9f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
boostText.GetComponent<TMP_Text>().text = "Boost expires in " + $"{boostLeft:0.0}" + "s";
|
||||||
|
}
|
||||||
|
else if (slownessLeft > 0f)
|
||||||
|
{
|
||||||
|
slownessLeft -= Time.deltaTime;
|
||||||
|
boostText.GetComponent<TMP_Text>().text = "Slowness expires in " + $"{slownessLeft:0.0}" + "s";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boostText.GetComponent<TMP_Text>().text = "";
|
||||||
|
}
|
||||||
|
if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.JoystickButton7) || Input.GetKey(KeyCode.Joystick2Button7))
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Menu");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SpawnBerries()
|
||||||
|
{
|
||||||
|
if (Time.time >= nextSpawnTime)
|
||||||
|
{
|
||||||
|
nextSpawnTime = Time.time + 1f / spawnRate;
|
||||||
|
float value = UnityEngine.Random.value;
|
||||||
|
GameObject gameObject;
|
||||||
|
SpriteRenderer spriteRenderer;
|
||||||
|
if (value <= 0.6f)
|
||||||
|
{
|
||||||
|
gameObject = new GameObject("Berry");
|
||||||
|
spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
|
||||||
|
spriteRenderer.sprite = Resources.Load<Sprite>("Berry");
|
||||||
|
gameObject.tag = "Berry";
|
||||||
|
}
|
||||||
|
else if (value <= 0.8f)
|
||||||
|
{
|
||||||
|
gameObject = new GameObject("PoisonBerry");
|
||||||
|
spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
|
||||||
|
spriteRenderer.sprite = Resources.Load<Sprite>("PoisonBerry");
|
||||||
|
gameObject.tag = "PoisonBerry";
|
||||||
|
}
|
||||||
|
else if (value <= 0.9f)
|
||||||
|
{
|
||||||
|
gameObject = new GameObject("SlowBerry");
|
||||||
|
spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
|
||||||
|
spriteRenderer.sprite = Resources.Load<Sprite>("SlowBerry");
|
||||||
|
gameObject.tag = "SlowBerry";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameObject = new GameObject("UltraBerry");
|
||||||
|
spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
|
||||||
|
spriteRenderer.sprite = Resources.Load<Sprite>("UltraBerry");
|
||||||
|
gameObject.tag = "UltraBerry";
|
||||||
|
}
|
||||||
|
spriteRenderer.sortingOrder = -5;
|
||||||
|
float num = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||||
|
float x = UnityEngine.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>();
|
||||||
|
rigidbody2D.gravityScale = 0f;
|
||||||
|
rigidbody2D.velocity = new Vector2(0f, -3f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
CheckIfGrounded();
|
||||||
|
if (screenWidth != Camera.main.orthographicSize * 2f * Camera.main.aspect)
|
||||||
|
{
|
||||||
|
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||||
|
ClampPosition(screenWidth, bird);
|
||||||
|
if (PlayerPrefs.GetInt("Setting2", 0) == 1)
|
||||||
|
{
|
||||||
|
GameObject gameObject = GameObject.Find("LeftArrow");
|
||||||
|
GameObject gameObject2 = GameObject.Find("RightArrow");
|
||||||
|
GameObject gameObject3 = GameObject.Find("JumpArrow");
|
||||||
|
GameObject gameObject4 = GameObject.Find("RestartButton");
|
||||||
|
GameObject gameObject5 = GameObject.Find("BackButton");
|
||||||
|
gameObject.transform.position = new Vector3((0f - screenWidth) / 2.5f, -4f, 0f);
|
||||||
|
gameObject2.transform.position = new Vector3(screenWidth / 2.5f, -4f, 0f);
|
||||||
|
gameObject4.transform.position = new Vector3(screenWidth / 2.3f, Camera.main.orthographicSize - 1.2f, 0f);
|
||||||
|
gameObject5.transform.position = new Vector3((0f - screenWidth) / 2.3f, Camera.main.orthographicSize - 1.2f, 0f);
|
||||||
|
if (PlayerPrefs.GetInt("Setting3", 0) == 1)
|
||||||
|
{
|
||||||
|
gameObject.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject2.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject3.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject4.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject5.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||||
|
gameObject3.transform.position = new Vector3(screenWidth / 2.5f, -1f, 0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameObject.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject2.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject3.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject4.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject5.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||||
|
gameObject3.transform.position = new Vector3(screenWidth / 2.5f, -2f, 0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GameObject[] array = GameObject.FindGameObjectsWithTag("Berry");
|
||||||
|
GameObject[] array2 = GameObject.FindGameObjectsWithTag("PoisonBerry");
|
||||||
|
GameObject[] array3 = GameObject.FindGameObjectsWithTag("UltraBerry");
|
||||||
|
GameObject[] array4 = GameObject.FindGameObjectsWithTag("SlowBerry");
|
||||||
|
GameObject[] array5 = array;
|
||||||
|
foreach (GameObject gameObject6 in array5)
|
||||||
|
{
|
||||||
|
if (gameObject6.transform.position.y < 0f - Camera.main.orthographicSize - 1f)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(gameObject6);
|
||||||
|
}
|
||||||
|
else if (Vector3.Distance(bird.transform.position, gameObject6.transform.position) < 1.5f)
|
||||||
|
{
|
||||||
|
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("eat"), Camera.main.transform.position);
|
||||||
|
UnityEngine.Object.Destroy(gameObject6);
|
||||||
|
score++;
|
||||||
|
UpdateScore(score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array5 = array2;
|
||||||
|
foreach (GameObject gameObject7 in array5)
|
||||||
|
{
|
||||||
|
if (gameObject7.transform.position.y < 0f - Camera.main.orthographicSize - 1f)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(gameObject7);
|
||||||
|
}
|
||||||
|
else if (Vector3.Distance(bird.transform.position, gameObject7.transform.position) < 1.5f)
|
||||||
|
{
|
||||||
|
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("death"), Camera.main.transform.position);
|
||||||
|
Respawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array5 = array3;
|
||||||
|
foreach (GameObject gameObject8 in array5)
|
||||||
|
{
|
||||||
|
if (gameObject8.transform.position.y < 0f - Camera.main.orthographicSize - 1f)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(gameObject8);
|
||||||
|
}
|
||||||
|
else if (Vector3.Distance(bird.transform.position, gameObject8.transform.position) < 1.5f)
|
||||||
|
{
|
||||||
|
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("powerup"), Camera.main.transform.position, 0.5f);
|
||||||
|
UnityEngine.Object.Destroy(gameObject8);
|
||||||
|
if (slownessLeft > 0f)
|
||||||
|
{
|
||||||
|
slownessLeft = 0f;
|
||||||
|
score++;
|
||||||
|
UpdateScore(score);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boostLeft += 10f;
|
||||||
|
score += 5;
|
||||||
|
UpdateScore(score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array5 = array4;
|
||||||
|
foreach (GameObject gameObject9 in array5)
|
||||||
|
{
|
||||||
|
if (gameObject9.transform.position.y < 0f - Camera.main.orthographicSize - 1f)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(gameObject9);
|
||||||
|
}
|
||||||
|
else if (Vector3.Distance(bird.transform.position, gameObject9.transform.position) < 1.5f)
|
||||||
|
{
|
||||||
|
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("slowness"), Camera.main.transform.position, 0.5f);
|
||||||
|
UnityEngine.Object.Destroy(gameObject9);
|
||||||
|
boostLeft = 0f;
|
||||||
|
slownessLeft = 10f;
|
||||||
|
if (score > 0)
|
||||||
|
{
|
||||||
|
score--;
|
||||||
|
UpdateScore(score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Respawn()
|
||||||
|
{
|
||||||
|
bird.transform.position = new Vector3(0f, -4.3f, 0f);
|
||||||
|
bird.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f);
|
||||||
|
rb.gravityScale = 0f;
|
||||||
|
rb.velocity = Vector2.zero;
|
||||||
|
score = 0;
|
||||||
|
boostLeft = 0f;
|
||||||
|
slownessLeft = 0f;
|
||||||
|
UpdateScore(score);
|
||||||
|
GameObject[] array = GameObject.FindGameObjectsWithTag("Berry");
|
||||||
|
GameObject[] array2 = GameObject.FindGameObjectsWithTag("PoisonBerry");
|
||||||
|
GameObject[] array3 = GameObject.FindGameObjectsWithTag("UltraBerry");
|
||||||
|
GameObject[] array4 = GameObject.FindGameObjectsWithTag("SlowBerry");
|
||||||
|
GameObject[] array5 = array;
|
||||||
|
for (int i = 0; i < array5.Length; i++)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(array5[i]);
|
||||||
|
}
|
||||||
|
array5 = array2;
|
||||||
|
for (int i = 0; i < array5.Length; i++)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(array5[i]);
|
||||||
|
}
|
||||||
|
array5 = array3;
|
||||||
|
for (int i = 0; i < array5.Length; i++)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(array5[i]);
|
||||||
|
}
|
||||||
|
array5 = array4;
|
||||||
|
for (int i = 0; i < array5.Length; i++)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(array5[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateScore(int score)
|
||||||
|
{
|
||||||
|
if (score > highscore)
|
||||||
|
{
|
||||||
|
highscore = score;
|
||||||
|
}
|
||||||
|
PlayerPrefs.SetInt("HighScore", highscore);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
scoreText.GetComponent<TMP_Text>().text = "Score: " + score;
|
||||||
|
highScoreText.GetComponent<TMP_Text>().text = "High Score: " + highscore;
|
||||||
|
if (desktopPlatforms.Contains(Application.platform))
|
||||||
|
{
|
||||||
|
client.SetPresence(new RichPresence
|
||||||
|
{
|
||||||
|
Details = "Playing Foodie Dash",
|
||||||
|
State = $"Score: {score}, High Score: {highscore}",
|
||||||
|
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 = new Timestamps
|
||||||
|
{
|
||||||
|
Start = startTimestamp
|
||||||
|
},
|
||||||
|
Buttons = new Button[2]
|
||||||
|
{
|
||||||
|
new Button
|
||||||
|
{
|
||||||
|
Label = "Play Foodie Dash in browser",
|
||||||
|
Url = "https://foodiedash.xytriza.com/browser"
|
||||||
|
},
|
||||||
|
new Button
|
||||||
|
{
|
||||||
|
Label = "Download Foodie Dash",
|
||||||
|
Url = "https://foodiedash.xytriza.com/download"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckIfGrounded()
|
||||||
|
{
|
||||||
|
GameObject gameObject = GameObject.Find("JumpArrow");
|
||||||
|
isGrounded = bird.transform.position.y <= groundYPosition + 0.05f;
|
||||||
|
rb.gravityScale = (isGrounded ? 0f : 1.5f);
|
||||||
|
if (bird.transform.position.y < groundYPosition)
|
||||||
|
{
|
||||||
|
bird.transform.position = new Vector2(bird.transform.position.x, groundYPosition);
|
||||||
|
rb.velocity = new Vector2(rb.velocity.x, 0f);
|
||||||
|
}
|
||||||
|
if (gameObject != null)
|
||||||
|
{
|
||||||
|
Renderer component = gameObject.GetComponent<Renderer>();
|
||||||
|
if (component != null)
|
||||||
|
{
|
||||||
|
component.material.color = (isGrounded ? Color.white : Color.red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnApplicationQuit()
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetInt("HighScore", highscore);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
if (desktopPlatforms.Contains(Application.platform))
|
||||||
|
{
|
||||||
|
client.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnApplicationPause(bool pauseStatus)
|
||||||
|
{
|
||||||
|
if (desktopPlatforms.Contains(Application.platform))
|
||||||
|
{
|
||||||
|
client.SetPresence(new RichPresence
|
||||||
|
{
|
||||||
|
Details = "Idle",
|
||||||
|
State = $"Score: {score}, High Score: {highscore}",
|
||||||
|
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!"
|
||||||
|
},
|
||||||
|
Buttons = new Button[2]
|
||||||
|
{
|
||||||
|
new Button
|
||||||
|
{
|
||||||
|
Label = "Play Foodie Dash in browser",
|
||||||
|
Url = "https://foodiedash.xytriza.com/browser"
|
||||||
|
},
|
||||||
|
new Button
|
||||||
|
{
|
||||||
|
Label = "Download Foodie Dash",
|
||||||
|
Url = "https://foodiedash.xytriza.com/download"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnApplicationFocus(bool focusStatus)
|
||||||
|
{
|
||||||
|
if (desktopPlatforms.Contains(Application.platform))
|
||||||
|
{
|
||||||
|
client.SetPresence(new RichPresence
|
||||||
|
{
|
||||||
|
Details = "Playing Foodie Dash",
|
||||||
|
State = $"Score: {score}, High Score: {highscore}",
|
||||||
|
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 = new Timestamps
|
||||||
|
{
|
||||||
|
Start = startTimestamp
|
||||||
|
},
|
||||||
|
Buttons = new Button[2]
|
||||||
|
{
|
||||||
|
new Button
|
||||||
|
{
|
||||||
|
Label = "Play Foodie Dash in browser",
|
||||||
|
Url = "https://foodiedash.xytriza.com/browser"
|
||||||
|
},
|
||||||
|
new Button
|
||||||
|
{
|
||||||
|
Label = "Download Foodie Dash",
|
||||||
|
Url = "https://foodiedash.xytriza.com/download"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class Leaderboard : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Button backButton;
|
||||||
|
|
||||||
|
public Button leaderboardsButton;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
leaderboardsButton.onClick.AddListener(LeaderboardsButton);
|
||||||
|
backButton.onClick.AddListener(BackButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LeaderboardsButton()
|
||||||
|
{
|
||||||
|
Application.OpenURL("https://berrydash.lncvrt.xyz/leaderboards");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BackButton()
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Menu");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
public class Loading : MonoBehaviour
|
||||||
|
{
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (!PlayerPrefs.HasKey("Setting1"))
|
||||||
|
{
|
||||||
|
if (!Application.isMobilePlatform)
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetInt("Setting1", 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetInt("Setting1", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!PlayerPrefs.HasKey("Setting2"))
|
||||||
|
{
|
||||||
|
if (!Application.isMobilePlatform)
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetInt("Setting2", 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetInt("Setting2", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!PlayerPrefs.HasKey("Setting3"))
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetInt("Setting3", 0);
|
||||||
|
}
|
||||||
|
SceneManager.LoadScene("Menu");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class Menu : MonoBehaviour
|
||||||
|
{
|
||||||
|
public RuntimePlatform[] desktopPlatforms = new RuntimePlatform[3]
|
||||||
|
{
|
||||||
|
RuntimePlatform.WindowsPlayer,
|
||||||
|
RuntimePlatform.LinuxPlayer,
|
||||||
|
RuntimePlatform.OSXPlayer
|
||||||
|
};
|
||||||
|
|
||||||
|
public GameObject exitObj;
|
||||||
|
|
||||||
|
public Button playBtn;
|
||||||
|
|
||||||
|
public Button settingsBtn;
|
||||||
|
|
||||||
|
public Button accountBtn;
|
||||||
|
|
||||||
|
public Button leaderboardBtn;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
Button component = exitObj.GetComponent<Button>();
|
||||||
|
if (desktopPlatforms.Contains(Application.platform))
|
||||||
|
{
|
||||||
|
component.onClick.AddListener(ExitClick);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Object.Destroy(exitObj);
|
||||||
|
}
|
||||||
|
playBtn.onClick.AddListener(PlayClick);
|
||||||
|
settingsBtn.onClick.AddListener(SettingsClick);
|
||||||
|
accountBtn.onClick.AddListener(AccountClick);
|
||||||
|
leaderboardBtn.onClick.AddListener(LeaderboardClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlayClick()
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Game");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SettingsClick()
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Settings");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AccountClick()
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Account");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LeaderboardClick()
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Leaderboard");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExitClick()
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class PauseMenu : MonoBehaviour
|
||||||
|
{
|
||||||
|
private GameObject pauseMenuObj;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
pauseMenuObj = GameObject.Find("Canvas/PauseMenu");
|
||||||
|
GameObject obj = GameObject.Find("Canvas/PauseMenu/ReturnToMenu");
|
||||||
|
GameObject gameObject = GameObject.Find("Canvas/PauseMenu/ReturnToMenu");
|
||||||
|
GameObject gameObject2 = GameObject.Find("Canvas/PauseMenu/ReturnToMenu");
|
||||||
|
Button component = obj.GetComponent<Button>();
|
||||||
|
Button component2 = gameObject.GetComponent<Button>();
|
||||||
|
Button component3 = gameObject2.GetComponent<Button>();
|
||||||
|
component.onClick.AddListener(MenuClick);
|
||||||
|
component2.onClick.AddListener(TogglePauseMenu);
|
||||||
|
component3.onClick.AddListener(SettingsClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TogglePauseMenu()
|
||||||
|
{
|
||||||
|
pauseMenuObj.SetActive(value: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MenuClick()
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Game");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SettingsClick()
|
||||||
|
{
|
||||||
|
pauseMenuObj.SetActive(!pauseMenuObj.activeSelf);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Player : MonoBehaviour
|
||||||
|
{
|
||||||
|
public float jumpForce;
|
||||||
|
|
||||||
|
private Rigidbody2D rb;
|
||||||
|
|
||||||
|
public float groundYPosition = -4.3f;
|
||||||
|
|
||||||
|
private bool isGrounded;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
rb = GetComponent<Rigidbody2D>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
CheckIfGrounded();
|
||||||
|
if (isGrounded && Input.GetKey(KeyCode.Space))
|
||||||
|
{
|
||||||
|
rb.velocity = Vector2.up * jumpForce;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckIfGrounded()
|
||||||
|
{
|
||||||
|
isGrounded = base.transform.position.y <= groundYPosition + 0.05f;
|
||||||
|
rb.gravityScale = (isGrounded ? 0f : 1.5f);
|
||||||
|
if (base.transform.position.y < groundYPosition)
|
||||||
|
{
|
||||||
|
base.transform.position = new Vector2(base.transform.position.x, groundYPosition);
|
||||||
|
rb.velocity = new Vector2(rb.velocity.x, 0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class Settings : MonoBehaviour
|
||||||
|
{
|
||||||
|
public float screenWidth;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||||
|
GameObject gameObject = GameObject.Find("Toggle1");
|
||||||
|
GameObject gameObject2 = GameObject.Find("Toggle2");
|
||||||
|
GameObject gameObject3 = GameObject.Find("Toggle3");
|
||||||
|
GameObject obj = GameObject.Find("BackButton");
|
||||||
|
Toggle setting1toggle = gameObject.GetComponent<Toggle>();
|
||||||
|
Toggle setting2toggle = gameObject2.GetComponent<Toggle>();
|
||||||
|
Toggle setting3toggle = gameObject3.GetComponent<Toggle>();
|
||||||
|
Button component = obj.GetComponent<Button>();
|
||||||
|
if (!Application.isMobilePlatform)
|
||||||
|
{
|
||||||
|
setting1toggle.isOn = PlayerPrefs.GetInt("Setting1") == 1;
|
||||||
|
setting2toggle.isOn = PlayerPrefs.GetInt("Setting2") == 1;
|
||||||
|
setting3toggle.isOn = PlayerPrefs.GetInt("Setting3") == 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setting1toggle.isOn = false;
|
||||||
|
setting2toggle.isOn = true;
|
||||||
|
setting3toggle.isOn = PlayerPrefs.GetInt("Setting3") == 1;
|
||||||
|
setting1toggle.interactable = false;
|
||||||
|
setting2toggle.interactable = false;
|
||||||
|
PlayerPrefs.SetInt("Setting1", 0);
|
||||||
|
PlayerPrefs.SetInt("Setting2", 1);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
component.onClick.AddListener(BackButton);
|
||||||
|
setting1toggle.onValueChanged.AddListener(delegate
|
||||||
|
{
|
||||||
|
Setting1ToggleValueChanged(setting1toggle);
|
||||||
|
});
|
||||||
|
setting2toggle.onValueChanged.AddListener(delegate
|
||||||
|
{
|
||||||
|
Setting2ToggleValueChanged(setting2toggle);
|
||||||
|
});
|
||||||
|
setting3toggle.onValueChanged.AddListener(delegate
|
||||||
|
{
|
||||||
|
Setting3ToggleValueChanged(setting3toggle);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Setting1ToggleValueChanged(Toggle change)
|
||||||
|
{
|
||||||
|
if (Application.platform != RuntimePlatform.Android && Application.platform != RuntimePlatform.IPhonePlayer)
|
||||||
|
{
|
||||||
|
Screen.fullScreen = change.isOn;
|
||||||
|
PlayerPrefs.SetInt("Setting1", change.isOn ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Setting2ToggleValueChanged(Toggle change)
|
||||||
|
{
|
||||||
|
if (!Application.isMobilePlatform)
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetInt("Setting2", change.isOn ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Setting3ToggleValueChanged(Toggle change)
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetInt("Setting3", change.isOn ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BackButton()
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Menu");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class UpdateRequired : MonoBehaviour
|
||||||
|
{
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
GameObject.Find("Canvas/Button").GetComponent<Button>().onClick.AddListener(TaskOnClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TaskOnClick()
|
||||||
|
{
|
||||||
|
Application.OpenURL("https://berrydash.lncvrt.xyz/download");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user