Merge branch 'master' of https://github.com/SweetTini/GlobalGameJam2020
This commit is contained in:
@@ -9,6 +9,7 @@ public class EventControls : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Player player;
|
||||
[SerializeField] private Camera camera;
|
||||
[SerializeField] private GameObject music;
|
||||
[SerializeField] private List<Tile> tiles;
|
||||
[SerializeField] private List<Tile> successTiles;
|
||||
[SerializeField] private List<Tile> failTiles;
|
||||
@@ -159,6 +160,17 @@ public class EventControls : MonoBehaviour
|
||||
.GetValueOrDefault();
|
||||
}
|
||||
|
||||
IEnumerator PlayVictoryMusic()
|
||||
{
|
||||
music = GameObject.Find("Music");
|
||||
var audioSrc = music.GetComponent<AudioSource>();
|
||||
audioSrc.Pause();
|
||||
SoundManagerScript.PlaySound("win");
|
||||
var clipSeconds = SoundManagerScript.audioSrc.clip.length;
|
||||
yield return new WaitForSeconds(clipSeconds);
|
||||
audioSrc.Play();
|
||||
}
|
||||
|
||||
private void PerformControlEvent()
|
||||
{
|
||||
nextControlAccumalator = 0;
|
||||
@@ -185,6 +197,7 @@ public class EventControls : MonoBehaviour
|
||||
// Destroy(currentEnemyCollider.gameObject);
|
||||
// currentEnemyCollider = null;
|
||||
hasFailed = false;
|
||||
StartCoroutine(PlayVictoryMusic());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +287,7 @@ public class EventControls : MonoBehaviour
|
||||
// var offset = camera.transform.position.x - (int)camera.transform.position.x;
|
||||
// transform.position = new Vector3(transform.position.x + offset, transform.position.y, 0);
|
||||
//}
|
||||
|
||||
|
||||
private EventControlTile GenerateEventControlTile(Vector3Int position)
|
||||
{
|
||||
var randomNumber = Random.Range(0, TileToKeyMappings.TileToKey.Count);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
@@ -32,6 +33,8 @@ public class Player : MonoBehaviour
|
||||
private bool isFighting = false;
|
||||
private bool isHurt = false;
|
||||
|
||||
private bool isPlayerHurt = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rigidBody = GetComponent<Rigidbody2D>();
|
||||
@@ -77,9 +80,10 @@ public class Player : MonoBehaviour
|
||||
{
|
||||
if (coll.gameObject.tag == "Pizza")
|
||||
{
|
||||
Destroy(coll.gameObject);
|
||||
currentHealth += currentHealth < startHealth ? 1 : 0;
|
||||
healthBar.size = new Vector2(1.5f * currentHealth, this.healthBar.size.y);
|
||||
//Destroy(coll.gameObject);
|
||||
//currentHealth += currentHealth < startHealth ? 1 : 0;
|
||||
//healthBar.size = new Vector2(1.5f * currentHealth, this.healthBar.size.y);
|
||||
Hurt();
|
||||
}
|
||||
else if (coll.gameObject.tag == "Coffee")
|
||||
{
|
||||
@@ -110,6 +114,19 @@ public class Player : MonoBehaviour
|
||||
return currentStamina <= startStamina ? (startStamina * percentage / 100) : 0;
|
||||
}
|
||||
|
||||
private void Hurt()
|
||||
{
|
||||
currentHealth -= currentHealth > 0 ? 1 : 0;
|
||||
healthBar.size = new Vector2(1.5f * currentHealth, this.healthBar.size.y);
|
||||
|
||||
if (currentHealth <= 0) GameOver();
|
||||
}
|
||||
|
||||
private void GameOver()
|
||||
{
|
||||
SceneManager.LoadScene("GameOver");
|
||||
}
|
||||
|
||||
|
||||
private void MovePlayer()
|
||||
{
|
||||
@@ -125,6 +142,8 @@ public class Player : MonoBehaviour
|
||||
isHurt = false;
|
||||
};
|
||||
|
||||
|
||||
PlayFightSound();
|
||||
HandleAnimations();
|
||||
}
|
||||
|
||||
@@ -230,21 +249,39 @@ public class Player : MonoBehaviour
|
||||
animator.SetBool("IsHurt", isHurt);
|
||||
}
|
||||
|
||||
private void PlayFightSound()
|
||||
{
|
||||
if (isFighting && !isPlayerHurt)
|
||||
{
|
||||
SoundManagerScript.PlaySound(GetRandomFightClipName());
|
||||
}
|
||||
}
|
||||
|
||||
private string GetRandomFightClipName()
|
||||
{
|
||||
var fightClipNames = new List<string> { "punch", "hard punch", "slap", "hard slap" };
|
||||
var randomNumber = UnityEngine.Random.Range(0, fightClipNames.Count);
|
||||
return fightClipNames[randomNumber];
|
||||
}
|
||||
|
||||
public void StartEncounter()
|
||||
{
|
||||
isPlayerHurt = false;
|
||||
isFighting = true;
|
||||
isMovementEnabled = false;
|
||||
}
|
||||
|
||||
public void EndEncounter()
|
||||
{
|
||||
isPlayerHurt = false;
|
||||
isFighting = false;
|
||||
isMovementEnabled = true;
|
||||
DecreaseStaminaAfterBugFight();
|
||||
}
|
||||
|
||||
public void ThrowUserInTheAirHurt()
|
||||
{
|
||||
{
|
||||
isPlayerHurt = true;
|
||||
GetComponent<Rigidbody2D>().velocity += new Vector2(Mathf.Sign(transform.localScale.x) * -1 * hurtVelocity, hurtVelocity);
|
||||
isFighting = false;
|
||||
isHurt = true;
|
||||
|
||||
@@ -5,8 +5,10 @@ using UnityEngine;
|
||||
public class SoundManagerScript : MonoBehaviour
|
||||
{
|
||||
|
||||
public static AudioClip jumpSound, screamSound, wrongButtonSound, bugLaughSound, drinkSound;
|
||||
static AudioSource audioSrc;
|
||||
public static AudioClip jumpSound, screamSound, wrongButtonSound,
|
||||
bugLaughSound, drinkSound, eatSound, punchSound, hardPunchSound,
|
||||
slapSound, hardSlapSound, winSound;
|
||||
public static AudioSource audioSrc;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -16,6 +18,12 @@ public class SoundManagerScript : MonoBehaviour
|
||||
wrongButtonSound = Resources.Load<AudioClip>("Audio/WrongButton");
|
||||
bugLaughSound = Resources.Load<AudioClip>("Audio/BugLaugh");
|
||||
drinkSound = Resources.Load<AudioClip>("Audio/Drink");
|
||||
eatSound = Resources.Load<AudioClip>("Audio/Eat");
|
||||
punchSound = Resources.Load<AudioClip>("Audio/Punch");
|
||||
hardPunchSound = Resources.Load<AudioClip>("Audio/HardPunch");
|
||||
slapSound = Resources.Load<AudioClip>("Audio/Slap");
|
||||
hardSlapSound = Resources.Load<AudioClip>("Audio/HardSlap");
|
||||
winSound = Resources.Load<AudioClip>("Audio/Win");
|
||||
|
||||
audioSrc = GetComponent<AudioSource>();
|
||||
}
|
||||
@@ -45,6 +53,26 @@ public class SoundManagerScript : MonoBehaviour
|
||||
case "drink":
|
||||
audioSrc.PlayOneShot(drinkSound);
|
||||
break;
|
||||
case "eat":
|
||||
audioSrc.PlayOneShot(eatSound);
|
||||
break;
|
||||
case "punch":
|
||||
audioSrc.PlayOneShot(punchSound);
|
||||
break;
|
||||
case "hard punch":
|
||||
audioSrc.PlayOneShot(hardPunchSound);
|
||||
break;
|
||||
case "slap":
|
||||
audioSrc.PlayOneShot(slapSound);
|
||||
break;
|
||||
case "hard slap":
|
||||
audioSrc.PlayOneShot(hardSlapSound);
|
||||
break;
|
||||
case "win":
|
||||
audioSrc.clip = winSound;
|
||||
audioSrc.PlayOneShot(winSound);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user