Adjust Bomb Color
This commit is contained in:
@@ -8,15 +8,26 @@ using Views;
|
||||
namespace ScriptableObjects {
|
||||
[CreateAssetMenu(fileName = "GameVariables", menuName = "Game Variables")]
|
||||
public class GameVariables : ScriptableObject {
|
||||
[Header("Prefabs")]
|
||||
public GameObject bgTilePrefabs;
|
||||
public GemTypeValues[] gemsPrefabs;
|
||||
public float bombDelay = 0.1f;
|
||||
public float bombSelfDelay = 0.05f;
|
||||
public int bombRadius = 1;
|
||||
public float dropHeight = 1;
|
||||
public float gemSpeed = 0.1f;
|
||||
public float scoreSpeed = 5;
|
||||
[Header("Board Setup")]
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
[Header("Bomb")]
|
||||
[Tooltip("How long before the gems around the bomb explode")]
|
||||
public float bombDelay = 0.1f;
|
||||
[Tooltip("How long before the bomb itself explodes")]
|
||||
public float bombSelfDelay = 0.05f;
|
||||
[Tooltip("How far the explosion reaches")]
|
||||
public int bombRadius = 1;
|
||||
|
||||
[Header("Gem and Bomb Spawn")]
|
||||
public float dropHeight = 1;
|
||||
public float gemSpeed = 0.1f;
|
||||
|
||||
[Header("Score")]
|
||||
public float scoreSpeed = 5;
|
||||
}
|
||||
}
|
||||
@@ -98,11 +98,11 @@ namespace Services {
|
||||
DestroyMatchedGems(position);
|
||||
|
||||
GemView gemView = this.objectPool.Get(GemType.Bomb, position, 0);
|
||||
gemView.name = "Gem - " + position.x + ", " + position.y + ' ' + GemType.Bomb;
|
||||
gemView.name = "Bomb - " + position.x + ", " + position.y + ' ' + GemType.Bomb;
|
||||
|
||||
int scoreValue = GemUtils.GetGemValues(color, this.gameVariables.gemsPrefabs).scoreValue;
|
||||
Gem bombGem = new Gem(GemType.Bomb, position, scoreValue, color);
|
||||
gemView.Bind(bombGem);
|
||||
gemView.Bind(bombGem, isBomb: true);
|
||||
|
||||
this.gemPresenters.Add(new GemPresenter(bombGem, gemView));
|
||||
SetGem(position, bombGem);
|
||||
|
||||
@@ -9,21 +9,40 @@ namespace Views {
|
||||
public class GemView : MonoBehaviour {
|
||||
private Gem gem;
|
||||
public Gem Gem => this.gem;
|
||||
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
private bool isFalling;
|
||||
[Header("Spawn Scale")]
|
||||
[SerializeField] private float spawnScaleFrom = 0f;
|
||||
[SerializeField] private float spawnScaleDuration = 0.12f;
|
||||
private const float SPAWN_SCALE_FROM = 0f;
|
||||
private const float SPAWN_SCALE_DURATION = 0.12f;
|
||||
|
||||
private CancellationTokenSource spawnScaleCts;
|
||||
|
||||
public void Bind(Gem gem) {
|
||||
public void Bind(Gem gem, bool isBomb = false) {
|
||||
this.gem = gem;
|
||||
this.gameObject.SetActive(true);
|
||||
|
||||
SetupGem(isBomb);
|
||||
PlaySpawnScale();
|
||||
}
|
||||
|
||||
private void SetupGem(bool isBomb) {
|
||||
this.spriteRenderer ??= GetComponent<SpriteRenderer>();
|
||||
|
||||
if (isBomb) {
|
||||
this.spriteRenderer.color = this.gem.MatchColor switch {
|
||||
GemType.Blue => Color.blue,
|
||||
GemType.Green => Color.green,
|
||||
GemType.Red => Color.red,
|
||||
GemType.Yellow => Color.yellow,
|
||||
GemType.Purple => Color.magenta,
|
||||
_ => this.spriteRenderer.color
|
||||
};
|
||||
} else {
|
||||
this.spriteRenderer.color = Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
public void Unbind() {
|
||||
this.spawnScaleCts?.Cancel();
|
||||
this.spawnScaleCts?.Dispose();
|
||||
@@ -39,27 +58,22 @@ namespace Views {
|
||||
this.spawnScaleCts?.Dispose();
|
||||
this.spawnScaleCts = new CancellationTokenSource();
|
||||
|
||||
this.transform.localScale = Vector3.one * this.spawnScaleFrom;
|
||||
this.transform.localScale = Vector3.one * SPAWN_SCALE_FROM;
|
||||
AnimateSpawnScaleAsync(this.spawnScaleCts.Token).Forget();
|
||||
}
|
||||
|
||||
private async UniTask AnimateSpawnScaleAsync(CancellationToken ct) {
|
||||
if (this.spawnScaleDuration <= 0f) {
|
||||
this.transform.localScale = Vector3.one;
|
||||
return;
|
||||
}
|
||||
|
||||
float timer = 0f;
|
||||
while (timer < this.spawnScaleDuration) {
|
||||
while (timer < SPAWN_SCALE_DURATION) {
|
||||
ct.ThrowIfCancellationRequested();
|
||||
|
||||
timer += Time.deltaTime;
|
||||
float scale = Mathf.Clamp01(timer / this.spawnScaleDuration);
|
||||
float scale = Mathf.Clamp01(timer / SPAWN_SCALE_DURATION);
|
||||
|
||||
scale = Mathf.SmoothStep(0f, 1f, scale);
|
||||
|
||||
this.transform.localScale = Vector3.LerpUnclamped(
|
||||
Vector3.one * this.spawnScaleFrom,
|
||||
Vector3.one * SPAWN_SCALE_FROM,
|
||||
Vector3.one,
|
||||
scale
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user