207 lines
5.6 KiB
C#
207 lines
5.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using CustomExtensions;
|
|
|
|
[System.Serializable]
|
|
public class RankLevel{
|
|
public string name;
|
|
public int minimumTrophies;
|
|
public int trophieLoss;
|
|
public int entryFee;
|
|
public int energyReward;
|
|
public Sprite image;
|
|
public Color color;
|
|
}
|
|
|
|
|
|
public static class ExtensionMethods
|
|
{
|
|
public static int RoundOff (this int i)
|
|
{
|
|
return ((int)Mathf.Round((float)i / 10f)) * 10;
|
|
}
|
|
}
|
|
|
|
|
|
public static class DebugHelpers{
|
|
public static int sphereLength = 10;
|
|
public static void DrawSphere(Vector3 position, float radius, Color? color = null){
|
|
if(color == null){
|
|
color = Color.white;
|
|
}
|
|
|
|
for(int i =1; i < sphereLength; i++){
|
|
float prevAngle =( Mathf.PI * 2) / i;
|
|
float curAngle =( Mathf.PI * 2) / i;
|
|
|
|
float curX =Mathf.Cos(curAngle) * radius;
|
|
float curY = Mathf.Sin(curAngle) * radius;
|
|
|
|
float prevX = Mathf.Cos(prevAngle) * radius;
|
|
float prevY = Mathf.Sin(prevAngle) * radius;
|
|
Debug.DrawLine(position + new Vector3(prevX, prevY),position + new Vector3(curX, curY), (Color)color);
|
|
}
|
|
}
|
|
}
|
|
|
|
public struct InputState{
|
|
public int Tick;
|
|
public Vector2 Input;
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"tick: {Tick}, input: {Input}";
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
InputState _obj = (InputState) obj;
|
|
if(_obj.Input == Input){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool CloseEnough(InputState other, float threshold) => Mathf.Abs((other.Input-Input).magnitude) < threshold;
|
|
}
|
|
|
|
public struct PlayerState{
|
|
public int Tick;
|
|
public Vector3 Position;
|
|
public Quaternion Rotation;
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"tick: {Tick},pos: {Position}, rot: {Rotation}";
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
PlayerState _obj = (PlayerState) obj;
|
|
if(_obj.Position == Position && _obj.Rotation == Rotation){
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public bool CloseEnough(PlayerState other, float threshold) => Mathf.Abs((other.Position-Position).magnitude) < threshold && Rotation.Approximately(other.Rotation, threshold);
|
|
|
|
public float Difference(PlayerState other){
|
|
return (Mathf.Abs((other.Position-Position).magnitude) + Rotation.Difference(other.Rotation))/2f;
|
|
}
|
|
|
|
}
|
|
|
|
public class Helpers{
|
|
public static int unixTimestamp = (int)System.DateTime.UtcNow.Subtract(new System.DateTime(1970, 1, 1)).TotalSeconds;
|
|
|
|
}
|
|
|
|
namespace CustomExtensions{
|
|
public static class QuaternionExtensions{
|
|
public static bool Approximately(this Quaternion quatA, Quaternion value, float acceptableRange)
|
|
{
|
|
return 1 - Mathf.Abs(Quaternion.Dot(quatA, value)) < acceptableRange;
|
|
}
|
|
public static float Difference(this Quaternion quatA, Quaternion value){
|
|
return 1 - Mathf.Abs(Quaternion.Dot(quatA, value));
|
|
}
|
|
|
|
|
|
public static float GetEnergy(this PickupItem.PickupType type){
|
|
switch(type){
|
|
case PickupItem.PickupType.Moon1:
|
|
return 1;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Moon2:
|
|
return 2;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Moon3:
|
|
return 3;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Moon4:
|
|
return 4;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Moon5:
|
|
return 5;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star:
|
|
return 0.5f;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star2:
|
|
return 1f;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star3:
|
|
return 1.5f;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star4:
|
|
return 2f;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star5:
|
|
return 2.5f;
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
public static Color GetColor(this PickupItem.PickupType type){
|
|
switch(type){
|
|
case PickupItem.PickupType.Moon1:
|
|
return Color.grey;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Moon2:
|
|
return Color.green;;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Moon3:
|
|
return Color.blue;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Moon4:
|
|
return Color.magenta;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Moon5:
|
|
return Color.yellow;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star:
|
|
return Color.grey;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star2:
|
|
return Color.green;;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star3:
|
|
return Color.blue;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star4:
|
|
return Color.magenta;
|
|
break;
|
|
|
|
case PickupItem.PickupType.Star5:
|
|
return Color.yellow;
|
|
break;
|
|
}
|
|
|
|
return Color.white;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} |