Skip to content

Commit

Permalink
Merge pull request #812 from GG-Studio-990001/801-ch2-접속-게임-슈퍼-아리오-브라…
Browse files Browse the repository at this point in the history
…더스-5

[CH2] 접속 게임 - 슈퍼 아리오 브라더스
  • Loading branch information
NearthYou authored Dec 9, 2024
2 parents a2893e2 + a6e2ea6 commit b43dc3d
Show file tree
Hide file tree
Showing 18 changed files with 647 additions and 115 deletions.
295 changes: 262 additions & 33 deletions Assets/Scenes/SuperArio.unity

Large diffs are not rendered by default.

66 changes: 46 additions & 20 deletions Assets/Scripts/Runtime/CH2/SuperArio/Ario.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Runtime.ETC;
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.InputSystem;
using System.Collections;

namespace Runtime.CH2.SuperArio
{
Expand All @@ -21,13 +20,17 @@ public class Ario : MonoBehaviour
private SpriteRenderer _spr;
private Sprite _initSprite;
private GameObject _pipe;
private int _life = 1;

public int _life;
private bool _isInvincible = false; // 무적 상태 여부
private float _invincibleDuration = 1.0f; // 무적 지속 시간
private float _blinkInterval = 0.1f; // 깜빡이는 간격
private Color _originalColor; // 원래 색상 저장

// 점프 버퍼 관련 변수
private float _jumpBufferTime = 0.2f; // 점프 입력 대기 시간
private float _jumpBufferTimeRemaining = 0f; // 남은 점프 대기 시간

private void Start()
{
_pipe = transform.GetChild(0).gameObject;
Expand All @@ -46,7 +49,16 @@ private void OnDestroy()

private void FixedUpdate()
{
if (!ArioManager.instance.isPlay) return;
if (!ArioManager.instance.IsPlay) return;

// 점프 대기 시간 동안 점프를 실행할지 여부 결정
if (_jumpBufferTimeRemaining > 0)
{
_jumpBufferTimeRemaining -= Time.fixedDeltaTime;
}

// 점프 처리
TryJump();

if (_isJump)
{
Expand Down Expand Up @@ -77,42 +89,46 @@ private void FixedUpdate()

public void OnMove(InputAction.CallbackContext context)
{
if (!ArioManager.instance.isPlay || ArioManager.instance.isPause)
if (!ArioManager.instance.IsPlay || ArioManager.instance.IsPause)
return;

Vector2 moveInput = context.ReadValue<Vector2>();

if (context.performed)
{
if (moveInput.y > 0 && transform.position.y <= _startPos.y && !_isJump) // 위쪽 (점프)
{
_isJump = true;
}
else if (moveInput.y < 0 && !_isJump) // 아래쪽
// 점프 중일 때 아래 방향키를 눌렀을 때 앉기 상태로 전환
if (moveInput.y < 0) // 아래쪽
{
if (_col.offset.y == 0)
_col.offset = new Vector2(0, -0.1f);
// 점프 중에도 앉기 상태로 변경
_animator.enabled = false;
_spr.sprite = sitSprite;
}
else if (moveInput.y > 0 && transform.position.y <= _startPos.y && !_isJump) // 위쪽 (점프)
{
_jumpBufferTimeRemaining = _jumpBufferTime; // 점프 입력을 버퍼에 저장
}
}
else if (context.canceled) // 아래 방향키를 뗐을 때
{
_animator.enabled = true;
_spr.sprite = _initSprite;

// 아래 방향키를 뗀 후, 앉기 상태를 원래 상태로 되돌림
if (_col.offset.y != 0)
_col.offset = new Vector2(0, 0);
}
}


private void InitData(bool isPlay)
{
transform.position = _startPos;
_isJump = false;
_isTop = false;
if (isPlay)
{
_life = 1;
_animator.enabled = true;
_pipe.SetActive(false);
}
Expand All @@ -122,7 +138,7 @@ private void InitData(bool isPlay)
_pipe.SetActive(true);
}
}

private IEnumerator UseItemCoroutine()
{
_invincibleDuration = 20f;
Expand All @@ -145,12 +161,12 @@ private IEnumerator UseItemCoroutine()
_spr.color = _originalColor;
_isInvincible = false;
}

public void UseInvincibleItem()
{
if (_isInvincible || !ArioManager.instance.GetItem || !ArioManager.instance.isPlay)
if (_isInvincible || !ArioManager.instance.HasItem || !ArioManager.instance.IsPlay)
return;

ArioManager.instance.ChangeItemSprite();
StartCoroutine(UseItemCoroutine());
}
Expand All @@ -174,20 +190,30 @@ private IEnumerator InvincibilityCoroutine()
_spr.enabled = true;
_isInvincible = false;
}

private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag(GlobalConst.ObstacleStr) && ArioManager.instance.isPlay && !_isInvincible)
if (other.CompareTag(GlobalConst.ObstacleStr) && ArioManager.instance.IsPlay && !_isInvincible)
{
_life--;
ArioManager.instance.ChangeHeartUI(_life);
StartCoroutine(InvincibilityCoroutine());
}
else if (other.CompareTag(GlobalConst.CoinStr) && ArioManager.instance.isPlay)
else if (other.CompareTag(GlobalConst.CoinStr) && ArioManager.instance.IsPlay)
{
ArioManager.instance.GetCoin();
other.gameObject.SetActive(false);
}
}

// 점프 버퍼를 처리하는 함수
private void TryJump()
{
if (_jumpBufferTimeRemaining > 0 && transform.position.y <= _startPos.y)
{
_isJump = true;
_jumpBufferTimeRemaining = 0f; // 점프 실행 후 버퍼를 리셋
}
}
}
}
}
114 changes: 76 additions & 38 deletions Assets/Scripts/Runtime/CH2/SuperArio/ArioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,53 @@ private void Awake()
}

instance = this;
GameSpeed = 1;
IsPause = true;
CurrentStage = "1-1";
}
#endregion

public Action<bool> OnPlay;
public Action<bool> OnEnterStore;

[SerializeField] private ArioUIController ui; // UI 컨트롤러
[SerializeField] private ObstacleManager obstacleManager; // 장애물 매니저
[SerializeField] private ObstacleSpawnDataSet dataSet; // ScriptableObject 데이터셋
[SerializeField] private CinemachineVirtualCamera stageCamera;
[SerializeField] private ArioUIController ui;
[SerializeField] private ObstacleManager obstacleManager;
[SerializeField] private ObstacleSpawnDataSet dataSet;
[SerializeField] private CinemachineVirtualCamera storeCamera;
[SerializeField] private Ario _ario;

public float GameSpeed { get; private set; }
public bool IsPlay { get; private set; }
public bool IsPause { get; private set; }
public bool HasItem { get; private set; }
public string CurrentStage { get; private set; }

public float gameSpeed = 1; // 현재 게임 속도
public bool isPlay;
public bool isPause = true;

private int _coinCnt;
public string _currentStage = "1-1"; // 초기 스테이지 설정
public bool GetItem { get; private set; }


private bool _isStore;

private void Start()
{
StartCoroutine(WaitStart());
}

public void RestartSuperArio()
{
if (IsPlay || _isStore)
return;

storeCamera.Priority = 10;
if (!isPlay)
StartGame();
StartGame();
}

public void EnterStore()
{
// 카메라 변경
storeCamera.Priority = 12;
OnEnterStore.Invoke(true);
// 입장 연출
ui.ActiveRestartText(false);
ChangeHeartUI(1);

_isStore = true;
OnEnterStore.Invoke(_isStore);
}

private IEnumerator WaitStart()
Expand All @@ -68,33 +75,64 @@ private IEnumerator WaitStart()
StartGame();
}

public void PauseKey()
{
IsPause = !IsPause;
}

private void StartGame()
{
InitData();
UpdateStage(CurrentStage);
IsPlay = true;
OnPlay.Invoke(IsPlay);
}

public bool LifeCheck()
{
if (_ario._life >= 3)
return false;
return true;
}

public void PlusLife()
{
ChangeHeartUI(_ario._life+1);
}

public bool ItemCheck()
{
if (HasItem)
return false;
return true;
}

private void InitData()
{
ui.ChangeCoinText("RAPLEY\n" + _coinCnt);
ui.ActiveRestartText(false);
ui.ChangeObstacleText(0);
ChangeHeartUI(1);
isPlay = true;
isPause = false;
GetItem = true;
OnPlay.Invoke(isPlay);
UpdateStage(_currentStage);
if(_ario._life <= 1)
ChangeHeartUI(1);
IsPause = false; // 시작 시 입력 방지
HasItem = true; // 테스트 용 아이템 지급
}

private void GameOver()
{
ui.ChangeObstacleText(0);
UpdateStage(_currentStage);
UpdateStage(CurrentStage);
ui.ActiveRestartText(true);
isPlay = false;
OnPlay.Invoke(isPlay);
IsPlay = false;
OnPlay.Invoke(IsPlay);
}

public void ChangeHeartUI(int life)
{
ui.ChangeHeartUI(life);
if (life == 0)
GameOver();
_ario._life = life;
}

public void GetCoin()
Expand All @@ -105,13 +143,13 @@ public void GetCoin()

public void ChangeItemSprite()
{
GetItem = false;
ui.ChangeItemSprite();
HasItem = false;
ui.UseItemSprite();
}

public void GetItemSprite()
public void GetItem()
{
GetItem = true;
HasItem = true;
ui.GetItemSprite();
}

Expand All @@ -128,13 +166,13 @@ public void UpdateStage(string stage)
{
return;
}

_currentStage = stage; // 현재 스테이지 갱신
gameSpeed = stageData.Speed + 4; // 게임 속도 갱신
ui.ChangeStageText($"WORLD\n{_currentStage}"); // UI에 스테이지 정보 갱신
CurrentStage = stage; // 현재 스테이지 갱신
GameSpeed = stageData.Speed + 4; // 게임 속도 갱신
ui.ChangeStageText($"WORLD\n{CurrentStage}"); // UI에 스테이지 정보 갱신

// 장애물 매니저에 스테이지 데이터 전달
obstacleManager.ChangeStage(_currentStage, dataSet);
obstacleManager.ChangeStage(CurrentStage, dataSet);
}

// 스테이지 변경 후 게임 재시작
Expand All @@ -148,16 +186,16 @@ public void NextStage(string nextStage)
else
{
UpdateStage(nextStage); // 일반 스테이지 업데이트
isPlay = true;
OnPlay.Invoke(isPlay);
IsPlay = true;
OnPlay.Invoke(IsPlay);
}
}

private void EnterRewardRoom()
{
// 보상 방으로 이동하는 로직
isPlay = false;
OnPlay.Invoke(isPlay); // 게임 상태 정지
IsPlay = false;
OnPlay.Invoke(IsPlay);
}

public string CalculateNextStage(string currentStage)
Expand Down
Loading

0 comments on commit b43dc3d

Please sign in to comment.