public static Vector3[] carPositions; // proper car positions so that the car is one the plane void Start() { //Screen.SetResolution(1920, 1080, true, 60); // prevents reading on game launch if (finishedMap) { WinDataClassHelper.LoadFromExternal(ref winData); handlePlayerUpdate(); finishedMap = false; } Time.timeScale = 1f; cameraLocations = new Vector3[] { new Vector3(22.42f, 3.46f, 17.65f), new Vector3(-1.91f, 6.15f, 41.69f), new Vector3(36.81f, 4.09f, 29.95f) }; cameraRotations = new Quaternion[] { Quaternion.Euler(0f, 0f, -3.446f), Quaternion.Euler(2.148f, 141.484f, 2.696f), Quaternion.Euler(-0.667f, -81.023f, 1.109f) }; // load cars positions carPositions = new Vector3[] { new Vector3(-516, -592.95f, 96.9325f), new Vector3(-516, -592.94f, 96.9325f), new Vector3(-516, -589.8253f, 96.9325f) }; //saveToJSON(player); player = new PlayerClass("", 0, 0, 0, 100000, 0); // change back to 1500 lol //savePlayerToExternal(player); // debug // loads the player's data upon startup LoadPlayerFromExternal(ref player); print(player.ownedCars); }
// load map complete file from persistent storage /* public void LoadFromExternal(ref WinDataClass wd){ * string dest = Application.persistentDataPath + "/winData.dat"; * FileStream file; * * if(File.Exists(dest)){ * file = File.OpenRead(dest); * }else{ * // create a default player json if it doesn't exist * //file = File.Create(dest); * //player = new PlayerClass("NewPlayer", 0, 0, 1000, 1500); * //player.name = "NewPlayer"; * //player.level = 0; * //player.currentExperience = 0; * //player.experienceForNextLevel = 1000; * //player.money = 1500; * print("error loading victory file"); * //print("here"); * //saveToJSON(player); * return; // something here * } * BinaryFormatter bf = new BinaryFormatter(); * * wd = (WinDataClass) bf.Deserialize(file); * //print(player.name); * //print(player.money); * //player = new PlayerClass("", 0,0,0,0); * * file.Close(); * * * //return JsonUtility.FromJson<PlayerClass>(json.text); * } */ public void handleWinData() { WinDataClassHelper.LoadFromExternal(ref winData); print("testtestestsetestset" + winData.expEarned); //decimal noteHitPercentage = (winData.notesHit/winData.mapTotalNotes)*100; // need to force a decimal value scoreText.GetComponent <Text>().text = winData.score + ""; maxComboText.GetComponent <Text>().text = winData.maxCombo + "x"; // returns the notes hit out of the total, and the percentage of notes hit. notesHitText.GetComponent <Text>().text = winData.notesHit + "/" + winData.mapTotalNotes + "(" + Math.Round((((decimal)winData.notesHit / (decimal)winData.mapTotalNotes) * 100), 2) + "%)"; moneyEarnedText.GetComponent <Text>().text = winData.moneyEarned + ""; expText.GetComponent <Text>().text = winData.expEarned + ""; // calculate grade gradeText.GetComponent <Text>().text = winData.grade; }
/* public void saveToExternal(WinDataClass wd){ * * string dest = Application.persistentDataPath + "/winData.dat"; * FileStream file; * //string jsonStr = JsonUtility.ToJson(player); * * if(File.Exists(dest)){ * file = File.OpenWrite(dest); * }else{ * file = File.Create(dest); * } * * BinaryFormatter bf = new BinaryFormatter(); * bf.Serialize(file, wd); * file.Close(); * } */ // handles updating the player data after a win // calculating the grade, etc. public void handleGameWin() { print("handleGameWin()"); //decimal moneyEarnedDecimal = (decimal)(Math.Sqrt(_playerScore) * (_playerNotesHit/totalNotes) + _playerMaxCombo)/100; //decimal expEarnedDecimal = (decimal)(Math.Sqrt(_playerScore)) * (_playerNotesHit/totalNotes) + (_playerMaxCombo == 1 ? 0 : _playerMaxCombo); WinDataClass winData = new WinDataClass(0, 0, 0, 0, 0, 0, ""); string calculatedGrade = ""; float notePercentage = (float)((decimal)_playerNotesHit / (decimal)totalNotes); if (notePercentage < 0.5) { calculatedGrade = "D"; } else if (notePercentage >= 0.5 && notePercentage < 0.6) { calculatedGrade = "C"; } else if (notePercentage >= 0.6 && notePercentage < 0.7) { calculatedGrade = "B"; } else if (notePercentage >= 0.7 && notePercentage < 0.8) { calculatedGrade = "A"; } else if (notePercentage >= 0.8 && notePercentage < 0.9) { calculatedGrade = "S"; } else if (notePercentage >= 0.9 && notePercentage < 1) { calculatedGrade = "SS"; } else { calculatedGrade = "ACE"; } winData.score = _playerScore; winData.maxCombo = _playerMaxCombo; winData.notesHit = _playerNotesHit; winData.mapTotalNotes = totalNotes; // can calculate the percentage using this and above winData.moneyEarned = (int)Math.Round((Math.Sqrt(_playerScore) * (float)((decimal)_playerNotesHit / (decimal)totalNotes) + _playerMaxCombo) / 100.0); // round money earned to closest integer winData.expEarned = (float)Math.Round(((Math.Sqrt(_playerScore)) * (float)((decimal)_playerNotesHit / (decimal)totalNotes) + (_playerMaxCombo == 1 ? 0 : _playerMaxCombo)), 2); // round exp to 2 digits winData.grade = calculatedGrade; print("big equation thing: " + Math.Round(((Math.Sqrt(_playerScore) * (float)((decimal)_playerNotesHit / (decimal)totalNotes) + _playerMaxCombo) / 100.0), 2)); /* * print("square root: " + (float)(Math.Sqrt(_playerScore))); * print("percentage: " + (float)((_playerNotesHit/totalNotes)*1.0)); * print("winData.moneyEarned: " + winData.moneyEarned); * print("winData.expEarned: " + winData.expEarned); */ //scoreboard beatMap.addWin(winData); beatMap.save(Application.persistentDataPath); WinDataClassHelper.saveToExternal(winData); _gameState = GameState.win; //SceneManager.LoadScene("VictoryRoyaleScene"); }