mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-06-10 22:20:40 +02:00
feat: rocket mode (#44)
Co-authored-by: Djelal BOUDJI <djelal@gmail.com>
This commit is contained in:
8
Assets/Scripts/GameMode/IGameMode.cs
Normal file
8
Assets/Scripts/GameMode/IGameMode.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
public interface IGameMode
|
||||
{
|
||||
void Update(Player player);
|
||||
void OnCollisionEnter(Player player, Collision2D collision);
|
||||
void OnCollisionExit(Player player, Collision2D collision);
|
||||
}
|
2
Assets/Scripts/GameMode/IGameMode.cs.meta
Normal file
2
Assets/Scripts/GameMode/IGameMode.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68e961c0b929a2a4d9e92b2f2bf9e197
|
78
Assets/Scripts/GameMode/NormalGameMode.cs
Normal file
78
Assets/Scripts/GameMode/NormalGameMode.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class NormalGameMode : IGameMode
|
||||
{
|
||||
private const float HorizontalSpeed = 8.6f;
|
||||
private const float JumpForce = 26.6581f;
|
||||
private const KeyCode JumpKey = KeyCode.Space;
|
||||
|
||||
public void Update(Player player)
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(HorizontalSpeed, player.RigidBody.linearVelocity.y);
|
||||
|
||||
if (player.HasStarted && player.IsColliding && Input.GetKey(JumpKey) && player.CanJump)
|
||||
{
|
||||
Jump(player);
|
||||
}
|
||||
|
||||
if (!IsJumping(player))
|
||||
{
|
||||
AlignRotation(player);
|
||||
player.Particle.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Particle.gameObject.SetActive(false);
|
||||
player.Transform.Rotate(Vector3.back * 360 * Time.deltaTime);
|
||||
}
|
||||
|
||||
UpdateParticlePositionAndRotation(player);
|
||||
}
|
||||
|
||||
private void Jump(Player player)
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0);
|
||||
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
|
||||
player.LevelsLoader.IncreaseTotalJumps();
|
||||
}
|
||||
|
||||
private bool IsJumping(Player player)
|
||||
{
|
||||
return !player.IsColliding;
|
||||
}
|
||||
|
||||
private void AlignRotation(Player player)
|
||||
{
|
||||
Vector3 rotation = player.Transform.rotation.eulerAngles;
|
||||
rotation.z = Mathf.Round(rotation.z / 90) * 90;
|
||||
player.Transform.rotation = Quaternion.Euler(rotation);
|
||||
}
|
||||
|
||||
private void UpdateParticlePositionAndRotation(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);
|
||||
}
|
||||
|
||||
public void OnCollisionEnter(Player player, Collision2D collision)
|
||||
{
|
||||
player.IsColliding = true;
|
||||
player.CanJump = true;
|
||||
|
||||
if (collision.gameObject.CompareTag("Kill"))
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
|
||||
if (collision.gameObject.CompareTag("Win"))
|
||||
{
|
||||
SceneManager.LoadScene("SelectLevelScene");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCollisionExit(Player player, Collision2D collision)
|
||||
{
|
||||
player.IsColliding = false;
|
||||
}
|
||||
}
|
2
Assets/Scripts/GameMode/NormalGameMode.cs.meta
Normal file
2
Assets/Scripts/GameMode/NormalGameMode.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 222f727842e308847a028d3fce55d364
|
43
Assets/Scripts/GameMode/ShipGameMode.cs
Normal file
43
Assets/Scripts/GameMode/ShipGameMode.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ShipGameMode : IGameMode
|
||||
{
|
||||
private const float HorizontalSpeed = 8.6f;
|
||||
private const float JumpForce = 26.6581f;
|
||||
private const KeyCode JumpKey = KeyCode.Space;
|
||||
|
||||
public void Update(Player player)
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(HorizontalSpeed, player.RigidBody.linearVelocity.y);
|
||||
|
||||
if (player.HasStarted && Input.GetKey(JumpKey))
|
||||
{
|
||||
Jump(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void Jump(Player player)
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0);
|
||||
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
|
||||
player.LevelsLoader.IncreaseTotalJumps();
|
||||
}
|
||||
|
||||
public void OnCollisionEnter(Player player, Collision2D collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Kill"))
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
if (collision.gameObject.CompareTag("Win"))
|
||||
{
|
||||
SceneManager.LoadScene("HomeScene");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCollisionExit(Player player, Collision2D collision)
|
||||
{
|
||||
// rien pour l'instant
|
||||
}
|
||||
}
|
2
Assets/Scripts/GameMode/ShipGameMode.cs.meta
Normal file
2
Assets/Scripts/GameMode/ShipGameMode.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28b5f8f9214141740af5157d6b421677
|
Reference in New Issue
Block a user