Add speed scaling and slide groundwork
This commit is contained in:
@@ -13,6 +13,11 @@ public class GameManager : MonoBehaviour {
|
||||
|
||||
private int score = 0; // 게임 점수
|
||||
|
||||
// 게임의 스피드를 올리는 변수
|
||||
public float gameSpeed = 1f;
|
||||
public float speedIncreaseRate = 0.05f;
|
||||
public float maxGameSpeed = 2f;
|
||||
|
||||
// 게임 시작과 동시에 싱글톤을 구성
|
||||
void Awake() {
|
||||
// 싱글톤 변수 instance가 비어있는가?
|
||||
@@ -38,6 +43,14 @@ public class GameManager : MonoBehaviour {
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
|
||||
if (!isGameover)
|
||||
{
|
||||
// 게임 진행시 게임 속도는 시간에 따라 증가
|
||||
gameSpeed += speedIncreaseRate * Time.deltaTime;
|
||||
// 게임 최대 속도는 max를 넘어서지 못하게
|
||||
gameSpeed = Mathf.Min(gameSpeed, maxGameSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
// 점수를 증가시키는 메서드
|
||||
|
||||
@@ -9,16 +9,29 @@ public class PlayerController : MonoBehaviour {
|
||||
private bool isGrounded = false; // 바닥에 닿았는지 나타냄
|
||||
private bool isDead = false; // 사망 상태
|
||||
|
||||
private bool isSliding = false; // 슬라이딩 상태
|
||||
|
||||
private Rigidbody2D playerRigidbody; // 사용할 리지드바디 컴포넌트
|
||||
private Animator animator; // 사용할 애니메이터 컴포넌트
|
||||
private AudioSource playerAudio; // 사용할 오디오 소스 컴포넌트
|
||||
|
||||
private CapsuleCollider2D playerCollider; // 플레이어의 콜라이더 충돌 범위
|
||||
private Vector2 originalColliderSize; // 기본 자세일 때 콜라이더 크기
|
||||
private Vector2 originalColliderOffset; // 기본 자세일 때 콜라이더 중심 위치
|
||||
public Vector2 slidingColliderSize; // 슬라이딩 자세일 때 콜라이더 크기
|
||||
public Vector2 slidingColliderOffset; // 슬라이딩 자세일 때 콜라이더 중심 위치
|
||||
|
||||
private void Start() {
|
||||
// 게임 오브젝트로부터 사용할 컴포넌트들을 가져와 변수에 할당
|
||||
playerRigidbody = GetComponent<Rigidbody2D>();
|
||||
animator = GetComponent<Animator>();
|
||||
playerAudio = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// 게임 콜라이더를 가져와서 현 상태를 저장
|
||||
playerCollider = GetComponent<CapsuleCollider2D>();
|
||||
originalColliderSize = playerCollider.size;
|
||||
originalColliderOffset = playerCollider.offset;
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
if(isDead)
|
||||
@@ -46,6 +59,16 @@ public class PlayerController : MonoBehaviour {
|
||||
}
|
||||
|
||||
animator.SetBool("Grounded", isGrounded);
|
||||
|
||||
// 마우스 오른쪽 버튼을 누르고 땅에 있는 상태이며 슬라이딩이 아닌 상태면 슬라이딩 작동
|
||||
if (Input.GetMouseButtonDown(1) && isGrounded && !isSliding)
|
||||
{
|
||||
StartSlide();
|
||||
}
|
||||
else if (Input.GetMouseButtonUp(1) && isSliding)
|
||||
{
|
||||
EndSlide();
|
||||
}
|
||||
}
|
||||
|
||||
private void Die() {
|
||||
@@ -83,4 +106,22 @@ public class PlayerController : MonoBehaviour {
|
||||
// 바닥에서 벗어났음을 감지하는 처리
|
||||
isGrounded = false;
|
||||
}
|
||||
|
||||
private void StartSlide()
|
||||
{
|
||||
isSliding = true;
|
||||
animator.SetBool("Sliding", true);
|
||||
|
||||
playerCollider.size = slidingColliderSize;
|
||||
playerCollider.offset = slidingColliderOffset;
|
||||
}
|
||||
|
||||
private void EndSlide()
|
||||
{
|
||||
isSliding = false;
|
||||
animator.SetBool("Sliding", false);
|
||||
|
||||
playerCollider.size = originalColliderSize;
|
||||
playerCollider.offset = originalColliderOffset;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ public class ScrollingObject : MonoBehaviour {
|
||||
// 게임 오브젝트를 왼쪽으로 일정 속도로 평행 이동하는 처리
|
||||
if(!GameManager.instance.isGameover)
|
||||
{
|
||||
transform.Translate(Vector3.left * speed * Time.deltaTime);
|
||||
transform.Translate(Vector3.left * speed * GameManager.instance.gameSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user