Near finish

This commit is contained in:
2023-07-30 23:14:41 +05:30
parent 1569760e7b
commit 400336ef4f
1979 changed files with 1696464 additions and 301 deletions

View File

@@ -0,0 +1,75 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManager : MonoBehaviour
{
public static AudioManager instance;
public AudioClip explosionSFX;
[SerializeField]public AudioSource SourceSFX;
[SerializeField]public AudioSource SourceMusic;
[SerializeField]public LevelAudioCombo[] levels;
public static bool isMuteMusic {get{
if(PlayerPrefs.HasKey("music")){
return PlayerPrefs.GetInt("music") == 1;
}else{
return false;
}
}}
public static bool isMuteSFX {get{
if(PlayerPrefs.HasKey("sfx")){
return PlayerPrefs.GetInt("sfx") == 1;
}else{
return false;
}
}}
public static void ToggleMusic(){
if(isMuteMusic){
PlayerPrefs.SetInt("music",1);
}else{
PlayerPrefs.SetInt("music",0);
}
}
public static void ToggleSFX(){
if(isMuteMusic){
PlayerPrefs.SetInt("sfx",1);
}else{
PlayerPrefs.SetInt("sfx",0);
}
}
void Awake(){
instance= this;
DontDestroyOnLoad(this);
}
public static void ChangeMusicToScene(string scene){
AudioClip chosen = instance.levels[0].clip;
foreach(LevelAudioCombo level in instance.levels){
if(level.name == scene){
chosen = level.clip;
break;
}
}
ChangeBGMusic(chosen);
}
public static void ChangeBGMusic(AudioClip clip){
instance.SourceMusic.Stop();
instance.SourceMusic.clip = clip;
instance.SourceMusic.Play();
}
public static void PlayExplosion(){
if(isMuteSFX){return;}
instance.SourceSFX.PlayOneShot(instance.explosionSFX);
}
}
[System.Serializable]
public class LevelAudioCombo{
public string name;
public AudioClip clip;
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b7cc87c2c1cae8f4380dfa133fc7a3c6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,8 +7,12 @@ public class CameraFollower : MonoBehaviour
public Transform target;
public float smoothness =0.1f;
public Vector3 offset;
public float speedFOVMultiplier = 1.3f;
float deFOV = 0;
public float fovSmoothness =0.1f;
void Start()
{
deFOV = Camera.main.orthographicSize;
// offset= transform.position - target.position;
}
@@ -16,5 +20,7 @@ public class CameraFollower : MonoBehaviour
void FixedUpdate()
{
transform.position = Vector3.Lerp(transform.position, new Vector3(target.position.x - offset.x, transform.position.y, transform.position.z), smoothness);
Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, (!PlayerController.instance.PowerupActive) ? deFOV : deFOV * speedFOVMultiplier, fovSmoothness);
}
}

View File

@@ -0,0 +1,388 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Google;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Networking;
public static class DataManager{
public const string API_ENDPOINT = "http://vps.playpoolstudios.com/faucet/ufo/api/";
public const string key = "#2CuV1Bit^S!sW1ZcgRv8BhrO";
public static UserData userData{get; private set;}
public static List<LeaderboardItemData> Leaderboard{get; private set;}
public static bool isLogged{ get{return userData != null;}}
public static void Signout(){
try{GoogleSignIn.DefaultInstance.SignOut();}catch{}
PlayerPrefs.DeleteAll();
PlayerPrefs.Save();
userData = null;
}
public static async Task<int> Login(string username,string password){
WWWForm form = new WWWForm();
form.AddField("username", username);
form.AddField("password", password);
form.AddField("key", key);
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "login.php", form))
{
var operation = request.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
Debug.Log("login response: " +request.downloadHandler.text);
if(request.downloadHandler.text.Contains("{")){
try{
userData = JsonConvert.DeserializeObject<UserData>(request.downloadHandler.text);
Debug.Log("Success parsing userdata");
PlayerPrefs.SetString("username", username);
PlayerPrefs.SetString("password", password);
PlayerPrefs.Save();
}catch(Exception e){
Debug.Log("Error parsing userdata");
UserData u = new UserData();
Debug.Log( JsonConvert.SerializeObject(u));
Debug.LogError(e.Message);
Debug.LogError(e.Source + e.StackTrace);
}
}else{
if(request.downloadHandler.text == "0"){
userData = new UserData(){username = username};
Debug.Log("Created local account");
}else{
MessageBox.ShowMessage("Error logging in, Server said\n" +request.downloadHandler.text);
return 1;
}
}
}
LoadingScreen.LoadLevel("MainMenu");
return 0;
}
public static async Task<int> LinkFH(string fhid){
WWWForm form = new WWWForm();
form.AddField("username", userData.username);
form.AddField("fhid", fhid);
form.AddField("key", key);
userData.faucet_id = int.Parse(fhid);
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "link_fh.php", form))
{
var operation = request.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
Debug.Log("fh link response: " +request.downloadHandler.text);
if(request.downloadHandler.text== "0"){
userData.faucet_id = int.Parse(fhid);
Debug.Log("FH Link success");
}else{
userData.faucet_id=-1;
MessageBox.ShowMessage("Failed to Link to FH ID " + fhid + "\nPlease contact support","Error");
return -1;
}
}
return 0;
}
public static async void GoogleLogin(string username){
WWWForm form = new WWWForm();
form.AddField("username", username);
form.AddField("key", key);
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "google_login.php", form))
{
var operation = request.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
Debug.Log("glogin response: " +request.downloadHandler.text);
// MessageBox.ShowMessage(request.downloadHandler.text);
if(request.downloadHandler.text.Contains("{")){
try{
userData = JsonConvert.DeserializeObject<UserData>(request.downloadHandler.text);
if(userData == null){
throw new NullReferenceException();
}
if(userData.username.Length < 3){
throw new IndexOutOfRangeException();
}
Debug.Log("Success parsing userdata");
PlayerPrefs.SetString("username", username);
PlayerPrefs.SetString("password", username);
PlayerPrefs.Save();
}catch(Exception e){
Debug.Log("Error parsing userdata");
}
}else{
if(request.downloadHandler.text == "0"){
userData = new UserData(){username = username};
}else{
MessageBox.ShowMessage("Error logging in, Server said\n" +request.downloadHandler.text);
return;
}
}
}
LoadingScreen.LoadLevel("MainMenu");
}
public static async void AddScores(int amount){
WWWForm form = new WWWForm();
Debug.Log(userData.ToString());
form.AddField("username", userData.username);
form.AddField("password", userData.password);
form.AddField("amount", amount);
form.AddField("key", key);
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "add_scores.php", form))
{
var operation = request.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
Debug.Log("add scores response: " +request.downloadHandler.text);
if(request.downloadHandler.text.Contains("{")){
try{
userData = JsonConvert.DeserializeObject<UserData>(request.downloadHandler.text);
if(userData == null){
throw new NullReferenceException();
}
if(userData.username.Length < 3){
throw new IndexOutOfRangeException();
}
Debug.Log("Success parsing userdata");
}catch(Exception e){
Debug.Log("Error parsing userdata");
}
}else{
MessageBox.ShowMessage("Error Updating scores, Server said\n" +request.downloadHandler.text);
}
}
LoadingScreen.LoadLevel("MainMenu");
}
public static async void AddItem(string php){
WWWForm form = new WWWForm();
Debug.Log(userData.ToString());
form.AddField("username", userData.username);
form.AddField("password", userData.password);
form.AddField("key", key);
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + php, form))
{
var operation = request.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
Debug.Log($"add {php} response: " +request.downloadHandler.text);
if(request.downloadHandler.text.Contains("{")){
try{
userData = JsonConvert.DeserializeObject<UserData>(request.downloadHandler.text);
if(userData == null){
throw new NullReferenceException();
}
if(userData.username.Length < 3){
throw new IndexOutOfRangeException();
}
Debug.Log("Success parsing userdata");
}catch(Exception e){
Debug.Log("Error parsing userdata");
}
}else{
MessageBox.ShowMessage($"Error Updating {php}, Server said\n" +request.downloadHandler.text);
}
}
// LoadingScreen.LoadLevel("MainMenu");
}
public static async Task RefreshLeaderboard(bool total = false){
WWWForm form = new WWWForm();
Debug.Log(userData.ToString());
form.AddField("username", userData.username);
if(total){
form.AddField("total", "1");
}
bool foundMe = false;
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "get_leaderboard.php", form))
{
var operation = request.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
Debug.Log("leaderboard response: " +request.downloadHandler.text);
if(request.downloadHandler.text.Contains("{")){
try{
string[] items = request.downloadHandler.text.Split("<td>");
Leaderboard = new List<LeaderboardItemData>();
foreach(string item in items){
if(item == DataManager.userData.username){
foundMe=true;
}
LeaderboardItemData newItem = JsonConvert.DeserializeObject<LeaderboardItemData>(item);
Leaderboard.Add(newItem);
}
Debug.Log("Success parsing userdata");
}catch(Exception e){
Debug.Log("Error parsing leaderboard");
}
}else{
MessageBox.ShowMessage("Error getting leaderboard, Server said\n" +request.downloadHandler.text);
}
}
if(!foundMe){
form.AddField("id",DataManager.userData.id);
form.AddField("topScore","1");
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "get_player_position.php", form))
{
var operation = request.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
Debug.Log("my position: " +request.downloadHandler.text);
LeaderboardItemData newItem = new LeaderboardItemData(){position=int.Parse(request.downloadHandler.text), name= DataManager.userData.username, topScore = int.Parse(DataManager.userData.top_score), Score = int.Parse(DataManager.userData.score)};
Leaderboard.Add(newItem);
}
}
}
public static async Task UpdateGame(int playtime, int score, int top_score){
WWWForm form = new WWWForm();
Debug.Log(userData.ToString());
form.AddField("username", userData.username);
form.AddField("password", userData.password);
form.AddField("playtime", playtime);
form.AddField("score", score);
form.AddField("totalScore", top_score);
form.AddField("key", key);
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "update_game.php", form))
{
var operation = request.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
Debug.Log("update playtime response: " +request.downloadHandler.text);
if(request.downloadHandler.text.Contains("{")){
try{
userData = JsonConvert.DeserializeObject<UserData>(request.downloadHandler.text);
if(userData == null){
throw new NullReferenceException();
}
if(userData.username.Length < 3){
throw new IndexOutOfRangeException();
}
Debug.Log("Success parsing userdata");
}catch(Exception e){
Debug.Log("Error parsing userdata");
}
}else{
MessageBox.ShowMessage("Error Updating playtime, Server said\n" +request.downloadHandler.text);
}
}
}
}
[System.Serializable]
public class UserData{
public string id;
public string username;
public string password;
public string score;
public string top_score;
public int faucet_id;
public string joined_time;
public string play_time;
public string total_games;
public string asteroids;
public string near_miss;
public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}
[System.Serializable]
public class LeaderboardItemData{
public int position;
public string name;
public int topScore;
public int Score;
public string DisplayName{get{
string _name= name;
if(name.Contains("#0")){
_name = _name.Substring(0,name.IndexOf("@gmail"));
}
return _name;
}}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 25d43c191f95bffa1a079175004a4d4a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -17,4 +17,21 @@ public class Range{
{
return $"min:{min}, max:{max}";
}
}
public class Helpers{
public static string SecondsToTime(int time,bool showSeconds= true){
int seconds = time % 60;
int mins = Mathf.FloorToInt((float)time/60f);
int hours = Mathf.FloorToInt((float)mins/60f);
string output="";
if(hours>0){output+=$"{hours}H ";}
if(mins>0){output+=$"{mins}m ";}
if(showSeconds){output+=$"{seconds}s";}
return output;
}
}

View File

@@ -5,6 +5,11 @@ using UnityEngine.U2D;
public class LevelGeneratorV2 : MonoBehaviour
{
public static LevelGeneratorV2 instance;
void Awake(){
instance= this;
}
public LineRenderer debugLine;
[SerializeField]public Range amplitude = new Range(1,2);
[SerializeField]public Range distance = new Range(2,5);
@@ -19,6 +24,7 @@ public class LevelGeneratorV2 : MonoBehaviour
public float tangentSmoothness = 1.5f;
float space =0;
float spaceBot =0;
[Header("Asteroids")]
public float asteroidGenerationHeightThreshold =6;
@@ -28,10 +34,15 @@ public class LevelGeneratorV2 : MonoBehaviour
public Range asteroidTorque = new Range(0.1f,0.5f);
public Range asteroidsPerBlock = new Range(4,8);
[Header("PowerUps")]
public GameObject powerupPrefabs;
public float powerupDistanceInterval = 500;
// Start is called before the first frame update
void Start()
{
lastPowerupX = powerupDistanceInterval;
Application.targetFrameRate = 60;
// #if UNITY_EDITOR
// debugLine.gameObject.SetActive(true);
@@ -57,10 +68,12 @@ public class LevelGeneratorV2 : MonoBehaviour
List<Vector3> points = new List<Vector3>();
float a;
public float heightSmoothness = 0.1f;
float lastPowerupX;
void GenerateNext(int amount = 50){
Range height = heights[Random.Range(0,heights.Length)];
Debug.Log(height);
if(space <= 0){space = height.GetRandom();}
if(spaceBot <= 0){spaceBot = height.GetRandom();}
space = Mathf.Lerp(space, height.GetRandom(), heightSmoothness);
if(points.Count <= 0){points.Add(new Vector3(0,0));}
@@ -85,6 +98,12 @@ public class LevelGeneratorV2 : MonoBehaviour
rb.transform.localScale = rb.transform.localScale * asteroidScale.GetRandom();
asteroids++;
}
if(lastPowerupX < x){
lastPowerupX += powerupDistanceInterval;
borrowedPickups.Add(ObjectPool.Spawn(powerupPrefabs, new Vector3(x,y)));
}
}
@@ -108,6 +127,7 @@ public class LevelGeneratorV2 : MonoBehaviour
//Top Terrain
SpriteShapeController top_controller = pooled[0];
spaceBot = Mathf.Lerp(spaceBot, height.GetRandom(), heightSmoothness);
borrowed.Add(pooled[0]);
pooled.RemoveAt(0);
@@ -115,18 +135,19 @@ public class LevelGeneratorV2 : MonoBehaviour
top_controller.spline.Clear();
InsertNewPoint(top_controller, points[startIndex]+ new Vector3(0, 50));
for(int i=startIndex; i < points.Count; i++){
InsertNewPoint(top_controller, points[i] + new Vector3(0, space));
InsertNewPoint(top_controller, points[i] + new Vector3(0, spaceBot));
}
InsertNewPoint(top_controller, points[points.Count-1] + new Vector3(0,50));
top_controller.GetComponent<PolygonCollider2D>().enabled=true;
top_controller.transform.position = Vector3.zero;
top_controller.gameObject.SetActive(false);
top_controller.gameObject.SetActive(true);
Debug.Log(space+ ", " + spaceBot);
UpdateLine();
}
public List<GameObject> borrowedAsteroids = new List<GameObject>();
public List<GameObject> borrowedPickups = new List<GameObject>();
void CleanupBorrowed(){
for(int i= borrowed.Count-1; i > 0; i--){
if(borrowed[i].spline.GetPosition(borrowed[i].spline.GetPointCount()-1).x < PlayerController.position.x -30){
@@ -141,6 +162,22 @@ public class LevelGeneratorV2 : MonoBehaviour
borrowedAsteroids.RemoveAt(i);
}
}
for(int i=borrowedPickups.Count-1; i> 0; i--){
if(borrowedPickups[i].transform.position.x + 20 < PlayerController.position.x){
ObjectPool.Despawn(borrowedPickups[i]);
borrowedPickups.RemoveAt(i);
}
}
}
public void DespawnPickup(GameObject obj){
ObjectPool.Despawn(obj);
borrowedPickups.Remove(obj);
}
public void DespawnAsteroid(GameObject obj){
ObjectPool.Despawn(obj);
borrowedAsteroids.Remove(obj);
}
void UpdateLine(){

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LoadingScreen : MonoBehaviour
{
public static LoadingScreen instance {get; private set;}
@@ -79,7 +80,10 @@ public class LoadingScreen : MonoBehaviour
}
Debug.Log("Loading scene vanishing");
loading = false;
AudioManager.ChangeMusicToScene(levelName);
}
void SetProgress(float value)

View File

@@ -0,0 +1,140 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Google;
using UnityEngine;
using UnityEngine.UI;
public class LoginManager : MonoBehaviour
{
public Text txtChangeLogin;
public Text txtLogin;
public InputField usernameInput,passwordInput;
public GameObject loadingPanel;
void Awake(){
loadingPanel.SetActive(true);
configuration = new GoogleSignInConfiguration {
WebClientId = "656661869871-klbj2ujfiucqic4uugb0d2t3p3vbe4jp.apps.googleusercontent.com",
RequestIdToken = true,
RequestEmail=true,
};
}
async void Start(){
if(PlayerPrefs.HasKey("username") && PlayerPrefs.HasKey("password")){
int result = await DataManager.Login(PlayerPrefs.GetString("username"), PlayerPrefs.GetString("password"));
if(result == 0){return;}
}
loadingPanel.SetActive(false);
}
public async void Login(){
if(usernameInput.text.Length < 4 || passwordInput.text.Length < 4){
MessageBox.ShowMessage("Username and Password must be longer than 4 characters","Invalid Input");
return;
}
loadingPanel.SetActive(true);
int result = await DataManager.Login(usernameInput.text, passwordInput.text);
if(result == 0){return;}
loadingPanel.SetActive(false);
}
public async void Register(){
loadingPanel.SetActive(true);
int result = await DataManager.Login(usernameInput.text, passwordInput.text);
if(result == 0){return;}
loadingPanel.SetActive(false);
}
private GoogleSignInConfiguration configuration;
public void OnSignIn() {
GoogleSignIn.Configuration = configuration;
GoogleSignIn.Configuration.UseGameSignIn = false;
GoogleSignIn.Configuration.RequestIdToken = true;
// AddStatusText("Calling SignIn");
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(
OnAuthenticationFinished);
}
public void OnSignOut() {
// AddStatusText("Calling SignOut");
GoogleSignIn.DefaultInstance.SignOut();
}
public void OnDisconnect() {
// AddStatusText("Calling Disconnect");
GoogleSignIn.DefaultInstance.Disconnect();
}
internal void OnAuthenticationFinished(Task<GoogleSignInUser> task) {
if (task.IsFaulted) {
using (IEnumerator<System.Exception> enumerator =
task.Exception.InnerExceptions.GetEnumerator()) {
if (enumerator.MoveNext()) {
GoogleSignIn.SignInException error =
(GoogleSignIn.SignInException)enumerator.Current;
// AddStatusText("Got Error: " + error.Status + " " + error.Message);
MessageBox.ShowMessage("Got Error: " + error.Status + " " + error.Message);
} else {
// AddStatusText("Got Unexpected Exception?!?" + task.Exception);
MessageBox.ShowMessage("Got Unexpected Exception?!?" + task.Exception);
}
}
} else if(task.IsCanceled) {
// AddStatusText("Canceled");
} else {
// AddStatusText("Welcome: " + task.Result.DisplayName + "!");
// MessageBox.ShowMessage($"email: {task.Result.Email}\nDisplay:{task.Result.DisplayName}\ntoken:{task.Result.IdToken}");
StartCoroutine(DoneLogin(task.Result.Email));
}
}
IEnumerator DoneLogin(string username){
yield return new WaitForSeconds(0.5f);
DataManager.GoogleLogin(username);
}
public void OnSignInSilently() {
GoogleSignIn.Configuration = configuration;
GoogleSignIn.Configuration.UseGameSignIn = false;
GoogleSignIn.Configuration.RequestIdToken = true;
// AddStatusText("Calling SignIn Silently");
GoogleSignIn.DefaultInstance.SignInSilently()
.ContinueWith(OnAuthenticationFinished);
}
public void OnGamesSignIn() {
GoogleSignIn.Configuration = configuration;
GoogleSignIn.Configuration.UseGameSignIn = true;
GoogleSignIn.Configuration.RequestIdToken = false;
// AddStatusText("Calling Games SignIn");
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(
OnAuthenticationFinished);
}
public bool isLogin => txtLogin.text == "Login";
public void ToggleLoginPage(){
if(txtLogin.text == "Login"){
txtLogin.text = "Register";
txtChangeLogin.text = "Have an account?";
}else{
txtLogin.text = "Login";
txtChangeLogin.text = "Don't have an account?";
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26e46304a63184ae48436af6cd324f8d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,20 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MainMenu : MonoBehaviour
{
{
public Text[] txtStats;
public GameObject LinkPanel;
public InputField FHIdInput;
public void OnPlay(){
LoadingScreen.LoadLevel("Game");
}
void Start()
{
public void OnQuit(){
Application.Quit();
}
// Update is called once per frame
void Update()
void Start()
{
if(!DataManager.isLogged){Application.LoadLevel(0);}
foreach(Text txtStat in txtStats){
txtStat.text = txtStat.text.Replace("{score}",DataManager.userData.score).Replace("{top_score}",DataManager.userData.top_score).Replace("{play_time}",Helpers.SecondsToTime(int.Parse(DataManager.userData.play_time),showSeconds:false)).Replace("{asteroids}",DataManager.userData.asteroids).Replace("{near_miss}",DataManager.userData.near_miss).Replace("{total_games}",DataManager.userData.total_games);
}
}
public void OnLinkPanelOpen(){
if(DataManager.userData.faucet_id > 0){
MessageBox.ShowMessage("This account has already linked to FH ID: " + DataManager.userData.faucet_id,"Already Linked");
return;
}else{
LinkPanel.SetActive(true);
}
}
public async void OnLink(){
if(FHIdInput.text.Length <=0){
MessageBox.ShowMessage("Please enter the FH ID to Link","Invalid");
return;
}
int fhid =-1;
try{
fhid = int.Parse(FHIdInput.text);
}catch{
MessageBox.ShowMessage("Please enter a valid number","Invalid Number");
return;
}
if(fhid < 0){return;}
LinkPanel.SetActive(false);
int result = await DataManager.LinkFH(fhid.ToString());
if(result==0)MessageBox.ShowMessage( "This account has been successfully linked to FH ID " + DataManager.userData.faucet_id,"Success");
}
public void OnSignout(){
DataManager.Signout();
LoadingScreen.LoadLevel("Login");
}
}

View File

@@ -0,0 +1,58 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MessageBox : MonoBehaviour
{
public static MessageBox instance { get; private set;}
void Awake(){
if(instance != null){Destroy(gameObject);}
instance = this;
canvasGroup = GetComponent<CanvasGroup>();
closeButton.onClick.AddListener(()=>{SetActive(false);});
}
private CanvasGroup canvasGroup;
[SerializeField]private Text messageTxt;
[SerializeField]private Text titleTxt;
[SerializeField]private Button closeButton;
void Start()
{
DontDestroyOnLoad(gameObject);
SetActive(false);
}
void SetActive(bool value){
// StartCoroutine(setActive(value));
canvasGroup.alpha= value ? 1 : 0;
canvasGroup.blocksRaycasts = value;
canvasGroup.interactable = value;
}
private static string message;
public static void ShowMessage(string message,string title = "Notice"){
if(instance == null){Debug.LogError("Message was shown before message box was init");return;}
instance.showMessage(message,title);
}
public void showMessage(string _message, string title){
message = _message;
titleTxt.text = title;
StartCoroutine(_showMessage());
SetActive(true);
}
IEnumerator _showMessage(){
messageTxt.text = "";
closeButton.gameObject.SetActive(false);
for(int i=0; i < message.Length; i++){
messageTxt.text += message[i];
yield return new WaitForSeconds(0.01f);
}
closeButton.gameObject.SetActive(true);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 616d1ce600831ae29bb4c5532189433e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NearMiss : MonoBehaviour
{
void OnTriggerExit2D(Collider2D other){
if(PlayerController.instance.PowerupActive){return;}
if(other.tag == "asteroid"){
DataManager.AddItem("add_near_miss.php");
PlayerController.NearMissFX();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1be184640afebda4b8d913b20706aa33
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -5,7 +5,23 @@ using UnityEngine;
public class Obstacle : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other){
if(other.tag == "Powerup"){
LevelGeneratorV2.instance.DespawnPickup(other.gameObject);
PlayerController.instance.ActivatePowerup();
return;
}
Debug.Log(other.name);
if(other.tag == "asteroid"){
if(PlayerController.instance.PowerupActive){
PlayerController.instance.SpawnExplosionFX(other.transform.position);
LevelGeneratorV2.instance.DespawnAsteroid(other.gameObject);
DataManager.AddItem("add_asteroid.php");
return;
}
}
PlayerController.instance.GameOver();
}
}

View File

@@ -1,14 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Newtonsoft.Json;
public class PlayerController : MonoBehaviour
{
void Awake(){
instance = this;
if(!DataManager.isLogged){
Application.LoadLevel(0);
}
}
public static PlayerController instance;
@@ -23,23 +27,21 @@ public class PlayerController : MonoBehaviour
public Text txtScore;
public GameObject ExplosionFX;
public AudioClip ExplosionSFX;
void Start()
{
}
// float t2=0;
// Update is called once per frame
float serverTimer = 0;
void FixedUpdate()
{
// if(t2 < 1){
// t2+=Time.deltaTime;
// return;
// }
transform.Translate(new Vector3(movingSpeed,0), Space.World);
transform.Translate(new Vector3(movingSpeed * (PowerupActive? PowerupSpeedMult : 1),0), Space.World);
input = Mathf.Lerp(input, dif / inputRange, inputSmoothness);
input = Mathf.Clamp(Mathf.Lerp(input, dif / inputRange, inputSmoothness),-1,1);
transform.Translate(new Vector3(0,input * verticalSpeed), Space.World);
transform.localEulerAngles = new Vector3(0,0,input * rotationRange);
@@ -48,7 +50,32 @@ public class PlayerController : MonoBehaviour
movingSpeed += speedIncremental * Time.deltaTime;
if(serverTimer < 10){
serverTimer+=Time.deltaTime;
}else{
serverTimer=0;
TalkWithServer();
}
playtime+=Time.deltaTime;
if(powerupTimer > 0){
powerupTimer-=Time.deltaTime;
}
}
float playtime=0;
int score=0;
async void TalkWithServer(){
await DataManager.UpdateGame((int)playtime, (int)(transform.position.x-score), (int)transform.position.x);
playtime=0;
score=(int)transform.position.x;
}
public float input = 0;
public float inputSmoothness =0.1f;
public float inputRange = 200;
@@ -71,13 +98,36 @@ public class PlayerController : MonoBehaviour
dif = 0;
startedPos = 0;
}
public Animator nearMissAnim;
public static void NearMissFX(){
instance.nearMissAnim.gameObject.SetActive(true);
instance.nearMissAnim.CrossFade("txt_intro",0.01f);
}
public float PowerupLife = 30;
public float PowerupSpeedMult = 1.3f;
public bool PowerupActive => powerupTimer > 0;
public float powerupTimer = 0;
public void ActivatePowerup(){
powerupTimer = PowerupLife;
}
public void GameOver(){
public async void GameOver(){
// Application.LoadLevel(0);
TalkWithServer();
DataManager.AddItem("add_game.php");
Instantiate(ExplosionFX, transform.position, Quaternion.identity);
AudioManager.PlayExplosion();
Destroy(gameObject);
await Task.Delay(500);
GameOverUI.Activate();
Instantiate(ExplosionFX, transform.position, Quaternion.identity);
Destroy(this);
}
public void SpawnExplosionFX(Vector3 pos){
Instantiate(ExplosionFX,pos, Quaternion.identity);
AudioManager.PlayExplosion();
}
}

View File

@@ -28,9 +28,10 @@ public class TweenHelper : MonoBehaviour
transform.localScale = startScale;
}
public bool intro = true;
void Start()
{
Intro();
if(intro)Intro();
}
public void Intro(){
@@ -76,6 +77,15 @@ public class TweenHelper : MonoBehaviour
}
public void MoveOut(){
LeanTween.move(gameObject, defaultPos + new Vector3(10000,0), position_time).setEase(position_type);
}
public void MoveIn(){
LeanTween.move(gameObject,Vector3.zero, position_time).setEase(position_type);
}
public void OutroAll(){
TweenManager.OutroAll();
}