2023-03-16 16:43:31 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class jatekmanager : MonoBehaviour
|
|
|
|
|
{
|
2023-03-16 17:40:08 +01:00
|
|
|
//gamestate-s cuccok
|
2023-03-16 16:43:31 +01:00
|
|
|
public static jatekmanager Instance;
|
|
|
|
|
public GameState State;
|
|
|
|
|
public static event Action<GameState> OnGameStateChanged;
|
|
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
//gameobjectek,gombok,scriptek
|
2023-05-13 16:51:40 +02:00
|
|
|
public GameObject playGomb;
|
2023-03-16 17:40:08 +01:00
|
|
|
public GameObject garazs;
|
|
|
|
|
public GameObject homeGomb;
|
|
|
|
|
public GameObject settingsGomb;
|
|
|
|
|
public GameObject shopGomb;
|
|
|
|
|
|
2023-03-21 15:36:23 +01:00
|
|
|
public GameObject goLeftButton;
|
|
|
|
|
public GameObject jumpButton;
|
|
|
|
|
public GameObject goRightButton;
|
|
|
|
|
|
2023-05-22 14:37:24 +02:00
|
|
|
public GameObject boby;
|
|
|
|
|
|
2023-03-21 15:36:23 +01:00
|
|
|
public TMP_Text scoreText;
|
|
|
|
|
public TMP_Text timerText;
|
|
|
|
|
|
2023-03-20 19:56:27 +01:00
|
|
|
|
|
|
|
|
private DatabaseData db;
|
|
|
|
|
private UsernameHandler usernameHandler;
|
|
|
|
|
private Score score;
|
|
|
|
|
private Timer timer;
|
2023-05-02 13:46:38 +02:00
|
|
|
private CoinCounter cc;
|
2023-03-20 19:56:27 +01:00
|
|
|
|
2023-03-16 16:43:31 +01:00
|
|
|
private void Awake()
|
|
|
|
|
{
|
2023-03-20 19:56:27 +01:00
|
|
|
Application.targetFrameRate = 60;
|
2023-03-23 19:11:36 +01:00
|
|
|
|
2023-03-16 16:43:31 +01:00
|
|
|
Instance = this;
|
2023-03-20 19:56:27 +01:00
|
|
|
db = FindObjectOfType<DatabaseData>();
|
|
|
|
|
usernameHandler = FindObjectOfType<UsernameHandler>();
|
|
|
|
|
score = FindObjectOfType<Score>();
|
|
|
|
|
timer = FindObjectOfType<Timer>();
|
2023-05-02 13:46:38 +02:00
|
|
|
cc = FindObjectOfType<CoinCounter>();
|
2023-03-16 16:43:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
UpdateGameState(GameState.Home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateGameState(GameState newState)
|
|
|
|
|
{
|
|
|
|
|
State = newState;
|
|
|
|
|
|
|
|
|
|
switch (newState)
|
|
|
|
|
{
|
|
|
|
|
case GameState.Home:
|
|
|
|
|
HandleHome();
|
|
|
|
|
break;
|
|
|
|
|
case GameState.Settings:
|
|
|
|
|
HandleSettings();
|
|
|
|
|
break;
|
|
|
|
|
case GameState.Shop:
|
|
|
|
|
HandleShop();
|
|
|
|
|
break;
|
|
|
|
|
case GameState.Game:
|
|
|
|
|
HandleGame();
|
|
|
|
|
break;
|
|
|
|
|
case GameState.Meghaltal:
|
|
|
|
|
HandleMeghaltal();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(newState), newState, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnGameStateChanged?.Invoke(newState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum GameState
|
|
|
|
|
{
|
|
|
|
|
Home,
|
|
|
|
|
Settings,
|
|
|
|
|
Shop,
|
|
|
|
|
Game,
|
|
|
|
|
Meghaltal
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
public void ChangeToHome()
|
|
|
|
|
{
|
|
|
|
|
UpdateGameState(GameState.Home);
|
|
|
|
|
homeGomb.SetActive(true);
|
|
|
|
|
settingsGomb.SetActive(true);
|
|
|
|
|
shopGomb.SetActive(true);
|
2023-05-13 16:51:40 +02:00
|
|
|
|
2023-03-21 15:36:23 +01:00
|
|
|
goLeftButton.SetActive(false);
|
|
|
|
|
jumpButton.SetActive(false);
|
|
|
|
|
goRightButton.SetActive(false);
|
|
|
|
|
scoreText.gameObject.SetActive(false);
|
|
|
|
|
timerText.gameObject.SetActive(false);
|
2023-03-16 17:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-16 16:43:31 +01:00
|
|
|
private async void HandleHome()
|
2023-03-21 15:36:23 +01:00
|
|
|
{
|
|
|
|
|
//deactivate buttons
|
2023-03-16 17:40:08 +01:00
|
|
|
StartCoroutine(TimerHome());
|
2023-05-13 16:51:40 +02:00
|
|
|
playGomb.SetActive(true);
|
2023-03-16 17:40:08 +01:00
|
|
|
GetComponent<GroundController>().enabled = false;
|
|
|
|
|
GetComponent<PlayerController>().enabled = false;
|
2023-03-21 15:36:23 +01:00
|
|
|
goLeftButton.SetActive(false);
|
|
|
|
|
jumpButton.SetActive(false);
|
|
|
|
|
goRightButton.SetActive(false);
|
|
|
|
|
scoreText.gameObject.SetActive(false);
|
|
|
|
|
timerText.gameObject.SetActive(false);
|
2023-03-16 17:40:08 +01:00
|
|
|
garazs.SetActive(true);
|
|
|
|
|
}
|
2023-03-16 16:43:31 +01:00
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
IEnumerator TimerHome()
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSecondsRealtime(2);
|
2023-05-13 16:51:40 +02:00
|
|
|
|
|
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeToSettings()
|
|
|
|
|
{
|
|
|
|
|
UpdateGameState(GameState.Settings);
|
2023-05-13 16:51:40 +02:00
|
|
|
playGomb.SetActive(false);
|
2023-03-16 16:43:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void HandleSettings()
|
|
|
|
|
{
|
2023-05-13 16:51:40 +02:00
|
|
|
playGomb.SetActive(false);
|
2023-03-21 15:36:23 +01:00
|
|
|
goLeftButton.SetActive(false);
|
|
|
|
|
jumpButton.SetActive(false);
|
|
|
|
|
goRightButton.SetActive(false);
|
|
|
|
|
scoreText.gameObject.SetActive(false);
|
|
|
|
|
timerText.gameObject.SetActive(false);
|
2023-05-13 16:51:40 +02:00
|
|
|
playGomb.SetActive(false);
|
2023-03-16 17:40:08 +01:00
|
|
|
}
|
2023-03-16 16:43:31 +01:00
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
public void ChangeToShop()
|
|
|
|
|
{
|
|
|
|
|
UpdateGameState(GameState.Shop);
|
2023-05-13 16:51:40 +02:00
|
|
|
|
2023-03-16 16:43:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void HandleShop()
|
|
|
|
|
{
|
2023-05-13 16:51:40 +02:00
|
|
|
playGomb.SetActive(false);
|
2023-03-21 15:36:23 +01:00
|
|
|
goLeftButton.SetActive(false);
|
|
|
|
|
jumpButton.SetActive(false);
|
|
|
|
|
goRightButton.SetActive(false);
|
|
|
|
|
scoreText.gameObject.SetActive(false);
|
|
|
|
|
timerText.gameObject.SetActive(false);
|
2023-03-16 17:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeToGame()
|
|
|
|
|
{
|
|
|
|
|
homeGomb.SetActive(false);
|
|
|
|
|
settingsGomb.SetActive(false);
|
|
|
|
|
shopGomb.SetActive(false);
|
2023-05-13 16:51:40 +02:00
|
|
|
playGomb.SetActive(false);
|
2023-03-20 19:56:27 +01:00
|
|
|
UpdateGameState(GameState.Game);
|
2023-05-13 16:51:40 +02:00
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
}
|
2023-03-16 16:43:31 +01:00
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
IEnumerator TimerGame()
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSecondsRealtime(1);
|
|
|
|
|
garazs.SetActive(false);
|
2023-05-13 16:51:40 +02:00
|
|
|
|
|
|
|
|
|
2023-03-16 16:43:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void HandleGame()
|
|
|
|
|
{
|
2023-03-16 17:40:08 +01:00
|
|
|
StartCoroutine(TimerGame());
|
2023-05-13 16:51:40 +02:00
|
|
|
|
2023-05-22 14:37:24 +02:00
|
|
|
boby.transform.position = new Vector3(0, boby.transform.position.y, boby.transform.position.z);
|
2023-05-13 16:51:40 +02:00
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
GetComponent <GroundController> ().enabled = true;
|
|
|
|
|
GetComponent <PlayerController>().enabled = true;
|
2023-05-02 13:46:38 +02:00
|
|
|
|
2023-05-13 16:51:40 +02:00
|
|
|
|
2023-03-21 15:36:23 +01:00
|
|
|
goLeftButton.SetActive(true);
|
|
|
|
|
jumpButton.SetActive(true);
|
|
|
|
|
goRightButton.SetActive(true);
|
|
|
|
|
scoreText.gameObject.SetActive(true);
|
2023-05-13 16:51:40 +02:00
|
|
|
timerText.gameObject.SetActive(true);;
|
|
|
|
|
|
2023-05-02 13:46:38 +02:00
|
|
|
|
2023-03-20 19:56:27 +01:00
|
|
|
timer.playTime.Start();
|
2023-05-13 16:51:40 +02:00
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
}
|
2023-03-16 16:43:31 +01:00
|
|
|
|
2023-03-16 17:40:08 +01:00
|
|
|
public void ChangeToMeghaltal()
|
|
|
|
|
{
|
|
|
|
|
UpdateGameState(GameState.Meghaltal);
|
2023-03-16 16:43:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void HandleMeghaltal()
|
|
|
|
|
{
|
2023-03-20 19:56:27 +01:00
|
|
|
//ora leallitasa
|
|
|
|
|
timer.playTime.Stop();
|
|
|
|
|
|
|
|
|
|
//Valtson at high score tabla scenebe utana ha megnyomott egy gombot ugy menjen vissza a menube
|
|
|
|
|
//toltse fel az adatokat a run-rol
|
|
|
|
|
db.PostNewScoreData(usernameHandler.userid, score.score, timer.convertTimeToString());
|
|
|
|
|
|
2023-05-02 13:46:38 +02:00
|
|
|
//coin feltoltes
|
2023-05-22 14:37:24 +02:00
|
|
|
db.PostUpdateCoinData(cc.coin, usernameHandler.userid);
|
2023-05-02 13:46:38 +02:00
|
|
|
|
2023-03-20 19:56:27 +01:00
|
|
|
SceneUIManager.LoadScene(1); //HighScore scene
|
|
|
|
|
|
|
|
|
|
|
2023-05-13 16:51:40 +02:00
|
|
|
/*
|
2023-03-16 17:40:08 +01:00
|
|
|
homeGomb.SetActive(true);
|
|
|
|
|
GetComponent<GroundController>().enabled = false;
|
|
|
|
|
GetComponent<PlayerController>().enabled = false;
|
2023-03-20 19:56:27 +01:00
|
|
|
garazs.SetActive(true);*/
|
2023-03-16 16:43:31 +01:00
|
|
|
}
|
2023-03-20 19:56:27 +01:00
|
|
|
}
|