mirror of
				https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
				synced 2025-06-27 11:58:51 +02:00 
			
		
		
		
	feat: level progression (#46)
This commit is contained in:
		| @@ -96,6 +96,19 @@ TextureImporter: | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   - serializedVersion: 4 | ||||
|     buildTarget: WebGL | ||||
|     maxTextureSize: 2048 | ||||
|     resizeAlgorithm: 0 | ||||
|     textureFormat: -1 | ||||
|     textureCompression: 1 | ||||
|     compressionQuality: 50 | ||||
|     crunchedCompression: 0 | ||||
|     allowsAlphaSplitting: 0 | ||||
|     overridden: 0 | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   spriteSheet: | ||||
|     serializedVersion: 2 | ||||
|     sprites: | ||||
| @@ -134,7 +147,8 @@ TextureImporter: | ||||
|     secondaryTextures: [] | ||||
|     spriteCustomMetadata: | ||||
|       entries: [] | ||||
|     nameFileIdTable: {} | ||||
|     nameFileIdTable: | ||||
|       CubePortalLabelled_0: -799402021850825835 | ||||
|   mipmapLimitGroupName:  | ||||
|   pSDRemoveMatte: 0 | ||||
|   userData:  | ||||
|   | ||||
| @@ -96,6 +96,19 @@ TextureImporter: | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   - serializedVersion: 4 | ||||
|     buildTarget: WebGL | ||||
|     maxTextureSize: 2048 | ||||
|     resizeAlgorithm: 0 | ||||
|     textureFormat: -1 | ||||
|     textureCompression: 1 | ||||
|     compressionQuality: 50 | ||||
|     crunchedCompression: 0 | ||||
|     allowsAlphaSplitting: 0 | ||||
|     overridden: 0 | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   spriteSheet: | ||||
|     serializedVersion: 2 | ||||
|     sprites: | ||||
| @@ -134,7 +147,8 @@ TextureImporter: | ||||
|     secondaryTextures: [] | ||||
|     spriteCustomMetadata: | ||||
|       entries: [] | ||||
|     nameFileIdTable: {} | ||||
|     nameFileIdTable: | ||||
|       GravityPortalALabelled_0: 4275758854765845916 | ||||
|   mipmapLimitGroupName:  | ||||
|   pSDRemoveMatte: 0 | ||||
|   userData:  | ||||
|   | ||||
| @@ -96,6 +96,19 @@ TextureImporter: | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   - serializedVersion: 4 | ||||
|     buildTarget: WebGL | ||||
|     maxTextureSize: 2048 | ||||
|     resizeAlgorithm: 0 | ||||
|     textureFormat: -1 | ||||
|     textureCompression: 1 | ||||
|     compressionQuality: 50 | ||||
|     crunchedCompression: 0 | ||||
|     allowsAlphaSplitting: 0 | ||||
|     overridden: 0 | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   spriteSheet: | ||||
|     serializedVersion: 2 | ||||
|     sprites: | ||||
| @@ -134,7 +147,8 @@ TextureImporter: | ||||
|     secondaryTextures: [] | ||||
|     spriteCustomMetadata: | ||||
|       entries: [] | ||||
|     nameFileIdTable: {} | ||||
|     nameFileIdTable: | ||||
|       GravityPortalBLabelled_0: -3032260323236093396 | ||||
|   mipmapLimitGroupName:  | ||||
|   pSDRemoveMatte: 0 | ||||
|   userData:  | ||||
|   | ||||
| @@ -96,6 +96,19 @@ TextureImporter: | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   - serializedVersion: 4 | ||||
|     buildTarget: WebGL | ||||
|     maxTextureSize: 2048 | ||||
|     resizeAlgorithm: 0 | ||||
|     textureFormat: -1 | ||||
|     textureCompression: 1 | ||||
|     compressionQuality: 50 | ||||
|     crunchedCompression: 0 | ||||
|     allowsAlphaSplitting: 0 | ||||
|     overridden: 0 | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   spriteSheet: | ||||
|     serializedVersion: 2 | ||||
|     sprites: | ||||
| @@ -134,7 +147,8 @@ TextureImporter: | ||||
|     secondaryTextures: [] | ||||
|     spriteCustomMetadata: | ||||
|       entries: [] | ||||
|     nameFileIdTable: {} | ||||
|     nameFileIdTable: | ||||
|       ShipPortalLabelled_0: -1834338360412052916 | ||||
|   mipmapLimitGroupName:  | ||||
|   pSDRemoveMatte: 0 | ||||
|   userData:  | ||||
|   | ||||
| @@ -96,6 +96,19 @@ TextureImporter: | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   - serializedVersion: 4 | ||||
|     buildTarget: WebGL | ||||
|     maxTextureSize: 2048 | ||||
|     resizeAlgorithm: 0 | ||||
|     textureFormat: -1 | ||||
|     textureCompression: 1 | ||||
|     compressionQuality: 50 | ||||
|     crunchedCompression: 0 | ||||
|     allowsAlphaSplitting: 0 | ||||
|     overridden: 0 | ||||
|     ignorePlatformSupport: 0 | ||||
|     androidETC2FallbackOverride: 0 | ||||
|     forceMaximumCompressionQuality_BC6H_BC7: 0 | ||||
|   spriteSheet: | ||||
|     serializedVersion: 2 | ||||
|     sprites: | ||||
| @@ -134,7 +147,8 @@ TextureImporter: | ||||
|     secondaryTextures: [] | ||||
|     spriteCustomMetadata: | ||||
|       entries: [] | ||||
|     nameFileIdTable: {} | ||||
|     nameFileIdTable: | ||||
|       Ship_0: -8820715720815460284 | ||||
|   mipmapLimitGroupName:  | ||||
|   pSDRemoveMatte: 0 | ||||
|   userData:  | ||||
|   | ||||
| @@ -1,6 +0,0 @@ | ||||
| { | ||||
|     "name": "Test Level", | ||||
|     "musicName": "BackOnTrack", | ||||
|     "order": 3, | ||||
|     "elements": [] | ||||
| } | ||||
| @@ -1,7 +0,0 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 43f43717f2648714d94051fe07bc3f15 | ||||
| TextScriptImporter: | ||||
|   externalObjects: {} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1556,7 +1556,7 @@ RectTransform: | ||||
|   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||||
|   m_AnchorMin: {x: 0.5, y: 0.5} | ||||
|   m_AnchorMax: {x: 0.5, y: 0.5} | ||||
|   m_AnchoredPosition: {x: -0.000013351, y: -147.36} | ||||
|   m_AnchoredPosition: {x: -52.318, y: -147.36} | ||||
|   m_SizeDelta: {x: 629.6868, y: 98.2373} | ||||
|   m_Pivot: {x: 0.5, y: 0.5} | ||||
| --- !u!114 &1571276506 | ||||
| @@ -1592,7 +1592,7 @@ MonoBehaviour: | ||||
|     m_HorizontalOverflow: 0 | ||||
|     m_VerticalOverflow: 0 | ||||
|     m_LineSpacing: 1 | ||||
|   m_Text: 'Progression:' | ||||
|   m_Text: 'Progression Max:' | ||||
| --- !u!222 &1571276507 | ||||
| CanvasRenderer: | ||||
|   m_ObjectHideFlags: 0 | ||||
|   | ||||
| @@ -16,9 +16,12 @@ public class LevelElement | ||||
| [System.Serializable] | ||||
| public class Level | ||||
| { | ||||
|     public static readonly int LAST_X = 15; | ||||
|     public string JsonName { get; set; } | ||||
|     public int TotalJumps { get; set; } | ||||
|     public int TotalAttempts { get; set; } | ||||
|     public int ProgressionPercent { get; set; } | ||||
|     public int ProgressionPercentMax { get; set; } | ||||
|  | ||||
|     public string name; | ||||
|     public string musicName; | ||||
| @@ -26,6 +29,20 @@ public class Level | ||||
|  | ||||
|     public List<LevelElement> elements; | ||||
|  | ||||
|     public float LastX | ||||
|     { | ||||
|         get | ||||
|         { | ||||
|             LevelElement lastElement = elements[^1]; | ||||
|             float lastX = LAST_X; | ||||
|             if (lastElement != null) | ||||
|             { | ||||
|                 lastX += lastElement.x; | ||||
|             } | ||||
|             return lastX; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static Level CreateFromJSON(string jsonString) | ||||
|     { | ||||
|         return JsonUtility.FromJson<Level>(jsonString); | ||||
|   | ||||
| @@ -1,10 +1,12 @@ | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
| using System.IO; | ||||
|  | ||||
| public class LevelLoader : MonoBehaviour | ||||
| { | ||||
|     public LevelsLoader levelsLoader; | ||||
|     public AudioSource audioSource; | ||||
|     public Text progressionText; | ||||
|  | ||||
|     private GameObject GetPrefab(string type) | ||||
|     { | ||||
| @@ -31,14 +33,7 @@ public class LevelLoader : MonoBehaviour | ||||
|  | ||||
|             instance.transform.localScale = new Vector3(newScaleX, newScaleY, originalScale.z); | ||||
|         } | ||||
|  | ||||
|         LevelElement lastElement = current.elements[^1]; | ||||
|         float lastX = 15; | ||||
|         if (lastElement != null) | ||||
|         { | ||||
|             lastX += lastElement.x; | ||||
|         } | ||||
|         Instantiate(GetPrefab("WinnerWall"), new Vector3(lastX, 0, 0), Quaternion.Euler(0, 0, 90)); | ||||
|         Instantiate(GetPrefab("WinnerWall"), new Vector3(current.LastX, 0, 0), Quaternion.Euler(0, 0, 90)); | ||||
|     } | ||||
|  | ||||
|     public void Start() | ||||
| @@ -52,6 +47,7 @@ public class LevelLoader : MonoBehaviour | ||||
|  | ||||
|     public void Update() | ||||
|     { | ||||
|  | ||||
|         Level current = levelsLoader.levelCurrent; | ||||
|         progressionText.text = current.ProgressionPercent + "%"; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -7,6 +7,7 @@ public class LevelStat | ||||
|  | ||||
|     public int totalJumps; | ||||
|     public int totalAttempts; | ||||
|     public int progressionPercent; | ||||
|  | ||||
|     public static LevelStat CreateFromJSON(string jsonString) | ||||
|     { | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| using UnityEngine; | ||||
| using System.Collections.Generic; | ||||
| using System.IO; | ||||
| using System; | ||||
|  | ||||
| public class LevelsLoader : MonoBehaviour | ||||
| { | ||||
| @@ -33,11 +34,14 @@ public class LevelsLoader : MonoBehaviour | ||||
|             level.JsonName = jsonTextFile.name; | ||||
|             level.TotalAttempts = 0; | ||||
|             level.TotalJumps = 0; | ||||
|             level.ProgressionPercent = 0; | ||||
|             level.ProgressionPercentMax = 0; | ||||
|  | ||||
|             if (levelStatsMap.TryGetValue(level.JsonName, out LevelStat levelStat)) | ||||
|             { | ||||
|                 level.TotalJumps = levelStat.totalJumps; | ||||
|                 level.TotalAttempts = levelStat.totalAttempts; | ||||
|                 level.TotalJumps = levelStat.totalJumps; | ||||
|                 level.ProgressionPercentMax = levelStat.progressionPercent; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
| @@ -59,7 +63,8 @@ public class LevelsLoader : MonoBehaviour | ||||
|         { | ||||
|             JsonName = levelCurrent.JsonName, | ||||
|             totalJumps = levelCurrent.TotalJumps, | ||||
|             totalAttempts = levelCurrent.TotalAttempts | ||||
|             totalAttempts = levelCurrent.TotalAttempts, | ||||
|             progressionPercent = levelCurrent.ProgressionPercentMax, | ||||
|         }; | ||||
|         string levelStatJson = JsonUtility.ToJson(levelStat, true) + "\n"; | ||||
|         File.WriteAllText(Path.Combine(Application.dataPath, "Resources", "LevelsStats", levelCurrent.JsonName + ".json"), levelStatJson); | ||||
| @@ -88,4 +93,22 @@ public class LevelsLoader : MonoBehaviour | ||||
|         levelCurrent.TotalAttempts += 1; | ||||
|         SaveLevelCurrent(); | ||||
|     } | ||||
|  | ||||
|     public int CalculateCurrentProgressionPercent(Vector3 playerPosition) | ||||
|     { | ||||
|         float lastX = levelCurrent.LastX; | ||||
|         GameObject winnerWallPrefab = Resources.Load<GameObject>("Prefabs/WinnerWall"); | ||||
|         float winnerWallWidth = winnerWallPrefab.GetComponent<Renderer>().bounds.size.x; | ||||
|         float marginError = 0.5f; | ||||
|         float totalDistance = lastX - (winnerWallWidth / 2) - marginError; | ||||
|  | ||||
|         float rawPercentage = (playerPosition.x / totalDistance) * 100; | ||||
|         int clampedPercentage = Mathf.Clamp(Mathf.RoundToInt(rawPercentage), 0, 100); | ||||
|  | ||||
|         levelCurrent.ProgressionPercent = clampedPercentage; | ||||
|         levelCurrent.ProgressionPercentMax = Math.Max(levelCurrent.ProgressionPercentMax, levelCurrent.ProgressionPercent); | ||||
|         SaveLevelCurrent(); | ||||
|  | ||||
|         return clampedPercentage; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -9,7 +9,7 @@ public class LevelProgression : MonoBehaviour | ||||
|  | ||||
|     private string GetText() | ||||
|     { | ||||
|         return "Progression: "; | ||||
|         return "Progression Max: " + levelsLoader.levelCurrent.ProgressionPercentMax + "%"; | ||||
|     } | ||||
|  | ||||
|     public void Start() | ||||
|   | ||||
							
								
								
									
										33
									
								
								Assets/Scripts/PauseMenu.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Assets/Scripts/PauseMenu.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| using UnityEngine; | ||||
| using UnityEngine.SceneManagement; | ||||
|  | ||||
| public class PauseMenu : MonoBehaviour | ||||
| { | ||||
|     public GameObject pauseMenu; | ||||
|     public GameObject pauseButton; | ||||
|     public LevelLoader levelLoader; | ||||
|  | ||||
|     public void Pause() | ||||
|     { | ||||
|         Time.timeScale = 0; | ||||
|         levelLoader.audioSource.Pause(); | ||||
|  | ||||
|         pauseMenu.SetActive(true); | ||||
|         pauseButton.SetActive(false); | ||||
|     } | ||||
|  | ||||
|     public void Home() | ||||
|     { | ||||
|         Time.timeScale = 1; | ||||
|         SceneManager.LoadScene("HomeScene"); | ||||
|     } | ||||
|  | ||||
|     public void Resume() | ||||
|     { | ||||
|         Time.timeScale = 1; | ||||
|         levelLoader.audioSource.Play(); | ||||
|  | ||||
|         pauseMenu.SetActive(false); | ||||
|         pauseButton.SetActive(true); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										2
									
								
								Assets/Scripts/PauseMenu.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								Assets/Scripts/PauseMenu.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: fe007f250f006dae5b98ae5c5a87113b | ||||
| @@ -42,6 +42,7 @@ public class Player : MonoBehaviour | ||||
|     public void Update() | ||||
|     { | ||||
|         CurrentGameMode.Update(this); | ||||
|         LevelsLoader.CalculateCurrentProgressionPercent(transform.position); | ||||
|     } | ||||
|  | ||||
|     public void OnCollisionEnter2D(Collision2D collision) | ||||
|   | ||||
| @@ -8,8 +8,6 @@ TagManager: | ||||
|   - Win | ||||
|   - LevelsLoader | ||||
|   - LevelLoader | ||||
|   - CubePortal | ||||
|   - ShipPortal | ||||
|   layers: | ||||
|   - Default | ||||
|   - TransparentFX | ||||
|   | ||||
		Reference in New Issue
	
	Block a user