From 358a47b5aebf9a784f7e89089640e7892756a5c6 Mon Sep 17 00:00:00 2001
From: akmaldika <13521070@mahasiswa.itb.ac.id>
Date: Sat, 11 May 2024 15:42:31 +0700
Subject: [PATCH] feat: difficulty setting

---
 .../Scripts/Managers/EnemyManager.cs          | 19 ++++++++++++++++
 .../Scripts/Player/PlayerHealth.cs            | 22 ++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/Assets/_CompletedAssets/Scripts/Managers/EnemyManager.cs b/Assets/_CompletedAssets/Scripts/Managers/EnemyManager.cs
index 5e617c69..e8cb71b3 100644
--- a/Assets/_CompletedAssets/Scripts/Managers/EnemyManager.cs
+++ b/Assets/_CompletedAssets/Scripts/Managers/EnemyManager.cs
@@ -13,6 +13,25 @@ namespace CompleteProject
         {
             // Call the Spawn function after a delay of the spawnTime and then continue to call after the same amount of time.
             InvokeRepeating("Spawn", spawnTime, spawnTime);
+
+            // set spawn time based on difficulty level mudah = 5, normal = 3, sulit = 2
+          
+            switch (PlayerPrefs.GetString("Difficulty", "mudah"))
+            {
+                case "mudah":
+                    spawnTime = 5f;
+                    break;
+                case "normal":
+                    spawnTime = 3f;
+                    break;
+                case "sulit":
+                    spawnTime = 2f;
+                    break;
+                default:
+                    spawnTime = 5f;
+                    break;
+            }
+    
         }
 
 
diff --git a/Assets/_CompletedAssets/Scripts/Player/PlayerHealth.cs b/Assets/_CompletedAssets/Scripts/Player/PlayerHealth.cs
index 6bbd76b2..ae0ae157 100644
--- a/Assets/_CompletedAssets/Scripts/Player/PlayerHealth.cs
+++ b/Assets/_CompletedAssets/Scripts/Player/PlayerHealth.cs
@@ -7,7 +7,7 @@ namespace CompleteProject
 {
     public class PlayerHealth : MonoBehaviour
     {
-        public float startingHealth = 100f;                            // The amount of health the player starts the game with.
+        public float startingHealth = 125f;                            // The amount of health the player starts the game with.
         public float currentHealth;                                   // The current health the player has.
         public Slider healthSlider;                                 // Reference to the UI's health bar.
         public Image effectImage;                                   // Reference to an image to flash on the screen on being hurt.
@@ -33,8 +33,28 @@ namespace CompleteProject
             playerMovement = GetComponent<PlayerMovement>();
             riffle = GetComponentInChildren<Riffle>();
 
+            // set starting health based on difficulty level mudah = 100, normal = 50, sulit = 25
+            
+            switch (PlayerPrefs.GetString("Difficulty", "mudah"))
+            {
+                case "mudah":
+                    startingHealth = 125f;
+                    break;
+                case "normal":
+                    startingHealth = 100f;
+                    break;
+                case "sulit":
+                    startingHealth = 50f;
+                    break;
+                default:
+                    startingHealth = 125f;
+                    break;
+            }
+            
             // Set the initial health of the player.
             currentHealth = startingHealth;
+
+
         }
 
 
-- 
GitLab