// Add cube public void AddCube(TimeCube cube) { // Create a clone GameObject clone = (GameObject)Instantiate(this.Prefab); clone.name = "playerClone" + this.Cubes.Count; cube.Clone = clone.GetComponent <Clone>(); // A cube should always remember its index cube.Index = this.Cubes.Count; // Add cube to list this.Cubes.Add(cube); }
// Called once per physics step void FixedUpdate() { // If exists, get a rewinding cube TimeCube rewindingCube = this.TCM.RewindingCube; // Check if rewinding (or will rewind) if (rewindingCube == null) { // If not, increment world time as usual this.WorldTime++; // If we've never seen this moment before, update furthest time if (this.WorldTime == this.FurthestTime + 1) { this.FurthestTime++; } // Debug: Show this step's WorldTime // Debug.Log("Just finished Globals.FixedUpdate! wT = " + this.WorldTime); } else { // Spaghetti code: Necessary because it affects WorldTime update, // which must happen first. if (rewindingCube.WillRewind) { rewindingCube.startRewinding(); } // If rewinding, let player adjust position this.Player.FixedControlRewind(); // Now that rewind has occurred, update world time this.WorldTime = rewindingCube.ActiveInterval.Start + Mathf.RoundToInt(rewindingCube.RewindPosition); } // Exit if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } }
// 'Standard' controls, called by Update public void ControlStandard() { // If grounded and pressing jump, then launch if (isGrounded && Input.GetButtonDown("Jump") && !isLaunching && !isHanging) { animator.SetTrigger("Jump_Launch"); isLaunching = true; } // If hanging and pressing jump, then climb if (isHanging && Input.GetButtonDown("Jump") && !isClimbing) { animator.SetTrigger("Climb"); isClimbing = true; } // If grounded, pressing fire and near cube, activate or enter cube if (isGrounded && Input.GetButtonDown("Fire1")) { // TODO: We need to streamline these linecast points. // We need to make sure we're not hitting terrain... // We should check on a single layer only, if possible. // Get linecast points float x1 = transform.position.x + (isFacingRight ? 1 : -1) * 1.2f; float y1 = transform.position.y + box.center.y - 0.4f * box.size.y; float y2 = transform.position.y + box.center.y + 0.4f * box.size.y; Vector2 start = new Vector2(x1, y1); Vector2 end = new Vector2(x1, y2); //Debug.Log("start = " + start + ", end = " + end); Debug.DrawLine(start, end, Color.green); // Perform linecast int result = Physics2D.LinecastNonAlloc(start, end, hits); // if(result > 0) { Debug.Log(string.Format("result = {0}, other = {1}", result, hits[0].collider.gameObject.tag)); } if (result > 0 && hits[0].collider.gameObject.tag == "TimeCube") { // Remember nearby cube cube = hits[0].collider.gameObject.GetComponent <TimeCube>(); // If cube is off, activate if (!cube.IsRecording && !cube.IsRewinding) { animator.SetTrigger("PushButton"); controls = "Activating"; } // If cube is recording, enter else if (cube.IsRecording) { beginEnterCube(); } } } // Bug: Check isLaunching AnimatorStateInfo state = animator.GetCurrentAnimatorStateInfo(0); if (isLaunching && !state.IsName("Jump_Launch")) { isLaunching = false; } }
// Called once per physics step void FixedUpdate() { // Get world time int t = this.globals.WorldTime; // Check if in past bool inPast = t < this.globals.FurthestTime ? true : false; // Check if at least one cube is recording bool isRecording = this.IsRecording; // Get minimum recording start time int minStart = this.MinStart; // Loop over non-time-traveler histories for (int i = 0; i < this.Histories.Count; i++) { // Get element History history = this.Histories[i]; // For non-time-travelers, the rules are simpler... if (!history.IsTimeTraveler) { // CASE 1 OF 2: NOT A TIME TRAVELER // If (in present and recording) or (in past and altered), store if (!inPast && isRecording) { history.StoreBones(t - minStart); } // If (in past and unaltered), restore if (inPast) { history.RestoreBones(t - minStart); } } } // Loop over time traveler histories for (int i = 0; i < this.Cubes.Count; i++) { // Get element TimeCube cube = this.Cubes[i]; // Get clone history History history = cube.Clone.History; // If cube is recording, store if (cube.IsRecording) { history.StoreBones(t - minStart); } // If cube is rewinding or replaying, restore if (cube.IsRewinding || cube.IsReplaying) { history.RestoreBones(t - minStart); } } // If all cubes are off, delete all intervals if (this.MaxEnd < t) { // Loop through cubes for (int i = 0; i < this.Cubes.Count; i++) { // Get element TimeCube cube = this.Cubes[i]; // Delete intervals if (cube.Intervals.Count > 0) { cube.Intervals.Clear(); // Debug: History clear message Debug.Log(cube.name + " history has been cleared!"); } } } }