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