From f89c8b5f6de9770d60f6a02ecf858b948d3bb72b Mon Sep 17 00:00:00 2001
From: Jean-Luc NELET <jean-luc.nelet@etu.u-pec.fr>
Date: Fri, 17 Jan 2025 13:20:36 +0100
Subject: [PATCH] =?UTF-8?q?T=C3=A9l=C3=A9verser=20les=20fichiers=20vers=20?=
 =?UTF-8?q?"/"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 BlackHole.cs    |  27 ++++++++++
 Droid.cs        | 139 ++++++++++++++++++++++++++++++++++++++++++++++++
 FallDetector.cs |  35 ++++++++++++
 Meteor.cs       |  19 +++++++
 MeteorRain.cs   |  36 +++++++++++++
 5 files changed, 256 insertions(+)
 create mode 100644 BlackHole.cs
 create mode 100644 Droid.cs
 create mode 100644 FallDetector.cs
 create mode 100644 Meteor.cs
 create mode 100644 MeteorRain.cs

diff --git a/BlackHole.cs b/BlackHole.cs
new file mode 100644
index 0000000..c90d4bc
--- /dev/null
+++ b/BlackHole.cs
@@ -0,0 +1,27 @@
+using UnityEngine;
+
+public class BlackHole : MonoBehaviour
+{
+    // Vitesse de rotation du trou noir
+    public float rotationSpeed = 10f;
+
+    // Méthode appelée à chaque frame pour faire tourner le trou noir
+    void Update()
+    {
+        transform.Rotate(0, rotationSpeed * Time.deltaTime, 0);
+    }
+    private void OnTriggerEnter(Collider other)
+    {
+        // Vérifie si le droïde ou tout autre objet entre dans le trou noir
+        if (other.gameObject.CompareTag("Player"))
+        {
+            Debug.Log("Droid destroyed by Black Hole!");
+            Destroy(other.gameObject); // Détruit le droïde
+        }
+        else
+        {
+            Debug.Log($"{other.gameObject.name} destroyed by Black Hole!");
+            Destroy(other.gameObject); // Détruit tout autre objet
+        }
+    }
+}
diff --git a/Droid.cs b/Droid.cs
new file mode 100644
index 0000000..7f54b11
--- /dev/null
+++ b/Droid.cs
@@ -0,0 +1,139 @@
+using UnityEngine;
+using UnityEngine.SceneManagement;
+using System.Collections;
+
+public class Droid : MonoBehaviour
+{
+    private bool jumpKeyWasPressed;
+    private float horizontalInput;
+    private bool isGrounded;
+    private Rigidbody rigidbodyComponent;
+
+    private int energyDisksCollected = 0;
+    private float speedMultiplier = 1f;
+    private float jumpMultiplier = 1f;
+    private bool isInvincible = false; // Empêche les dégâts multiples
+
+
+    [SerializeField] private int life = 2; // Niveau de vie initial
+    [SerializeField] private GameObject fusee;
+    [SerializeField] private UIManager uiManager;
+
+    void Start()
+    {
+        rigidbodyComponent = GetComponent<Rigidbody>();
+
+        // Recherche automatique du UIManager
+        if (uiManager == null)
+        {
+            uiManager = FindObjectOfType<UIManager>();
+            if (uiManager == null)
+            {
+                Debug.LogError("UIManager is not assigned and could not be found in the scene!");
+            }
+        }
+    }
+
+    void Update()
+    {
+        if (Input.GetKeyDown(KeyCode.Space))
+        {
+            jumpKeyWasPressed = true;
+        }
+
+        horizontalInput = Input.GetAxis("Horizontal");
+
+        if (Input.GetKeyDown(KeyCode.S))
+        {
+            LaunchRocket();
+        }
+
+        // Vérifie si le droïde tombe sous -10 en Y
+        if (transform.position.y < -10)
+        {
+            TriggerGameOver();
+        }
+    }
+
+    private void FixedUpdate()
+    {
+        rigidbodyComponent.velocity = new Vector3(horizontalInput * 2 * speedMultiplier, rigidbodyComponent.velocity.y, 0);
+
+        if (jumpKeyWasPressed && isGrounded)
+        {
+            rigidbodyComponent.AddForce(Vector3.up * 5 * jumpMultiplier, ForceMode.VelocityChange);
+            jumpKeyWasPressed = false;
+        }
+    }
+
+    private void OnCollisionStay(Collision collision)
+    {
+        isGrounded = true;
+    }
+
+    private void OnCollisionExit(Collision collision)
+    {
+        isGrounded = false;
+    }
+
+    private IEnumerator InvincibilityDelay()
+{
+    isInvincible = true; // Active l'invincibilité
+    yield return new WaitForSeconds(1.0f); // Attendre 1 seconde (modifiable)
+    isInvincible = false; // Désactive l'invincibilité
+}
+
+
+    private void OnTriggerEnter(Collider other)
+    {
+        if (other.gameObject.layer == 8) // Disques énergétiques
+        {
+            Destroy(other.gameObject);
+            energyDisksCollected++;
+            life++; // Augmente la vie
+            Debug.Log("Vie augmentée : " + life);
+
+            // Augmente les capacités après 3 disques collectés
+            if (energyDisksCollected == 3)
+            {
+                speedMultiplier = 2f;
+                jumpMultiplier = 2f;
+            }
+        }
+
+        if (other.gameObject.layer == 14) // Ennemis
+        {
+            life -= 2; // Réduit la vie
+            Debug.Log("Vie réduite : " + life);
+            Destroy(other.gameObject);
+             StartCoroutine(InvincibilityDelay());
+
+            if (life <= 0)
+            {
+                TriggerGameOver();
+            }
+        }
+
+        if (other.tag == "Exit")
+        {
+            SceneManager.LoadScene("scene1");
+        }
+    }
+
+    private void LaunchRocket()
+    {
+        GameObject rocket = Instantiate(fusee, transform.position, transform.rotation);
+        Rigidbody rocketRigidbody = rocket.GetComponent<Rigidbody>();
+
+        rocketRigidbody.velocity = new Vector3(20, rocketRigidbody.velocity.y, 0);
+    }
+
+    private void TriggerGameOver()
+    {
+        if (uiManager != null)
+        {
+            uiManager.TriggerGameOver();
+        }
+        Debug.Log("Game Over");
+    }
+}
diff --git a/FallDetector.cs b/FallDetector.cs
new file mode 100644
index 0000000..eb1b30a
--- /dev/null
+++ b/FallDetector.cs
@@ -0,0 +1,35 @@
+using UnityEngine;
+
+public class FallDetector : MonoBehaviour
+{
+    private UIManager uiManager;
+
+    void Start()
+    {
+        // Récupère la référence du UIManager dans la scène
+        uiManager = FindObjectOfType<UIManager>();
+        if (uiManager == null)
+        {
+            Debug.LogError("UIManager not found in the scene!");
+        }
+    }
+
+    void OnTriggerEnter(Collider other)
+    {
+        // Assurez-vous que l'objet détecté est le droïde
+        Debug.Log("Collision detected with: " + other.gameObject.name);
+
+        if (other.CompareTag("Player"))
+        {
+            Debug.Log("Player detected - Triggering game over");
+            if (uiManager != null)
+            {
+                uiManager.TriggerGameOver();
+            }
+            else
+            {
+                Debug.LogError("UIManager reference is null!");
+            }
+        }
+    }
+}
diff --git a/Meteor.cs b/Meteor.cs
new file mode 100644
index 0000000..bcc8491
--- /dev/null
+++ b/Meteor.cs
@@ -0,0 +1,19 @@
+using UnityEngine;
+
+public class Meteor : MonoBehaviour
+{
+    public float fallSpeed = 2f; // Vitesse de chute
+
+    void Update()
+    {
+        // Déplace la météorite uniquement vers le bas
+        transform.position += Vector3.down * fallSpeed * Time.deltaTime;
+    }
+
+    private void OnCollisionEnter(Collision collision)
+    {
+        // Détruit l'objet touché
+        Debug.Log($"{collision.gameObject.name} destroyed by Meteorite!");
+        Destroy(collision.gameObject);
+    }
+}
diff --git a/MeteorRain.cs b/MeteorRain.cs
new file mode 100644
index 0000000..ee2985b
--- /dev/null
+++ b/MeteorRain.cs
@@ -0,0 +1,36 @@
+using System.Collections;
+using UnityEngine;
+
+public class MeteorRain : MonoBehaviour
+{
+    [SerializeField] private GameObject meteorPrefab; // Préfab pour les météorites
+
+    // Coroutine qui crée une météorite toutes les 3 secondes
+    private IEnumerator Start()
+    {
+        while (true)
+        {
+            yield return new WaitForSeconds(5f);
+            Create(); // Appelle la méthode pour créer une météorite
+        }
+    }
+
+    // Méthode pour créer une météorite
+    private void Create()
+    {
+        // Instancie une nouvelle météorite à la position de MeteorRain
+        GameObject meteor = Instantiate(meteorPrefab, transform.position, transform.rotation);
+
+        // Applique une force aléatoire pour la trajectoire de la météorite
+        Rigidbody meteorRigidbody = meteor.GetComponent<Rigidbody>();
+        if (meteorRigidbody != null)
+        {
+            Vector3 randomForce = new Vector3(
+                Random.Range(-10.0f, 10.0f),  // Force horizontale aléatoire
+                Random.Range(-10.0f, 0f),   // Force verticale aléatoire
+                0f                          // Pas de force en profondeur
+            );
+            meteorRigidbody.AddForce(randomForce, ForceMode.Impulse);
+        }
+    }
+}