Base game sfx done
This commit is contained in:
@@ -3,14 +3,20 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using LightReflectiveMirror;
|
||||
using UnityEngine.SceneManagement;
|
||||
public class AutoConnect : MonoBehaviour
|
||||
{
|
||||
public static AutoConnect instance;
|
||||
public bool isClient;
|
||||
public static int serverPort;
|
||||
public bool isRanked;
|
||||
public kcp2k.KcpTransport transport;
|
||||
void Start()
|
||||
{
|
||||
instance = this;
|
||||
if(isClient && !DBmanager.LoggedIn){
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
if (isRanked)
|
||||
{
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ public class MinigameManager : NetworkBehaviour
|
||||
{
|
||||
public static MinigameManager instance;
|
||||
public bool isRanked;
|
||||
[SyncVar]
|
||||
public bool RankedGameStarted=false;
|
||||
[SyncVar(hook =nameof(OnWinnerChanged))]
|
||||
public int winnerId=-1;
|
||||
@@ -17,7 +18,15 @@ public class MinigameManager : NetworkBehaviour
|
||||
public double startedTime = 0;
|
||||
public GameObject waitingScreen;
|
||||
public RankedGameSummary rankedSummary;
|
||||
[SyncVar(hook= nameof(OnMapRadisuChanged))]
|
||||
public float mapRadius;
|
||||
[SyncVar(hook=nameof(OnMapCenterChanged))]
|
||||
public Vector2 mapCenter = Vector2.zero;
|
||||
public Transform safeZone;
|
||||
public float safeZoneCoolTime = 60;
|
||||
public float safeZoneShrinkTime = 30;
|
||||
float safeZoneShrinkSpeed;
|
||||
|
||||
public int maxMoons, maxStars = 100;
|
||||
public Transform pickupItemsParent;
|
||||
private List<PickupItem> ActiveMoons = new List<PickupItem>();
|
||||
@@ -36,22 +45,13 @@ public class MinigameManager : NetworkBehaviour
|
||||
|
||||
DBmanager.OnStateChanged.AddListener(UpdateMaterialValues);
|
||||
UpdateMaterialValues();
|
||||
|
||||
safeZoneShrinkSpeed = mapRadius / safeZoneShrinkTime;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// if(!DBmanager.LoggedIn){SceneManager.LoadScene(0);} //Signed out, no game for u
|
||||
|
||||
if(isRanked){
|
||||
// RankedGameStarted= (FindObjectsOfType<SpaceshipController>().Length >=2);
|
||||
if(!RankedGameStarted && !isServer){
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
if(players.Length >= 2){
|
||||
RankedGameStarted=true;
|
||||
}
|
||||
}
|
||||
waitingScreen.SetActive(!RankedGameStarted);
|
||||
}
|
||||
|
||||
if (!isServer) { return; }
|
||||
|
||||
@@ -59,16 +59,46 @@ public class MinigameManager : NetworkBehaviour
|
||||
KillOutOfBoundsPlayers();
|
||||
if(isRanked){RankedMechanics();}
|
||||
}
|
||||
public float timeElapsed => (float)(NetworkTime.time - startedTime);
|
||||
bool shrinkStarted =false;
|
||||
uint[] PlayersIds;
|
||||
Vector2 newMapCenter = Vector2.zero;
|
||||
public void StartRanked(){
|
||||
startedTime=NetworkTime.time;
|
||||
RankedGameStarted=true;
|
||||
|
||||
void RankedMechanics(){
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
if(players.Length < 2){
|
||||
//Not enough players
|
||||
}else{
|
||||
if(!RankedGameStarted){
|
||||
startedTime=NetworkTime.time;
|
||||
PlayersIds = new uint[players.Length];
|
||||
for(int i=0; i < players.Length; i++){
|
||||
PlayersIds[i] = players[i].netId;
|
||||
}
|
||||
}
|
||||
void RankedMechanics(){
|
||||
mapCenter += ((newMapCenter - mapCenter) / safeZoneShrinkTime) * Time.deltaTime;
|
||||
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
if(players.Length >= 2 && !RankedGameStarted){
|
||||
if(players[0].ready && players[1].ready){
|
||||
//Both are ready
|
||||
StartRanked();
|
||||
}
|
||||
RankedGameStarted=true;
|
||||
}
|
||||
|
||||
|
||||
if(RankedGameStarted){
|
||||
if(timeElapsed > safeZoneCoolTime){
|
||||
if(!shrinkStarted){
|
||||
shrinkStarted=true;
|
||||
newMapCenter = getRandomPointInCirlce(mapCenter, mapRadius /2f);
|
||||
KillfeedMgr.instance.AddNewEntry("Safe zone is shrinking!");
|
||||
RpcKillfeed("Safe-zone is Shrinking!");
|
||||
}
|
||||
if(mapRadius > 3){
|
||||
mapRadius -= Time.deltaTime * safeZoneShrinkSpeed;
|
||||
safeZone.localScale = new Vector3(mapRadius, mapRadius,mapRadius);
|
||||
}
|
||||
}
|
||||
|
||||
if(players[0].moonsCollected >= 30){
|
||||
//player 1 has won
|
||||
winnerId = (int)players[0].netId;
|
||||
@@ -90,8 +120,26 @@ public class MinigameManager : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapRadisuChanged(float oldVal, float newVal){
|
||||
if(isRanked){
|
||||
safeZone.localScale = new Vector3(mapRadius, mapRadius,mapRadius);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapCenterChanged(Vector2 oldPos, Vector2 newPos){
|
||||
if(isRanked){
|
||||
safeZone.position = newPos;
|
||||
}
|
||||
}
|
||||
|
||||
void RpcKillfeed(string message){
|
||||
KillfeedMgr.instance.AddNewEntry(message);
|
||||
}
|
||||
|
||||
|
||||
void OnWinnerChanged(int oldVal, int newVal){
|
||||
if(newVal<= 0){return;}
|
||||
// if(!isLocalPlayer){return;}
|
||||
Debug.Log($"{newVal} id won!");
|
||||
SpaceshipController localPlayer = SceneData.localPlayer.GetComponent<SpaceshipController>();
|
||||
if(newVal == localPlayer.netId){
|
||||
@@ -109,16 +157,31 @@ public class MinigameManager : NetworkBehaviour
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
foreach (SpaceshipController player in players)
|
||||
{
|
||||
if (Vector3.Distance(player.transform.position, Vector3.zero) > mapRadius)
|
||||
if (Vector3.Distance(player.transform.position, mapCenter) > mapRadius)
|
||||
{
|
||||
//Out of bounds. Kill him
|
||||
player.Die("Playzone");
|
||||
if(isRanked){
|
||||
player.DecreaseTrail(Time.deltaTime * 4);
|
||||
if(player.trailTime < 1){
|
||||
winnerId = (int)(PlayersIds[0] == player.netId ? PlayersIds[1] : PlayersIds[0]);
|
||||
player.Die("Playzone");
|
||||
|
||||
}
|
||||
}else{
|
||||
player.Die("Playzone");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandlePickupSpawn()
|
||||
{
|
||||
foreach(PickupItem moon in ActiveMoons){
|
||||
if(Vector2.Distance(Vector2.zero, moon.transform.position) > mapRadius){
|
||||
moon.Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
int moonsNeed = maxMoons - ActiveMoons.Count;
|
||||
int starsNeed = maxStars - ActiveStars.Count;
|
||||
|
||||
|
||||
52
Assets/Game/Scripts/Minigame/RankedSplash.cs
Normal file
52
Assets/Game/Scripts/Minigame/RankedSplash.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
public class RankedSplash : MonoBehaviour
|
||||
{
|
||||
public int playerCountRequired;
|
||||
public TMP_Text statusTxt;
|
||||
void Start()
|
||||
{
|
||||
statusTxt.text = "Waiting for confirmation";
|
||||
}
|
||||
bool allConnected= false;
|
||||
string rules = @"1.Last one standing or the first to \ncollect 30 moons wins!
|
||||
2.Stay in safe zone to survive
|
||||
3.Safe-Zone gets shrinked in 5 mins
|
||||
4.Have fun!";
|
||||
void Update()
|
||||
{
|
||||
// if(AutoConnect.instance.isClient){return;}
|
||||
if(MinigameManager.instance ==null){return;}
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
if(players.Length >= playerCountRequired && players[0].ready && players[1].ready){
|
||||
//Start the match!
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if(!MinigameManager.instance.RankedGameStarted){
|
||||
|
||||
if(!allConnected && players.Length < playerCountRequired){
|
||||
statusTxt.text = "Waiting for opponents to connect";
|
||||
}else{
|
||||
if(!allConnected){
|
||||
allConnected = true;
|
||||
MessageDialog.instance.ShowQuestion("Confirm", $"Click yes to confirm you understand the rules below.\n{rules}", OnAgree, ()=>{}, onlyYes:true);
|
||||
}
|
||||
|
||||
if(players[0].ready && players[1].ready){
|
||||
//Start the match!
|
||||
gameObject.SetActive(false);
|
||||
}else{
|
||||
statusTxt.text = "Waiting for players to get ready";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnAgree(){
|
||||
SceneData.localPlayer.GetComponent<SpaceshipController>().SetReady(true);
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/RankedSplash.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/RankedSplash.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8aaf26be5e0f9cf6ea304725e39a0f8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -29,7 +29,7 @@ public class SceneDataHolder : MonoBehaviour
|
||||
}
|
||||
|
||||
public void ShowDeadscreen(int xpEarned, int metalEarned, double survivalTime){
|
||||
AdsManager.instance.ShowInterestitial();
|
||||
if(AdsManager.instance!=null){AdsManager.instance.ShowInterestitial();}
|
||||
deadScreen.SetActive(true);
|
||||
xpEarnings.SetActive(xpEarned > 0); metalEarnings.SetActive(metalEarned > 0);
|
||||
xpEarnings.GetComponentInChildren<TMP_Text>().text = xpEarned.ToString();
|
||||
|
||||
@@ -8,6 +8,7 @@ using UnityEngine.UI;
|
||||
public class SkinShopManager : MonoBehaviour
|
||||
{
|
||||
public static SkinShopManager instance;
|
||||
public Building skinShopBuilding;
|
||||
public SkinsData skinsData;
|
||||
public GameObject popup;
|
||||
|
||||
@@ -53,6 +54,13 @@ public class SkinShopManager : MonoBehaviour
|
||||
}
|
||||
skinShopItems = new List<SkinShopItem>();
|
||||
for(int i=0; i<skinsData.skins.Length;i++){
|
||||
int rarity = 0;
|
||||
if(skinsData.skins[i].skinType == SkinType.Rare){rarity=1;}
|
||||
if(skinsData.skins[i].skinType == SkinType.Legendary){rarity=2;}
|
||||
|
||||
if(skinShopBuilding.curLevel < rarity){
|
||||
continue;
|
||||
}
|
||||
SkinShopItem newItem = Instantiate(listItemPrefab, listItemsParent).GetComponent<SkinShopItem>();
|
||||
newItem.Set(skinsData.skins[i]);
|
||||
skinShopItems.Add(newItem);
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Collections;
|
||||
|
||||
public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
[SyncVar]
|
||||
public bool ready;
|
||||
public SpriteRenderer playerImg;
|
||||
public SkinsData skins;
|
||||
[SyncVar(hook = nameof(OnSkinChanged))]
|
||||
@@ -26,8 +28,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
public bool dead;
|
||||
[SyncVar]
|
||||
public float speed;
|
||||
[SyncVar(hook = nameof(OnScaleChanged))]
|
||||
public float scaleMultiplier = 1;
|
||||
public float _scaleMultiplier = 1;
|
||||
public Text pnameTxt;
|
||||
public Transform body;
|
||||
public TrailMgr trailMgr;
|
||||
@@ -49,6 +50,19 @@ public class SpaceshipController : NetworkBehaviour
|
||||
|
||||
public float distanceFromCenter = 0;
|
||||
|
||||
public void SetReady(bool value){
|
||||
if(isServer){
|
||||
ready =value;
|
||||
}else{
|
||||
CmdSetReady(value);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetReady(bool value){
|
||||
ready= value;
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetPname(string value)
|
||||
{
|
||||
@@ -57,6 +71,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
void OnPnameChanged(string oldName, string newName)
|
||||
{
|
||||
pnameTxt.text = newName;
|
||||
Debug.Log(pname + " Joined the game");
|
||||
}
|
||||
|
||||
[Command]
|
||||
@@ -85,6 +100,13 @@ public class SpaceshipController : NetworkBehaviour
|
||||
void OnTrailTimeChanged(float oldValue, float newValue)
|
||||
{
|
||||
trailMgr.trail.time = newValue;
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
SceneData.holder.boostBtn.gameObject.SetActive(scale > 1);
|
||||
if(scale <=1 && boosting){
|
||||
CmdSetBoosting(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnBoostDown()
|
||||
@@ -117,17 +139,6 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void OnScaleChanged(float oldScale, float newScale)
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
SceneData.holder.boostBtn.gameObject.SetActive(newScale > 1);
|
||||
if(newScale <=1 && boosting){
|
||||
CmdSetBoosting(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetBoosting(bool value)
|
||||
{
|
||||
@@ -144,7 +155,6 @@ public class SpaceshipController : NetworkBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
scaleMultiplier = 1;
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
ResetStats();
|
||||
@@ -193,6 +203,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
int roundedTime => Mathf.FloorToInt((float)timeInMillis / 100f) * 100;
|
||||
|
||||
int lastClientUpdateTime = 0;
|
||||
float scale => Mathf.Clamp(1+(trailTime * _scaleMultiplier),1,10);
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (MinigameManager.instance.isRanked && !MinigameManager.instance.RankedGameStarted) { return; }
|
||||
@@ -200,8 +211,8 @@ public class SpaceshipController : NetworkBehaviour
|
||||
pnameTxt.rectTransform.rotation = Quaternion.Euler(Vector3.zero);
|
||||
|
||||
//Update size of trail and spaceship
|
||||
transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(scaleMultiplier, scaleMultiplier, scaleMultiplier), 0.1f);
|
||||
trailMgr.trail.startWidth = Mathf.Lerp(trailMgr.trail.startWidth, scaleMultiplier, 0.1f);
|
||||
transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(scale, scale, scale), 0.1f);
|
||||
trailMgr.trail.startWidth = Mathf.Lerp(trailMgr.trail.startWidth, scale, 0.1f);
|
||||
|
||||
if (dead) { return; }
|
||||
|
||||
@@ -235,12 +246,12 @@ public class SpaceshipController : NetworkBehaviour
|
||||
if (isServer)
|
||||
{
|
||||
//boost check
|
||||
if (boosting && scaleMultiplier > 1)
|
||||
if (boosting && scale > 1)
|
||||
{
|
||||
speed = movingSpeed * 2;
|
||||
scaleMultiplier -= Time.deltaTime;
|
||||
|
||||
if (scaleMultiplier < 1) { scaleMultiplier = 1; } //Clamp in case gets lower
|
||||
DecreaseTrail(Time.deltaTime * 3);
|
||||
// scaleMultiplier -= Time.deltaTime;
|
||||
// if (scaleMultiplier < 1) { scaleMultiplier = 1; } //Clamp in case gets lower
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -512,8 +523,8 @@ public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
Kills++;
|
||||
Scores += 10; //TODO: Need to change Scores on kills?
|
||||
scaleMultiplier += 0.05f;
|
||||
OnScaleChanged(scaleMultiplier, scaleMultiplier);
|
||||
// scaleMultiplier += 0.05f;
|
||||
// OnScaleChanged(scaleMultiplier, scaleMultiplier);
|
||||
IncreaseTrail(trailIncrementRate);
|
||||
RpcOnKill();
|
||||
}
|
||||
@@ -537,7 +548,14 @@ public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
trailTime = trailMgr.trail.time + rate;
|
||||
trailMgr.trail.time = trailTime;
|
||||
Debug.Log("Increasing trail of" + pname);
|
||||
// Debug.Log("Increasing trail of" + pname);
|
||||
}
|
||||
|
||||
public void DecreaseTrail(float rate)
|
||||
{
|
||||
trailTime = Mathf.Clamp(trailMgr.trail.time - rate,0,float.MaxValue);
|
||||
trailMgr.trail.time = trailTime;
|
||||
// Debug.Log("Decreasing trail of" + pname);
|
||||
}
|
||||
|
||||
[Command]
|
||||
@@ -553,13 +571,13 @@ public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
case PickupItem.PickupType.Moon:
|
||||
IncreaseTrail(trailIncrementRate);
|
||||
scaleMultiplier += 0.05f;
|
||||
// scaleMultiplier += 0.05f;
|
||||
moonsCollected++;
|
||||
break;
|
||||
|
||||
case PickupItem.PickupType.Star:
|
||||
IncreaseTrail(trailIncrementRate / 2f);
|
||||
scaleMultiplier += 0.025f;
|
||||
// scaleMultiplier += 0.025f;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -583,8 +601,8 @@ public class SpaceshipController : NetworkBehaviour
|
||||
Debug.Log($"Sending death signal to {pname} by {killer}");
|
||||
|
||||
//Handle Respawning
|
||||
OnScaleChanged(scaleMultiplier, 1);
|
||||
scaleMultiplier = 1;
|
||||
// OnScaleChanged(scaleMultiplier, 1);
|
||||
// scaleMultiplier = 1;
|
||||
dead = true;
|
||||
Scores = 0;
|
||||
Kills = 0;
|
||||
|
||||
Reference in New Issue
Block a user