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

@@ -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();
}
}