This commit is contained in:
Gerard Gascón 2025-04-24 17:37:25 +02:00
commit 341a877b4a
2338 changed files with 1346408 additions and 0 deletions

View file

@ -0,0 +1,87 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
public class ClypiController : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler{
[SerializeField] Canvas canvas;
RectTransform rectTransform;
Vector3 startPos;
void Awake(){
rectTransform = GetComponent<RectTransform>();
startPos = transform.position;
}
public void OnBeginDrag(PointerEventData eventData){
}
public void OnDrag(PointerEventData eventData){
rectTransform.anchoredPosition += eventData.delta / canvas.scaleFactor;
}
public void OnEndDrag(PointerEventData eventData){
}
public void OnPointerDown(PointerEventData eventData){
}
[SerializeField] Animator textFieldAnim = default;
[Space]
[SerializeField] TMP_Animated text = default;
[SerializeField] Dialogue dialogue = default;
int currentTime;
[SerializeField, Min(0)] float moveForce = 50f;
[SerializeField, Range(0, 1)] float moveDuration = .25f;
bool moveClose;
Vector2 randomDirection;
void OnEnable(){
transform.position = startPos;
currentTime = 0;
text.ClearText();
StartCoroutine(ShowFirstText());
textFieldAnim.SetTrigger("Open");
}
public void OnClick(){
if (moveClose)
return;
StartCoroutine(StopClosing());
randomDirection = Random.insideUnitCircle.normalized * moveForce;
moveClose = true;
currentTime++;
if(currentTime <= dialogue.sentences.Length - 1){
text.ReadText(dialogue.sentences[currentTime]);
}else{
StopCoroutine(StopClosing());
gameObject.SetActive(false);
moveClose = false;
}
}
IEnumerator ShowFirstText(){
yield return new WaitForSecondsRealtime(.75f);
text.ReadText(dialogue.sentences[0]);
}
void Update(){
if (moveClose){
rectTransform.anchoredPosition += randomDirection * Time.unscaledDeltaTime;
rectTransform.anchoredPosition = new Vector2(Mathf.Clamp(rectTransform.anchoredPosition.x, -284f, 262f), Mathf.Clamp(rectTransform.anchoredPosition.y, -126f, 246f));
}
}
IEnumerator StopClosing(){
yield return new WaitForSecondsRealtime(moveDuration);
moveClose = false;
}
}

View file

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

View file

@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DiskSelector : MonoBehaviour{
[SerializeField] int skinSelected = 0;
[SerializeField] bool[] skinsUnlocked = new bool[5];
[SerializeField] Button[] disks = new Button[5];
// Start is called before the first frame update
void Awake(){
if (!PlayerPrefs.HasKey("Disk"))
PlayerPrefs.SetInt("Disk", 0);
for (int i = 0; i < skinsUnlocked.Length; i++){
if(PlayerPrefs.GetInt("DiskUnlocked", 0) >= i){
skinsUnlocked[i] = true;
}
if (!skinsUnlocked[i]){
disks[i].interactable = false;
}
}
}
public void SelectDisk(int number){
PlayerPrefs.SetInt("Disk", number);
}
}

View file

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

View file

@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class DragAndDrop : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler{
[SerializeField] Canvas canvas;
RectTransform rectTransform;
void Awake(){
rectTransform = GetComponent<RectTransform>();
}
public void OnBeginDrag(PointerEventData eventData){
}
public void OnDrag(PointerEventData eventData){
rectTransform.anchoredPosition += eventData.delta / canvas.scaleFactor;
}
public void OnEndDrag(PointerEventData eventData){
}
public void OnPointerDown(PointerEventData eventData){
}
}

View file

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

View file

@ -0,0 +1,139 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class HighscoreTable : MonoBehaviour{
[SerializeField] Transform entryContainer = default;
[SerializeField] Transform entryTemplate = default;
List<HighscoreEntry> highscoreEntryList;
List<Transform> highscoreEntryTransformList;
// Start is called before the first frame update
void Awake(){
entryTemplate.gameObject.SetActive(false);
string jsonString = PlayerPrefs.GetString("HighscoreTable");
Highscores highscores = JsonUtility.FromJson<Highscores>(jsonString);
if(highscores != null){
for (int i = 0; i < highscores.highscoreEntryList.Count; i++){
for (int j = i + 1; j < highscores.highscoreEntryList.Count; j++){
if (highscores.highscoreEntryList[j].percentage > highscores.highscoreEntryList[i].percentage){
HighscoreEntry tmp = highscores.highscoreEntryList[i];
highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j];
highscores.highscoreEntryList[j] = tmp;
}
}
}
for (int i = 0; i < highscores.highscoreEntryList.Count; i++){
for (int j = 0; j < highscores.highscoreEntryList.Count; j++){
if (j >= 5){
highscores.highscoreEntryList.RemoveAt(j);
}
}
if (i >= 5){
highscores.highscoreEntryList.RemoveAt(i);
}
}
highscoreEntryTransformList = new List<Transform>();
foreach (HighscoreEntry highscoreEntry in highscores.highscoreEntryList){
CreateHighscoreEntryTransform(highscoreEntry, entryContainer, highscoreEntryTransformList);
}
}else{
highscoreEntryList = new List<HighscoreEntry>() {
new HighscoreEntry { boss = false, name = "AAA", percentage = 0, time = 0 },
new HighscoreEntry { boss = false, name = "AAA", percentage = 0, time = 0 },
new HighscoreEntry { boss = false, name = "AAA", percentage = 0, time = 0 },
new HighscoreEntry { boss = false, name = "AAA", percentage = 0, time = 0 },
new HighscoreEntry { boss = false, name = "AAA", percentage = 0, time = 0 }
};
for (int i = 0; i < highscoreEntryList.Count; i++){
for (int j = i + 1; j < highscoreEntryList.Count; j++){
if (highscoreEntryList[j].percentage > highscoreEntryList[i].percentage){
HighscoreEntry tmp = highscoreEntryList[i];
highscoreEntryList[i] = highscoreEntryList[j];
highscoreEntryList[j] = tmp;
}
}
}
highscoreEntryTransformList = new List<Transform>();
foreach (HighscoreEntry highscoreEntry in highscoreEntryList){
CreateHighscoreEntryTransform(highscoreEntry, entryContainer, highscoreEntryTransformList);
}
Highscores highscore = new Highscores { highscoreEntryList = highscoreEntryList };
string json = JsonUtility.ToJson(highscore);
PlayerPrefs.SetString("HighscoreTable", json);
PlayerPrefs.Save();
}
}
void CreateHighscoreEntryTransform(HighscoreEntry highscoreEntry, Transform container, List<Transform> transformList){
float templateHeight = 35f;
Transform entryTransform = Instantiate(entryTemplate, container);
RectTransform entryRectTransform = entryTransform.GetComponent<RectTransform>();
entryRectTransform.anchoredPosition = new Vector2(0, entryTemplate.GetComponent<RectTransform>().anchoredPosition.y - templateHeight * transformList.Count);
entryTransform.gameObject.SetActive(true);
#region Name
string name = highscoreEntry.name;
entryTransform.Find("Name").GetComponent<TextMeshProUGUI>().text = name;
#endregion
#region Time
int time = highscoreEntry.time;
float tempTime = time / 60f;
int minutes = Mathf.FloorToInt(tempTime);
tempTime = (tempTime - Mathf.FloorToInt(tempTime)) * 60;
int seconds = Mathf.RoundToInt(tempTime);
string minuteString = minutes < 10 ? "0" + minutes.ToString() : minutes.ToString();
string secondString = seconds < 10 ? "0" + seconds.ToString() : seconds.ToString();
entryTransform.Find("Time").GetComponent<TextMeshProUGUI>().text = minuteString + ":" + secondString;
#endregion
#region Percentage
int percentage = highscoreEntry.percentage;
entryTransform.Find("Percentage").GetComponent<TextMeshProUGUI>().text = percentage + "%";
#endregion
#region Boss
bool boss = highscoreEntry.boss;
entryTransform.Find("BossIcon").gameObject.SetActive(boss);
#endregion
transformList.Add(entryTransform);
}
void AddHighscoreEntry(int time, int percentage, string name, bool boss){
HighscoreEntry highscoreEntry = new HighscoreEntry {name = name, percentage = percentage, time = time, boss = boss};
string jsonString = PlayerPrefs.GetString("HighscoreTable");
Highscores highscores = JsonUtility.FromJson<Highscores>(jsonString);
highscores.highscoreEntryList.Add(highscoreEntry);
string json = JsonUtility.ToJson(highscores);
PlayerPrefs.SetString("HighscoreTable", json);
PlayerPrefs.Save();
}
class Highscores{
public List<HighscoreEntry> highscoreEntryList;
}
[System.Serializable]
class HighscoreEntry{
public bool boss;
public int time;
public int percentage;
public string name;
}
}

View file

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

View file

@ -0,0 +1,92 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PauseMenu : MonoBehaviour{
[SerializeField, Range(0, 1)] float transitionDuration = .67f;
Animator anim = default;
bool paused;
bool canPause;
Canvas canvas;
PlayerController player;
float percentage;
float velocity;
[SerializeField] Image percentageSlider = default;
[SerializeField] TextMeshProUGUI percentageText = default;
// Start is called before the first frame update
void Awake(){
canvas = GetComponent<Canvas>();
anim = GetComponent<Animator>();
canvas.enabled = false;
canPause = true;
player = FindObjectOfType<PlayerController>();
}
// Update is called once per frame
void Update(){
if (Input.GetKeyDown(KeyCode.Escape)){
if (paused){
StartCoroutine(DisablePause());
anim.SetTrigger("Exit");
canvas.enabled = false;
paused = false;
}else if(canPause){
Time.timeScale = 0;
anim.SetTrigger("Enter");
paused = true;
canvas.enabled = true;
canPause = false;
}
}
percentageSlider.fillAmount = Mathf.SmoothDamp(percentageSlider.fillAmount, percentage / 100, ref velocity, 1, 100, Time.unscaledDeltaTime);
}
public void UpdateSlider(){
percentage = player.percentage;
percentageText.text = percentage + "%";
percentageSlider.fillAmount = 0;
}
public void Resume(){
Time.timeScale = 0;
anim.SetTrigger("Enter");
paused = true;
canvas.enabled = true;
canPause = false;
}
public void Retry(){
PlayerPrefs.DeleteKey("HP");
PlayerPrefs.DeleteKey("Percentage");
PlayerPrefs.DeleteKey("TimeSurvived");
Time.timeScale = 1;
GameMaster.Instance.ResetLevel();
Destroy(GameMaster.Instance.gameObject);
Loader.Load(SceneManager.GetActiveScene().buildIndex);
}
public void Quit(){
GameMaster.Instance.ResetLevel();
Destroy(GameMaster.Instance.gameObject);
PlayerPrefs.DeleteKey("HP");
PlayerPrefs.DeleteKey("Percentage");
PlayerPrefs.DeleteKey("TimeSurvived");
Time.timeScale = 1;
Loader.Load(0);
}
IEnumerator DisablePause(){
yield return new WaitForSecondsRealtime(transitionDuration);
Time.timeScale = 1;
canPause = true;
}
}

View file

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

View file

@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Percentage : MonoBehaviour{
PlayerController player;
float percentage;
float velocity;
[SerializeField] Image percentageSlider = default;
[SerializeField] TextMeshProUGUI percentageText = default;
[SerializeField] TextMeshProUGUI timeText = default;
void Awake(){
player = FindObjectOfType<PlayerController>();
}
// Update is called once per frame
void Update(){
percentageSlider.fillAmount = Mathf.SmoothDamp(percentageSlider.fillAmount, percentage / 100, ref velocity, 1, 100, Time.unscaledDeltaTime);
}
public void UpdateSlider(){
percentage = player.percentage;
percentageText.text = percentage + "%";
percentageSlider.fillAmount = 0;
if(timeText != null){
int time = Mathf.RoundToInt(player.timeSurvived);
float tempTime = time / 60f;
int minutes = Mathf.FloorToInt(tempTime);
tempTime = (tempTime - Mathf.FloorToInt(tempTime)) * 60;
int seconds = Mathf.RoundToInt(tempTime);
string minuteString = minutes < 10 ? "0" + minutes.ToString() : minutes.ToString();
string secondString = seconds < 10 ? "0" + seconds.ToString() : seconds.ToString();
timeText.text = "time: " + minuteString + ":" + secondString;
}
}
}

View file

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

View file

@ -0,0 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnlockDisk : MonoBehaviour{
public void Unlock(){
PlayerPrefs.SetInt("DiskUnlocked", PlayerPrefs.GetInt("DiskUnlocked", 0) + 1);
}
}

View file

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