You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
328 lines
10 KiB
328 lines
10 KiB
using System.Collections; |
|
using Ai; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using UnityEngine.EventSystems; |
|
using UnityEngine.SceneManagement; |
|
using TMPro; |
|
|
|
public class GameBoard : BaseBoard { |
|
|
|
public static GameBoard Instance { get; private set; } |
|
|
|
MainCharacter m_mainCharacter = null; |
|
GameStick m_gameStick = null; |
|
SimpleProgressBar m_mainCharHealthBar = null; |
|
|
|
Vector3 m_stickDefaultPos = new Vector3(); |
|
Vector3 m_mouseDownPos = new Vector3(); |
|
|
|
int m_mainCharCurrentLvl = 0; |
|
|
|
bool m_wasMouseDown = false; |
|
[SerializeField] bool m_needStartAddAbDialog = false; |
|
[SerializeField] private bool m_needStartAngelDialog; |
|
[SerializeField] private bool m_needStartDevilDialog; |
|
[SerializeField] private bool m_needStartFortuneDialog; |
|
[SerializeField] private bool m_needLaserSound = false; |
|
|
|
[SerializeField] GameObject m_topHudObj; |
|
[SerializeField] GameObject m_angelObj; |
|
[SerializeField] GameObject m_devilObj; |
|
[SerializeField] GameObject m_slotObj; |
|
|
|
Button m_buttonPause; |
|
AudioSource m_runSoundSource; |
|
|
|
TextMeshProUGUI m_lvlUpLabel; |
|
|
|
int m_hudBasePosY = -100000000; |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public MainCharacter MainCharacter |
|
{ |
|
get { return m_mainCharacter; } |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void Awake() |
|
{ |
|
Instance = this; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void Start () |
|
{ |
|
SoundsManager.Instance.StopAllSounds(); |
|
|
|
InitGameStick(); |
|
InitMainCharacter(); |
|
InitButtons(); |
|
InitLaserSound(); |
|
|
|
GlobalsVar.gBoard = this; |
|
GlobalsVar.gUser.SetUserMaxLevel(SceneManager.GetActiveScene().name); |
|
GlobalsVar.gCurrentRoomInRun++; |
|
|
|
MusicManager.Instance.FadeDownMusicVolume(); |
|
|
|
m_lvlUpLabel = GameObject.Find("LevelUpText").GetComponent<TextMeshProUGUI>(); |
|
m_lvlUpLabel.text = "LVL " + GlobalsVar.gPlayerLvlUpInRun.ToString(); |
|
|
|
ApplaySafeAreaHudShift(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void InitLaserSound() |
|
{ |
|
if (m_needLaserSound) |
|
{ |
|
string soundName = "laser"; |
|
int stageId = CommonFunctions.GetStageId(); |
|
if (stageId == 3) |
|
soundName = "shark"; |
|
|
|
SoundsManager.Instance.PlaySound(soundName, 0f, true); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void InitButtons() |
|
{ |
|
GameObject pauseBtn = GameObject.Find("PauseButton"); |
|
if (pauseBtn) |
|
{ |
|
m_buttonPause = pauseBtn.GetComponent<Button>(); |
|
m_buttonPause.onClick.AddListener(ButtonPress); |
|
} |
|
} |
|
|
|
//------------------------------------------------------------------ |
|
override public void ApplaySafeAreaHudShift() |
|
{ |
|
if (m_topHudObj) |
|
{ |
|
Vector3 localPos = m_topHudObj.transform.localPosition; |
|
m_hudBasePosY = (int)localPos.y; |
|
|
|
m_topHudObj.transform.localPosition = new Vector3(localPos.x, m_hudBasePosY - GlobalsVar.gSafeAreaHudShift, localPos.z); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void ButtonPress() |
|
{ |
|
SoundsManager.Instance.PlaySound("button_click"); |
|
|
|
GameObject currentClickedObj = EventSystem.current.currentSelectedGameObject; |
|
if (currentClickedObj == m_buttonPause.gameObject) |
|
{ |
|
StopRunSound(); |
|
GameObject pauseDlg = StartDialog("InGamePauseDialog"); |
|
pauseDlg.GetComponent<InGamePauseDialog>().Init(); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void InitGameStick() |
|
{ |
|
m_gameStick = GameObject.Find("stick").GetComponent<GameStick>(); |
|
m_stickDefaultPos = m_gameStick.transform.position; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public void InitMainCharacter(MainCharacter character = null) |
|
{ |
|
//m_mainCharHealthBar = GameObject.Find("health_bar").GetComponent<SimpleProgressBar>(); |
|
//m_mainCharHealthBar.Init(); |
|
|
|
m_mainCharacter = character ? character : GameObject.Find("MainCharacter").GetComponent<MainCharacter>(); |
|
m_mainCharacter.Init(); |
|
m_mainCharacter.GameBoard = this; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public override void Update () |
|
{ |
|
base.Update(); |
|
|
|
UpdateNeedStartAddAbDialog(); |
|
UpdateNeedStartAngelDialog(); |
|
UpdateNeedStartDevilDialog(); |
|
UpdateNeedStartFortuneDialog(); |
|
UpdateGameStick(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void UpdateNeedStartAddAbDialog() |
|
{ |
|
if (!m_needStartAddAbDialog) |
|
return; |
|
|
|
GlobalsVar.gPlayerLvlUpInRun++; |
|
m_lvlUpLabel.text = "LVL " + GlobalsVar.gPlayerLvlUpInRun.ToString(); |
|
|
|
m_needStartAddAbDialog = false; |
|
GameObject addAbDilogObj = StartDialog("AddInGameAbDialog"); |
|
addAbDilogObj.GetComponent<AddInGameAbilityDialog>().Init(); |
|
|
|
m_mainCharacter.SetState(CharacterState.DEFAULT); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void UpdateNeedStartAngelDialog() |
|
{ |
|
if (!m_needStartAngelDialog) |
|
return; |
|
|
|
if (!m_angelObj) |
|
{ |
|
CommonFunctions.myassert(false); |
|
return; |
|
} |
|
|
|
float dist = (m_angelObj.transform.position - m_mainCharacter.transform.position).magnitude; |
|
if (dist > 2f) |
|
return; |
|
|
|
StopRunSound(); |
|
m_needStartAngelDialog = false; |
|
StartDialog("AngelDialog"); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void UpdateNeedStartDevilDialog() |
|
{ |
|
if (!m_needStartDevilDialog) |
|
return; |
|
|
|
if (!m_devilObj) |
|
{ |
|
CommonFunctions.myassert(false); |
|
return; |
|
} |
|
|
|
float dist = (m_devilObj.transform.position - m_mainCharacter.transform.position).magnitude; |
|
if (dist > 2f) |
|
return; |
|
|
|
StopRunSound(); |
|
m_needStartDevilDialog = false; |
|
StartDialog("DevilDialog"); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void UpdateNeedStartFortuneDialog() |
|
{ |
|
if (!m_needStartFortuneDialog) |
|
return; |
|
|
|
if (!m_slotObj) |
|
{ |
|
CommonFunctions.myassert(false); |
|
return; |
|
} |
|
|
|
float dist = (m_slotObj.transform.position - m_mainCharacter.transform.position).magnitude; |
|
if (dist > 2.3f) |
|
return; |
|
|
|
StopRunSound(); |
|
m_needStartFortuneDialog = false; |
|
StartDialog("SlotMachineDialog"); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void UpdateGameStick() |
|
{ |
|
if (DialogsCount > 0) |
|
return; |
|
|
|
if (m_mainCharacter.IsDead) |
|
return; |
|
|
|
if (Input.GetMouseButtonDown(0) && !m_wasMouseDown) |
|
{ |
|
m_wasMouseDown = true; |
|
m_mouseDownPos = Input.mousePosition; |
|
m_mouseDownPos.z = 0; |
|
|
|
Vector3 neededStickPos = m_mouseDownPos; |
|
m_gameStick.transform.position = neededStickPos; |
|
|
|
m_gameStick.SetDefault(false); |
|
m_mainCharacter.SetState(CharacterState.MOVE_STATE); |
|
|
|
if (m_runSoundSource == null) |
|
m_runSoundSource = SoundsManager.Instance.PlaySound("run", 0, true); |
|
} |
|
else if (Input.GetMouseButton(0) && m_wasMouseDown) |
|
{ |
|
Vector3 dirVec = Input.mousePosition - m_mouseDownPos; |
|
float delta = System.Math.Abs(dirVec.magnitude); |
|
m_gameStick.SetArrowScale(delta); |
|
m_gameStick.UpdateArrow(dirVec.normalized); |
|
|
|
var needMult = delta / 100f > 1f ? 1f : delta / 100f; |
|
UpdateGameCharacter(dirVec.normalized * needMult); |
|
} |
|
else if (Input.GetMouseButtonUp(0) && m_wasMouseDown) |
|
{ |
|
m_wasMouseDown = false; |
|
m_mouseDownPos = new Vector3(); |
|
|
|
m_gameStick.transform.position = m_stickDefaultPos; |
|
m_gameStick.SetDefault(true); |
|
|
|
m_mainCharacter.SetState(CharacterState.DEFAULT); |
|
|
|
StopRunSound(); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public void StopRunSound() |
|
{ |
|
if (m_runSoundSource) |
|
{ |
|
m_runSoundSource.Stop(); |
|
m_runSoundSource = null; |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void UpdateGameCharacter(Vector3 dir) |
|
{ |
|
if (!m_mainCharacter) |
|
return; |
|
|
|
dir.z = dir.y; |
|
dir.y = 0; |
|
m_mainCharacter.SetDir(dir, m_gameStick.GetArrowYScale()); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public void SetStickDefault() |
|
{ |
|
m_gameStick.transform.position = m_stickDefaultPos; |
|
m_gameStick.SetDefault(true); |
|
} |
|
|
|
public void LevelUp() |
|
{ |
|
StartCoroutine(WaitLevelFinish()); |
|
} |
|
|
|
private IEnumerator WaitLevelFinish() |
|
{ |
|
yield return new WaitUntil(() => AiController.Instance.TargetingEnemies.Count <= 0); |
|
|
|
GlobalsVar.gPlayerLvlUpInRun++; |
|
m_lvlUpLabel.text = "LVL " + GlobalsVar.gPlayerLvlUpInRun.ToString(); |
|
|
|
GameObject addAbDilogObj = StartDialog("AddInGameAbDialog"); |
|
addAbDilogObj.GetComponent<AddInGameAbilityDialog>().Init(); |
|
|
|
m_mainCharacter.SetState(CharacterState.DEFAULT); |
|
} |
|
}
|
|
|