mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-06-10 22:20:40 +02:00
feat: sounds effects (click on button, win and death) (#67)
This commit is contained in:
19
Assets/Scripts/AIToggle.cs
Normal file
19
Assets/Scripts/AIToggle.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AI : MonoBehaviour
|
||||
{
|
||||
public Toggle AIToggle;
|
||||
public Player player;
|
||||
|
||||
public void OnAiChange()
|
||||
{
|
||||
player.IsAI = AIToggle.isOn;
|
||||
}
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
AIToggle = GetComponent<Toggle>();
|
||||
AIToggle.isOn = player.IsAI;
|
||||
}
|
||||
}
|
2
Assets/Scripts/AIToggle.cs.meta
Normal file
2
Assets/Scripts/AIToggle.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b63079a9773c036389c5b87c12e728c3
|
@ -1,10 +1,10 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class NormalGameMode : IGameMode
|
||||
{
|
||||
public bool editMode { get; set; } = false;
|
||||
private const float HorizontalSpeed = 8.6f;
|
||||
private const float JumpForce = 26.6581f;
|
||||
private const KeyCode JumpKey = KeyCode.Space;
|
||||
@ -16,7 +16,6 @@ public class NormalGameMode : IGameMode
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(HorizontalSpeed * player.SpeedMultiplier, player.RigidBody.linearVelocity.y);
|
||||
|
||||
|
||||
if (player.IsColliding && Input.GetKey(JumpKey) && !isRotating)
|
||||
{
|
||||
Debug.Log("Player is Jumping");
|
||||
@ -88,27 +87,6 @@ public class NormalGameMode : IGameMode
|
||||
public void OnCollisionEnter(Player player, Collision2D collision)
|
||||
{
|
||||
player.IsColliding = true;
|
||||
|
||||
if (collision.gameObject.CompareTag("Kill"))
|
||||
{
|
||||
if (editMode)
|
||||
{
|
||||
GameObject spawn = new GameObject("AutoSpawnPoint");
|
||||
spawn.transform.position = new Vector3(-16, -3, 0f);
|
||||
player.transform.position = spawn.transform.position;
|
||||
player.RigidBody.linearVelocity = Vector2.zero;
|
||||
player.SpeedMultiplier = 1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
}
|
||||
|
||||
if (collision.gameObject.CompareTag("Win"))
|
||||
{
|
||||
SceneManager.LoadScene("SelectLevelScene");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCollisionExit(Player player, Collision2D collision)
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
@ -67,17 +68,6 @@ public class ShipGameMode : IGameMode
|
||||
|
||||
public void OnCollisionEnter(Player player, Collision2D collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Kill"))
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
return;
|
||||
}
|
||||
if (collision.gameObject.CompareTag("Win"))
|
||||
{
|
||||
SceneManager.LoadScene("HomeScene");
|
||||
return;
|
||||
}
|
||||
|
||||
float currentAngle = GetCurrentZAngle(player);
|
||||
float shortestAngle = Mathf.DeltaAngle(currentAngle, 0);
|
||||
player.Transform.rotation = Quaternion.RotateTowards(player.Transform.rotation, Quaternion.Euler(0, 0, 0), Mathf.Abs(shortestAngle));
|
||||
|
@ -7,7 +7,7 @@ public class LevelLoader : MonoBehaviour
|
||||
public LevelsLoader levelsLoader;
|
||||
public bool editMode;
|
||||
public bool createMode;
|
||||
public AudioSource audioSource;
|
||||
public AudioSource musicSource;
|
||||
public Text progressionText;
|
||||
private readonly float groundY = -6.034f;
|
||||
|
||||
@ -18,18 +18,18 @@ public class LevelLoader : MonoBehaviour
|
||||
|
||||
private void LoadAudio()
|
||||
{
|
||||
audioSource.clip = Resources.Load<AudioClip>(Path.Combine("Musics", levelsLoader.levelCurrent.musicName));
|
||||
musicSource.clip = Resources.Load<AudioClip>(Path.Combine("Musics", levelsLoader.levelCurrent.musicName));
|
||||
|
||||
if (PlayerPrefs.HasKey("Volume"))
|
||||
{
|
||||
audioSource.volume = PlayerPrefs.GetFloat("Volume");
|
||||
musicSource.volume = PlayerPrefs.GetFloat("Volume");
|
||||
}
|
||||
else
|
||||
{
|
||||
audioSource.volume = 1f;
|
||||
musicSource.volume = 1f;
|
||||
}
|
||||
|
||||
audioSource.Play();
|
||||
musicSource.Play();
|
||||
}
|
||||
|
||||
private void LoadElements()
|
||||
@ -40,10 +40,10 @@ public class LevelLoader : MonoBehaviour
|
||||
GameObject prefab = GetPrefab(element.type);
|
||||
GameObject instance = Instantiate(prefab, new Vector3(element.x, element.y, 0), Quaternion.identity);
|
||||
|
||||
// if (prefab.CompareTag("Kill"))
|
||||
// {
|
||||
Instantiate(Resources.Load<GameObject>("AICollider"), new Vector3(element.x - 1, element.y, 0), Quaternion.identity);
|
||||
// }
|
||||
if (prefab.CompareTag("Kill"))
|
||||
{
|
||||
Instantiate(Resources.Load<GameObject>("AICollider"), new Vector3(element.x - 1, element.y, 0), Quaternion.identity);
|
||||
}
|
||||
|
||||
Vector3 originalScale = instance.transform.localScale;
|
||||
float newScaleX = element.scaleX > 0 ? element.scaleX : originalScale.x;
|
||||
|
@ -1,12 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class LevelHomeButton : MonoBehaviour
|
||||
{
|
||||
public AudioSource sfxSource;
|
||||
|
||||
public static IEnumerator PlaySoundAndLoadScene(AudioSource sfxSource, string scene)
|
||||
{
|
||||
yield return new WaitWhile(() => sfxSource.isPlaying);
|
||||
SceneManager.LoadScene(scene);
|
||||
}
|
||||
|
||||
public void GoToHome()
|
||||
{
|
||||
PlayerPrefs.SetInt("CreateMode", 0);
|
||||
PlayerPrefs.SetInt("EditMode", 0);
|
||||
SceneManager.LoadScene("HomeScene");
|
||||
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "click"));
|
||||
sfxSource.Play();
|
||||
StartCoroutine(PlaySoundAndLoadScene(sfxSource, "HomeScene"));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelNextButton : MonoBehaviour
|
||||
{
|
||||
public AudioSource sfxSource;
|
||||
public LevelsLoader levelsLoader;
|
||||
|
||||
public void Start()
|
||||
@ -20,5 +22,7 @@ public class LevelNextButton : MonoBehaviour
|
||||
public void NextLevel()
|
||||
{
|
||||
levelsLoader.NextLevel();
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "click"));
|
||||
sfxSource.Play();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelPreviousButton : MonoBehaviour
|
||||
{
|
||||
public AudioSource sfxSource;
|
||||
public LevelsLoader levelsLoader;
|
||||
|
||||
public void Start()
|
||||
@ -20,5 +22,7 @@ public class LevelPreviousButton : MonoBehaviour
|
||||
public void PreviousLevel()
|
||||
{
|
||||
levelsLoader.PreviousLevel();
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "click"));
|
||||
sfxSource.Play();
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,25 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
public AudioSource sfxSource;
|
||||
|
||||
public void LaunchGame()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("SelectLevelScene");
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "click"));
|
||||
sfxSource.Play();
|
||||
|
||||
StartCoroutine(LevelHomeButton.PlaySoundAndLoadScene(sfxSource, "SelectLevelScene"));
|
||||
}
|
||||
|
||||
public void OpenImport()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("ImportScene");
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "click"));
|
||||
sfxSource.Play();
|
||||
|
||||
StartCoroutine(LevelHomeButton.PlaySoundAndLoadScene(sfxSource, "ImportScene"));
|
||||
}
|
||||
|
||||
public void QuitGame()
|
||||
@ -20,22 +29,34 @@ public class MainMenu : MonoBehaviour
|
||||
|
||||
public void LevelEditor()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("LevelEditorScene");
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "click"));
|
||||
sfxSource.Play();
|
||||
|
||||
StartCoroutine(LevelHomeButton.PlaySoundAndLoadScene(sfxSource, "LevelEditorScene"));
|
||||
}
|
||||
|
||||
public void CreateVoidLevel()
|
||||
{
|
||||
PlayerPrefs.SetInt("CreateMode", 1);
|
||||
SceneManager.LoadScene("LevelEditorScene");
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "click"));
|
||||
sfxSource.Play();
|
||||
|
||||
StartCoroutine(LevelHomeButton.PlaySoundAndLoadScene(sfxSource, "LevelEditorScene"));
|
||||
}
|
||||
|
||||
public void EditorChoice()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("EditorChoiceScene");
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "click"));
|
||||
sfxSource.Play();
|
||||
|
||||
StartCoroutine(LevelHomeButton.PlaySoundAndLoadScene(sfxSource, "EditorChoiceScene"));
|
||||
}
|
||||
|
||||
public void EditLevel()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("SelectLevelToEditScene");
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "click"));
|
||||
sfxSource.Play();
|
||||
|
||||
StartCoroutine(LevelHomeButton.PlaySoundAndLoadScene(sfxSource, "SelectLevelToEditScene"));
|
||||
}
|
||||
}
|
||||
|
@ -13,26 +13,26 @@ public class PauseMenu : MonoBehaviour
|
||||
{
|
||||
if (PlayerPrefs.HasKey("Volume"))
|
||||
{
|
||||
levelLoader.audioSource.volume = PlayerPrefs.GetFloat("Volume");
|
||||
volumeSlider.value = levelLoader.audioSource.volume;
|
||||
levelLoader.musicSource.volume = PlayerPrefs.GetFloat("Volume");
|
||||
volumeSlider.value = levelLoader.musicSource.volume;
|
||||
}
|
||||
else
|
||||
{
|
||||
levelLoader.audioSource.volume = 1f;
|
||||
levelLoader.musicSource.volume = 1f;
|
||||
volumeSlider.value = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeVolume()
|
||||
{
|
||||
levelLoader.audioSource.volume = volumeSlider.value;
|
||||
PlayerPrefs.SetFloat("Volume", levelLoader.audioSource.volume);
|
||||
levelLoader.musicSource.volume = volumeSlider.value;
|
||||
PlayerPrefs.SetFloat("Volume", levelLoader.musicSource.volume);
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
Time.timeScale = 0;
|
||||
levelLoader.audioSource.Pause();
|
||||
levelLoader.musicSource.Pause();
|
||||
|
||||
pauseMenu.SetActive(true);
|
||||
pauseButton.SetActive(false);
|
||||
@ -47,7 +47,7 @@ public class PauseMenu : MonoBehaviour
|
||||
public void Resume()
|
||||
{
|
||||
Time.timeScale = 1;
|
||||
levelLoader.audioSource.Play();
|
||||
levelLoader.musicSource.Play();
|
||||
|
||||
pauseMenu.SetActive(false);
|
||||
pauseButton.SetActive(true);
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
@ -12,6 +13,8 @@ public class Player : MonoBehaviour
|
||||
public bool HasStarted { get; set; } = false;
|
||||
public bool CanJump { get; set; } = true;
|
||||
public PauseMenu pauseMenu;
|
||||
public AudioSource sfxSource;
|
||||
public bool editMode { get; set; } = false;
|
||||
|
||||
public IGameMode CurrentGameMode { get; set; }
|
||||
public float SpeedMultiplier = 1f;
|
||||
@ -87,6 +90,31 @@ public class Player : MonoBehaviour
|
||||
public virtual void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
CurrentGameMode?.OnCollisionEnter(this, collision);
|
||||
|
||||
if (collision.gameObject.CompareTag("Kill"))
|
||||
{
|
||||
if (editMode)
|
||||
{
|
||||
GameObject spawn = new GameObject("AutoSpawnPoint");
|
||||
spawn.transform.position = new Vector3(-16, -3, 0f);
|
||||
transform.position = spawn.transform.position;
|
||||
RigidBody.linearVelocity = Vector2.zero;
|
||||
SpeedMultiplier = 1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "death"));
|
||||
sfxSource.Play();
|
||||
StartCoroutine(LevelHomeButton.PlaySoundAndLoadScene(sfxSource, SceneManager.GetActiveScene().name));
|
||||
}
|
||||
}
|
||||
|
||||
if (collision.gameObject.CompareTag("Win"))
|
||||
{
|
||||
sfxSource.clip = Resources.Load<AudioClip>(Path.Combine("Sounds", "win"));
|
||||
sfxSource.Play();
|
||||
StartCoroutine(LevelHomeButton.PlaySoundAndLoadScene(sfxSource, "SelectLevelScene"));
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCollisionExit2D(Collision2D collision)
|
||||
|
@ -8,6 +8,7 @@ public class TestManager : MonoBehaviour
|
||||
public Transform spawnPoint;
|
||||
public GameObject editorUI;
|
||||
public PlayerCamera playerCamera;
|
||||
public AudioSource sfxSource;
|
||||
|
||||
private bool isTesting = false;
|
||||
|
||||
@ -27,7 +28,7 @@ public class TestManager : MonoBehaviour
|
||||
else
|
||||
{
|
||||
gameMode = new NormalGameMode();
|
||||
((NormalGameMode)gameMode).editMode = true;
|
||||
currentPlayer.editMode = true;
|
||||
currentPlayer.ChangeGameMode(gameMode);
|
||||
currentPlayer.SpeedMultiplier = 0f;
|
||||
|
||||
|
Reference in New Issue
Block a user