void Awake() { // Time button cameraGrey = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraGrey>(); // shader stoppableObjectManager = GameObject.FindGameObjectWithTag("StoppableObjectManager").GetComponent <StoppableObjectManager>(); // manager timeGUI = Resources.FindObjectsOfTypeAll <TimeGUI>()[0] as TimeGUI; // Animation spriteRenderer = GetComponent <SpriteRenderer>(); // Sprite flip X rb = GetComponent <Rigidbody2D>(); // physics animator = GetComponent <Animator>(); // Animator // Item collection bag = GetComponent <Bag>(); // Bonus room movableCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <MovableCamera>(); countDown = Resources.FindObjectsOfTypeAll <CountDown>()[0] as CountDown; // Falling gravity = Physics.gravity.y; // fall force boxCollider2D = GetComponent <BoxCollider2D>(); // raycast width sceneHeight = GameObject.FindGameObjectWithTag("OuterBorder").GetComponent <OuterBorder>().BorderHeight(); // Sound play // soundManager = GameObject.FindGameObjectWithTag("SoundManager").GetComponent<SoundManager>(); soundManager = GetComponent <SoundManager>(); }
// --------------------------------------------------------------------- end Level select scene --------------------------------------------------------------------- // --------------------------------------------------------------------- game scene --------------------------------------------------------------------- public void Checkpoint(int checkpointId, Bag bag) { // Load data CharacterData characterData = LoadCharacter(); // Get checkpoint info // stage string stage = SceneManager.GetActiveScene().name; // time TimeGUI timeGUI = GameObject.FindObjectOfType(typeof(TimeGUI)) as TimeGUI; float time = timeGUI.GetTime(); // key, jewellery List <ItemColor> keys = bag.GetAllKeys(); Dictionary <ItemColor, int> jewellarys = bag.GetAllJewellarys(); // Store to character data CheckPoint checkpoint = new CheckPoint(); checkpoint.stage = stage; checkpoint.checkPointId = checkpointId; checkpoint.time = time; checkpoint.keys = keys; checkpoint.jewellarys = jewellarys; characterData.checkpoint = checkpoint; // Save SaveCharacter(characterData); }
private int finalScore; // time score + jewellery score public void UpdateGUI() { // Time TimeGUI timeGUI = Resources.FindObjectsOfTypeAll <TimeGUI>()[0] as TimeGUI; double time = System.Math.Round(timeGUI.GetTime(), 2); int idealTime = timeGUI.GetIdealTime(); timeText.text = time + "s"; int timeScore = idealTime * 1000; // 1st time category timeScore -= (int)((time - idealTime) * 1000); // time: 0s, 60s, 90s, 120s // score: 120000, 60000, 30000, 0 // Jewellery Bag bag = Resources.FindObjectsOfTypeAll <Bag>()[0] as Bag; Dictionary <ItemColor, int> jewellerys = bag.GetAllJewellarys(); ItemColor[] colors = ItemColor.GetValues(typeof(ItemColor)) as ItemColor[]; DisableJewelleryIcon(jewellerys); int jewelleryScore = GetJewelleryScore(jewellerys); // 2nd time category // score: 5000, 10000, 15000 // Final score finalScore = timeScore + jewelleryScore; // Update data GetComponent <BinaryCharacterSaver>().StageClear(finalScore); // int scoreAppendDigit = GetScoreAppendDigit(finalScore, 6); // 000000 // string scoreAppend = GetScoreAppendString(scoreAppendDigit); // scoreText.text = scoreAppend + finalScore; // buttons.SetActive(true); }
public void LoadCheckpoint() { CharacterData characterData = LoadCharacter(); // Get checkpoint info CheckPoint checkpoint = characterData.checkpoint; // have checkpoint if (checkpoint.stage != null) { float time = checkpoint.time; // Set character data // time TimeGUI timeGUI = GameObject.FindObjectOfType(typeof(TimeGUI)) as TimeGUI; timeGUI.SetTime(time); // key, jewellery List <ItemColor> keys = checkpoint.keys; Dictionary <ItemColor, int> jewellarys = checkpoint.jewellarys; Bag bag = GameObject.FindGameObjectWithTag("Player").GetComponent <Bag>(); bag.AddList(keys); bag.AddList(jewellarys); // checkpoint and position Transform player = GameObject.FindGameObjectWithTag("Player").transform; int checkpointId = checkpoint.checkPointId; Vector2 startPosition = Checkpoints.GetChild(checkpointId).position; for (int index = 0; index <= checkpointId; index++) // remove previous checkpoint first { // Destroy(Checkpoints.GetChild(index).gameObject); Checkpoints.GetChild(index).gameObject.gameObject.SetActive(false); } // Also remove collected item Key[] sceneKeys = GameObject.FindObjectsOfType(typeof(Key)) as Key[]; foreach (Key sceneKey in sceneKeys) // Loop by scene key { // destroy scene key gameObject if collected before if (keys.Contains(sceneKey.ItemColor)) { Destroy(sceneKey.gameObject); } } Jewellary[] sceneJewellarys = GameObject.FindObjectsOfType(typeof(Jewellary)) as Jewellary[]; Goal[] goals = GameObject.FindObjectsOfType(typeof(Goal)) as Goal[]; foreach (Jewellary sceneJewellary in sceneJewellarys) // Loop by scene key { // destroy scene key gameObject if collected before // And disable the red door ItemColor color = sceneJewellary.ItemColor; if (jewellarys.ContainsKey(sceneJewellary.ItemColor)) { Destroy(sceneJewellary.gameObject); if (color == ItemColor.red) // Red door can't open again { foreach (Goal goal in goals) { if (goal.redKey) { goal.DisableDoor(false); break; // break search red door } } } } } // Load player to checkpoint position player.position = startPosition; // Transition for player ready // StartCoroutine(LoadCheckpointTransition()); } }