Added spring

This commit is contained in:
Pasha Bibko
2026-04-16 13:22:52 +01:00
parent 6868788af7
commit 646ef895c3
15 changed files with 639 additions and 36 deletions

View File

@@ -12,14 +12,14 @@ namespace Fruitomation.Game
private void Start()
{
TriggerDetector.SetAction((other) =>
TriggerDetector.SetAction(other =>
{
if (other.transform.parent.TryGetComponent(out Rigidbody2D body))
{
Vector3 force = new(-transform.localScale.x, 0f, 0f);
body?.AddForce(force * Mathf.PI, ForceMode2D.Impulse);
}
});
}, TriggerType.Stay);
}
private void Update()

View File

@@ -0,0 +1,7 @@
namespace Fruitomation.Game
{
public class SlicerBuilding : Building
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f2a0d2e92ab8436a8854e59ee269188a
timeCreated: 1776341863

View File

@@ -0,0 +1,35 @@
using UnityEngine;
using System;
namespace Fruitomation.Game
{
public class SpringBuilding : Building
{
[SerializeField] private TriggerDetector Trigger;
private void Start()
{
Trigger.SetAction(other =>
{
if (other.transform.parent.TryGetComponent(out Rigidbody2D body))
{
Vector2 v0 = body.linearVelocity;
float magnitude = Math.Max(v0.magnitude * 0.8f, 20f);
Vector2 v1 = new Vector2(v0.x * 1.2f, Math.Abs(v0.y)).normalized * magnitude;
body.linearVelocity = v1;
}
}, TriggerType.Enter);
Trigger.SetAction(other =>
{
if (other.transform.parent.TryGetComponent(out Rigidbody2D body))
{
Vector2 v0 = body.linearVelocity;
v0.y = Math.Max(1f, v0.y);
body.linearVelocity = v0;
}
}, TriggerType.Stay);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d85c1768ca4c6594dbdb161463af59dc

View File

@@ -49,25 +49,25 @@ namespace Fruitomation.Game
{
List<GameObject> unlocked = new() { ApplePrefab };
if (UpgradeManager.Unlocked(BasicUpgrade.Grapes))
if (UpgradeManager.Is(BasicUpgrade.Grapes))
unlocked.Add(GrapePrefab);
if (UpgradeManager.Unlocked(BasicUpgrade.Bananas))
if (UpgradeManager.Is(BasicUpgrade.Bananas))
unlocked.Add(BananaPrefab);
if (UpgradeManager.Unlocked(BasicUpgrade.Kiwi))
if (UpgradeManager.Is(BasicUpgrade.Kiwi))
unlocked.Add(KiwiPrefab);
if (UpgradeManager.Unlocked(BasicUpgrade.Mangoes))
if (UpgradeManager.Is(BasicUpgrade.Mangoes))
unlocked.Add(MangoPrefab);
if (UpgradeManager.Unlocked(BasicUpgrade.Durian))
if (UpgradeManager.Is(BasicUpgrade.Durian))
unlocked.Add(DurianPrefab);
if (UpgradeManager.Unlocked(BasicUpgrade.BuddhasHand))
if (UpgradeManager.Is(BasicUpgrade.BuddhasHand))
unlocked.Add(BuddhasHandPrefab);
if (UpgradeManager.Unlocked(BasicUpgrade.Pitayas))
if (UpgradeManager.Is(BasicUpgrade.Pitayas))
unlocked.Add(PitayaPrefab);
GameObject prefab = unlocked[Random.Range(0, unlocked.Count)];

View File

@@ -3,11 +3,37 @@ using System;
namespace Fruitomation.Game
{
public enum TriggerType
{
Enter,
Stay
}
public class TriggerDetector : MonoBehaviour
{
private Action<Collider2D> RegisteredAction;
private Action<Collider2D> RegisteredActionStay;
private Action<Collider2D> RegisteredActionEnter;
public void SetAction(Action<Collider2D> action) => RegisteredAction = action;
private void OnTriggerStay2D(Collider2D other) => RegisteredAction?.Invoke(other);
private TriggerType Type;
public void SetAction(Action<Collider2D> action, TriggerType type)
{
switch (type)
{
case TriggerType.Stay:
RegisteredActionStay = action;
return;
case TriggerType.Enter:
RegisteredActionEnter = action;
return;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}
private void OnTriggerEnter2D(Collider2D other) => RegisteredActionEnter?.Invoke(other);
private void OnTriggerStay2D(Collider2D other) => RegisteredActionStay?.Invoke(other);
}
}

View File

@@ -49,7 +49,11 @@ namespace Fruitomation.Game
PitayaIceCream,
SpicedPitayaIceCream,
}
[Serializable] public enum IncrementalUpgrade
{
}
public class UnlockedUpgrades
{
[Serializable] public class Serialized
@@ -130,7 +134,7 @@ namespace Fruitomation.Game
public static void Unlock(BasicUpgrade upgrade) => CurrentUpgrades.Unlock(upgrade);
public static bool Unlocked(BasicUpgrade upgrade) => CurrentUpgrades.IsUnlocked(upgrade);
public static bool Is(BasicUpgrade upgrade) => CurrentUpgrades.IsUnlocked(upgrade);
#if UNITY_EDITOR
[MenuItem("Fruitomation/Reset Upgrades")]