mirror of
				https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
				synced 2025-06-27 11:58:51 +02:00 
			
		
		
		
	feat: save level statistics
This commit is contained in:
		@@ -7,7 +7,6 @@ public class Level
 | 
			
		||||
    public string musicName;
 | 
			
		||||
    public int totalJumps;
 | 
			
		||||
    public int totalAttempts;
 | 
			
		||||
    public int killedCount;
 | 
			
		||||
    public int order;
 | 
			
		||||
 | 
			
		||||
    public static Level CreateFromJSON(string jsonString)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using UnityEngine;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
 | 
			
		||||
public class LevelsLoader : MonoBehaviour
 | 
			
		||||
{
 | 
			
		||||
@@ -24,6 +25,12 @@ public class LevelsLoader : MonoBehaviour
 | 
			
		||||
        levels.Sort((x, y) => x.order.CompareTo(y.order));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void SaveLevelCurrent()
 | 
			
		||||
    {
 | 
			
		||||
        string json = JsonUtility.ToJson(levelCurrent, true);
 | 
			
		||||
        File.WriteAllText(Path.Combine(Application.dataPath, "Resources", "Levels", levelCurrent.name + ".json"), json);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void NextLevel()
 | 
			
		||||
    {
 | 
			
		||||
        int currentIndex = levels.IndexOf(levelCurrent);
 | 
			
		||||
@@ -35,4 +42,16 @@ public class LevelsLoader : MonoBehaviour
 | 
			
		||||
        int currentIndex = levels.IndexOf(levelCurrent);
 | 
			
		||||
        levelCurrent = levels[(currentIndex - 1 + levels.Count) % levels.Count];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void IncreaseTotalJumps()
 | 
			
		||||
    {
 | 
			
		||||
        levelCurrent.totalJumps += 1;
 | 
			
		||||
        SaveLevelCurrent();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void IncreaseTotalAttempts()
 | 
			
		||||
    {
 | 
			
		||||
        levelCurrent.totalAttempts += 1;
 | 
			
		||||
        SaveLevelCurrent();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ public class Player : MonoBehaviour
 | 
			
		||||
    public void Start()
 | 
			
		||||
    {
 | 
			
		||||
        levelsLoader = GameObject.FindGameObjectWithTag("LevelsLoader").GetComponent<LevelsLoader>();
 | 
			
		||||
        levelsLoader.IncreaseTotalAttempts();
 | 
			
		||||
 | 
			
		||||
        audioSource.clip = Resources.Load<AudioClip>(Path.Combine("Musics", levelsLoader.levelCurrent.musicName));
 | 
			
		||||
        audioSource.Play();
 | 
			
		||||
@@ -62,6 +63,7 @@ public class Player : MonoBehaviour
 | 
			
		||||
    {
 | 
			
		||||
        rigidBody.linearVelocity = new Vector2(rigidBody.linearVelocity.x, 0);
 | 
			
		||||
        rigidBody.AddForce(Vector2.up * 26.6581f, ForceMode2D.Impulse);
 | 
			
		||||
        levelsLoader.IncreaseTotalJumps();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private bool IsJumping()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user