This commit is contained in:
2023-10-18 22:44:51 +05:30
parent 07f04580b7
commit 6d89914005
33 changed files with 11416 additions and 100 deletions

View File

@@ -80,6 +80,8 @@ public class AdsManager : MonoBehaviour
}
StartCoroutine(ReloadAds(false));
DataManager.AddAdImpression();
}
@@ -119,11 +121,11 @@ public class AdsManager : MonoBehaviour
rewardedAd = ad;
rewardedAd.OnAdPaid += OnRewardSuccess;
//rewardedAd.OnAdPaid += OnRewardSuccess;
});
}
private void OnRewardSuccess(AdValue obj)
private void OnRewardSuccess()
{
Debug.Log("Rewarded Ad success, code:1032");
GameManager.AdWatched();
@@ -138,6 +140,7 @@ public class AdsManager : MonoBehaviour
{
rewardedAd.Show((Reward reward) =>
{
OnRewardSuccess();
// TODO: Reward the user.
Debug.Log(String.Format(rewardMsg, reward.Type, reward.Amount));
});

View File

@@ -20,6 +20,7 @@ public class AudioManager : MonoBehaviour
[SerializeField]private AudioSource sfxSource;
[SerializeField]private AudioSource dropSfxSource;
[SerializeField]private AudioClip[] lowHits, midHits, hardHits;
[SerializeField] private AudioClip lowSplash, midSplash, hardSplash;
[SerializeField]private AudioClip[] drop;
[SerializeField]private float dropMinPitch = 0.5f;
[SerializeField]private float dropMaxPitch = 1.5f;
@@ -39,6 +40,19 @@ public class AudioManager : MonoBehaviour
instance.dropSfx(magnitude);
}
public static void SplashSFX(int level)
{
switch (level)
{
case 1:
instance.sfxSource.PlayOneShot(instance.lowSplash, 0.3f); break;
case 2:
instance.sfxSource.PlayOneShot(instance.midSplash, 0.3f); break;
case 3:
instance.sfxSource.PlayOneShot(instance.hardSplash, 0.3f); break;
}
}
public static bool ToggleMute(){
isMute = !isMute;
Refresh();

View File

@@ -4,7 +4,7 @@ using UnityEngine;
public class CheckUpdates : MonoBehaviour
{
public static int ClientVersion = 2;
public static int ClientVersion = 4;
public static int ServerVersion;
public float interval = 30;

12
Assets/Scripts/Coin.cs Normal file
View File

@@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Coin : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D col){
if(col.tag == "Player"){
Destroy(gameObject);
}
}
}

View File

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

View File

@@ -233,6 +233,50 @@ public static class DataManager{
// LoadingScreen.LoadLevel("MainMenu");
}
public static async void AddAdImpression(){
WWWForm form = new WWWForm();
Debug.Log(userData.ToString());
form.AddField("username", userData.username);
form.AddField("password", userData.password);
form.AddField("key", key);
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "add_impression.php", form))
{
var operation = request.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
Debug.Log("add ad impression response: " +request.downloadHandler.text);
if(request.downloadHandler.text.Contains("{")){
try{
userData = JsonConvert.DeserializeObject<UserData>(request.downloadHandler.text);
if(userData == null){
throw new NullReferenceException();
}
if(userData.username.Length < 3){
throw new IndexOutOfRangeException();
}
Debug.Log("Success parsing userdata");
}catch(Exception e){
Debug.Log("Error parsing userdata");
}
}else{
MessageBox.ShowMessage("Error Updating add_impression, Server said\n" +request.downloadHandler.text);
}
}
// LoadingScreen.LoadLevel("MainMenu");
}
public static async Task RefreshLeaderboard(bool total = false){
WWWForm form = new WWWForm();

View File

@@ -140,7 +140,10 @@ public class GameManager : MonoBehaviour
GameOverUI.SetActive(true);
adCounter++;
if(adCounter > 1 || DataManager.userData.faucetId > 0){
if(DataManager.userData.faucetId > 0){
AdsManager.instance.ShowIntAd();
}
else if(adCounter > 1){
adCounter=0;
AdsManager.instance.ShowIntAd();
}

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.U2D;
@@ -10,16 +11,24 @@ public class LevelGenerator : MonoBehaviour
public int LevelCount = 1000;
public float groundLevel = -5.5f;
public float maxHeight = 5;
public float waterRequiredHeight = 2f;
public Vector2 minDiff, maxDiff;
public Vector3[] points {get; private set;}
public List<Vector3> absolutePoints = new List<Vector3>();
public GameObject holePrefab;
public GameObject flagPrefab;
public GameObject treePrefab;
public GameObject coinPrefab;
public GameObject waterPrefab;
public static List<GameObject> holes;
public GameObject WaterSplashFX;
public int GoalDistance= 10;
void Awake()
{
@@ -42,9 +51,11 @@ public class LevelGenerator : MonoBehaviour
SpriteShapeController spriteShapeController = Instantiate(spriteShapeControllerPrefab, new Vector3(offset,0),Quaternion.identity).GetComponent<SpriteShapeController>();
spriteShapeController.spline.Clear();
points = new Vector3[LevelCount+1];
for(int i=0; i < LevelCount; i++){
if(i ==0){
points[i] = new Vector3(0,groundLevel);
absolutePoints.Add(points[i] + new Vector3(lastOffset, 0));
spriteShapeController.spline.InsertPointAt(i, points[i]);
continue;
}
@@ -59,6 +70,7 @@ public class LevelGenerator : MonoBehaviour
newY -= Mathf.Abs(addition.y);
}
points[i] = new Vector3(newX, newY);
absolutePoints.Add(points[i] + new Vector3(lastOffset,0));
// spriteShapeController.spline.InsertPointAt(i, points[i]);
InsertNewPoint(spriteShapeController, points[i]);
@@ -73,18 +85,52 @@ public class LevelGenerator : MonoBehaviour
newTree.transform.localScale = Vector3.one * Random.Range(0.75f, 1.1f);
}
/* if(Random.Range(0f,1f) > 0.8f){
Instantiate(coinPrefab, points[i] + new Vector3(0,5), Quaternion.identity);
}*/
if(i % GoalDistance == 0){
InsertNewPoint(spriteShapeController, points[i] + new Vector3(0, -1f));
InsertNewPoint(spriteShapeController, points[i] + new Vector3(1f, -1f));
InsertNewPoint(spriteShapeController, points[i] + new Vector3(1f, 0f));
Vector3 newHolePos = points[i] + new Vector3(lastOffset,0);
// if( i > GoalDistance * 2){
// Vector3 prevHolePos = points[i-GoalDistance] + new Vector3(lastOffset,0);
// //Calc between prev-new
// Debug.Log($"{newHolePos}-{prevHolePos} = {newHolePos - prevHolePos}");
// Instantiate(coinPrefab, ((newHolePos - prevHolePos) * 0.5f) + new Vector3(prevHolePos.x,prevHolePos.y + 3),Quaternion.identity);
// }
Instantiate(flagPrefab,newHolePos, Quaternion.identity);
holes.Add(Instantiate(holePrefab,newHolePos, Quaternion.identity));
}
if (i > 3 && (i-1) % GoalDistance != 0 )
{
if (points[i].y > points[i - 1].y + waterRequiredHeight && points[i - 2].y > points[i - 1].y + waterRequiredHeight)
{
SpriteShapeController waterSprite = Instantiate(waterPrefab, new Vector3(lastOffset, 0), Quaternion.identity).GetComponent<SpriteShapeController>();
waterSprite.spline.Clear();
float lowestPoint = points[i].y;
if (lowestPoint > points[i - 2].y)
{
lowestPoint = points[i - 2].y;
}
InsertNewPoint(waterSprite, points[i - 1] - new Vector3(1, 1));
InsertNewPoint(waterSprite, new Vector3(points[i].x - 1, lowestPoint - 1));
InsertNewPoint(waterSprite, new Vector3(points[i - 2].x + 1, lowestPoint - 1));
}
}
}
@@ -117,4 +163,14 @@ public class LevelGenerator : MonoBehaviour
}
}
#if UNITY_EDITOR
private void OnDrawGizmos()
{
foreach(Vector3 point in absolutePoints)
{
Handles.Label(point, point.ToString());
}
}
#endif
}

View File

@@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
public class ObjectPool : MonoBehaviour
{
public static ObjectPool instance;
public static Dictionary<string, List<GameObject>> pool = new Dictionary<string, List<GameObject>>();
void Awake(){
pool = new Dictionary<string, List<GameObject>>();
instance= this;
}
public static GameObject Spawn(GameObject obj, Vector3 position, int ttl = 0){
if(pool.ContainsKey(obj.name)){
// Debug.Log($"Has key : {pool[obj.name].Count}");
//use from pool
if(pool[obj.name].Count <=0){
GameObject go = Instantiate(obj, position, Quaternion.identity);
return go;
}else{
GameObject chosen = pool[obj.name][0].gameObject;
chosen.gameObject.SetActive(true);
chosen.transform.position = position;
pool[obj.name].RemoveAt(0);
// Debug.Log("Reusing");
if (ttl > 0)
{
Deactivate(chosen, ttl);
}
return chosen;
}
}else{
GameObject go = Instantiate(obj, position, Quaternion.identity);
if(ttl > 0) { Deactivate(go, ttl);}
return go;
}
}
async static void Deactivate(GameObject go, int ttl)
{
await Task.Delay(ttl);
Despawn(go);
}
public static void Despawn(GameObject obj){
string objName = obj.name.Replace("(Clone)","");
if(!pool.ContainsKey(objName)){
pool.Add(objName, new List<GameObject>());
}
pool[objName].Add(obj);
obj.SetActive(false);
// Debug.Log($"Adding {objName} back to pool, " + pool[objName].Count);
}
}

View File

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

55
Assets/Scripts/Water.cs Normal file
View File

@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Water : MonoBehaviour
{
Rigidbody2D body;
public float effect = 0.05f;
public float waterOffset = 0.1f;
private void FixedUpdate()
{
if (body == null) { return; }
body.velocity = Vector3.Lerp(body.velocity, new Vector2(0, -0.01f), effect);
}
private void OnTriggerEnter2D(Collider2D collision)
{
body = collision.GetComponent<Rigidbody2D>();
// GameObject FX = ObjectPool.Spawn(LevelGenerator.instance.WaterSplashFX, new Vector3(collision.transform.position.x, transform.position.y + waterOffset), ttl: 2500) ;
GameObject FX = ObjectPool.Spawn(LevelGenerator.instance.WaterSplashFX, collision.transform.position, ttl: 2500);
FX.GetComponent<ParticleSystem>().Play();
FX.transform.eulerAngles = new Vector3(-90, 0, 0);
int splashHardness = 1;
if (collision.attachedRigidbody.velocity.sqrMagnitude > 40) splashHardness = 2;
if (collision.attachedRigidbody.velocity.sqrMagnitude > 100) splashHardness = 3;
Debug.Log(collision.attachedRigidbody.velocity.sqrMagnitude);
AudioManager.SplashSFX(splashHardness);
if(body.GetComponent<GolfBall>() != null)
{
body.transform.GetChild(0).gameObject.SetActive(true);
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (body.GetComponent<GolfBall>() != null)
{
body.transform.GetChild(0).gameObject.SetActive(true);
}
body = null;
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(transform.position + new Vector3(0.5f, waterOffset), transform.position + new Vector3(-0.5f, waterOffset));
}
}

View File

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