protected override void Update() { base.Update(); // Prevent the camera from moving forward if the player is behind minScreenX to prevent loss God.Stopped = God.CameraCoords(this.transform.position).x < minScreenX; }
protected virtual void Update() { // Use escape to pause if (Input.GetKeyDown(KeyCode.Escape)) { this.Pause(); } if (Menu.InPlay) { // Remove the speedMultiplier when the timer expires if (this.speedCounter > 0) { this.speedCounter -= Time.deltaTime; if (this.speedCounter <= 0) { this.speedMultiplier = 1.0f; this.speedCounter = 0; } } // Use space bar to jump if (Input.GetKeyDown(KeyCode.Space)) { this.JumpEnter(); } if (Input.GetKeyUp(KeyCode.Space)) { this.JumpExit(); } // The player loses if they fall outside of the camera if (!God.InCamera(this.transform.position)) { LossMenu.HandleLoss(this.score); Scoreboard.AddScore(new HighScore { Score = this.score, Distance = (int)this.transform.position.x, Date = DateTime.Now, Difficulty = Settings.Difficulty }); } // Tell the camera to skip ahead if the player surpasses maxScreenX if (God.CameraCoords(this.transform.position).x > maxScreenX) { God.Skip(1 / (1 - God.CameraCoords(this.transform.position).x)); } // Apply upward jetpack force if the player is currently jetpacking if (this.isJetpacking) { this.GetComponent <Rigidbody2D>().AddForce(new Vector2(0, jumpJetpackForce * Time.deltaTime * Settings.JumpPower)); } // Move forward with the current speed multiplier and update the HUD distance int lastX = (int)this.transform.position.x; this.transform.Translate(new Vector3(God.ScrollSpeed * this.SpeedMultiplier * Time.deltaTime, 0, 0)); if ((int)this.transform.position.x > lastX) { HUD.UpdateDistance((int)this.transform.position.x); } } // Set the player to static when not in play and dynamic when in play if (this.GetComponent <Rigidbody2D>().bodyType == RigidbodyType2D.Static && Menu.InPlay) { this.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic; // Upon exiting pause, restore the previous velocity this.GetComponent <Rigidbody2D>().velocity = this.lastVelocity; } else if (this.GetComponent <Rigidbody2D>().bodyType == RigidbodyType2D.Dynamic && !Menu.InPlay) { this.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Static; } }