Merge branch 'master' of https://github.com/SweetTini/GlobalGameJam2020
This commit is contained in:
@@ -74,10 +74,12 @@ public class BugMovement : MonoBehaviour
|
||||
public void DisableMovement()
|
||||
{
|
||||
isMovementDisabled = true;
|
||||
rigidBody.constraints = RigidbodyConstraints2D.FreezeAll;
|
||||
}
|
||||
|
||||
public void EnableMovement()
|
||||
{
|
||||
isMovementDisabled = false;
|
||||
rigidBody.constraints = RigidbodyConstraints2D.FreezeRotation | RigidbodyConstraints2D.FreezePositionY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ 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> pressedTiles;
|
||||
[SerializeField] private List<Tile> successTiles;
|
||||
[SerializeField] private List<Tile> failTiles;
|
||||
[SerializeField] private Tile plusTile;
|
||||
@@ -42,6 +44,7 @@ public class EventControls : MonoBehaviour
|
||||
private EventControlTile currentEventControl;
|
||||
private bool isInBattle = false;
|
||||
private bool hasFailed = false;
|
||||
private int buttonPressAnimationAccumalator = 0;
|
||||
|
||||
private Collider2D currentPlayerCollider;
|
||||
private Collider2D currentEnemyCollider;
|
||||
@@ -159,12 +162,35 @@ 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;
|
||||
|
||||
if (currentEventControl == null)
|
||||
currentEventControl = eventControlTilesInCycle.First(x => !x.isPlusTile && !x.isPerformed);
|
||||
else
|
||||
{
|
||||
if (buttonPressAnimationAccumalator >= framesPerControlTile)
|
||||
{
|
||||
tilemap.SetTile(currentEventControl.position, currentEventControl.isPressed ? currentEventControl.pressedTile :
|
||||
currentEventControl.tile);
|
||||
currentEventControl.isPressed = !currentEventControl.isPressed;
|
||||
buttonPressAnimationAccumalator = 0;
|
||||
}
|
||||
else
|
||||
buttonPressAnimationAccumalator++;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(currentEventControl.keyCode))
|
||||
{
|
||||
@@ -178,19 +204,20 @@ public class EventControls : MonoBehaviour
|
||||
eventTriggered = false;
|
||||
eventCycleAccumalator = 0;
|
||||
|
||||
if (maxNumberOfControlTiles == numberOfEventsCount)
|
||||
if (maxNumberOfEvents == numberOfEventsCount)
|
||||
{
|
||||
player.EndEncounter();
|
||||
isInBattle = false;
|
||||
// Destroy(currentEnemyCollider.gameObject);
|
||||
// currentEnemyCollider = null;
|
||||
hasFailed = false;
|
||||
StartCoroutine(PlayVictoryMusic());
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (eventCycleAccumalator >= eventCycleInSeconds * framesPerSecond)
|
||||
else if (eventCycleAccumalator >= eventCycleInSeconds * framesPerSecond * player.GetStaminaDifficultyFactor())
|
||||
{
|
||||
eventTriggered = false;
|
||||
isInBattle = false;
|
||||
@@ -242,7 +269,7 @@ public class EventControls : MonoBehaviour
|
||||
eventDrawn = false;
|
||||
numberOfControlTilesSet = 0;
|
||||
|
||||
if (maxNumberOfControlTiles == numberOfEventsCount)
|
||||
if (maxNumberOfEvents == numberOfEventsCount)
|
||||
{
|
||||
if (currentEnemyCollider != null && hasFailed)
|
||||
Physics2D.IgnoreCollision(currentPlayerCollider, currentEnemyCollider, false);
|
||||
@@ -281,6 +308,7 @@ public class EventControls : MonoBehaviour
|
||||
|
||||
return new EventControlTile(TileToKeyMappings.TileToKey[randomNumber],
|
||||
tiles[randomNumber],
|
||||
pressedTiles[randomNumber],
|
||||
successTiles[randomNumber],
|
||||
failTiles[randomNumber],
|
||||
position);
|
||||
@@ -292,6 +320,7 @@ public class EventControls : MonoBehaviour
|
||||
plusTile,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
position,
|
||||
true);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
@@ -30,6 +31,7 @@ public class Player : MonoBehaviour
|
||||
private Animator animator;
|
||||
private bool isMovementEnabled = true;
|
||||
private bool isFighting = false;
|
||||
private bool isHurt = false;
|
||||
|
||||
private bool isPlayerHurt = false;
|
||||
|
||||
@@ -38,11 +40,13 @@ public class Player : MonoBehaviour
|
||||
rigidBody = GetComponent<Rigidbody2D>();
|
||||
collider = GetComponent<Collider2D>();
|
||||
animator = GetComponent<Animator>();
|
||||
currentHealth = 1; // startHealth;
|
||||
currentStamina = 50; // startStamina;
|
||||
|
||||
currentHealth = startHealth;
|
||||
healthBar.size = new Vector2(1.5f * startHealth, healthBar.size.y);
|
||||
|
||||
currentStamina = startStamina;
|
||||
staminaInitialSize = staminaBar.size.x;
|
||||
staminaBar.size = new Vector2(staminaInitialSize * 0.5f, staminaBar.size.y);
|
||||
staminaBar.size = new Vector2(staminaInitialSize, staminaBar.size.y);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -76,8 +80,8 @@ public class Player : MonoBehaviour
|
||||
{
|
||||
if (coll.gameObject.tag == "Pizza")
|
||||
{
|
||||
Destroy(coll.gameObject);
|
||||
SoundManagerScript.PlaySound("eat");
|
||||
Destroy(coll.gameObject);
|
||||
currentHealth += currentHealth < startHealth ? 1 : 0;
|
||||
healthBar.size = new Vector2(1.5f * currentHealth, this.healthBar.size.y);
|
||||
}
|
||||
@@ -101,11 +105,27 @@ public class Player : MonoBehaviour
|
||||
{
|
||||
int result = currentStamina - GetStaminaValueChange(bugStaminaDamagePercent);
|
||||
currentStamina = result < 0 ? 0 : result;
|
||||
float multiplier = currentStamina * 1f / startStamina;
|
||||
staminaBar.size = new Vector2(staminaInitialSize * multiplier, staminaBar.size.y);
|
||||
}
|
||||
|
||||
private int GetStaminaValueChange(int percentage)
|
||||
{
|
||||
return currentStamina < startStamina ? (startStamina * percentage / 100) : 0;
|
||||
return currentStamina <= startStamina ? (startStamina * percentage / 100) : 0;
|
||||
}
|
||||
|
||||
private void Hurt()
|
||||
{
|
||||
currentHealth = 3; // TODO: REMOVE!
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +137,13 @@ public class Player : MonoBehaviour
|
||||
Run();
|
||||
FlipSprite();
|
||||
}
|
||||
|
||||
if (Mathf.Abs(rigidBody.velocity.y) < runErrorThreshold)
|
||||
{
|
||||
isHurt = false;
|
||||
};
|
||||
|
||||
|
||||
PlayFightSound();
|
||||
HandleAnimations();
|
||||
}
|
||||
@@ -156,6 +183,16 @@ public class Player : MonoBehaviour
|
||||
{
|
||||
rigidBody.velocity = new Vector2(actualRunSpeed * -1, rigidBody.velocity.y);
|
||||
}
|
||||
|
||||
// Run
|
||||
if (Input.GetKeyUp(KeyCode.RightArrow))
|
||||
{
|
||||
rigidBody.velocity = new Vector2(0, rigidBody.velocity.y);
|
||||
}
|
||||
else if (Input.GetKeyUp(KeyCode.LeftArrow))
|
||||
{
|
||||
rigidBody.velocity = new Vector2(0, rigidBody.velocity.y);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsPlayerOnGround()
|
||||
@@ -220,6 +257,7 @@ public class Player : MonoBehaviour
|
||||
animator.SetBool("IsGround", IsPlayerOnGround());
|
||||
animator.SetFloat("YVelocity", rigidBody.velocity.y);
|
||||
animator.SetBool("IsFighting", isFighting);
|
||||
animator.SetBool("IsHurt", isHurt);
|
||||
}
|
||||
|
||||
private void PlayFightSound()
|
||||
@@ -242,6 +280,8 @@ public class Player : MonoBehaviour
|
||||
isPlayerHurt = false;
|
||||
isFighting = true;
|
||||
isMovementEnabled = false;
|
||||
rigidBody.gravityScale = 0f;
|
||||
rigidBody.velocity = Vector2.zero;
|
||||
}
|
||||
|
||||
public void EndEncounter()
|
||||
@@ -249,6 +289,8 @@ public class Player : MonoBehaviour
|
||||
isPlayerHurt = false;
|
||||
isFighting = false;
|
||||
isMovementEnabled = true;
|
||||
rigidBody.gravityScale = 1f;
|
||||
DecreaseStaminaAfterBugFight();
|
||||
}
|
||||
|
||||
public void ThrowUserInTheAirHurt()
|
||||
@@ -256,5 +298,12 @@ public class Player : MonoBehaviour
|
||||
isPlayerHurt = true;
|
||||
GetComponent<Rigidbody2D>().velocity += new Vector2(Mathf.Sign(transform.localScale.x) * -1 * hurtVelocity, hurtVelocity);
|
||||
isFighting = false;
|
||||
isHurt = true;
|
||||
Hurt();
|
||||
}
|
||||
|
||||
public float GetStaminaDifficultyFactor()
|
||||
{
|
||||
return currentStamina / (startStamina * 1f);
|
||||
}
|
||||
}
|
||||
|
||||
21
Assets/Scripts/SceneLodarManual.cs
Normal file
21
Assets/Scripts/SceneLodarManual.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SceneLodarManual : MonoBehaviour
|
||||
{
|
||||
public Button button;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
button.onClick.AddListener(LoadScene);
|
||||
}
|
||||
|
||||
void LoadScene()
|
||||
{
|
||||
SceneManager.LoadScene("LevelOne");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/SceneLodarManual.cs.meta
Normal file
11
Assets/Scripts/SceneLodarManual.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14c874c8615088f458e5473b40714b56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,7 +8,7 @@ public class SoundManagerScript : MonoBehaviour
|
||||
public static AudioClip jumpSound, screamSound, wrongButtonSound,
|
||||
bugLaughSound, drinkSound, eatSound, punchSound, hardPunchSound,
|
||||
slapSound, hardSlapSound, winSound;
|
||||
static AudioSource audioSrc;
|
||||
public static AudioSource audioSrc;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -23,6 +23,7 @@ public class SoundManagerScript : MonoBehaviour
|
||||
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>();
|
||||
}
|
||||
@@ -35,42 +36,46 @@ public class SoundManagerScript : MonoBehaviour
|
||||
|
||||
public static void PlaySound(string clip)
|
||||
{
|
||||
AudioClip sound = null;
|
||||
switch (clip)
|
||||
{
|
||||
case "jump":
|
||||
audioSrc.PlayOneShot(jumpSound);
|
||||
sound = jumpSound;
|
||||
break;
|
||||
case "scream":
|
||||
audioSrc.PlayOneShot(screamSound);
|
||||
sound = screamSound;
|
||||
break;
|
||||
case "wrong":
|
||||
audioSrc.PlayOneShot(wrongButtonSound);
|
||||
sound = wrongButtonSound;
|
||||
break;
|
||||
case "bug laugh":
|
||||
audioSrc.PlayOneShot(bugLaughSound);
|
||||
sound = bugLaughSound;
|
||||
break;
|
||||
case "drink":
|
||||
audioSrc.PlayOneShot(drinkSound);
|
||||
sound = drinkSound;
|
||||
break;
|
||||
case "eat":
|
||||
audioSrc.PlayOneShot(eatSound);
|
||||
sound = eatSound;
|
||||
break;
|
||||
case "punch":
|
||||
audioSrc.PlayOneShot(punchSound);
|
||||
sound = punchSound;
|
||||
break;
|
||||
case "hard punch":
|
||||
audioSrc.PlayOneShot(hardPunchSound);
|
||||
sound = hardPunchSound;
|
||||
break;
|
||||
case "slap":
|
||||
audioSrc.PlayOneShot(slapSound);
|
||||
sound = slapSound;
|
||||
break;
|
||||
case "hard slap":
|
||||
audioSrc.PlayOneShot(hardSlapSound);
|
||||
sound = hardSlapSound;
|
||||
break;
|
||||
case "win":
|
||||
audioSrc.PlayOneShot(winSound);
|
||||
sound = winSound;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
audioSrc.clip = sound;
|
||||
audioSrc.PlayOneShot(sound);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user