Store WIP
This commit is contained in:
parent
fe14f582b9
commit
df54712168
1077
Assets/Scenes/Login.unity
Normal file
1077
Assets/Scenes/Login.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Scenes/Login.unity.meta
Normal file
7
Assets/Scenes/Login.unity.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 469333b49e5f2ea428467efd468af64e
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
4095
Assets/Scenes/Menu.unity
Normal file
4095
Assets/Scenes/Menu.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Scenes/Menu.unity.meta
Normal file
7
Assets/Scenes/Menu.unity.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d3ae632d33cb1684f843457f14138d90
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -307,8 +307,8 @@ Transform:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 187158564}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -7.4247, z: 0}
|
||||
m_LocalScale: {x: 1, y: 15.209486, z: 1}
|
||||
m_LocalPosition: {x: 0, y: -14.0033, z: 0}
|
||||
m_LocalScale: {x: 1, y: 28.367321, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1987779770}
|
||||
m_RootOrder: 0
|
||||
|
|
@ -904,6 +904,10 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 343276379f35b714985aa57c6a87b4d8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
pogeColors:
|
||||
- {r: 1, g: 1, b: 1, a: 1}
|
||||
- {r: 1, g: 0.9719708, b: 0.4575472, a: 1}
|
||||
- {r: 0.36320752, g: 0.955507, b: 1, a: 1}
|
||||
body: {fileID: 1345529968}
|
||||
<Velocity>k__BackingField: {x: 0, y: 0}
|
||||
gravity: 0.005
|
||||
|
|
@ -974,7 +978,7 @@ Transform:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1345529965}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -5.08, y: 8.51, z: 0}
|
||||
m_LocalPosition: {x: -1.38, y: 8.51, z: 0}
|
||||
m_LocalScale: {x: 0.0681212, y: 0.0681212, z: 0.0681212}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
|
|
|
|||
86
Assets/Scripts/DataManager.cs
Normal file
86
Assets/Scripts/DataManager.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class DataManager{
|
||||
public const string API_Endpoint="http://vmi1005083.contaboserver.net/pogebird/api/";
|
||||
public static string Username{get; private set;}
|
||||
public static bool LoggedIn {get{return PlayerPrefs.HasKey("username");}}
|
||||
|
||||
public static int selectedPogeLevel{get;private set;}
|
||||
public static List<int> pogePurchased {get {
|
||||
string p =PlayerPrefs.GetString("poge_purchased");
|
||||
List<int> l = new List<int>();
|
||||
if(p.Contains("gold")){
|
||||
l.Add(1);
|
||||
}
|
||||
if(p.Contains("diamond")){
|
||||
l.Add(2);
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
public static void PurchasePoge(string index){
|
||||
PlayerPrefs.SetString("poge_purchased",PlayerPrefs.GetString("poge_purchased") + index);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public static int total{get{
|
||||
return (int)PlayerPrefs.GetFloat("Money");
|
||||
}
|
||||
set{
|
||||
PlayerPrefs.SetFloat("Money", value);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadFromSave(){
|
||||
Username = PlayerPrefs.GetString("username");
|
||||
LoadSaveData();
|
||||
}
|
||||
|
||||
|
||||
public static bool OnLoginDone(string username,string response){
|
||||
int uid = -1;
|
||||
try{
|
||||
uid = int.Parse(response);
|
||||
}catch{
|
||||
Debug.LogError("Error in registering : " + response);
|
||||
}
|
||||
|
||||
|
||||
if(uid >=0){
|
||||
Username = username +"#"+ uid;
|
||||
PlayerPrefs.SetString("username", Username);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
LoadSaveData();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static void LoadSaveData(){
|
||||
if(PlayerPrefs.HasKey("poge")){
|
||||
selectedPogeLevel = PlayerPrefs.GetInt("poge");
|
||||
}else{
|
||||
PlayerPrefs.SetInt("poge",0);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
if(PlayerPrefs.HasKey("poge_purchased")){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void SelectPoge(int i){
|
||||
PlayerPrefs.SetInt("poge",i);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/DataManager.cs.meta
Normal file
11
Assets/Scripts/DataManager.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6179ef5eb99010845b760cb4660ca4ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -26,6 +26,6 @@ public class GameUI : MonoBehaviour
|
|||
|
||||
|
||||
public void Restart(){
|
||||
SceneManager.LoadScene(0);
|
||||
SceneManager.LoadScene(2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
58
Assets/Scripts/Leaderboard.cs
Normal file
58
Assets/Scripts/Leaderboard.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Leaderboard : MonoBehaviour
|
||||
{
|
||||
public GameObject rowPrefab;
|
||||
public Transform itemsParent;
|
||||
|
||||
public void Show(){
|
||||
gameObject.SetActive(true);
|
||||
|
||||
|
||||
StartCoroutine(show());
|
||||
}
|
||||
|
||||
|
||||
IEnumerator show(){
|
||||
WWW req = new WWW(DataManager.API_Endpoint +"get_leaderboard.php");
|
||||
yield return req;
|
||||
|
||||
Debug.Log("Leaderboard: " + req.text);
|
||||
|
||||
if(req.text.Contains("<td>") && req.text.Contains("<tr>")){
|
||||
|
||||
string[] col = {"<td>"};
|
||||
string[] row = {"<tr>"};
|
||||
|
||||
string[] columns = req.text.Split(col,System.StringSplitOptions.RemoveEmptyEntries);
|
||||
//Purge
|
||||
for(int i=0; i < itemsParent.childCount; i++){
|
||||
if(itemsParent.GetChild(i) != rowPrefab){
|
||||
Destroy(itemsParent.GetChild(i));
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
rowPrefab.SetActive(true);
|
||||
for (int i =0; i < columns.Length; i++)
|
||||
{
|
||||
string column = columns[i];
|
||||
string[] rows = column.Split(row, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(rows.Length < 2){
|
||||
Debug.Log("Error");
|
||||
}
|
||||
|
||||
|
||||
GameObject newRow = Instantiate(rowPrefab, itemsParent);
|
||||
newRow.transform.GetChild(0).GetComponent<Text>().text = $"{i+1}. {rows[0]}";
|
||||
newRow.transform.GetChild(1).GetComponent<Text>().text ="$"+rows[1];
|
||||
}
|
||||
rowPrefab.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Leaderboard.cs.meta
Normal file
11
Assets/Scripts/Leaderboard.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9e1b7dedd9a4c3a48beb8d9c72821cf1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/Scripts/Login.cs
Normal file
40
Assets/Scripts/Login.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
public class Login : MonoBehaviour
|
||||
{
|
||||
public InputField loginInput;
|
||||
public Button loginBtn;
|
||||
|
||||
|
||||
void Awake(){
|
||||
if(DataManager.LoggedIn){
|
||||
DataManager.LoadFromSave();
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
loginBtn.onClick.AddListener(OnLogin);
|
||||
loginInput.onValueChanged.AddListener(OnInputChanged);
|
||||
}
|
||||
public void OnLogin(){
|
||||
StartCoroutine(login(loginInput.text));
|
||||
}
|
||||
|
||||
void OnInputChanged(string newVal){
|
||||
loginBtn.interactable = newVal.Length > 2;
|
||||
}
|
||||
|
||||
IEnumerator login(string username){
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("username", username);
|
||||
form.AddField("key","#2CuV1Bit^S!sW1ZcgRv8BhrO");
|
||||
|
||||
WWW req = new WWW(DataManager.API_Endpoint +"register_instant.php", form);
|
||||
yield return req;
|
||||
|
||||
if(DataManager.OnLoginDone(username, req.text)){
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Login.cs.meta
Normal file
11
Assets/Scripts/Login.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4298e4b28e5f9e842a01e087801b1a17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Scripts/MenuManager.cs
Normal file
51
Assets/Scripts/MenuManager.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
public class MenuManager : MonoBehaviour
|
||||
{
|
||||
public Text txtUsername;
|
||||
public Text txtMoney;
|
||||
|
||||
public Button playBtn;
|
||||
public Button storeBtn;
|
||||
public Button leaderboardBtn;
|
||||
public Leaderboard leaderboard;
|
||||
public Store store;
|
||||
public static MenuManager instance;
|
||||
void Start()
|
||||
{
|
||||
instance = this;
|
||||
if(!DataManager.LoggedIn){SceneManager.LoadScene(0); return;}
|
||||
Refresh();
|
||||
|
||||
playBtn.onClick.AddListener(OnPlay);
|
||||
storeBtn.onClick.AddListener(OnStoreBtn);
|
||||
leaderboardBtn.onClick.AddListener(OnLeaderboardBtn);
|
||||
}
|
||||
|
||||
void OnPlay(){
|
||||
SceneManager.LoadScene(2);
|
||||
}
|
||||
|
||||
void OnStoreBtn(){
|
||||
store.Show();
|
||||
}
|
||||
|
||||
void OnLeaderboardBtn(){
|
||||
leaderboard.Show();
|
||||
}
|
||||
|
||||
public static void Refresh(){
|
||||
if(instance != null){
|
||||
instance.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
|
||||
txtUsername.text = txtUsername.text.Replace("{username}", DataManager.Username);
|
||||
txtMoney.text = "$" + DataManager.total.ToString();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MenuManager.cs.meta
Normal file
11
Assets/Scripts/MenuManager.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 474b1819f34c1224192a1651fccc4bb7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -4,6 +4,7 @@ using UnityEngine;
|
|||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
public Color[] pogeColors;
|
||||
[SerializeField]private Transform body;
|
||||
[field:SerializeField]public Vector2 Velocity {get; private set;}
|
||||
[SerializeField]private float gravity=1;
|
||||
|
|
@ -38,6 +39,7 @@ public class Player : MonoBehaviour
|
|||
timeAliveMoney = GetComponent<TimeAliveMoney>();
|
||||
isAlive = true;
|
||||
spriteRenderer.sprite =normalFace;
|
||||
spriteRenderer.color = pogeColors[DataManager.selectedPogeLevel];
|
||||
|
||||
startPos = body.position;
|
||||
Velocity = new Vector2(forwardSpeed,0);
|
||||
|
|
@ -51,7 +53,9 @@ public class Player : MonoBehaviour
|
|||
int lastX = 0;
|
||||
void FixedUpdate()
|
||||
{
|
||||
|
||||
if(Input.GetKey(KeyCode.X)){
|
||||
DataManager.total = 5000000;
|
||||
}
|
||||
|
||||
if (!gameStarted)
|
||||
{
|
||||
|
|
|
|||
104
Assets/Scripts/Store.cs
Normal file
104
Assets/Scripts/Store.cs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Store : MonoBehaviour
|
||||
{
|
||||
public GameObject noMoneyText;
|
||||
|
||||
public Button poge_silver;
|
||||
public Button poge_gold;
|
||||
public Button poge_diamond;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
if(DataManager.selectedPogeLevel == 0){
|
||||
SelectSilver();
|
||||
}else if(DataManager.selectedPogeLevel == 1){
|
||||
SelectGold();
|
||||
}else if(DataManager.selectedPogeLevel == 2){
|
||||
SelectDiamond();
|
||||
}
|
||||
poge_silver.onClick.AddListener(SelectSilver);
|
||||
poge_gold.onClick.AddListener(SelectGold);
|
||||
poge_diamond.onClick.AddListener(SelectDiamond);
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
public void Show(){
|
||||
noMoneyText.SetActive(false);
|
||||
gameObject.SetActive(true);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void SelectSilver(){
|
||||
poge_silver.transform.GetChild(0).gameObject.SetActive(true);
|
||||
poge_gold.transform.GetChild(0).gameObject.SetActive(false);
|
||||
poge_diamond.transform.GetChild(0).gameObject.SetActive(false);
|
||||
DataManager.SelectPoge(0);
|
||||
|
||||
Refresh();
|
||||
|
||||
}
|
||||
public float goldPrice =50000;
|
||||
public float diamondPrice = 500000;
|
||||
void SelectGold(){
|
||||
|
||||
if(!DataManager.pogePurchased.Contains(1)){
|
||||
if(DataManager.total < goldPrice){
|
||||
noMoneyText.SetActive(true);
|
||||
|
||||
return;
|
||||
}else{
|
||||
DataManager.total =(int)(DataManager.total- goldPrice);
|
||||
|
||||
}
|
||||
}
|
||||
poge_silver.transform.GetChild(0).gameObject.SetActive(false);
|
||||
poge_gold.transform.GetChild(0).gameObject.SetActive(true);
|
||||
poge_diamond.transform.GetChild(0).gameObject.SetActive(false);
|
||||
DataManager.SelectPoge(1);
|
||||
Refresh();
|
||||
|
||||
}void SelectDiamond(){
|
||||
if(!DataManager.pogePurchased.Contains(2)){
|
||||
if(DataManager.total < diamondPrice){
|
||||
noMoneyText.SetActive(true);
|
||||
|
||||
return;
|
||||
}else{
|
||||
DataManager.total =(int)(DataManager.total- diamondPrice);
|
||||
|
||||
}
|
||||
}
|
||||
poge_silver.transform.GetChild(0).gameObject.SetActive(false);
|
||||
poge_gold.transform.GetChild(0).gameObject.SetActive(false);
|
||||
poge_diamond.transform.GetChild(0).gameObject.SetActive(true);
|
||||
DataManager.SelectPoge(2);
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Refresh()
|
||||
{
|
||||
MenuManager.Refresh();
|
||||
noMoneyText.SetActive(false);
|
||||
|
||||
if(DataManager.pogePurchased.Contains(1)){
|
||||
poge_gold.transform.GetChild(1).GetChild(1).GetComponent<Text>().text = "Purchased";
|
||||
}else{
|
||||
poge_gold.transform.GetChild(1).GetChild(1).GetComponent<Text>().text = "$50000";
|
||||
|
||||
}
|
||||
if(DataManager.pogePurchased.Contains(2)){
|
||||
poge_diamond.transform.GetChild(1).GetChild(1).GetComponent<Text>().text = "Purchased";
|
||||
}else{
|
||||
poge_diamond.transform.GetChild(1).GetChild(1).GetComponent<Text>().text = "$500000";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Store.cs.meta
Normal file
11
Assets/Scripts/Store.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c1f4cee93d3f3814b99a93c78153ec83
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using UnityEngine;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
|
||||
public class TimeAliveMoney : MonoBehaviour
|
||||
{
|
||||
|
|
@ -26,10 +27,13 @@ public class TimeAliveMoney : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
float moneyEarned => timeAlive * moneyPerSecond;
|
||||
public void OnPlayerDeath()
|
||||
{
|
||||
totalMoneyEarned += timeAlive * moneyPerSecond;
|
||||
SaveMoney();
|
||||
StartCoroutine(SaveDataToServer((int)moneyEarned));
|
||||
|
||||
timeAlive = 0f;
|
||||
totalMoneyText.text = ((int)totalMoneyEarned).ToString() + "$";
|
||||
}
|
||||
|
|
@ -39,5 +43,24 @@ public class TimeAliveMoney : MonoBehaviour
|
|||
{
|
||||
PlayerPrefs.SetFloat("Money", totalMoneyEarned);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
}
|
||||
|
||||
IEnumerator SaveDataToServer(int _moneyEarned){
|
||||
WWWForm f1 = new WWWForm();
|
||||
f1.AddField("username", DataManager.Username);
|
||||
f1.AddField("total",(int)totalMoneyEarned);
|
||||
|
||||
WWW reqTotal = new WWW(DataManager.API_Endpoint + "set_total.php",f1);
|
||||
yield return reqTotal;
|
||||
|
||||
WWWForm f2 = new WWWForm();
|
||||
f2.AddField("username", DataManager.Username);
|
||||
f2.AddField("best", (int)_moneyEarned);
|
||||
|
||||
WWW reqBest = new WWW(DataManager.API_Endpoint + "set_best.php",f2);
|
||||
yield return reqBest;
|
||||
|
||||
Debug.Log(reqBest.text);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,12 @@ EditorBuildSettings:
|
|||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Scenes:
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/Login.unity
|
||||
guid: 469333b49e5f2ea428467efd468af64e
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/Menu.unity
|
||||
guid: d3ae632d33cb1684f843457f14138d90
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/SampleScene.unity
|
||||
guid: 2cda990e2423bbf4892e6590ba056729
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user