This commit is contained in:
Gerard Gascón 2025-04-24 14:30:07 +02:00
commit 102013b228
1443 changed files with 1065651 additions and 0 deletions

View file

@ -0,0 +1,193 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class JustaGameController : MonoBehaviour
{
[SerializeField] ScenesTransitionController scenesTransition;
[SerializeField] int actualRound = 1;
[SerializeField] JustaPlayerController player;
[SerializeField] JustaPlayerController enemy;
[SerializeField] bool paused;
[SerializeField] GameObject countDownPanel;
[SerializeField] JustaTargetComboObjects[] targetObjects;
[SerializeField] Image player_HPBar;
[SerializeField] Image enemy_HPBar;
[SerializeField] JustaTrigger trigger;
[SerializeField] GameObject gameHUD;
bool scoreDistributed;
// Start is called before the first frame update
void Start()
{
//BeforeGame();
StartCoroutine(AudioManager.instance.FadeIn("transicion", 1));
}
private void BeforeGame()
{
StartCoroutine(BeforeGameCoroutine());
}
private IEnumerator BeforeGameCoroutine()
{
//Cinematica inicial
yield return new WaitForSecondsRealtime(2);
//Tutorial
StartGame();
}
public void StartGame()
{
StartCoroutine(AudioManager.instance.FadeOut("transicion", 1));
StartCoroutine(AudioManager.instance.FadeIn("02_caballos", 1));
StartCoroutine(StartGameCoroutine());
}
private IEnumerator StartGameCoroutine()
{
ShowGameHUD();
while (!GameFinished())
{
Debug.Log("Ronda: " + actualRound);
Debug.Log("Vida enemy " + enemy.GetCurrentLives() + " vida player " + player.GetCurrentLives());
SetNewCombo();
countDownPanel.SetActive(true);
yield return new WaitForSecondsRealtime(4f);
AudioManager.instance.PlayOneShot("SFX_silbato");
countDownPanel.SetActive(false);
trigger.paused = false;
enemy.StartRunning();
player.StartRunning();
yield return new WaitForSecondsRealtime(9f);
trigger.paused = true;
CreateEnemyPuntuation();
CheckRoundWinner();
actualRound++;
}
yield return null;
}
private void CreateEnemyPuntuation()
{
float points = Random.Range(1f, 5f);
enemy.SetRoundPoints(points);
}
private bool GameFinished()
{
if (player.GetCurrentLives() <= 0)
{
ReturnToMenu(enemy.GetComponent<CharacterIdController>().characterId, player.GetComponent<CharacterIdController>().characterId);
return true;
}
if (enemy.GetCurrentLives() <= 0)
{
ReturnToMenu(player.GetComponent<CharacterIdController>().characterId, enemy.GetComponent<CharacterIdController>().characterId);
return true;
}
return false;
}
private void CheckRoundWinner()
{
float enemyPoints = enemy.GetRoundPoints();
float playerPoints = player.GetRoundPoints();
if (enemyPoints <= playerPoints)
{
Debug.Log("Has ganado la ronda: enemigo: " + enemyPoints + " tuyos:" + playerPoints);
AudioManager.instance.PlayOneShot("SFX_campanillas");
enemy_HPBar.fillAmount -= 0.2f;
LooseLife(enemy);
}
else
{
Debug.Log("Has ganado la ronda: enemigo: " + enemyPoints + " tuyos:" + playerPoints);
player_HPBar.fillAmount -= 0.2f;
LooseLife(player);
}
enemy.SetRoundPoints(0);
player.SetRoundPoints(0);
}
private void LooseLife(JustaPlayerController character)
{
character.LooseLife();
}
private void SetNewCombo()
{
foreach (JustaTargetComboObjects target in targetObjects)
{
target.SetRandomKey();
}
}
// Update is called once per frame
void Update()
{
}
void ShowGameHUD()
{
gameHUD.SetActive(true);
}
void ReturnToMenu(int winner, int looser) {
StartCoroutine(AudioManager.instance.FadeOut("02_caballos", 1));
if (!scoreDistributed)
{
StartCoroutine(BetweenScenePass.instance.DistributeScore(
BetweenScenePass.Games.Jousting,
winner,
null));
int newWinner1 = winner;
int i = 0;
while (i <100)
{
newWinner1 = Random.Range(0, 6);
i++;
if (newWinner1 != winner && newWinner1 != looser)
{
break;
}
}
StartCoroutine(BetweenScenePass.instance.DistributeScore(
BetweenScenePass.Games.Jousting,
newWinner1,
null));
int newWinner2;
newWinner2 = winner;
i = 0;
while (i <100)
{
newWinner2 = Random.Range(0, 6);
i++;
if (newWinner2 != winner && newWinner2 != looser && newWinner2 != newWinner1)
{
break;
}
}
StartCoroutine(BetweenScenePass.instance.DistributeScore(
BetweenScenePass.Games.Jousting,
newWinner2,
scenesTransition));
scoreDistributed = true;
}
}
}

View file

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

View file

@ -0,0 +1,164 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JustaPlayerController : MonoBehaviour
{
[SerializeField] float speed;
[SerializeField] float maxSpeed;
[SerializeField] float aceleration;
[SerializeField] float timeOfRunning;
[SerializeField] float timeOfBracking;
[SerializeField] float timeBetweenRounds;
[SerializeField] public Animator anim;
Vector3 initialPos;
[SerializeField] int maxLives;
int currentLife;
[SerializeField] float roundPoints = 0;
[SerializeField] JustaTrigger trigger;
[SerializeField] float multiplier;
[SerializeField] float mistakePoints;
[SerializeField] GameObject feedbackError;
[SerializeField] GameObject feedbackGreat;
[SerializeField] GameObject feedbackPerfect;
// Start is called before the first frame update
void Start()
{
if (CompareTag("Player"))
anim = GetComponent<CharacterIdController>().SetPlayerCustom();
initialPos = this.transform.position;
currentLife = maxLives;
//StartRunning();
}
public int GetCurrentLives()
{
return this.currentLife;
}
public float GetRoundPoints()
{
return this.roundPoints;
}
public void SetRoundPoints(float points)
{
this.roundPoints = points;
}
public void Mistake()
{
//Mal activar
StartCoroutine(ActivateFeedBack(feedbackError));
roundPoints -= mistakePoints;
if (roundPoints < 0)
{
roundPoints = 0;
}
//Debug.Log("Fallo. Puntos actual: " + roundPoints);
}
public void WinPoints(float distance)
{
//Max distance = 0.5 -> 0,5 puntos
//Min distance = 0 -> 2 puntos
float points = 0;
if (distance <= 0.2f)
{
points = 2;
//Genial activar
StartCoroutine(ActivateFeedBack(feedbackPerfect));
} else if (distance > 0.2f && distance < 0.5f)
{
points = 1;
//Bien activar
StartCoroutine(ActivateFeedBack(feedbackGreat));
}
else
{
points = 0.5f;
//Bien activar
StartCoroutine(ActivateFeedBack(feedbackGreat));
}
roundPoints += points;
//Debug.Log("Puntos ganados: " + points + " puntos totales: " + roundPoints);
}
private IEnumerator ActivateFeedBack(GameObject feedback)
{
feedback.SetActive(true);
yield return new WaitForSeconds(0.3f);
feedback.SetActive(false);
}
public void LooseLife()
{
currentLife--;
}
public void StartRunning()
{
StartCoroutine(StartRunningCoroutine());
}
private IEnumerator PasosCaballo(float delay)
{
float i = 0;
while (true && i < 10000)
{
i += 0.1f;
AudioManager.instance.PlayOneShot("SFX_pasosCaballo"+Random.Range(1,5), true);
yield return new WaitForSecondsRealtime(delay);
}
}
private IEnumerator StartRunningCoroutine()
{
float i = 0;
Coroutine corutina = StartCoroutine(PasosCaballo(0.45f));
while (i < timeOfRunning)
{
i += Time.deltaTime;
if (speed < maxSpeed)
{
speed += Time.deltaTime * aceleration;
}
anim.SetFloat("VelocityY", speed);
this.transform.Translate(Vector3.forward * speed * Time.deltaTime);
yield return null;
}
StopCoroutine(corutina);
corutina = StartCoroutine(PasosCaballo(0.65f));
i = 0;
while (i < timeOfBracking)
{
i += Time.deltaTime;
if (speed > 0)
{
speed -= Time.deltaTime * aceleration * 2;
}
anim.SetFloat("VelocityY", speed);
this.transform.Translate(Vector3.forward * speed * Time.deltaTime);
yield return null;
}
StopCoroutine(corutina);
yield return new WaitForSecondsRealtime(timeBetweenRounds);
ResetPlayer();
}
private void ResetPlayer()
{
this.transform.position = initialPos;
this.roundPoints = 0;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8649b0a7466d9e64ab78e7f7f44d4e6a
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 System;
using UnityEngine;
using TMPro;
public class JustaTargetComboObjects : MonoBehaviour
{
public enum KeyType { W, A, S, D};
public KeyType key;
[SerializeField] TextMeshPro text;
public void SetRandomKey()
{
int num = UnityEngine.Random.Range(0, Enum.GetValues(typeof(KeyType)).Length);
switch (num)
{
case 0:
key = KeyType.W;
text.text = "W";
break;
case 1:
key = KeyType.A;
text.text = "A";
break;
case 2:
key = KeyType.S;
text.text = "S";
break;
case 3:
key = KeyType.D;
text.text = "D";
break;
default:
key = KeyType.W;
text.text = "W";
break;
}
}
}

View file

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

View file

@ -0,0 +1,115 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JustaTrigger : MonoBehaviour
{
[SerializeField] JustaPlayerController player;
JustaTargetComboObjects targetCollisioning = null;
[HideInInspector] public bool paused = true;
// Update is called once per frame
void Update()
{
if (!paused)
{
if (Input.anyKeyDown)
{
if (!Input.GetKeyDown(KeyCode.Escape))
{
AudioManager.instance.PlayOneShot("SFX_caballoBufido" + UnityEngine.Random.Range(1, 3), true);
if (targetCollisioning == null)
{
LoosePoints();
}
else
{
JustaTargetComboObjects.KeyType key = targetCollisioning.key;
switch (key)
{
case JustaTargetComboObjects.KeyType.W:
if (Input.GetKeyDown(KeyCode.W))
{
WinPoints(this.transform.position, targetCollisioning.gameObject.transform.position);
}
else
{
LoosePoints();
}
break;
case JustaTargetComboObjects.KeyType.A:
if (Input.GetKeyDown(KeyCode.A))
{
WinPoints(this.transform.position, targetCollisioning.gameObject.transform.position);
}
else
{
LoosePoints();
}
break;
case JustaTargetComboObjects.KeyType.S:
if (Input.GetKeyDown(KeyCode.S))
{
WinPoints(this.transform.position, targetCollisioning.gameObject.transform.position);
}
else
{
LoosePoints();
}
break;
case JustaTargetComboObjects.KeyType.D:
if (Input.GetKeyDown(KeyCode.D))
{
WinPoints(this.transform.position, targetCollisioning.gameObject.transform.position);
}
else
{
LoosePoints();
}
break;
}
}
}
}
}
}
private void LoosePoints()
{
player.Mistake();
}
private void WinPoints(Vector3 triggerPos, Vector3 targetPos)
{
float distance = Vector3.Distance(triggerPos, targetPos);
player.WinPoints(distance);
}
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("TargetJusta"))
{
if (targetCollisioning == null)
{
targetCollisioning = other.GetComponent<JustaTargetComboObjects>();
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("TargetJusta"))
{
if (targetCollisioning != null)
{
targetCollisioning = null;
}
}
}
}

View file

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