new movement

This commit is contained in:
2023-03-07 21:06:25 +01:00
parent 927ea1f885
commit 07697c1d20
11 changed files with 587 additions and 132 deletions

View File

@@ -6,6 +6,15 @@ public class CoinCounter : MonoBehaviour
{
public ulong coin = 0; //szedje le db-bol a playerhez a coint
private DatabaseData dd;
//get player coin at startup based on username
private void Awake() {
dd = FindObjectOfType<DatabaseData>();
//dd.GetCoinData("Playmaker1210");
}
public void AddCoin(ulong number){
coin += number;
}

View File

@@ -12,10 +12,13 @@ public class DatabaseData : MonoBehaviour
public HighScoreTable hst; //high score table ui
public string jsondata; //json szoveg
private CoinCounter coinc;
private void Awake() {
hst = FindObjectOfType<HighScoreTable>(); //High Score Table referencia
htdc = new HighScoreTableDataContainer(); //High Score Table Container objektum
players = new PlayerList(); //jatekos lista osztaly
coinc = FindObjectOfType<CoinCounter>();
}
private void Start() {
@@ -37,6 +40,8 @@ public class DatabaseData : MonoBehaviour
public void PostNewScoreData() => StartCoroutine(IPostNewScoreData());
public void PostNewPalyaData() => StartCoroutine(IPostNewPalyaData());
public void GetCoinData(string username) => StartCoroutine(IGetPlayerCoins(username));
private IEnumerator IGetPlayerData() {
input.text = "Loading..."; //ideiglenes szoveg amig nem jelenik meg az adat szoveg
@@ -66,6 +71,30 @@ public class DatabaseData : MonoBehaviour
}
private IEnumerator IGetCurretPlayer(int userid){
string uri = "http://localhost:3000/currentplayer";
var uwr = new UnityWebRequest(uri, "POST");
byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes("{\"bevitel1\":"+userid+"}"); //palya id megadasa
uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend); //felkuldi a palya id-t
uwr.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
uwr.SetRequestHeader("Content-Type", "application/json");
yield return uwr.SendWebRequest();
if (uwr.isNetworkError) {
Debug.Log(uwr.error);
} else {
jsondata = uwr.downloadHandler.text; //json szoveg eltarolasa
Debug.Log("current player json: " + jsondata);
jsonParser(jsondata); //json adat atalakitasa
foreach(var p in players.player) {
p.ConvertDate(); //datum eltarolasa es atalakitasa datum tipussa
Debug.Log("p_id: " + p.player_id + " username: " + p.player_name + " join date: " + p.joindate.printDate() + "\n");
}
}
}
private IEnumerator IGetHighScoreData(int palya_id){
string uri = "http://localhost:3000/toplist";
@@ -104,7 +133,7 @@ public class DatabaseData : MonoBehaviour
Debug.Log(uwr.error);
} else {
Debug.Log(uwr.downloadHandler.text);
coinc.coin = ulong.Parse(uwr.downloadHandler.text);
}
}

View File

@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
@@ -16,49 +17,78 @@ public class PlayerController : MonoBehaviour
private Vector2 startTouchPosition; //erintes kezdo pozicio
private Vector2 endTouchPosition; //erintes vegpozicio
public ControllType activeControllType;
public Button leftButton;
public Button jumpButton;
public Button rightButton;
public enum ControllType
{
Swipe,
Button
}
private void Awake() {
cc = FindObjectOfType<CameraController>(); //kamera vezerlo referencia
activeControllType = ControllType.Button;
}
public void setControllType(ControllType controlltype){
activeControllType = controlltype;
}
private void Update(){
//jumping
if(Input.touchCount > 0){
Touch touch = Input.GetTouch(0); //elso erintes lekerese
if(activeControllType == ControllType.Swipe){
leftButton.gameObject.SetActive(false);
jumpButton.gameObject.SetActive(false);
rightButton.gameObject.SetActive(false);
if(touch.phase == TouchPhase.Began){ //ha az erintes elkezdotott
isTapped = true;
timeSinceLastTap = Time.time;
}
//jumping
if(Input.touchCount > 0){
Touch touch = Input.GetTouch(0); //elso erintes lekerese
if(touch.phase == TouchPhase.Ended){ //ha az erintes befejezodott
isTapped = false;
timeSinceLastTap = 0f;
}
if(touch.phase == TouchPhase.Began){ //ha az erintes elkezdotott
isTapped = true;
timeSinceLastTap = Time.time;
}
if(isTapped && rb.transform.position.y <= 0.16f){
if(Time.time - timeSinceLastTap >= holdTime){ //ha nyomva tartotta a beallitott ideig
Debug.Log("Long tapped");
rb.AddForce(new Vector3(0, jumpforce, 0)); //ugras
if(touch.phase == TouchPhase.Ended){ //ha az erintes befejezodott
isTapped = false;
timeSinceLastTap = 0f;
}
if(isTapped && rb.transform.position.y <= 0.16f){
if(Time.time - timeSinceLastTap >= holdTime){ //ha nyomva tartotta a beallitott ideig
Debug.Log("Long tapped");
jump();
isTapped = false;
}
}
}
}
//new character controller with swipe lane changing
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){ //elso erintes elkezdodott
startTouchPosition = Input.GetTouch(0).position;
}
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){ //elso erintes befejezodott
endTouchPosition = Input.GetTouch(0).position;
if(endTouchPosition.x < startTouchPosition.x){ //balra huzott
//left
goLeft();
}else if(endTouchPosition.x > startTouchPosition.x){ //jobbra huzott
//right
goRight();
//new character controller with swipe lane changing
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){ //elso erintes elkezdodott
startTouchPosition = Input.GetTouch(0).position;
}
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){ //elso erintes befejezodott
endTouchPosition = Input.GetTouch(0).position;
if(endTouchPosition.x < startTouchPosition.x){ //balra huzott
//left
goLeft();
}else if(endTouchPosition.x > startTouchPosition.x){ //jobbra huzott
//right
goRight();
}
}
}else if(activeControllType == ControllType.Button){
jumpforce = 2;
leftButton.onClick.AddListener(goRight);
jumpButton.onClick.AddListener(jump);
rightButton.onClick.AddListener(goLeft);
}
}
@@ -73,4 +103,8 @@ public class PlayerController : MonoBehaviour
cc.xPostion = 3; //kamera xPozicioja
rb.transform.position = new Vector3(rb.transform.position.x - sideMovement, rb.transform.position.y, rb.transform.position.z);
}
private void jump(){
rb.AddForce(new Vector3(0, jumpforce, 0)); //ugras
}
}

View File

@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class SetButtonSize : MonoBehaviour
{
public Canvas canvas;
public Button leftButton;
public Button jumpButton;
public Button rightButton;
private Vector2 canvasSize;
private void Awake() {
canvasSize = new Vector2(canvas.GetComponent<RectTransform>().rect.width, canvas.GetComponent<RectTransform>().rect.height);
///leftButton
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e84dc5ac17504204da8ccd1fb2c9bbfe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.Threading;
using UnityEditor;
public class fps : MonoBehaviour
{
@@ -13,10 +13,12 @@ public class fps : MonoBehaviour
// Update is called once per frame
void Update()
{
#if UNITY_EDITOR
if (Time.unscaledTime > _timer) {
int fps = (int)(1f / Time.unscaledDeltaTime);
fpsText.text = "FPS: " + fps;
_timer = Time.unscaledTime + _hudRefreshRate;
}
#endif
}
}