Rewrite a lot of the Game Player so it isn't stuck in 2010
This commit is contained in:
11 files changed
+1838
-1569
No files matched your search
@@ -27,28 +27,30 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
private float speedyLeft;
|
||||
private float antiLeft;
|
||||
private float goldenLeft;
|
||||
private float screenWidth;
|
||||
internal bool isGrounded;
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
[SerializeField] private TMP_Text highScoreText;
|
||||
[SerializeField] private TMP_Text boostText;
|
||||
[SerializeField] private GameObject bird;
|
||||
[SerializeField] private GameObject pausePanel;
|
||||
[SerializeField] private Rigidbody2D rb;
|
||||
public AudioSource backgroundMusic;
|
||||
private float lastMoveTime;
|
||||
[SerializeField] internal AudioSource backgroundMusic;
|
||||
[SerializeField] private GameObject berryParent;
|
||||
[SerializeField] private TMP_Text levelText;
|
||||
|
||||
[SerializeField] private Button pauseButton;
|
||||
|
||||
[SerializeField] private Image bird;
|
||||
[SerializeField] private GameObject berryTemplate;
|
||||
[SerializeField] private Rigidbody2D rb;
|
||||
[SerializeField] private RectTransform canvasRect;
|
||||
[SerializeField] private BoxCollider2D groundCollider;
|
||||
private UnityEngine.Vector2 velocityBeforePause = new();
|
||||
|
||||
internal bool IsGrounded() => Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), groundCollider).distance <= 0.1f;
|
||||
|
||||
void Awake() {
|
||||
Instance = this;
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
}
|
||||
|
||||
void Start() {
|
||||
lastMoveTime = Time.time;
|
||||
UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
|
||||
|
||||
Cursor.visible = false;
|
||||
@@ -59,22 +61,16 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
}
|
||||
|
||||
void MoveBird() {
|
||||
float screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
float baseSpeed = 0.18f * (screenWidth / 20.19257f);
|
||||
float speedModifier = 1f;
|
||||
bool doMoveRight = false;
|
||||
bool doMoveLeft = false;
|
||||
bool doJump = false;
|
||||
bool doBack = false;
|
||||
float movespeed = baseSpeed;
|
||||
if (boostLeft > 0f || speedyLeft > 0f) {
|
||||
movespeed = baseSpeed * 1.39f;
|
||||
} else if (slownessLeft > 0f) {
|
||||
movespeed = baseSpeed * 0.56f;
|
||||
}
|
||||
CheckIfGrounded();
|
||||
if (boostLeft > 0f || speedyLeft > 0f) speedModifier = 1.39f;
|
||||
else if (slownessLeft > 0f) speedModifier = 0.56f;
|
||||
|
||||
float birdX = bird.transform.position.x;
|
||||
float birdY = bird.transform.position.y;
|
||||
float birdX = bird.GetComponent<RectTransform>().anchoredPosition.x;
|
||||
float birdY = bird.GetComponent<RectTransform>().anchoredPosition.y;
|
||||
|
||||
var berryScores = new System.Collections.Generic.Dictionary<string, float> {
|
||||
{ "NormalBerry", 1f },
|
||||
@@ -90,7 +86,8 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
var allBerries = new System.Collections.Generic.List<(float x, float y, float score)>();
|
||||
foreach (var kvp in berryScores) {
|
||||
foreach (var b in GameObject.FindGameObjectsWithTag(kvp.Key)) {
|
||||
allBerries.Add((b.transform.position.x, b.transform.position.y, kvp.Value));
|
||||
var rt = b.GetComponent<RectTransform>();
|
||||
allBerries.Add((rt.anchoredPosition.x, rt.anchoredPosition.y, kvp.Value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +113,7 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
|
||||
float closestBadX = float.MaxValue;
|
||||
float closestBadDist = float.MaxValue;
|
||||
float dodgeLookahead = collectRadius + movespeed * 8f;
|
||||
float dodgeLookahead = collectRadius + 1.7f * speedModifier * 8f;
|
||||
|
||||
foreach (var (bx, by, score) in allBerries) {
|
||||
if (score >= 0f) continue;
|
||||
@@ -158,7 +155,7 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
clusters.Add((wTotal > 0f ? wX / wTotal : ax, wY / count, total));
|
||||
}
|
||||
|
||||
float bestScore = 0f;
|
||||
float bestScore = float.MinValue;
|
||||
float bestX = float.MaxValue;
|
||||
bool foundTarget = false;
|
||||
|
||||
@@ -166,9 +163,8 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
if (cs <= 0f) continue;
|
||||
if (PathHasDanger(cx)) continue;
|
||||
float dist = Mathf.Abs(cx - birdX);
|
||||
float adjusted = cs - dist * 0.05f;
|
||||
if (adjusted > bestScore) {
|
||||
bestScore = adjusted;
|
||||
if (cs > bestScore) {
|
||||
bestScore = cs;
|
||||
bestX = cx;
|
||||
foundTarget = true;
|
||||
}
|
||||
@@ -201,27 +197,21 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(-movespeed, 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(-(1.7f * speedModifier), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1.35f, 1.35f, 1.35f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(movespeed, 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(1.7f * speedModifier, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1.35f, 1.35f, 1.35f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doJump && isGrounded) {
|
||||
lastMoveTime = Time.time;
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded()) {
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 12f;
|
||||
} else if (slownessLeft > 0f) {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 6f;
|
||||
} else {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 9f;
|
||||
}
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f);
|
||||
else if (slownessLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 220f);
|
||||
else rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 300f);
|
||||
}
|
||||
if (doBack) {
|
||||
TogglePause();
|
||||
@@ -234,27 +224,21 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
UnityEngine.Vector3 dir = berry.transform.position - bird.transform.position;
|
||||
if (dir.magnitude < (antiLeft > 0 ? 3f : 4.5f)) {
|
||||
berry.GetComponent<Rigidbody2D>().linearVelocity = dir.normalized * (antiLeft > 0 ? 5f : -5f);
|
||||
ClampPosition(berry, false);
|
||||
ClampPosition(berry.GetComponent<Image>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClampPosition(GameObject obj, bool modifyY = true) {
|
||||
var cam = Camera.main;
|
||||
var pos = obj.transform.position;
|
||||
var bounds = obj.GetComponent<Renderer>().bounds.extents;
|
||||
void ClampPosition(Image image) {
|
||||
RectTransform birdRect = image.GetComponent<RectTransform>();
|
||||
float halfW = canvasRect.rect.width / 2f;
|
||||
float halfBirdW = birdRect.rect.width / 2f;
|
||||
|
||||
float zDist = Mathf.Abs(cam.transform.position.z - pos.z);
|
||||
|
||||
UnityEngine.Vector3 min = cam.ViewportToWorldPoint(new UnityEngine.Vector3(0, 0, zDist));
|
||||
UnityEngine.Vector3 max = cam.ViewportToWorldPoint(new UnityEngine.Vector3(1, 1, zDist));
|
||||
|
||||
pos.x = Mathf.Clamp(pos.x, min.x + bounds.x, max.x - bounds.x);
|
||||
if (modifyY) pos.y = Mathf.Clamp(pos.y, min.y + bounds.y, max.y - bounds.y);
|
||||
|
||||
obj.transform.position = pos;
|
||||
UnityEngine.Vector2 pos = birdRect.anchoredPosition;
|
||||
pos.x = Mathf.Clamp(pos.x, -halfW + halfBirdW, halfW - halfBirdW);
|
||||
birdRect.anchoredPosition = pos;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
@@ -293,217 +277,96 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
}
|
||||
float spawnProbability = UnityEngine.Random.value;
|
||||
if (!pausePanel.activeSelf) {
|
||||
GameObject newBerry = new("Berry");
|
||||
Image newBerry = Instantiate(berryTemplate).GetComponent<Image>();
|
||||
newBerry.transform.SetParent(berryParent.transform);
|
||||
SpriteRenderer spriteRenderer = newBerry.AddComponent<SpriteRenderer>();
|
||||
|
||||
if (spawnProbability <= 0.425f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/Berry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/Berry");
|
||||
newBerry.tag = "NormalBerry";
|
||||
} else if (spawnProbability <= 0.60) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/PoisonBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/PoisonBerry");
|
||||
newBerry.tag = "PoisonBerry";
|
||||
} else if (spawnProbability <= 0.65f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/SlowBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/SlowBerry");
|
||||
newBerry.tag = "SlowBerry";
|
||||
} else if (spawnProbability <= 0.75f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/UltraBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/UltraBerry");
|
||||
newBerry.tag = "UltraBerry";
|
||||
} else if (spawnProbability <= 0.85f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/SpeedyBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/SpeedyBerry");
|
||||
newBerry.tag = "SpeedyBerry";
|
||||
} else if (spawnProbability <= 0.90f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/BerryNoColor");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/BerryNoColor");
|
||||
newBerry.tag = "RandomBerry";
|
||||
RainbowSpriteRender randomBerryRainbowImage = newBerry.AddComponent<RainbowSpriteRender>();
|
||||
RainbowImage randomBerryRainbowImage = newBerry.gameObject.AddComponent<RainbowImage>();
|
||||
randomBerryRainbowImage.frequency = 5f;
|
||||
} else if (spawnProbability <= 0.95f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/AntiBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/AntiBerry");
|
||||
newBerry.tag = "AntiBerry";
|
||||
} else {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/GoldenBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/GoldenBerry");
|
||||
newBerry.tag = "GoldenBerry";
|
||||
}
|
||||
spriteRenderer.sortingOrder = -5;
|
||||
|
||||
float screenWidth = Camera.main.orthographicSize * 2 * Camera.main.aspect;
|
||||
float spawnPositionX = UnityEngine.Random.Range(-screenWidth / 2.17f, screenWidth / 2.17f);
|
||||
newBerry.transform.position = new UnityEngine.Vector3(spawnPositionX, Camera.main.orthographicSize + 1f, 0f);
|
||||
|
||||
Rigidbody2D rb = newBerry.AddComponent<Rigidbody2D>();
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
float spawnPositionX = UnityEngine.Random.Range(-(canvasRect.rect.width / 2 - newBerry.rectTransform.rect.width), canvasRect.rect.width / 2 - newBerry.rectTransform.rect.width);
|
||||
newBerry.transform.localPosition = new UnityEngine.Vector3(spawnPositionX, (canvasRect.rect.height / 2) + newBerry.rectTransform.rect.height, 0f);
|
||||
newBerry.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) {
|
||||
audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
}
|
||||
if (screenWidth != Camera.main.orthographicSize * 2f * Camera.main.aspect) {
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
ClampPosition(bird);
|
||||
GameObject[] allberries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allberries) {
|
||||
ClampPosition(berry, false);
|
||||
}
|
||||
}
|
||||
GameObject[] normalBerries = GameObject.FindGameObjectsWithTag("NormalBerry");
|
||||
GameObject[] poisonBerries = GameObject.FindGameObjectsWithTag("PoisonBerry");
|
||||
GameObject[] slowBerries = GameObject.FindGameObjectsWithTag("SlowBerry");
|
||||
GameObject[] ultraBerries = GameObject.FindGameObjectsWithTag("UltraBerry");
|
||||
GameObject[] speedyBerries = GameObject.FindGameObjectsWithTag("SpeedyBerry");
|
||||
GameObject[] randomBerries = GameObject.FindGameObjectsWithTag("RandomBerry");
|
||||
GameObject[] antiBerries = GameObject.FindGameObjectsWithTag("AntiBerry");
|
||||
GameObject[] goldenBerries = GameObject.FindGameObjectsWithTag("GoldenBerry");
|
||||
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
|
||||
if (!pausePanel.activeSelf) {
|
||||
if (Time.time - lastMoveTime > 20) {
|
||||
lastMoveTime = float.MaxValue;
|
||||
EnablePause();
|
||||
}
|
||||
CheckIfGrounded();
|
||||
foreach (GameObject normalBerry in normalBerries) {
|
||||
if (normalBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(normalBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, normalBerry.transform.position) < 1.5f) {
|
||||
totalNormalBerries++;
|
||||
DoNormalBerry(normalBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
normalBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
normalBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("CoinBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
|
||||
.ToArray();
|
||||
|
||||
if (!pausePanel.activeSelf) foreach (GameObject berry in allBerries) {
|
||||
if (berry.GetComponent<RectTransform>().anchoredPosition.y < -(canvasRect.rect.height / 2) - berry.GetComponent<RectTransform>().rect.height) Destroy(berry);
|
||||
else if (Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), berry.GetComponent<CircleCollider2D>()).distance <= 0.1f) {
|
||||
switch (berry.tag) {
|
||||
case "NormalBerry":
|
||||
DoNormalBerry(berry, true);
|
||||
break;
|
||||
case "PoisonBerry":
|
||||
DoPoisonBerry();
|
||||
break;
|
||||
case "SlowBerry":
|
||||
DoSlowBerry(berry, true);
|
||||
break;
|
||||
case "UltraBerry":
|
||||
DoUltraBerry(berry, true);
|
||||
break;
|
||||
case "SpeedyBerry":
|
||||
DoSpeedyBerry(berry, true);
|
||||
break;
|
||||
case "RandomBerry":
|
||||
DoRandomBerry(berry);
|
||||
break;
|
||||
case "AntiBerry":
|
||||
DoAntiBerry(berry, true);
|
||||
break;
|
||||
case "GoldenBerry":
|
||||
DoGoldenBerry(berry, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (GameObject poisonBerry in poisonBerries) {
|
||||
if (poisonBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(poisonBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, poisonBerry.transform.position) < 1.5f) {
|
||||
totalPoisonBerries++;
|
||||
DoPoisonBerry();
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
poisonBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
poisonBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject slowBerry in slowBerries) {
|
||||
if (slowBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(slowBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, slowBerry.transform.position) < 1.5f) {
|
||||
totalSlowBerries++;
|
||||
DoSlowBerry(slowBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
slowBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
slowBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject ultraBerry in ultraBerries) {
|
||||
if (ultraBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(ultraBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, ultraBerry.transform.position) < 1.5f) {
|
||||
totalUltraBerries++;
|
||||
DoUltraBerry(ultraBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
ultraBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
ultraBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject speedyBerry in speedyBerries) {
|
||||
if (speedyBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(speedyBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, speedyBerry.transform.position) < 1.5f) {
|
||||
totalSpeedyBerries++;
|
||||
DoSpeedyBerry(speedyBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
speedyBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
speedyBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject randomBerry in randomBerries) {
|
||||
if (randomBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(randomBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, randomBerry.transform.position) < 1.5f) {
|
||||
totalRandomBerries++;
|
||||
Action[] funcs = {
|
||||
() => DoNormalBerry(randomBerry),
|
||||
() => DoSlowBerry(randomBerry),
|
||||
() => DoUltraBerry(randomBerry),
|
||||
() => DoSpeedyBerry(randomBerry),
|
||||
() => DoAntiBerry(randomBerry),
|
||||
() => DoGoldenBerry(randomBerry)
|
||||
};
|
||||
funcs[UnityEngine.Random.Range(0, funcs.Length)]();
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
randomBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
randomBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject antiBerry in antiBerries) {
|
||||
if (antiBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(antiBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, antiBerry.transform.position) < 1.5f) {
|
||||
totalAntiBerries++;
|
||||
DoAntiBerry(antiBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
antiBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
antiBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject goldenBerry in goldenBerries) {
|
||||
if (goldenBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(goldenBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, goldenBerry.transform.position) < 1.5f) {
|
||||
totalGoldenBerries++;
|
||||
DoGoldenBerry(goldenBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
goldenBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
goldenBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = UnityEngine.Vector2.zero;
|
||||
GameObject[] allberries = normalBerries
|
||||
.Concat(poisonBerries)
|
||||
.Concat(slowBerries)
|
||||
.Concat(ultraBerries)
|
||||
.Concat(speedyBerries)
|
||||
.Concat(randomBerries)
|
||||
.Concat(antiBerries)
|
||||
.Concat(goldenBerries)
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allberries) {
|
||||
berry.GetComponent<Rigidbody2D>().linearVelocity = UnityEngine.Vector2.zero;
|
||||
}
|
||||
if (berry != null) berry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, speedyLeft < 0 ? 200f : -375f);
|
||||
}
|
||||
else foreach (GameObject berry in allBerries) berry.GetComponent<Rigidbody2D>().linearVelocity = UnityEngine.Vector2.zero;
|
||||
if ((Application.platform == RuntimePlatform.Android && Keyboard.current.escapeKey.wasPressedThisFrame) || !Application.isMobilePlatform && (Keyboard.current.escapeKey.wasPressedThisFrame || (Gamepad.current != null && (Gamepad.current.startButton.wasPressedThisFrame || Gamepad.current.buttonEast.wasPressedThisFrame)))) TogglePause();
|
||||
}
|
||||
|
||||
void Respawn() {
|
||||
bird.transform.position = new UnityEngine.Vector3(0f, -4.3f, 0f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1.35f, 1.35f, 1.35f);
|
||||
bird.GetComponent<RectTransform>().anchoredPosition = new UnityEngine.Vector3(0f, 64f, 0f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = UnityEngine.Vector2.zero;
|
||||
score = 0;
|
||||
@@ -513,7 +376,7 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
antiLeft = 0f;
|
||||
UpdateStats(0, 1);
|
||||
|
||||
GameObject[] allberries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
|
||||
@@ -522,9 +385,7 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allberries) {
|
||||
Destroy(berry);
|
||||
}
|
||||
foreach (GameObject berry in allBerries) Destroy(berry);
|
||||
}
|
||||
|
||||
void UpdateStats(BigInteger scoreAddAmount, BigInteger attemptAddAmount) {
|
||||
@@ -548,23 +409,15 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
if (level != levelBefore) AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Levelup"), Camera.main.transform.position, 1f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
}
|
||||
|
||||
void CheckIfGrounded() {
|
||||
isGrounded = bird.transform.position.y <= -4.1299996f;
|
||||
|
||||
rb.gravityScale = isGrounded ? 0f : 1.5f;
|
||||
|
||||
if (bird.transform.position.y < -4.1359f) {
|
||||
bird.transform.position = new UnityEngine.Vector2(bird.transform.position.x, -4.1359f);
|
||||
rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TogglePause() {
|
||||
if (pausePanel.activeSelf) DisablePause();
|
||||
else EnablePause();
|
||||
}
|
||||
|
||||
internal void EnablePause() {
|
||||
velocityBeforePause = rb.linearVelocity;
|
||||
rb.linearVelocity = new();
|
||||
rb.gravityScale = 0f;
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
backgroundMusic.GetComponent<GameMusicHandler>().PauseMusic();
|
||||
@@ -572,6 +425,9 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
}
|
||||
|
||||
internal void DisablePause() {
|
||||
rb.gravityScale = 80f;
|
||||
rb.linearVelocity = velocityBeforePause;
|
||||
velocityBeforePause = new();
|
||||
if (AutoGamePlayerPauseMenu.Instance.statsMenu.activeSelf) {
|
||||
AutoGamePlayerPauseMenu.Instance.statsMenuExitButton.onClick.Invoke();
|
||||
return;
|
||||
@@ -580,7 +436,6 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
AutoGamePlayerPauseMenu.Instance.ToggleEditingUI();
|
||||
return;
|
||||
}
|
||||
lastMoveTime = Time.time;
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
backgroundMusic.GetComponent<GameMusicHandler>().ResumeMusic();
|
||||
@@ -596,19 +451,22 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
void DoNormalBerry(GameObject berry) {
|
||||
void DoNormalBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalNormalBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Eat"), Camera.main.transform.position, 1.2f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
UpdateStats(1, 0);
|
||||
}
|
||||
|
||||
void DoPoisonBerry() {
|
||||
totalPoisonBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Death"), Camera.main.transform.position, 1.2f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Respawn();
|
||||
UpdateStats(0, 0);
|
||||
}
|
||||
|
||||
void DoSlowBerry(GameObject berry) {
|
||||
void DoSlowBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalSlowBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Downgrade"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
boostLeft = 0f;
|
||||
@@ -621,7 +479,8 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
void DoUltraBerry(GameObject berry) {
|
||||
void DoUltraBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalUltraBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Powerup"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
speedyLeft = 0f;
|
||||
@@ -636,7 +495,8 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
void DoSpeedyBerry(GameObject berry) {
|
||||
void DoSpeedyBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalSpeedyBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/SpeedyPowerup"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
boostLeft = 0f;
|
||||
@@ -647,7 +507,21 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
UpdateStats(10, 0);
|
||||
}
|
||||
|
||||
void DoAntiBerry(GameObject berry) {
|
||||
void DoRandomBerry(GameObject berry) {
|
||||
totalRandomBerries++;
|
||||
Action[] funcs = {
|
||||
() => DoNormalBerry(berry, false),
|
||||
() => DoSlowBerry(berry, false),
|
||||
() => DoUltraBerry(berry, false),
|
||||
() => DoSpeedyBerry(berry, false),
|
||||
() => DoAntiBerry(berry, false),
|
||||
() => DoGoldenBerry(berry, false)
|
||||
};
|
||||
funcs[UnityEngine.Random.Range(0, funcs.Length)]();
|
||||
}
|
||||
|
||||
void DoAntiBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalAntiBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Downgrade"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
boostLeft = 0f;
|
||||
@@ -658,7 +532,8 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
UpdateStats(0, 0);
|
||||
}
|
||||
|
||||
void DoGoldenBerry(GameObject berry) {
|
||||
void DoGoldenBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalGoldenBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Powerup"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
boostLeft = 0f;
|
||||
|
||||
@@ -17,16 +17,10 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
private float speedyLeft;
|
||||
private float antiLeft;
|
||||
private float goldenLeft;
|
||||
private float screenWidth;
|
||||
internal bool isGrounded;
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
[SerializeField] private TMP_Text boostText;
|
||||
[SerializeField] private GameObject bird;
|
||||
[SerializeField] private GameObject pausePanel;
|
||||
[SerializeField] private Rigidbody2D rb;
|
||||
public AudioSource backgroundMusic;
|
||||
[SerializeField] private SpriteRenderer overlayRender;
|
||||
private float lastMoveTime;
|
||||
[SerializeField] internal AudioSource backgroundMusic;
|
||||
[SerializeField] private GameObject berryParent;
|
||||
|
||||
[SerializeField] private GameObject mobileButtons;
|
||||
@@ -47,11 +41,19 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
private float nothingBerryChance;
|
||||
private bool useAI;
|
||||
|
||||
[SerializeField] private Image bird;
|
||||
[SerializeField] private GameObject berryTemplate;
|
||||
[SerializeField] private Rigidbody2D rb;
|
||||
[SerializeField] private RectTransform canvasRect;
|
||||
[SerializeField] private BoxCollider2D groundCollider;
|
||||
private UnityEngine.Vector2 velocityBeforePause = new();
|
||||
|
||||
internal bool IsGrounded() => Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), groundCollider).distance <= 0.1f;
|
||||
|
||||
[SerializeField] private TMP_Text aiText;
|
||||
|
||||
void Awake() {
|
||||
Instance = this;
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
}
|
||||
|
||||
void Start() {
|
||||
@@ -73,7 +75,6 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
Destroy(customGameTempData.gameObject);
|
||||
if (useAI) aiText.gameObject.SetActive(true);
|
||||
|
||||
SpriteRenderer birdRender = bird.GetComponent<SpriteRenderer>();
|
||||
if (!useAI) {
|
||||
var backgroundColor = BazookaManager.Instance.GetColorSettingBackground();
|
||||
Camera.main.backgroundColor = new Color(
|
||||
@@ -82,59 +83,17 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
int.Parse(backgroundColor[2].ToString()) / 255f
|
||||
);
|
||||
|
||||
var customIconData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
if (customIconData.Selected == null) {
|
||||
var birdColor = BazookaManager.Instance.GetColorSettingIcon();
|
||||
var overlayColor = BazookaManager.Instance.GetColorSettingOverlay();
|
||||
bird.GetComponent<SpriteRenderer>().color = new Color(
|
||||
int.Parse(birdColor[0].ToString()) / 255f,
|
||||
int.Parse(birdColor[1].ToString()) / 255f,
|
||||
int.Parse(birdColor[2].ToString()) / 255f
|
||||
);
|
||||
bird.transform.GetChild(0).GetComponent<SpriteRenderer>().color = new Color(
|
||||
int.Parse(overlayColor[0].ToString()) / 255f,
|
||||
int.Parse(overlayColor[1].ToString()) / 255f,
|
||||
int.Parse(overlayColor[2].ToString()) / 255f
|
||||
);
|
||||
|
||||
int icon = BazookaManager.Instance.GetBirdIcon();
|
||||
int iconOverlay = BazookaManager.Instance.GetBirdOverlay();
|
||||
if (icon == 1) {
|
||||
birdRender.sprite = Tools.GetIconForUser(BazookaManager.Instance.GetAccountID() ?? 0);
|
||||
} else {
|
||||
birdRender.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + icon);
|
||||
}
|
||||
if (iconOverlay == 8) {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + iconOverlay);
|
||||
overlayRender.transform.localPosition = new UnityEngine.Vector3(-0.37f, 0.32f, 0f);
|
||||
} else if (iconOverlay == 11) {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + iconOverlay);
|
||||
overlayRender.transform.localScale = new UnityEngine.Vector3(1.1f, 1.1f, 1.1f); //yea i didnt feel like doing it for all lmao
|
||||
overlayRender.transform.localPosition = new UnityEngine.Vector3(-0.3141809f, 0.4324968f, 0f);
|
||||
} else if (iconOverlay == 13) {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + iconOverlay);
|
||||
overlayRender.transform.localPosition = new UnityEngine.Vector3(-0.3559977f, 0.3179995f, 0f);
|
||||
} else {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + iconOverlay);
|
||||
}
|
||||
if (birdRender.sprite == null) {
|
||||
birdRender.sprite = Resources.Load<Sprite>("Icons/Icons/bird_1");
|
||||
BazookaManager.Instance.SetBirdIcon(1);
|
||||
}
|
||||
if (overlayRender.sprite == null && iconOverlay != 0) {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_1");
|
||||
BazookaManager.Instance.SetBirdOverlay(1);
|
||||
}
|
||||
} else if (customIconData.Selected != null)
|
||||
foreach (var icon in customIconData.Purchased)
|
||||
if (icon == customIconData.Selected) {
|
||||
var waitingForCustomIcon = birdRender.gameObject.AddComponent<WaitingForCustomIcon>();
|
||||
waitingForCustomIcon.ID = customIconData.Selected;
|
||||
CustomIconLoader.Init(new[] { waitingForCustomIcon });
|
||||
}
|
||||
Tools.LoadIcon(
|
||||
bird,
|
||||
bird.transform.GetChild(0).GetComponent<Image>(),
|
||||
BazookaManager.Instance.GetBirdIcon(),
|
||||
BazookaManager.Instance.GetBirdOverlay(),
|
||||
BazookaManager.Instance.GetColorSettingIcon(),
|
||||
BazookaManager.Instance.GetColorSettingOverlay(),
|
||||
BazookaManager.Instance.GetCustomBirdIconData().Selected
|
||||
);
|
||||
} else {
|
||||
birdRender.sprite = Resources.Load<Sprite>("Icons/Icons/bird_1");
|
||||
Destroy(overlayRender.gameObject);
|
||||
Destroy(bird.transform.GetChild(0).gameObject);
|
||||
var rainbowCam = Camera.main.gameObject.AddComponent<RainbowCamera>();
|
||||
rainbowCam.frequency = 4f;
|
||||
rainbowCam.brightness = 24;
|
||||
@@ -144,9 +103,7 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
leftButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
lastMoveTime = Time.time;
|
||||
UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
|
||||
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
backgroundMusic.volume = BazookaManager.Instance.GetSettingMusicVolume();
|
||||
@@ -155,20 +112,14 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
|
||||
void MoveBird() {
|
||||
float screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
float baseSpeed = 0.18f * (screenWidth / 20.19257f);
|
||||
float speedModifier = 1f;
|
||||
bool doMoveRight = false;
|
||||
bool doMoveLeft = false;
|
||||
bool doJump = false;
|
||||
bool doRestart = false;
|
||||
bool doBack = false;
|
||||
float movespeed = baseSpeed;
|
||||
if (boostLeft > 0f || speedyLeft > 0f) {
|
||||
movespeed = baseSpeed * 1.39f;
|
||||
} else if (slownessLeft > 0f) {
|
||||
movespeed = baseSpeed * 0.56f;
|
||||
}
|
||||
CheckIfGrounded();
|
||||
if (boostLeft > 0f || speedyLeft > 0f) speedModifier = 1.39f;
|
||||
else if (slownessLeft > 0f) speedModifier = 0.56f;
|
||||
bool controllerLeft = Gamepad.current != null && (Gamepad.current.leftStick.left.isPressed || Gamepad.current.dpad.left.isPressed || Gamepad.current.rightStick.left.isPressed);
|
||||
bool controllerRight = Gamepad.current != null && (Gamepad.current.leftStick.right.isPressed || Gamepad.current.dpad.right.isPressed || Gamepad.current.rightStick.right.isPressed);
|
||||
bool controllerJump = Gamepad.current != null && (Gamepad.current.leftStick.up.isPressed || Gamepad.current.leftStick.down.isPressed || Gamepad.current.dpad.up.isPressed || Gamepad.current.dpad.down.isPressed || Gamepad.current.rightStick.up.isPressed || Gamepad.current.rightStick.down.isPressed);
|
||||
@@ -199,27 +150,21 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(-movespeed, 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(-(1.7f * speedModifier), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1.35f, 1.35f, 1.35f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(movespeed, 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(1.7f * speedModifier, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1.35f, 1.35f, 1.35f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doJump && isGrounded) {
|
||||
lastMoveTime = Time.time;
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded()) {
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 12f;
|
||||
} else if (slownessLeft > 0f) {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 6f;
|
||||
} else {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 9f;
|
||||
}
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f);
|
||||
else if (slownessLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 220f);
|
||||
else rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 300f);
|
||||
}
|
||||
if (doBack) {
|
||||
TogglePause();
|
||||
@@ -235,7 +180,7 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
UnityEngine.Vector3 dir = berry.transform.position - bird.transform.position;
|
||||
if (dir.magnitude < (antiLeft > 0 ? 3f : 4.5f)) {
|
||||
berry.GetComponent<Rigidbody2D>().linearVelocity = dir.normalized * (antiLeft > 0 ? 5f : -5f);
|
||||
ClampPosition(berry, false);
|
||||
ClampPosition(berry.GetComponent<Image>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,22 +188,16 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
|
||||
void MoveBirdAI() {
|
||||
float screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
float baseSpeed = 0.18f * (screenWidth / 20.19257f);
|
||||
float speedModifier = 1f;
|
||||
bool doMoveRight = false;
|
||||
bool doMoveLeft = false;
|
||||
bool doJump = false;
|
||||
bool doBack = false;
|
||||
float movespeed = baseSpeed;
|
||||
if (boostLeft > 0f || speedyLeft > 0f) {
|
||||
movespeed = baseSpeed * 1.39f;
|
||||
} else if (slownessLeft > 0f) {
|
||||
movespeed = baseSpeed * 0.56f;
|
||||
}
|
||||
CheckIfGrounded();
|
||||
if (boostLeft > 0f || speedyLeft > 0f) speedModifier = 1.39f;
|
||||
else if (slownessLeft > 0f) speedModifier = 0.56f;
|
||||
|
||||
float birdX = bird.transform.position.x;
|
||||
float birdY = bird.transform.position.y;
|
||||
float birdX = bird.GetComponent<RectTransform>().anchoredPosition.x;
|
||||
float birdY = bird.GetComponent<RectTransform>().anchoredPosition.y;
|
||||
|
||||
var berryScores = new System.Collections.Generic.Dictionary<string, float> {
|
||||
{ "NormalBerry", 1f },
|
||||
@@ -274,7 +213,8 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
var allBerries = new System.Collections.Generic.List<(float x, float y, float score)>();
|
||||
foreach (var kvp in berryScores) {
|
||||
foreach (var b in GameObject.FindGameObjectsWithTag(kvp.Key)) {
|
||||
allBerries.Add((b.transform.position.x, b.transform.position.y, kvp.Value));
|
||||
var rt = b.GetComponent<RectTransform>();
|
||||
allBerries.Add((rt.anchoredPosition.x, rt.anchoredPosition.y, kvp.Value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +240,7 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
|
||||
float closestBadX = float.MaxValue;
|
||||
float closestBadDist = float.MaxValue;
|
||||
float dodgeLookahead = collectRadius + movespeed * 8f;
|
||||
float dodgeLookahead = collectRadius + 1.7f * speedModifier * 8f;
|
||||
|
||||
foreach (var (bx, by, score) in allBerries) {
|
||||
if (score >= 0f) continue;
|
||||
@@ -342,7 +282,7 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
clusters.Add((wTotal > 0f ? wX / wTotal : ax, wY / count, total));
|
||||
}
|
||||
|
||||
float bestScore = 0f;
|
||||
float bestScore = float.MinValue;
|
||||
float bestX = float.MaxValue;
|
||||
bool foundTarget = false;
|
||||
|
||||
@@ -350,9 +290,8 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
if (cs <= 0f) continue;
|
||||
if (PathHasDanger(cx)) continue;
|
||||
float dist = Mathf.Abs(cx - birdX);
|
||||
float adjusted = cs - dist * 0.05f;
|
||||
if (adjusted > bestScore) {
|
||||
bestScore = adjusted;
|
||||
if (cs > bestScore) {
|
||||
bestScore = cs;
|
||||
bestX = cx;
|
||||
foundTarget = true;
|
||||
}
|
||||
@@ -385,60 +324,48 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(-movespeed, 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(-(1.7f * speedModifier), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1.35f, 1.35f, 1.35f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(movespeed, 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(1.7f * speedModifier, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1.35f, 1.35f, 1.35f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doJump && isGrounded) {
|
||||
lastMoveTime = Time.time;
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded()) {
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 12f;
|
||||
} else if (slownessLeft > 0f) {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 6f;
|
||||
} else {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 9f;
|
||||
}
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f);
|
||||
else if (slownessLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 220f);
|
||||
else rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 300f);
|
||||
}
|
||||
if (doBack) {
|
||||
TogglePause();
|
||||
}
|
||||
if (antiLeft > 0f || goldenLeft > 0f) {
|
||||
string[] berryTags = { "NormalBerry", "SlowBerry", "UltraBerry", "SpeedyBerry", "RandomBerry", "AntiBerry", "GoldenBerry", "NothingBerry" };
|
||||
string[] berryTags = { "NormalBerry", "SlowBerry", "UltraBerry", "SpeedyBerry", "RandomBerry", "AntiBerry", "GoldenBerry" };
|
||||
if (antiLeft > 0f) berryTags.Append("PoisonBerry");
|
||||
foreach (string tag in berryTags) {
|
||||
foreach (var berry in GameObject.FindGameObjectsWithTag(tag)) {
|
||||
UnityEngine.Vector3 dir = berry.transform.position - bird.transform.position;
|
||||
if (dir.magnitude < (antiLeft > 0 ? 3f : 4.5f)) {
|
||||
berry.GetComponent<Rigidbody2D>().linearVelocity = dir.normalized * (antiLeft > 0 ? 5f : -5f);
|
||||
ClampPosition(berry, false);
|
||||
ClampPosition(berry.GetComponent<Image>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClampPosition(GameObject obj, bool modifyY = true) {
|
||||
var cam = Camera.main;
|
||||
var pos = obj.transform.position;
|
||||
var bounds = obj.GetComponent<Renderer>().bounds.extents;
|
||||
void ClampPosition(Image image) {
|
||||
RectTransform birdRect = image.GetComponent<RectTransform>();
|
||||
float halfW = canvasRect.rect.width / 2f;
|
||||
float halfBirdW = birdRect.rect.width / 2f;
|
||||
|
||||
float zDist = Mathf.Abs(cam.transform.position.z - pos.z);
|
||||
|
||||
UnityEngine.Vector3 min = cam.ViewportToWorldPoint(new UnityEngine.Vector3(0, 0, zDist));
|
||||
UnityEngine.Vector3 max = cam.ViewportToWorldPoint(new UnityEngine.Vector3(1, 1, zDist));
|
||||
|
||||
pos.x = Mathf.Clamp(pos.x, min.x + bounds.x, max.x - bounds.x);
|
||||
if (modifyY) pos.y = Mathf.Clamp(pos.y, min.y + bounds.y, max.y - bounds.y);
|
||||
|
||||
obj.transform.position = pos;
|
||||
UnityEngine.Vector2 pos = birdRect.anchoredPosition;
|
||||
pos.x = Mathf.Clamp(pos.x, -halfW + halfBirdW, halfW - halfBirdW);
|
||||
birdRect.anchoredPosition = pos;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
@@ -479,263 +406,76 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
float spawnProbability = Random.value;
|
||||
if (!pausePanel.activeSelf) {
|
||||
float cumulative = 0f;
|
||||
GameObject newBerry = new("Berry");
|
||||
Image newBerry = Instantiate(berryTemplate).GetComponent<Image>();
|
||||
newBerry.transform.SetParent(berryParent.transform);
|
||||
SpriteRenderer spriteRenderer = newBerry.AddComponent<SpriteRenderer>();
|
||||
|
||||
cumulative += normalBerryChance / 100f;
|
||||
if (spawnProbability <= cumulative) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/Berry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/Berry");
|
||||
newBerry.tag = "NormalBerry";
|
||||
goto finish;
|
||||
}
|
||||
cumulative += poisonBerryChance / 100f;
|
||||
if (spawnProbability <= cumulative) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/PoisonBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/PoisonBerry");
|
||||
newBerry.tag = "PoisonBerry";
|
||||
goto finish;
|
||||
}
|
||||
cumulative += slowBerryChance / 100f;
|
||||
if (spawnProbability <= cumulative) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/SlowBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/SlowBerry");
|
||||
newBerry.tag = "SlowBerry";
|
||||
goto finish;
|
||||
}
|
||||
cumulative += ultraBerryChance / 100f;
|
||||
if (spawnProbability <= cumulative) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/UltraBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/UltraBerry");
|
||||
newBerry.tag = "UltraBerry";
|
||||
goto finish;
|
||||
}
|
||||
cumulative += speedyBerryChance / 100f;
|
||||
if (spawnProbability <= cumulative) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/SpeedyBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/SpeedyBerry");
|
||||
newBerry.tag = "SpeedyBerry";
|
||||
goto finish;
|
||||
}
|
||||
cumulative += randomBerryChance / 100f;
|
||||
if (spawnProbability <= cumulative) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/BerryNoColor");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/BerryNoColor");
|
||||
newBerry.tag = "RandomBerry";
|
||||
RainbowSpriteRender randomBerryRainbowImage = newBerry.AddComponent<RainbowSpriteRender>();
|
||||
RainbowImage randomBerryRainbowImage = newBerry.gameObject.AddComponent<RainbowImage>();
|
||||
randomBerryRainbowImage.frequency = 5f;
|
||||
goto finish;
|
||||
}
|
||||
cumulative += antiBerryChance / 100f;
|
||||
if (spawnProbability <= cumulative) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/AntiBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/AntiBerry");
|
||||
newBerry.tag = "AntiBerry";
|
||||
goto finish;
|
||||
}
|
||||
cumulative += goldenBerryChance / 100f;
|
||||
if (spawnProbability <= cumulative) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/GoldenBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/GoldenBerry");
|
||||
newBerry.tag = "GoldenBerry";
|
||||
goto finish;
|
||||
}
|
||||
cumulative += nothingBerryChance / 100f;
|
||||
if (spawnProbability <= cumulative) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/BerryNoColor");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/BerryNoColor");
|
||||
newBerry.tag = "NothingBerry";
|
||||
goto finish;
|
||||
}
|
||||
finish:
|
||||
spriteRenderer.sortingOrder = -5;
|
||||
|
||||
float screenWidth = Camera.main.orthographicSize * 2 * Camera.main.aspect;
|
||||
float spawnPositionX = Random.Range(-screenWidth / 2.17f, screenWidth / 2.17f);
|
||||
newBerry.transform.position = new UnityEngine.Vector3(spawnPositionX, Camera.main.orthographicSize + 1f, 0f);
|
||||
|
||||
Rigidbody2D rb = newBerry.AddComponent<Rigidbody2D>();
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
float spawnPositionX = Random.Range(-(canvasRect.rect.width / 2 - newBerry.rectTransform.rect.width), canvasRect.rect.width / 2 - newBerry.rectTransform.rect.width);
|
||||
newBerry.transform.localPosition = new UnityEngine.Vector3(spawnPositionX, (canvasRect.rect.height / 2) + newBerry.rectTransform.rect.height, 0f);
|
||||
newBerry.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) {
|
||||
audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
}
|
||||
if (screenWidth != Camera.main.orthographicSize * 2f * Camera.main.aspect) {
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
ClampPosition(bird);
|
||||
GameObject[] allberries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("NothingBerry"))
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allberries) {
|
||||
ClampPosition(berry, false);
|
||||
}
|
||||
}
|
||||
GameObject[] normalBerries = GameObject.FindGameObjectsWithTag("NormalBerry");
|
||||
GameObject[] poisonBerries = GameObject.FindGameObjectsWithTag("PoisonBerry");
|
||||
GameObject[] slowBerries = GameObject.FindGameObjectsWithTag("SlowBerry");
|
||||
GameObject[] ultraBerries = GameObject.FindGameObjectsWithTag("UltraBerry");
|
||||
GameObject[] speedyBerries = GameObject.FindGameObjectsWithTag("SpeedyBerry");
|
||||
GameObject[] randomBerries = GameObject.FindGameObjectsWithTag("RandomBerry");
|
||||
GameObject[] antiBerries = GameObject.FindGameObjectsWithTag("AntiBerry");
|
||||
GameObject[] goldenBerries = GameObject.FindGameObjectsWithTag("GoldenBerry");
|
||||
GameObject[] nothingBerries = GameObject.FindGameObjectsWithTag("NothingBerry");
|
||||
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
|
||||
if (!pausePanel.activeSelf) {
|
||||
if (Time.time - lastMoveTime > 20) {
|
||||
lastMoveTime = float.MaxValue;
|
||||
EnablePause();
|
||||
}
|
||||
CheckIfGrounded();
|
||||
foreach (GameObject normalBerry in normalBerries) {
|
||||
if (normalBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(normalBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, normalBerry.transform.position) < 1.5f) {
|
||||
DoNormalBerry(normalBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
normalBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
normalBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject poisonBerry in poisonBerries) {
|
||||
if (poisonBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(poisonBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, poisonBerry.transform.position) < 1.5f) {
|
||||
DoPoisonBerry();
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
poisonBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
poisonBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject slowBerry in slowBerries) {
|
||||
if (slowBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(slowBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, slowBerry.transform.position) < 1.5f) {
|
||||
DoSlowBerry(slowBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
slowBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
slowBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject ultraBerry in ultraBerries) {
|
||||
if (ultraBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(ultraBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, ultraBerry.transform.position) < 1.5f) {
|
||||
DoUltraBerry(ultraBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
ultraBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
ultraBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject speedyBerry in speedyBerries) {
|
||||
if (speedyBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(speedyBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, speedyBerry.transform.position) < 1.5f) {
|
||||
DoSpeedyBerry(speedyBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
speedyBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
speedyBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject randomBerry in randomBerries) {
|
||||
if (randomBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(randomBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, randomBerry.transform.position) < 1.5f) {
|
||||
System.Action[] funcs = {
|
||||
() => DoNormalBerry(randomBerry),
|
||||
() => DoSlowBerry(randomBerry),
|
||||
() => DoUltraBerry(randomBerry),
|
||||
() => DoSpeedyBerry(randomBerry),
|
||||
() => DoAntiBerry(randomBerry)
|
||||
};
|
||||
funcs[Random.Range(0, funcs.Length)]();
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
randomBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
randomBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject antiBerry in antiBerries) {
|
||||
if (antiBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(antiBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, antiBerry.transform.position) < 1.5f) {
|
||||
DoAntiBerry(antiBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
antiBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
antiBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject goldenBerry in goldenBerries) {
|
||||
if (goldenBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(goldenBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, goldenBerry.transform.position) < 1.5f) {
|
||||
DoGoldenBerry(goldenBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
goldenBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
goldenBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject nothingBerry in nothingBerries) {
|
||||
if (nothingBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(nothingBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, nothingBerry.transform.position) < 1.5f) {
|
||||
DoNothingBerry(nothingBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
nothingBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
nothingBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = UnityEngine.Vector2.zero;
|
||||
GameObject[] allberries = normalBerries
|
||||
.Concat(poisonBerries)
|
||||
.Concat(slowBerries)
|
||||
.Concat(ultraBerries)
|
||||
.Concat(speedyBerries)
|
||||
.Concat(randomBerries)
|
||||
.Concat(antiBerries)
|
||||
.Concat(goldenBerries)
|
||||
.Concat(nothingBerries)
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allberries) {
|
||||
berry.GetComponent<Rigidbody2D>().linearVelocity = UnityEngine.Vector2.zero;
|
||||
}
|
||||
}
|
||||
if ((Application.platform == RuntimePlatform.Android && Keyboard.current.escapeKey.wasPressedThisFrame) || !Application.isMobilePlatform && (Keyboard.current.escapeKey.wasPressedThisFrame || (Gamepad.current != null && (Gamepad.current.startButton.wasPressedThisFrame || Gamepad.current.buttonEast.wasPressedThisFrame)))) TogglePause();
|
||||
}
|
||||
|
||||
void Respawn() {
|
||||
bird.transform.position = new UnityEngine.Vector3(0f, -4.3f, 0f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1.35f, 1.35f, 1.35f);
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = UnityEngine.Vector2.zero;
|
||||
score = 0;
|
||||
boostLeft = 0f;
|
||||
slownessLeft = 0f;
|
||||
speedyLeft = 0f;
|
||||
antiLeft = 0f;
|
||||
UpdateStats(0, 1);
|
||||
|
||||
GameObject[] allberries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
|
||||
@@ -745,9 +485,69 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("NothingBerry"))
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allberries) {
|
||||
Destroy(berry);
|
||||
|
||||
if (!pausePanel.activeSelf) foreach (GameObject berry in allBerries) {
|
||||
if (berry.GetComponent<RectTransform>().anchoredPosition.y < -(canvasRect.rect.height / 2) - berry.GetComponent<RectTransform>().rect.height) Destroy(berry);
|
||||
else if (Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), berry.GetComponent<CircleCollider2D>()).distance <= 0.1f) {
|
||||
switch (berry.tag) {
|
||||
case "NormalBerry":
|
||||
DoNormalBerry(berry);
|
||||
break;
|
||||
case "PoisonBerry":
|
||||
DoPoisonBerry();
|
||||
break;
|
||||
case "SlowBerry":
|
||||
DoSlowBerry(berry);
|
||||
break;
|
||||
case "UltraBerry":
|
||||
DoUltraBerry(berry);
|
||||
break;
|
||||
case "SpeedyBerry":
|
||||
DoSpeedyBerry(berry);
|
||||
break;
|
||||
case "RandomBerry":
|
||||
DoRandomBerry(berry);
|
||||
break;
|
||||
case "AntiBerry":
|
||||
DoAntiBerry(berry);
|
||||
break;
|
||||
case "GoldenBerry":
|
||||
DoGoldenBerry(berry);
|
||||
break;
|
||||
case "NothingBerry":
|
||||
DoNothingBerry(berry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (berry != null) berry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, speedyLeft < 0 ? 200f : -375f);
|
||||
}
|
||||
else foreach (GameObject berry in allBerries) berry.GetComponent<Rigidbody2D>().linearVelocity = UnityEngine.Vector2.zero;
|
||||
if ((Application.platform == RuntimePlatform.Android && Keyboard.current.escapeKey.wasPressedThisFrame) || !Application.isMobilePlatform && (Keyboard.current.escapeKey.wasPressedThisFrame || (Gamepad.current != null && (Gamepad.current.startButton.wasPressedThisFrame || Gamepad.current.buttonEast.wasPressedThisFrame)))) TogglePause();
|
||||
}
|
||||
|
||||
void Respawn() {
|
||||
bird.GetComponent<RectTransform>().anchoredPosition = new UnityEngine.Vector3(0f, 64f, 0f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = UnityEngine.Vector2.zero;
|
||||
score = 0;
|
||||
boostLeft = 0f;
|
||||
slownessLeft = 0f;
|
||||
speedyLeft = 0f;
|
||||
antiLeft = 0f;
|
||||
UpdateStats(0, 1);
|
||||
|
||||
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("NothingBerry"))
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allBerries) Destroy(berry);
|
||||
}
|
||||
|
||||
void UpdateStats(BigInteger scoreAddAmount, BigInteger attemptAddAmount) {
|
||||
@@ -759,24 +559,15 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
DiscordRPCHandler.Instance.UpdateRPC("Playing in custom mode", "Score: " + Tools.FormatWithCommas(score));
|
||||
}
|
||||
|
||||
void CheckIfGrounded() {
|
||||
isGrounded = bird.transform.position.y <= -4.1299996f;
|
||||
|
||||
rb.gravityScale = isGrounded ? 0f : 1.5f;
|
||||
|
||||
if (bird.transform.position.y < -4.1359f) {
|
||||
bird.transform.position = new UnityEngine.Vector2(bird.transform.position.x, -4.1359f);
|
||||
rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 0f);
|
||||
}
|
||||
if (Application.isMobilePlatform) jumpButton.transform.GetChild(0).GetComponent<TMP_Text>().color = isGrounded ? Color.white : Color.red;
|
||||
}
|
||||
|
||||
internal void TogglePause() {
|
||||
if (pausePanel.activeSelf) DisablePause();
|
||||
else EnablePause();
|
||||
}
|
||||
|
||||
internal void EnablePause() {
|
||||
velocityBeforePause = rb.linearVelocity;
|
||||
rb.linearVelocity = new();
|
||||
rb.gravityScale = 0f;
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
backgroundMusic.GetComponent<GameMusicHandler>().PauseMusic();
|
||||
@@ -784,11 +575,13 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
|
||||
internal void DisablePause() {
|
||||
rb.gravityScale = 80f;
|
||||
rb.linearVelocity = velocityBeforePause;
|
||||
velocityBeforePause = new();
|
||||
if (CustomGamePlayerPauseMenu.Instance.editingUI == true) {
|
||||
CustomGamePlayerPauseMenu.Instance.ToggleEditingUI();
|
||||
return;
|
||||
}
|
||||
lastMoveTime = Time.time;
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
backgroundMusic.GetComponent<GameMusicHandler>().ResumeMusic();
|
||||
@@ -855,6 +648,18 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
UpdateStats(10, 0);
|
||||
}
|
||||
|
||||
void DoRandomBerry(GameObject berry) {
|
||||
System.Action[] funcs = {
|
||||
() => DoNormalBerry(berry),
|
||||
() => DoSlowBerry(berry),
|
||||
() => DoUltraBerry(berry),
|
||||
() => DoSpeedyBerry(berry),
|
||||
() => DoAntiBerry(berry),
|
||||
() => DoGoldenBerry(berry)
|
||||
};
|
||||
funcs[Random.Range(0, funcs.Length)]();
|
||||
}
|
||||
|
||||
void DoAntiBerry(GameObject berry) {
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Downgrade"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class CustomGamePlayerPauseMenu : MonoBehaviour {
|
||||
jumpButton.interactable = !jumpDraggableUI.canDrag;
|
||||
rightButton.interactable = !rightDraggableUI.canDrag;
|
||||
leftButton.interactable = !leftDraggableUI.canDrag;
|
||||
jumpButton.transform.GetChild(0).GetComponent<TMP_Text>().color = !jumpDraggableUI.canDrag ? CustomGamePlayer.Instance.isGrounded ? Color.white : Color.red : Color.white;
|
||||
jumpButton.transform.GetChild(0).GetComponent<TMP_Text>().color = !jumpDraggableUI.canDrag ? CustomGamePlayer.Instance.IsGrounded() ? Color.white : Color.red : Color.white;
|
||||
restartButton.interactable = CustomGamePlayer.Instance.score != 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,18 +29,12 @@ public class GamePlayer : MonoBehaviour {
|
||||
private float speedyLeft;
|
||||
private float antiLeft;
|
||||
private float goldenLeft;
|
||||
private float screenWidth;
|
||||
internal bool isGrounded;
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
[SerializeField] private TMP_Text highScoreText;
|
||||
[SerializeField] private TMP_Text boostText;
|
||||
[SerializeField] private TMP_Text coinText;
|
||||
[SerializeField] private GameObject bird;
|
||||
[SerializeField] private GameObject pausePanel;
|
||||
[SerializeField] private Rigidbody2D rb;
|
||||
public AudioSource backgroundMusic;
|
||||
[SerializeField] private SpriteRenderer overlayRender;
|
||||
private float lastMoveTime;
|
||||
[SerializeField] internal AudioSource backgroundMusic;
|
||||
[SerializeField] private GameObject berryParent;
|
||||
[SerializeField] private TMP_Text levelText;
|
||||
|
||||
@@ -51,9 +45,17 @@ public class GamePlayer : MonoBehaviour {
|
||||
[SerializeField] private Button rightButton;
|
||||
[SerializeField] private Button leftButton;
|
||||
|
||||
[SerializeField] private Image bird;
|
||||
[SerializeField] private GameObject berryTemplate;
|
||||
[SerializeField] private Rigidbody2D rb;
|
||||
[SerializeField] private RectTransform canvasRect;
|
||||
[SerializeField] private BoxCollider2D groundCollider;
|
||||
private UnityEngine.Vector2 velocityBeforePause = new();
|
||||
|
||||
internal bool IsGrounded() => Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), groundCollider).distance <= 0.1f;
|
||||
|
||||
void Awake() {
|
||||
Instance = this;
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
}
|
||||
|
||||
void Start() {
|
||||
@@ -64,59 +66,16 @@ public class GamePlayer : MonoBehaviour {
|
||||
int.Parse(backgroundColor[2].ToString()) / 255f
|
||||
);
|
||||
|
||||
var customIconData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
SpriteRenderer birdRender = bird.GetComponent<SpriteRenderer>();
|
||||
if (customIconData.Selected == null) {
|
||||
var birdColor = BazookaManager.Instance.GetColorSettingIcon();
|
||||
var overlayColor = BazookaManager.Instance.GetColorSettingOverlay();
|
||||
bird.GetComponent<SpriteRenderer>().color = new Color(
|
||||
int.Parse(birdColor[0].ToString()) / 255f,
|
||||
int.Parse(birdColor[1].ToString()) / 255f,
|
||||
int.Parse(birdColor[2].ToString()) / 255f
|
||||
);
|
||||
bird.transform.GetChild(0).GetComponent<SpriteRenderer>().color = new Color(
|
||||
int.Parse(overlayColor[0].ToString()) / 255f,
|
||||
int.Parse(overlayColor[1].ToString()) / 255f,
|
||||
int.Parse(overlayColor[2].ToString()) / 255f
|
||||
);
|
||||
Tools.LoadIcon(
|
||||
bird,
|
||||
bird.transform.GetChild(0).GetComponent<Image>(),
|
||||
BazookaManager.Instance.GetBirdIcon(),
|
||||
BazookaManager.Instance.GetBirdOverlay(),
|
||||
BazookaManager.Instance.GetColorSettingIcon(),
|
||||
BazookaManager.Instance.GetColorSettingOverlay(),
|
||||
BazookaManager.Instance.GetCustomBirdIconData().Selected
|
||||
);
|
||||
|
||||
int icon = BazookaManager.Instance.GetBirdIcon();
|
||||
int iconOverlay = BazookaManager.Instance.GetBirdOverlay();
|
||||
if (icon == 1) {
|
||||
birdRender.sprite = Tools.GetIconForUser(BazookaManager.Instance.GetAccountID() ?? 0);
|
||||
} else {
|
||||
birdRender.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + icon);
|
||||
}
|
||||
if (iconOverlay == 8) {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + iconOverlay);
|
||||
overlayRender.transform.localPosition = new UnityEngine.Vector3(-0.37f, 0.32f, 0f);
|
||||
} else if (iconOverlay == 11) {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + iconOverlay);
|
||||
overlayRender.transform.localScale = new UnityEngine.Vector3(1.1f, 1.1f, 1.1f); //yea i didnt feel like doing it for all lmao
|
||||
overlayRender.transform.localPosition = new UnityEngine.Vector3(-0.3141809f, 0.4324968f, 0f);
|
||||
} else if (iconOverlay == 13) {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + iconOverlay);
|
||||
overlayRender.transform.localPosition = new UnityEngine.Vector3(-0.3559977f, 0.3179995f, 0f);
|
||||
} else {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + iconOverlay);
|
||||
}
|
||||
if (birdRender.sprite == null) {
|
||||
birdRender.sprite = Resources.Load<Sprite>("Icons/Icons/bird_1");
|
||||
BazookaManager.Instance.SetBirdIcon(1);
|
||||
}
|
||||
if (overlayRender.sprite == null && iconOverlay != 0) {
|
||||
overlayRender.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_1");
|
||||
BazookaManager.Instance.SetBirdOverlay(1);
|
||||
}
|
||||
} else if (customIconData.Selected != null)
|
||||
foreach (var icon in customIconData.Purchased)
|
||||
if (icon == customIconData.Selected) {
|
||||
var waitingForCustomIcon = birdRender.gameObject.AddComponent<WaitingForCustomIcon>();
|
||||
waitingForCustomIcon.ID = customIconData.Selected;
|
||||
CustomIconLoader.Init(new[] { waitingForCustomIcon });
|
||||
}
|
||||
|
||||
lastMoveTime = Time.time;
|
||||
UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
|
||||
highscore = BazookaManager.Instance.GetGameStoreHighScore();
|
||||
totalNormalBerries = BazookaManager.Instance.GetGameStoreTotalNormalBerries();
|
||||
@@ -139,20 +98,14 @@ public class GamePlayer : MonoBehaviour {
|
||||
}
|
||||
|
||||
void MoveBird() {
|
||||
float screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
float baseSpeed = 0.18f * (screenWidth / 20.19257f);
|
||||
float speedModifier = 1f;
|
||||
bool doMoveRight = false;
|
||||
bool doMoveLeft = false;
|
||||
bool doJump = false;
|
||||
bool doRestart = false;
|
||||
bool doBack = false;
|
||||
float movespeed = baseSpeed;
|
||||
if (boostLeft > 0f || speedyLeft > 0f) {
|
||||
movespeed = baseSpeed * 1.39f;
|
||||
} else if (slownessLeft > 0f) {
|
||||
movespeed = baseSpeed * 0.56f;
|
||||
}
|
||||
CheckIfGrounded();
|
||||
if (boostLeft > 0f || speedyLeft > 0f) speedModifier = 1.39f;
|
||||
else if (slownessLeft > 0f) speedModifier = 0.56f;
|
||||
bool controllerLeft = Gamepad.current != null && (Gamepad.current.leftStick.left.isPressed || Gamepad.current.dpad.left.isPressed || Gamepad.current.rightStick.left.isPressed);
|
||||
bool controllerRight = Gamepad.current != null && (Gamepad.current.leftStick.right.isPressed || Gamepad.current.dpad.right.isPressed || Gamepad.current.rightStick.right.isPressed);
|
||||
bool controllerJump = Gamepad.current != null && (Gamepad.current.leftStick.up.isPressed || Gamepad.current.leftStick.down.isPressed || Gamepad.current.dpad.up.isPressed || Gamepad.current.dpad.down.isPressed || Gamepad.current.rightStick.up.isPressed || Gamepad.current.rightStick.down.isPressed);
|
||||
@@ -183,27 +136,21 @@ public class GamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(-movespeed, 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(-(1.7f * speedModifier), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1.35f, 1.35f, 1.35f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(movespeed, 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(1.7f * speedModifier, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1.35f, 1.35f, 1.35f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doJump && isGrounded) {
|
||||
lastMoveTime = Time.time;
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded()) {
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 12f;
|
||||
} else if (slownessLeft > 0f) {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 6f;
|
||||
} else {
|
||||
rb.linearVelocity = UnityEngine.Vector2.up * 9f;
|
||||
}
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f);
|
||||
else if (slownessLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 220f);
|
||||
else rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 300f);
|
||||
}
|
||||
if (doBack) {
|
||||
TogglePause();
|
||||
@@ -219,27 +166,21 @@ public class GamePlayer : MonoBehaviour {
|
||||
UnityEngine.Vector3 dir = berry.transform.position - bird.transform.position;
|
||||
if (dir.magnitude < (antiLeft > 0 ? 3f : 4.5f)) {
|
||||
berry.GetComponent<Rigidbody2D>().linearVelocity = dir.normalized * (antiLeft > 0 ? 5f : -5f);
|
||||
ClampPosition(berry, false);
|
||||
ClampPosition(berry.GetComponent<Image>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClampPosition(GameObject obj, bool modifyY = true) {
|
||||
var cam = Camera.main;
|
||||
var pos = obj.transform.position;
|
||||
var bounds = obj.GetComponent<Renderer>().bounds.extents;
|
||||
void ClampPosition(Image image) {
|
||||
RectTransform birdRect = image.GetComponent<RectTransform>();
|
||||
float halfW = canvasRect.rect.width / 2f;
|
||||
float halfBirdW = birdRect.rect.width / 2f;
|
||||
|
||||
float zDist = Mathf.Abs(cam.transform.position.z - pos.z);
|
||||
|
||||
UnityEngine.Vector3 min = cam.ViewportToWorldPoint(new UnityEngine.Vector3(0, 0, zDist));
|
||||
UnityEngine.Vector3 max = cam.ViewportToWorldPoint(new UnityEngine.Vector3(1, 1, zDist));
|
||||
|
||||
pos.x = Mathf.Clamp(pos.x, min.x + bounds.x, max.x - bounds.x);
|
||||
if (modifyY) pos.y = Mathf.Clamp(pos.y, min.y + bounds.y, max.y - bounds.y);
|
||||
|
||||
obj.transform.position = pos;
|
||||
UnityEngine.Vector2 pos = birdRect.anchoredPosition;
|
||||
pos.x = Mathf.Clamp(pos.x, -halfW + halfBirdW, halfW - halfBirdW);
|
||||
birdRect.anchoredPosition = pos;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
@@ -278,246 +219,50 @@ public class GamePlayer : MonoBehaviour {
|
||||
}
|
||||
float spawnProbability = UnityEngine.Random.value;
|
||||
if (!pausePanel.activeSelf) {
|
||||
GameObject newBerry = new("Berry");
|
||||
Image newBerry = Instantiate(berryTemplate).GetComponent<Image>();
|
||||
newBerry.transform.SetParent(berryParent.transform);
|
||||
SpriteRenderer spriteRenderer = newBerry.AddComponent<SpriteRenderer>();
|
||||
|
||||
if (spawnProbability <= 0.375f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/Berry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/Berry");
|
||||
newBerry.tag = "NormalBerry";
|
||||
} else if (spawnProbability <= 0.55f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/PoisonBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/PoisonBerry");
|
||||
newBerry.tag = "PoisonBerry";
|
||||
} else if (spawnProbability <= 0.60f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/SlowBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/SlowBerry");
|
||||
newBerry.tag = "SlowBerry";
|
||||
} else if (spawnProbability <= 0.70f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/UltraBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/UltraBerry");
|
||||
newBerry.tag = "UltraBerry";
|
||||
} else if (spawnProbability <= 0.80f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/SpeedyBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/SpeedyBerry");
|
||||
newBerry.tag = "SpeedyBerry";
|
||||
} else if (spawnProbability <= 0.85f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/CoinBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/CoinBerry");
|
||||
newBerry.tag = "CoinBerry";
|
||||
} else if (spawnProbability <= 0.90f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/BerryNoColor");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/BerryNoColor");
|
||||
newBerry.tag = "RandomBerry";
|
||||
RainbowSpriteRender randomBerryRainbowImage = newBerry.AddComponent<RainbowSpriteRender>();
|
||||
RainbowImage randomBerryRainbowImage = newBerry.gameObject.AddComponent<RainbowImage>();
|
||||
randomBerryRainbowImage.frequency = 5f;
|
||||
} else if (spawnProbability <= 0.95f) {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/AntiBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/AntiBerry");
|
||||
newBerry.tag = "AntiBerry";
|
||||
} else {
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/GoldenBerry");
|
||||
newBerry.sprite = Resources.Load<Sprite>("Berries/GoldenBerry");
|
||||
newBerry.tag = "GoldenBerry";
|
||||
}
|
||||
spriteRenderer.sortingOrder = -5;
|
||||
|
||||
float screenWidth = Camera.main.orthographicSize * 2 * Camera.main.aspect;
|
||||
float spawnPositionX = UnityEngine.Random.Range(-screenWidth / 2.17f, screenWidth / 2.17f);
|
||||
newBerry.transform.position = new UnityEngine.Vector3(spawnPositionX, Camera.main.orthographicSize + 1f, 0f);
|
||||
|
||||
Rigidbody2D rb = newBerry.AddComponent<Rigidbody2D>();
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
float spawnPositionX = UnityEngine.Random.Range(-(canvasRect.rect.width / 2 - newBerry.rectTransform.rect.width), canvasRect.rect.width / 2 - newBerry.rectTransform.rect.width);
|
||||
newBerry.transform.localPosition = new UnityEngine.Vector3(spawnPositionX, (canvasRect.rect.height / 2) + newBerry.rectTransform.rect.height, 0f);
|
||||
newBerry.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) {
|
||||
audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
}
|
||||
if (screenWidth != Camera.main.orthographicSize * 2f * Camera.main.aspect) {
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
ClampPosition(bird);
|
||||
GameObject[] allberries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("CoinBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allberries) {
|
||||
ClampPosition(berry, false);
|
||||
}
|
||||
}
|
||||
GameObject[] normalBerries = GameObject.FindGameObjectsWithTag("NormalBerry");
|
||||
GameObject[] poisonBerries = GameObject.FindGameObjectsWithTag("PoisonBerry");
|
||||
GameObject[] slowBerries = GameObject.FindGameObjectsWithTag("SlowBerry");
|
||||
GameObject[] ultraBerries = GameObject.FindGameObjectsWithTag("UltraBerry");
|
||||
GameObject[] speedyBerries = GameObject.FindGameObjectsWithTag("SpeedyBerry");
|
||||
GameObject[] coinBerries = GameObject.FindGameObjectsWithTag("CoinBerry");
|
||||
GameObject[] randomBerries = GameObject.FindGameObjectsWithTag("RandomBerry");
|
||||
GameObject[] antiBerries = GameObject.FindGameObjectsWithTag("AntiBerry");
|
||||
GameObject[] goldenBerries = GameObject.FindGameObjectsWithTag("GoldenBerry");
|
||||
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
|
||||
if (!pausePanel.activeSelf) {
|
||||
if (Time.time - lastMoveTime > 20) {
|
||||
lastMoveTime = float.MaxValue;
|
||||
EnablePause();
|
||||
}
|
||||
CheckIfGrounded();
|
||||
foreach (GameObject normalBerry in normalBerries) {
|
||||
if (normalBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(normalBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, normalBerry.transform.position) < 1.5f) {
|
||||
totalNormalBerries++;
|
||||
DoNormalBerry(normalBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
normalBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
normalBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject poisonBerry in poisonBerries) {
|
||||
if (poisonBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(poisonBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, poisonBerry.transform.position) < 1.5f) {
|
||||
totalPoisonBerries++;
|
||||
DoPoisonBerry();
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
poisonBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
poisonBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject slowBerry in slowBerries) {
|
||||
if (slowBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(slowBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, slowBerry.transform.position) < 1.5f) {
|
||||
totalSlowBerries++;
|
||||
DoSlowBerry(slowBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
slowBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
slowBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject ultraBerry in ultraBerries) {
|
||||
if (ultraBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(ultraBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, ultraBerry.transform.position) < 1.5f) {
|
||||
totalUltraBerries++;
|
||||
DoUltraBerry(ultraBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
ultraBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
ultraBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject speedyBerry in speedyBerries) {
|
||||
if (speedyBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(speedyBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, speedyBerry.transform.position) < 1.5f) {
|
||||
totalSpeedyBerries++;
|
||||
DoSpeedyBerry(speedyBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
speedyBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
speedyBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject coinBerry in coinBerries) {
|
||||
if (coinBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(coinBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, coinBerry.transform.position) < 1.5f) {
|
||||
totalCoinBerries++;
|
||||
DoCoinBerry(coinBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
coinBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
coinBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject randomBerry in randomBerries) {
|
||||
if (randomBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(randomBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, randomBerry.transform.position) < 1.5f) {
|
||||
totalRandomBerries++;
|
||||
Action[] funcs = {
|
||||
() => DoNormalBerry(randomBerry),
|
||||
() => DoSlowBerry(randomBerry),
|
||||
() => DoUltraBerry(randomBerry),
|
||||
() => DoSpeedyBerry(randomBerry),
|
||||
() => DoAntiBerry(randomBerry),
|
||||
() => DoGoldenBerry(randomBerry)
|
||||
};
|
||||
funcs[UnityEngine.Random.Range(0, funcs.Length)]();
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
randomBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
randomBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject antiBerry in antiBerries) {
|
||||
if (antiBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(antiBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, antiBerry.transform.position) < 1.5f) {
|
||||
totalAntiBerries++;
|
||||
DoAntiBerry(antiBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
antiBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
antiBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
foreach (GameObject goldenBerry in goldenBerries) {
|
||||
if (goldenBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f) {
|
||||
Destroy(goldenBerry);
|
||||
} else if (UnityEngine.Vector3.Distance(bird.transform.position, goldenBerry.transform.position) < 1.5f) {
|
||||
totalGoldenBerries++;
|
||||
DoGoldenBerry(goldenBerry);
|
||||
}
|
||||
if (speedyLeft > 0) {
|
||||
goldenBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
|
||||
} else {
|
||||
goldenBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = UnityEngine.Vector2.zero;
|
||||
GameObject[] allberries = normalBerries
|
||||
.Concat(poisonBerries)
|
||||
.Concat(slowBerries)
|
||||
.Concat(ultraBerries)
|
||||
.Concat(speedyBerries)
|
||||
.Concat(coinBerries)
|
||||
.Concat(randomBerries)
|
||||
.Concat(antiBerries)
|
||||
.Concat(goldenBerries)
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allberries) {
|
||||
berry.GetComponent<Rigidbody2D>().linearVelocity = UnityEngine.Vector2.zero;
|
||||
}
|
||||
}
|
||||
if ((Application.platform == RuntimePlatform.Android && Keyboard.current.escapeKey.wasPressedThisFrame) || !Application.isMobilePlatform && (Keyboard.current.escapeKey.wasPressedThisFrame || (Gamepad.current != null && (Gamepad.current.startButton.wasPressedThisFrame || Gamepad.current.buttonEast.wasPressedThisFrame)))) TogglePause();
|
||||
}
|
||||
|
||||
void Respawn() {
|
||||
bird.transform.position = new UnityEngine.Vector3(0f, -4.3f, 0f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1.35f, 1.35f, 1.35f);
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = UnityEngine.Vector2.zero;
|
||||
score = 0;
|
||||
boostLeft = 0f;
|
||||
slownessLeft = 0f;
|
||||
speedyLeft = 0f;
|
||||
antiLeft = 0f;
|
||||
UpdateStats(0, 1);
|
||||
|
||||
GameObject[] allberries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
|
||||
@@ -527,9 +272,69 @@ public class GamePlayer : MonoBehaviour {
|
||||
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allberries) {
|
||||
Destroy(berry);
|
||||
|
||||
if (!pausePanel.activeSelf) foreach (GameObject berry in allBerries) {
|
||||
if (berry.GetComponent<RectTransform>().anchoredPosition.y < -(canvasRect.rect.height / 2) - berry.GetComponent<RectTransform>().rect.height) Destroy(berry);
|
||||
else if (Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), berry.GetComponent<CircleCollider2D>()).distance <= 0.1f) {
|
||||
switch (berry.tag) {
|
||||
case "NormalBerry":
|
||||
DoNormalBerry(berry, true);
|
||||
break;
|
||||
case "PoisonBerry":
|
||||
DoPoisonBerry();
|
||||
break;
|
||||
case "SlowBerry":
|
||||
DoSlowBerry(berry, true);
|
||||
break;
|
||||
case "UltraBerry":
|
||||
DoUltraBerry(berry, true);
|
||||
break;
|
||||
case "SpeedyBerry":
|
||||
DoSpeedyBerry(berry, true);
|
||||
break;
|
||||
case "CoinBerry":
|
||||
DoCoinBerry(berry, true);
|
||||
break;
|
||||
case "RandomBerry":
|
||||
DoRandomBerry(berry);
|
||||
break;
|
||||
case "AntiBerry":
|
||||
DoAntiBerry(berry, true);
|
||||
break;
|
||||
case "GoldenBerry":
|
||||
DoGoldenBerry(berry, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (berry != null) berry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, speedyLeft < 0 ? 200f : -375f);
|
||||
}
|
||||
else foreach (GameObject berry in allBerries) berry.GetComponent<Rigidbody2D>().linearVelocity = UnityEngine.Vector2.zero;
|
||||
if ((Application.platform == RuntimePlatform.Android && Keyboard.current.escapeKey.wasPressedThisFrame) || !Application.isMobilePlatform && (Keyboard.current.escapeKey.wasPressedThisFrame || (Gamepad.current != null && (Gamepad.current.startButton.wasPressedThisFrame || Gamepad.current.buttonEast.wasPressedThisFrame)))) TogglePause();
|
||||
}
|
||||
|
||||
void Respawn() {
|
||||
bird.GetComponent<RectTransform>().anchoredPosition = new UnityEngine.Vector3(0f, 64f, 0f);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = UnityEngine.Vector2.zero;
|
||||
score = 0;
|
||||
boostLeft = 0f;
|
||||
slownessLeft = 0f;
|
||||
speedyLeft = 0f;
|
||||
antiLeft = 0f;
|
||||
UpdateStats(0, 1);
|
||||
|
||||
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
|
||||
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("CoinBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
|
||||
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
|
||||
.ToArray();
|
||||
foreach (GameObject berry in allBerries) Destroy(berry);
|
||||
}
|
||||
|
||||
void UpdateStats(BigInteger scoreAddAmount, BigInteger attemptAddAmount) {
|
||||
@@ -569,25 +374,15 @@ public class GamePlayer : MonoBehaviour {
|
||||
if (level != levelBefore) AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Levelup"), Camera.main.transform.position, 1f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
}
|
||||
|
||||
void CheckIfGrounded() {
|
||||
isGrounded = bird.transform.position.y <= -4.1299996f;
|
||||
|
||||
rb.gravityScale = isGrounded ? 0f : 1.5f;
|
||||
|
||||
if (bird.transform.position.y < -4.1359f) {
|
||||
bird.transform.position = new UnityEngine.Vector2(bird.transform.position.x, -4.1359f);
|
||||
rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 0f);
|
||||
}
|
||||
var btnColor = BazookaManager.Instance.GetColorSettingButton();
|
||||
if (Application.isMobilePlatform) jumpButton.transform.GetChild(0).GetComponent<TMP_Text>().color = isGrounded ? new Color(int.Parse(btnColor[0].ToString()) / 255f, int.Parse(btnColor[1].ToString()) / 255f, int.Parse(btnColor[2].ToString()) / 255f) : Color.red;
|
||||
}
|
||||
|
||||
internal void TogglePause() {
|
||||
if (pausePanel.activeSelf) DisablePause();
|
||||
else EnablePause();
|
||||
}
|
||||
|
||||
internal void EnablePause() {
|
||||
velocityBeforePause = rb.linearVelocity;
|
||||
rb.linearVelocity = new();
|
||||
rb.gravityScale = 0f;
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
backgroundMusic.GetComponent<GameMusicHandler>().PauseMusic();
|
||||
@@ -595,6 +390,9 @@ public class GamePlayer : MonoBehaviour {
|
||||
}
|
||||
|
||||
internal void DisablePause() {
|
||||
rb.gravityScale = 80f;
|
||||
rb.linearVelocity = velocityBeforePause;
|
||||
velocityBeforePause = new();
|
||||
if (GamePlayerPauseMenu.Instance.statsMenu.activeSelf) {
|
||||
GamePlayerPauseMenu.Instance.statsMenuExitButton.onClick.Invoke();
|
||||
return;
|
||||
@@ -603,7 +401,6 @@ public class GamePlayer : MonoBehaviour {
|
||||
GamePlayerPauseMenu.Instance.ToggleEditingUI();
|
||||
return;
|
||||
}
|
||||
lastMoveTime = Time.time;
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
backgroundMusic.GetComponent<GameMusicHandler>().ResumeMusic();
|
||||
@@ -619,19 +416,22 @@ public class GamePlayer : MonoBehaviour {
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
void DoNormalBerry(GameObject berry) {
|
||||
void DoNormalBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalNormalBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Eat"), Camera.main.transform.position, 1.2f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
UpdateStats(1, 0);
|
||||
}
|
||||
|
||||
void DoPoisonBerry() {
|
||||
totalPoisonBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Death"), Camera.main.transform.position, 1.2f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Respawn();
|
||||
UpdateStats(0, 0);
|
||||
}
|
||||
|
||||
void DoSlowBerry(GameObject berry) {
|
||||
void DoSlowBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalSlowBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Downgrade"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
boostLeft = 0f;
|
||||
@@ -644,7 +444,8 @@ public class GamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
void DoUltraBerry(GameObject berry) {
|
||||
void DoUltraBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalUltraBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Powerup"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
speedyLeft = 0f;
|
||||
@@ -659,7 +460,8 @@ public class GamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
void DoSpeedyBerry(GameObject berry) {
|
||||
void DoSpeedyBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalSpeedyBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/SpeedyPowerup"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
boostLeft = 0f;
|
||||
@@ -670,14 +472,30 @@ public class GamePlayer : MonoBehaviour {
|
||||
UpdateStats(10, 0);
|
||||
}
|
||||
|
||||
void DoCoinBerry(GameObject berry) {
|
||||
void DoCoinBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalCoinBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/CoinCollect"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
totalCoins += 10;
|
||||
UpdateStats(0, 0);
|
||||
}
|
||||
|
||||
void DoAntiBerry(GameObject berry) {
|
||||
void DoRandomBerry(GameObject berry) {
|
||||
totalRandomBerries++;
|
||||
Action[] funcs = {
|
||||
() => DoNormalBerry(berry, false),
|
||||
() => DoSlowBerry(berry, false),
|
||||
() => DoUltraBerry(berry, false),
|
||||
() => DoSpeedyBerry(berry, false),
|
||||
() => DoCoinBerry(berry, false),
|
||||
() => DoAntiBerry(berry, false),
|
||||
() => DoGoldenBerry(berry, false)
|
||||
};
|
||||
funcs[UnityEngine.Random.Range(0, funcs.Length)]();
|
||||
}
|
||||
|
||||
void DoAntiBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalAntiBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Downgrade"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
boostLeft = 0f;
|
||||
@@ -688,7 +506,8 @@ public class GamePlayer : MonoBehaviour {
|
||||
UpdateStats(0, 0);
|
||||
}
|
||||
|
||||
void DoGoldenBerry(GameObject berry) {
|
||||
void DoGoldenBerry(GameObject berry, bool increment) {
|
||||
if (increment) totalGoldenBerries++;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Powerup"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
Destroy(berry);
|
||||
boostLeft = 0f;
|
||||
|
||||
@@ -158,7 +158,7 @@ public class GamePlayerPauseMenu : MonoBehaviour {
|
||||
jumpButton.interactable = !jumpDraggableUI.canDrag;
|
||||
rightButton.interactable = !rightDraggableUI.canDrag;
|
||||
leftButton.interactable = !leftDraggableUI.canDrag;
|
||||
jumpButton.transform.GetChild(0).GetComponent<TMP_Text>().color = !jumpDraggableUI.canDrag ? GamePlayer.Instance.isGrounded ? Color.white : Color.red : Color.white;
|
||||
jumpButton.transform.GetChild(0).GetComponent<TMP_Text>().color = !jumpDraggableUI.canDrag ? GamePlayer.Instance.IsGrounded() ? Color.white : Color.red : Color.white;
|
||||
restartButton.interactable = GamePlayer.Instance.score != 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -126,4 +127,30 @@ public static class Tools {
|
||||
string dateStr = date.ToShortDateString();
|
||||
return $"{dateStr}, {timeStr}";
|
||||
}
|
||||
|
||||
public static Color JArayToColor(JArray data) {
|
||||
return new Color(
|
||||
int.Parse(data[0].ToString()) / 255f,
|
||||
int.Parse(data[1].ToString()) / 255f,
|
||||
int.Parse(data[2].ToString()) / 255f
|
||||
);
|
||||
}
|
||||
|
||||
public static void LoadIcon(Image icon, Image overlay, int iconId, int overlayId, JArray iconColor, JArray overlayColor, string customIcon) {
|
||||
if (customIcon == null || customIcon.Trim() == string.Empty) {
|
||||
icon.color = JArayToColor(iconColor);
|
||||
overlay.color = JArayToColor(overlayColor);
|
||||
|
||||
if (iconId == 1) icon.sprite = GetIconForUser(BazookaManager.Instance.GetAccountID() ?? 0);
|
||||
else icon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + iconId);
|
||||
if (overlayId != 0) {
|
||||
overlay.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlayId);
|
||||
overlay.gameObject.SetActive(true);
|
||||
}
|
||||
} else {
|
||||
var waitingForCustomIcon = icon.gameObject.AddComponent<WaitingForCustomIcon>();
|
||||
waitingForCustomIcon.ID = customIcon;
|
||||
CustomIconLoader.Init(new[] { waitingForCustomIcon });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user