mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-06-10 22:20:40 +02:00
feat: init AI (#60)
This commit is contained in:
@ -5,4 +5,6 @@ public interface IGameMode
|
||||
void Update(Player player);
|
||||
void OnCollisionEnter(Player player, Collision2D collision);
|
||||
void OnCollisionExit(Player player, Collision2D collision);
|
||||
|
||||
void Jump(Player player);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class NormalGameMode : IGameMode
|
||||
UpdateParticlePositionAndRotation(player);
|
||||
}
|
||||
|
||||
private void Jump(Player player)
|
||||
public void Jump(Player player)
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0);
|
||||
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
|
||||
|
@ -55,7 +55,7 @@ public class ShipGameMode : IGameMode
|
||||
return angle;
|
||||
}
|
||||
|
||||
private void Jump(Player player)
|
||||
public void Jump(Player player)
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0);
|
||||
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
|
||||
|
@ -38,6 +38,11 @@ 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);
|
||||
// }
|
||||
|
||||
Vector3 originalScale = instance.transform.localScale;
|
||||
float newScaleX = element.scaleX > 0 ? element.scaleX : originalScale.x;
|
||||
float newScaleY = element.scaleY > 0 ? element.scaleY : originalScale.y;
|
||||
|
@ -24,9 +24,13 @@ public class Player : MonoBehaviour
|
||||
|
||||
GameObject loaderObj = GameObject.FindGameObjectWithTag("LevelsLoader");
|
||||
if (loaderObj != null)
|
||||
{
|
||||
LevelsLoader = loaderObj.GetComponent<LevelsLoader>();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("LevelsLoader introuvable : Progression désactivée pour ce niveau.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@ -38,13 +42,33 @@ public class Player : MonoBehaviour
|
||||
CurrentGameMode = new NormalGameMode();
|
||||
}
|
||||
|
||||
public bool IsAI
|
||||
{
|
||||
get
|
||||
{
|
||||
if (PlayerPrefs.HasKey("AI"))
|
||||
{
|
||||
return PlayerPrefs.GetInt("AI") == 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
PlayerPrefs.SetInt("AI", value ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (CurrentGameMode != null)
|
||||
CurrentGameMode.Update(this);
|
||||
CurrentGameMode?.Update(this);
|
||||
|
||||
if (LevelsLoader != null)
|
||||
{
|
||||
LevelsLoader.CalculateCurrentProgressionPercent(transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnCollisionEnter2D(Collision2D collision)
|
||||
@ -79,6 +103,10 @@ public class Player : MonoBehaviour
|
||||
SpeedMultiplier /= 1.5f;
|
||||
Destroy(collision.gameObject);
|
||||
}
|
||||
else if (collision.CompareTag("AICollider") && IsAI)
|
||||
{
|
||||
CurrentGameMode.Jump(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeGameMode(IGameMode newMode)
|
||||
|
Reference in New Issue
Block a user