init
This commit is contained in:
commit
102013b228
1443 changed files with 1065651 additions and 0 deletions
91
Assets/Scripts/SacksGame/SacksGameController.cs
Normal file
91
Assets/Scripts/SacksGame/SacksGameController.cs
Normal file
|
@ -0,0 +1,91 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class SacksGameController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] ScenesTransitionController scenesTransition;
|
||||
|
||||
[SerializeField] List<SaltosSacosController> players;
|
||||
|
||||
[SerializeField] GameObject tutorialPanel;
|
||||
[SerializeField] GameObject countdownPanel;
|
||||
[SerializeField] GameObject gameOverPanel;
|
||||
|
||||
private GameObject winner;
|
||||
|
||||
[Header("Camera Settings")]
|
||||
[SerializeField] CinemachineVirtualCamera cameraGame;
|
||||
[SerializeField] CinemachineVirtualCamera cameraFinish;
|
||||
[SerializeField] float cinematicVelocity;
|
||||
|
||||
bool scoreDistributed;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartCoroutine(AudioManager.instance.FadeIn("transicion", 1));
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
StartCoroutine(BeforeStartGame());
|
||||
}
|
||||
|
||||
|
||||
private IEnumerator BeforeStartGame()
|
||||
{
|
||||
//Fin Cinematica
|
||||
StartCoroutine(AudioManager.instance.FadeOut("transicion", 1));
|
||||
StartCoroutine(AudioManager.instance.FadeIn("06_sacos", 1));
|
||||
//AudioManager.instance.FadeIn("transicion", 1);
|
||||
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
countdownPanel.SetActive(true);
|
||||
yield return new WaitForSecondsRealtime(4f);
|
||||
countdownPanel.SetActive(false);
|
||||
AudioManager.instance.PlayOneShot("SFX_silbato");
|
||||
foreach (SaltosSacosController player in players)
|
||||
{
|
||||
player.StartGame(this);
|
||||
}
|
||||
AudioManager.instance.FadeOut("transicion", 1);
|
||||
AudioManager.instance.FadeIn("06_sacos", 1);
|
||||
}
|
||||
|
||||
public void GameOver(GameObject _winner)
|
||||
{
|
||||
StartCoroutine(AudioManager.instance.FadeOut("06_sacos", 1));
|
||||
winner = _winner;
|
||||
foreach (SaltosSacosController player in players)
|
||||
{
|
||||
if (winner.Equals(player.gameObject))
|
||||
{
|
||||
if (player.GetIsPlayable())
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_campanillas");
|
||||
}
|
||||
}
|
||||
}
|
||||
gameOverPanel.SetActive(true);
|
||||
cameraFinish.gameObject.SetActive(true);
|
||||
cameraGame.gameObject.SetActive(false);
|
||||
foreach (SaltosSacosController player in players)
|
||||
{
|
||||
player.GameOver();
|
||||
}
|
||||
|
||||
if (!scoreDistributed)
|
||||
{
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Sacks,
|
||||
winner.GetComponent<CharacterIdController>().CharacterId,
|
||||
scenesTransition,
|
||||
1.5f));
|
||||
|
||||
scoreDistributed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/SacksGame/SacksGameController.cs.meta
Normal file
11
Assets/Scripts/SacksGame/SacksGameController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2fe34818e27db8d41b22b07f177508b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
185
Assets/Scripts/SacksGame/SaltosSacosController.cs
Normal file
185
Assets/Scripts/SacksGame/SaltosSacosController.cs
Normal file
|
@ -0,0 +1,185 @@
|
|||
using System.CodeDom;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SaltosSacosController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] CharacterController controller = default;
|
||||
[SerializeField] public Animator anim;
|
||||
|
||||
[SerializeField] bool isPlayable;
|
||||
|
||||
[Header("Jump Settings")]
|
||||
[SerializeField, Min(0)] float jumpHeight;
|
||||
[SerializeField, Min(0)] float jumpDistance;
|
||||
[SerializeField, Min(0)] float jumpTime;
|
||||
[SerializeField] float gravity = -9.8f;
|
||||
|
||||
[Header("Detect Collisions")]
|
||||
[SerializeField] Transform groundCheck = default;
|
||||
[SerializeField, Range(0, .5f)] float groundDistance = .4f;
|
||||
[SerializeField]LayerMask groundMask;
|
||||
bool isGrounded;
|
||||
|
||||
[Header("Fall Settings")]
|
||||
[SerializeField] float fallingTime;
|
||||
|
||||
[Header("IA Settings")]
|
||||
[SerializeField, Min(0)] float maxDesviation;
|
||||
|
||||
Vector3 velocity;
|
||||
bool falling = false;
|
||||
bool gameFinished = false;
|
||||
bool gameStarted = false;
|
||||
|
||||
[SerializeField] MeshRenderer meshRenderer;
|
||||
[SerializeField] Material baseMaterial;
|
||||
[SerializeField] Material fallingMaterial;
|
||||
|
||||
private float timeOfJump;
|
||||
private float timeSinceJump;
|
||||
|
||||
private SacksGameController gameController;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if(gameObject.CompareTag("Player"))
|
||||
anim = GetComponent<CharacterIdController>().SetPlayerCustom();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (isPlayable && gameStarted && !gameFinished)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.W))
|
||||
{
|
||||
CheckJump();
|
||||
}
|
||||
}
|
||||
if (!IsGrounded())
|
||||
{
|
||||
velocity.y += gravity * Time.deltaTime;
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
timeOfJump += Time.deltaTime;
|
||||
} else
|
||||
{
|
||||
timeOfJump = 0;
|
||||
velocity.y = -4f;
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetIsPlayable()
|
||||
{
|
||||
return isPlayable;
|
||||
}
|
||||
|
||||
private void CheckJump()
|
||||
{
|
||||
if (IsGrounded())
|
||||
{
|
||||
if (!falling)
|
||||
{
|
||||
Jump();
|
||||
}
|
||||
} else
|
||||
{
|
||||
Fall();
|
||||
}
|
||||
}
|
||||
|
||||
private void Fall()
|
||||
{
|
||||
StartCoroutine(FallCoroutine());
|
||||
}
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
StartCoroutine(JumpCoroutine());
|
||||
if (isPlayable)
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_saltoSacos" + Random.Range(1, 5), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_saltoSacosEnemigos", true);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator JumpCoroutine()
|
||||
{
|
||||
float i = 0;
|
||||
while (i < jumpTime)
|
||||
{
|
||||
anim.SetTrigger("SacksJump");
|
||||
Vector3 jumpVelocity = new Vector3(jumpDistance, jumpHeight, 0);
|
||||
controller.Move(jumpVelocity * Time.deltaTime);
|
||||
i += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FallCoroutine()
|
||||
{
|
||||
falling = true;
|
||||
meshRenderer.material = fallingMaterial;
|
||||
yield return new WaitForSecondsRealtime(fallingTime);
|
||||
meshRenderer.material = baseMaterial;
|
||||
falling = false;
|
||||
}
|
||||
|
||||
private IEnumerator IA_Jump()
|
||||
{
|
||||
Debug.Log("IA Jump Started");
|
||||
float firstWait = Random.Range(0.1f, 0.3f);
|
||||
yield return new WaitForSecondsRealtime(firstWait);
|
||||
while (!gameFinished)
|
||||
{
|
||||
float totalTimeToWait = jumpTime;
|
||||
int desviation = Random.Range(0,14);
|
||||
float timeToWait = 0;
|
||||
if (desviation > 0)
|
||||
{
|
||||
timeToWait = Random.Range(0.12f, 0.15f);
|
||||
totalTimeToWait += timeToWait;
|
||||
} else
|
||||
{
|
||||
timeToWait = Random.Range(0.05f, 0.1f);
|
||||
totalTimeToWait += timeToWait;
|
||||
}
|
||||
CheckJump();
|
||||
yield return new WaitForSecondsRealtime(totalTimeToWait);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartGame(SacksGameController controller)
|
||||
{
|
||||
gameController = controller;
|
||||
gameStarted = true;
|
||||
if (isPlayable == false)
|
||||
{
|
||||
StartCoroutine(IA_Jump());
|
||||
}
|
||||
}
|
||||
|
||||
public void GameOver()
|
||||
{
|
||||
gameFinished = true;
|
||||
|
||||
}
|
||||
|
||||
private bool IsGrounded()
|
||||
{
|
||||
return Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("FinishLine"))
|
||||
{
|
||||
gameController.GameOver(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/SacksGame/SaltosSacosController.cs.meta
Normal file
11
Assets/Scripts/SacksGame/SaltosSacosController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 60308fa1c544a1142b6f9ab9d2a9b3bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue