-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update 2.0, Time Master and Investigator rewrite
Rewriting of the Time Master and the Investigator The time master now stores the position of all players.. The animation of the footprints is now managed by a coroutine.
- Loading branch information
Showing
11 changed files
with
121 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,54 @@ | ||
using RolesMods.Utility; | ||
using Reactor; | ||
using RolesMods.Utility; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace RolesMods.Systems.Investigator { | ||
class FootPrint { | ||
public static List<FootPrint> allFootprint = new List<FootPrint>(); | ||
|
||
private readonly float footPrintSize; | ||
private Color footPrintColor; | ||
private Vector3 footPrintPosition; | ||
private readonly float footPrintDuration; | ||
private readonly int footPrintUnixTime; | ||
private GameObject footPrint; | ||
private Vector2 velocity; | ||
private SpriteRenderer spriteRenderer; | ||
private readonly PlayerControl player; | ||
public PlayerControl player; | ||
public Vector2 position; | ||
|
||
public FootPrint(float footPrintSize, float footPrintDuration, PlayerControl player) { | ||
this.footPrintSize = footPrintSize; | ||
this.footPrintColor = Palette.PlayerColors[(int) player.Data.ColorId]; | ||
this.footPrintPosition = player.transform.position; | ||
this.footPrintDuration = footPrintDuration; | ||
this.velocity = player.gameObject.GetComponent<Rigidbody2D>().velocity; | ||
this.player = player; | ||
this.footPrintUnixTime = (int) DateTimeOffset.Now.ToUnixTimeSeconds(); | ||
|
||
this.position = player.transform.position; | ||
if (RolesMods.AnonymousFootPrint.GetValue()) | ||
this.footPrintColor = new Color(0.2f, 0.2f, 0.2f, 1f); | ||
|
||
Start(); | ||
} | ||
|
||
private void Start() { | ||
footPrint = new GameObject("FootPrint"); | ||
footPrint.transform.position = footPrintPosition; | ||
footPrint.transform.localPosition = footPrintPosition; | ||
footPrint.transform.position = position; | ||
footPrint.transform.localPosition = position; | ||
footPrint.transform.localScale = new Vector2(footPrintSize, footPrintSize); | ||
footPrint.transform.SetParent(player.transform.parent); | ||
footPrint.transform.Rotate(Vector3.forward * Vector2.SignedAngle(Vector2.up, velocity)); | ||
footPrint.transform.Rotate(Vector3.forward * Vector2.SignedAngle(Vector2.up, player.gameObject.GetComponent<Rigidbody2D>().velocity)); | ||
|
||
spriteRenderer = footPrint.AddComponent<SpriteRenderer>(); | ||
spriteRenderer.sprite = HelperSprite.LoadSpriteFromEmbeddedResources("RolesMods.Resources.Footprint.png", 100f); | ||
spriteRenderer.sprite = ResourceLoader.FootprintSprite; | ||
spriteRenderer.color = footPrintColor; | ||
|
||
footPrint.SetActive(true); | ||
allFootprint.Add(this); | ||
Coroutines.Start(CoFadeOutAndDestroy(footPrintDuration)); | ||
} | ||
|
||
private void DestroyThis() { | ||
UnityEngine.Object.Destroy(footPrint); | ||
allFootprint.Remove(this); | ||
} | ||
public IEnumerator CoFadeOutAndDestroy(float duration) { | ||
for (float time = 0f; time < duration; time += Time.deltaTime) { | ||
footPrintColor = Palette.PlayerColors[(int) player.Data.ColorId]; | ||
|
||
public void Update() { | ||
int currentUnixTime = (int) DateTimeOffset.Now.ToUnixTimeSeconds(); | ||
float alpha = Mathf.Max((1f - ((currentUnixTime - footPrintUnixTime) / footPrintDuration)), 0f); | ||
this.footPrintColor = Palette.PlayerColors[(int) player.Data.ColorId]; | ||
|
||
if (alpha < 0 || alpha > 1) | ||
alpha = 0; | ||
if (spriteRenderer) | ||
spriteRenderer.color = new Color(footPrintColor.r, footPrintColor.g, footPrintColor.b, Mathf.Clamp(1f - time / duration, 0f, 1f)); | ||
|
||
footPrintColor = new Color(footPrintColor.r, footPrintColor.g, footPrintColor.b, alpha); | ||
spriteRenderer.color = footPrintColor; | ||
|
||
if (footPrintUnixTime + (int) footPrintDuration < currentUnixTime) | ||
DestroyThis(); | ||
} | ||
yield return null; | ||
} | ||
|
||
public Vector3 FootPrintPosition { | ||
get => footPrintPosition; | ||
UnityEngine.Object.Destroy(footPrint); | ||
allFootprint.Remove(this); | ||
} | ||
|
||
public PlayerControl Player => player; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace RolesMods.Systems.TimeMaster { | ||
public class GameHistory { | ||
public Vector3 position; | ||
public DateTime positionTime; | ||
public Vector2 velocity; | ||
|
||
public GameHistory(Vector3 position, DateTime positionTime, Vector2 velocity) { | ||
this.position = position; | ||
this.positionTime = positionTime; | ||
this.velocity = velocity; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.