Merge branch 'develop' of github.com:boudji-ludwig-pett/cnam-geometry-dash into map-editor-design

This commit is contained in:
Vincent PETT
2025-03-31 17:38:48 +02:00
34 changed files with 2737 additions and 645 deletions

View File

@ -9,7 +9,7 @@ public class NormalGameMode : IGameMode
public void Update(Player player)
{
player.RigidBody.linearVelocity = new Vector2(HorizontalSpeed, player.RigidBody.linearVelocity.y);
player.RigidBody.linearVelocity = new Vector2(HorizontalSpeed * player.SpeedMultiplier, player.RigidBody.linearVelocity.y);
if (player.HasStarted && player.IsColliding && Input.GetKey(JumpKey) && player.CanJump)
{

View File

@ -6,34 +6,51 @@ public class ShipGameMode : IGameMode
private const float HorizontalSpeed = 8.6f;
private const float JumpForce = 26.6581f;
private const KeyCode JumpKey = KeyCode.Space;
private const float UpperAngle = 45f;
private const float LowerAngle = -45f;
private const float RotationLerpSpeed = 5f;
private const float RotationTransitionDuration = 0.5f;
public void Update(Player player)
{
player.RigidBody.linearVelocity = new Vector2(HorizontalSpeed, player.RigidBody.linearVelocity.y);
player.RigidBody.linearVelocity = new Vector2(HorizontalSpeed * player.SpeedMultiplier, player.RigidBody.linearVelocity.y);
if (player.HasStarted && Input.GetKey(JumpKey))
bool jumpPressed = Input.GetKey(JumpKey);
if (player.HasStarted && jumpPressed)
{
Jump(player);
if (Input.GetKeyDown(JumpKey))
{
player.Transform.rotation = Quaternion.Euler(0, 0, UpperAngle);
}
else
{
player.Transform.rotation = Quaternion.Euler(0, 0, UpperAngle);
}
}
else
{
float currentAngle = GetCurrentZAngle(player);
float t = Mathf.Clamp01(Time.deltaTime / RotationTransitionDuration);
float interpolationFactor = Mathf.Sin(t * (Mathf.PI / 2));
float newAngle = Mathf.Lerp(currentAngle, LowerAngle, interpolationFactor);
player.Transform.rotation = Quaternion.Euler(0, 0, newAngle);
}
float targetAngle = Input.GetKey(JumpKey) ? UpperAngle : LowerAngle;
float currentAngle = player.Transform.rotation.eulerAngles.z;
if (currentAngle > 180f)
currentAngle -= 360f;
float newAngle = Mathf.Lerp(currentAngle, targetAngle, RotationLerpSpeed * Time.deltaTime);
player.Transform.rotation = Quaternion.Euler(0, 0, newAngle);
UpdateParticlePositionAndRotation(player);
if (player.Particle.gameObject.activeSelf)
{
player.Particle.gameObject.SetActive(false);
}
}
private void UpdateParticlePositionAndRotation(Player player)
private float GetCurrentZAngle(Player player)
{
player.Particle.transform.position = player.Transform.position + new Vector3(-0.19f, -0.64f, -10);
player.Particle.transform.rotation = Quaternion.Euler(0, 0, 150.464f);
float angle = player.Transform.rotation.eulerAngles.z;
if (angle > 180f)
angle -= 360f;
return angle;
}
private void Jump(Player player)
@ -56,7 +73,7 @@ public class ShipGameMode : IGameMode
return;
}
float currentAngle = player.Transform.rotation.eulerAngles.z;
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));
}

View File

@ -16,6 +16,16 @@ public class LevelLoader : MonoBehaviour
private void LoadAudio()
{
audioSource.clip = Resources.Load<AudioClip>(Path.Combine("Musics", levelsLoader.levelCurrent.musicName));
if (PlayerPrefs.HasKey("Volume"))
{
audioSource.volume = PlayerPrefs.GetFloat("Volume");
}
else
{
audioSource.volume = 1f;
}
audioSource.Play();
}

View File

@ -1,11 +1,33 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PauseMenu : MonoBehaviour
{
public GameObject pauseMenu;
public GameObject pauseButton;
public LevelLoader levelLoader;
public Slider volumeSlider;
public void Start()
{
if (PlayerPrefs.HasKey("Volume"))
{
levelLoader.audioSource.volume = PlayerPrefs.GetFloat("Volume");
volumeSlider.value = levelLoader.audioSource.volume;
}
else
{
levelLoader.audioSource.volume = 1f;
volumeSlider.value = 1f;
}
}
public void ChangeVolume()
{
levelLoader.audioSource.volume = volumeSlider.value;
PlayerPrefs.SetFloat("Volume", levelLoader.audioSource.volume);
}
public void Pause()
{

View File

@ -13,6 +13,7 @@ public class Player : MonoBehaviour
public bool CanJump { get; set; } = true;
public IGameMode CurrentGameMode { get; set; }
public float SpeedMultiplier = 1f;
public void Awake()
{
@ -67,6 +68,16 @@ public class Player : MonoBehaviour
SpriteRenderer.sprite = Resources.Load<Sprite>("Shapes/BaseSquare");
ChangeGameMode(new NormalGameMode());
}
else if (collision.CompareTag("BonusBoostSpeed"))
{
SpeedMultiplier *= 1.5f;
Destroy(collision.gameObject);
}
else if (collision.CompareTag("BonusSlowSpeed"))
{
SpeedMultiplier /= 1.5f;
Destroy(collision.gameObject);
}
}
public void ChangeGameMode(IGameMode newMode)

View File

@ -3,7 +3,8 @@ using UnityEngine;
public class PlayerCamera : MonoBehaviour
{
public GameObject playerObject;
public const float MIN_Y_FOLLOW = 2.0f;
public float normalMinYFollow = 2.0f;
public float shipMinYFollow = 6.0f;
private float initialY;
private void Start()
@ -13,9 +14,16 @@ public class PlayerCamera : MonoBehaviour
private void Update()
{
float targetY = initialY;
Player player = playerObject.GetComponent<Player>();
if (playerObject.transform.position.y > MIN_Y_FOLLOW)
float minYFollow = normalMinYFollow;
if (player.CurrentGameMode is ShipGameMode)
{
minYFollow = shipMinYFollow;
}
float targetY = initialY;
if (playerObject.transform.position.y > minYFollow)
{
targetY = playerObject.transform.position.y;
}