Pull request #14: Jason

Merge in CEGJ/ludumdare50 from jason to dev

* commit '8e0d1874dc8a7e351227fe9b9b3248b3dfed83f6':
  Don't screen shake when throwing minion
  Can get attack rumble while sucking?
  Added rumble on screen shake and suck
  Cleared nullable warnings
This commit is contained in:
Jason Durand 01 2022-04-04 00:11:29 +00:00
commit cec2ab48fb
10 changed files with 55 additions and 30 deletions

View File

@ -58,6 +58,7 @@ MonoBehaviour:
gameFlowManager: {fileID: 0} gameFlowManager: {fileID: 0}
stats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} stats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
globalCamera: {fileID: 0} globalCamera: {fileID: 0}
screenShaker: {fileID: 0}
jumpSource: {fileID: 7164870411903264125} jumpSource: {fileID: 7164870411903264125}
jumpSounds: jumpSounds:
- {fileID: 8300000, guid: 2f93dc5371f10744ba49e29576e8a6a7, type: 3} - {fileID: 8300000, guid: 2f93dc5371f10744ba49e29576e8a6a7, type: 3}
@ -104,6 +105,7 @@ MonoBehaviour:
- {fileID: 8300000, guid: 4e2519f9a65bd484d95111774c762843, type: 3} - {fileID: 8300000, guid: 4e2519f9a65bd484d95111774c762843, type: 3}
playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
playerMovement: {fileID: 0} playerMovement: {fileID: 0}
screenShaker: {fileID: 0}
--- !u!114 &1967503440015794769 --- !u!114 &1967503440015794769
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -145,6 +147,7 @@ MonoBehaviour:
suckSource: {fileID: 3555231741827846396} suckSource: {fileID: 3555231741827846396}
suckSounds: suckSounds:
- {fileID: 8300000, guid: c12a57d990960ce44bc7cf4d5f63d32b, type: 3} - {fileID: 8300000, guid: c12a57d990960ce44bc7cf4d5f63d32b, type: 3}
screenShaker: {fileID: 0}
soundManager: {fileID: 0} soundManager: {fileID: 0}
--- !u!114 &1214567908930553477 --- !u!114 &1214567908930553477
MonoBehaviour: MonoBehaviour:

View File

@ -5,9 +5,9 @@ using UnityEngine.Serialization;
public class AIEntity : Entity { public class AIEntity : Entity {
[SerializeField] protected AudioSource attackSource; [SerializeField] protected AudioSource attackSource = null!;
[SerializeField] protected AudioClip[] attackSounds; [SerializeField] protected AudioClip[] attackSounds = null!;
[FormerlySerializedAs("stats")] [FormerlySerializedAs("stats")]
[SerializeField] [SerializeField]
@ -78,12 +78,12 @@ public class AIEntity : Entity {
return enemies.HasFlag(other.entityType) && other.IsAlive(); return enemies.HasFlag(other.entityType) && other.IsAlive();
} }
override public bool TakeDamage(float amount, Entity other, bool sound=true) { override public bool TakeDamage(float amount, Entity other, bool sound = true, bool intentional = false) {
//TODO Should we warn if target is null here? //TODO Should we warn if target is null here?
if (target != null && target.GetComponent<VampireEntity>() is { }) if (target != null && target.GetComponent<VampireEntity>() is { })
target = other.transform; target = other.transform;
return base.TakeDamage(amount, other, sound); return base.TakeDamage(amount, other, sound, intentional);
} }
#region Flip #region Flip

View File

@ -45,9 +45,9 @@ public class Arena : MonoBehaviour {
SafeZone safeZone = null!; SafeZone safeZone = null!;
[field: SerializeField] int currWaveSize = 0; [field: SerializeField] int currWaveSize = 0;
[SerializeField] AudioSource waveSource; [SerializeField] AudioSource waveSource = null!;
[SerializeField] AudioClip[] waveSounds; [SerializeField] AudioClip[] waveSounds = null!;
[HideInInspector] public SoundManager soundManager; [HideInInspector] public SoundManager soundManager = null!;
void Awake() { void Awake() {

View File

@ -121,10 +121,12 @@ public class BloodSucker : MonoBehaviour {
bloodParticles.Play(); bloodParticles.Play();
currentTarget.OnSuck(true); currentTarget.OnSuck(true);
soundManager.PlaySound(suckingSource, suckingSounds, randomPitch: true, createTempSourceIfBusy: false); soundManager.PlaySound(suckingSource, suckingSounds, randomPitch: true, createTempSourceIfBusy: false);
screenShaker.StartHeldRumble();
} else { } else {
bloodParticles.Stop(true, ParticleSystemStopBehavior.StopEmitting); bloodParticles.Stop(true, ParticleSystemStopBehavior.StopEmitting);
if(!(currentTarget is null))currentTarget.OnSuck(false); if(!(currentTarget is null))currentTarget.OnSuck(false);
soundManager.StopSound(suckingSource); soundManager.StopSound(suckingSource);
screenShaker.StopHeldRumble();
} }
} }

View File

@ -93,7 +93,7 @@ public class Entity : MonoBehaviour {
} }
//Apply damage to the entity, returns true if it is still alive //Apply damage to the entity, returns true if it is still alive
public virtual bool TakeDamage(float amount, Entity other, bool sound = true) { public virtual bool TakeDamage(float amount, Entity other, bool sound = true, bool intentional = false) {
Health -= amount; Health -= amount;
healthBar.SetHealthFraction(Health / initialHealth); healthBar.SetHealthFraction(Health / initialHealth);

View File

@ -181,12 +181,12 @@ public class GameFlowManager : MonoBehaviour {
gameFlowManager.SetPauseLevel(PauseLevel.PreventActions); gameFlowManager.SetPauseLevel(PauseLevel.PreventActions);
} }
public override void LeaveState() => gameFlowManager.startTxt.transform.parent.gameObject.SetActive(false);
public override BaseState? UpdateState(){ public override BaseState? UpdateState(){
gameFlowManager.FadeStartTxt(); gameFlowManager.FadeStartTxt();
return null; return null;
} }
public override void LeaveState() => gameFlowManager.startTxt.transform.parent.gameObject.SetActive(false);
} }
public class GameplayFlowState : GameFlowState { public class GameplayFlowState : GameFlowState {

View File

@ -81,7 +81,7 @@ public class MinionThrower : MonoBehaviour {
if (minionHealthCost >= vampireEntity.Health) { if (minionHealthCost >= vampireEntity.Health) {
return; return;
} }
vampireEntity.TakeDamage(minionHealthCost, vampireEntity); vampireEntity.TakeDamage(minionHealthCost, vampireEntity, intentional: true);
currentCooldownTimer = playerStats.currentInitialCooldown; currentCooldownTimer = playerStats.currentInitialCooldown;

View File

@ -21,13 +21,13 @@ public class PlayerMovement : MonoBehaviour {
VampireEntity vampireEntity = null!; VampireEntity vampireEntity = null!;
Animator animator = null!; Animator animator = null!;
public bool facingRight { get; private set; } = true; public bool facingRight { get; private set; } = true;
[HideInInspector] public ScreenShaker screenShaker; [HideInInspector] public ScreenShaker screenShaker = null!;
[SerializeField] AudioSource jumpSource; [SerializeField] AudioSource jumpSource = null!;
[SerializeField] AudioClip[] jumpSounds; [SerializeField] AudioClip[] jumpSounds = null!;
[SerializeField] AudioSource landSource; [SerializeField] AudioSource landSource = null!;
[SerializeField] AudioClip[] landSounds; [SerializeField] AudioClip[] landSounds = null!;
[HideInInspector] public SoundManager soundManager; [HideInInspector] public SoundManager soundManager = null!;
bool lastJumpButton; bool lastJumpButton;
@ -42,6 +42,7 @@ public class PlayerMovement : MonoBehaviour {
currentState = new ImmobileMovementState(this); currentState = new ImmobileMovementState(this);
soundManager = FindObjectOfType<SoundManager>(); soundManager = FindObjectOfType<SoundManager>();
screenShaker = FindObjectOfType<ScreenShaker>(); screenShaker = FindObjectOfType<ScreenShaker>();
} }
void Start() { void Start() {
@ -195,7 +196,7 @@ public class PlayerMovement : MonoBehaviour {
// playerMovement.animator.SetBool("Jumping", true); // playerMovement.animator.SetBool("Jumping", true);
playerMovement.animator.Play("Player_Jump"); playerMovement.animator.Play("Player_Jump");
playerMovement.soundManager.PlaySound(playerMovement.jumpSource, playerMovement.jumpSounds, randomPitch: true, createTempSourceIfBusy: true); playerMovement.soundManager.PlaySound(playerMovement.jumpSource, playerMovement.jumpSounds, randomPitch: true, createTempSourceIfBusy: true);
playerMovement.screenShaker.Shake(); playerMovement.screenShaker.Shake(rumbleLowFreq:0f, rumbleHighFreq:0f);
} }
public override void LeaveState() { public override void LeaveState() {
// playerMovement.animator.SetBool("Jumping", false); // playerMovement.animator.SetBool("Jumping", false);

View File

@ -1,30 +1,49 @@
#nullable enable
using System.Collections; using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Cinemachine; using Cinemachine;
using UnityEngine.InputSystem;
public class ScreenShaker : MonoBehaviour { public class ScreenShaker : MonoBehaviour {
CinemachineVirtualCamera cam = null!;
CinemachineVirtualCamera cam; CinemachineBasicMultiChannelPerlin noise = null!;
CinemachineBasicMultiChannelPerlin noise; Coroutine? coroutine;
(float, float)? heldRumble;
void Awake() { void Awake() {
cam = GetComponent<CinemachineVirtualCamera>(); cam = GetComponent<CinemachineVirtualCamera>();
noise = cam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>(); noise = cam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
} }
public void Shake(float magnitude = 1f, float duration = 0.2f) { public void Shake(float magnitude = 1f, float rumbleLowFreq = 0.25f, float rumbleHighFreq = 0.75f, float duration = 0.2f) {
StartCoroutine(ShakeCoroutine(magnitude, duration)); if (coroutine is {})
StopCoroutine(coroutine);
coroutine = StartCoroutine(ShakeCoroutine(magnitude, rumbleLowFreq, rumbleHighFreq, duration));
} }
IEnumerator ShakeCoroutine(float magnitude, float duration) { public void StartHeldRumble(float rumbleLowFreq = 0.25f, float rumbleHighFreq = 0.75f) {
heldRumble = (rumbleLowFreq, rumbleHighFreq);
Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq);
}
public void StopHeldRumble() {
heldRumble = null;
Gamepad.current.ResetHaptics();
}
IEnumerator ShakeCoroutine(float magnitude, float rumbleLowFreq, float rumbleHighFreq, float duration) {
noise.m_AmplitudeGain = magnitude; noise.m_AmplitudeGain = magnitude;
noise.m_FrequencyGain = 10f; noise.m_FrequencyGain = 10f;
Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq);
yield return new WaitForSeconds(duration); yield return new WaitForSecondsRealtime(duration);
noise.m_AmplitudeGain = 0f; noise.m_AmplitudeGain = 0f;
noise.m_FrequencyGain = 1f; noise.m_FrequencyGain = 1f;
if (heldRumble != null)
Gamepad.current.SetMotorSpeeds(heldRumble.Value.Item1, heldRumble.Value.Item2);
else
Gamepad.current.ResetHaptics();
} }
} }

View File

@ -30,12 +30,12 @@ public class VampireEntity : Entity {
TakeDamage(playerStats.bloodLossRate * Time.deltaTime, this, sound: false); TakeDamage(playerStats.bloodLossRate * Time.deltaTime, this, sound: false);
} }
public override bool TakeDamage(float amount, Entity other, bool sound = true) { public override bool TakeDamage(float amount, Entity other, bool sound = true, bool intentional = false) {
if (sound) { if (sound && !intentional) {
screenShaker.Shake(); screenShaker.Shake();
} }
return base.TakeDamage(amount, other, sound); return base.TakeDamage(amount, other, sound, intentional);
} }
public bool IsInSafeZone() => playerMovement.IsInSafeZone; public bool IsInSafeZone() => playerMovement.IsInSafeZone;