Adjust Bomb Color

This commit is contained in:
2025-12-16 20:34:13 +08:00
parent b97a9e73d8
commit d10d574cff
5 changed files with 61 additions and 49 deletions

View File

@@ -51,11 +51,22 @@ MonoBehaviour:
explosionPrefab: {fileID: 8968486364681163996, guid: 05c754e3d4f9fd349ac1def58d17670f, explosionPrefab: {fileID: 8968486364681163996, guid: 05c754e3d4f9fd349ac1def58d17670f,
type: 3} type: 3}
scoreValue: 10 scoreValue: 10
width: 7
height: 7
bombColors:
- type: 0
color: {r: 0.02800417, g: 0, b: 1, a: 1}
- type: 1
color: {r: 0, g: 1, b: 0.056184053, a: 1}
- type: 2
color: {r: 1, g: 0, b: 0, a: 1}
- type: 3
color: {r: 1, g: 0.9118239, b: 0, a: 1}
- type: 4
color: {r: 0.9601507, g: 0, b: 1, a: 1}
bombDelay: 0.75 bombDelay: 0.75
bombSelfDelay: 0.25 bombSelfDelay: 0.25
bombRadius: 2 bombRadius: 2
dropHeight: 2 dropHeight: 2
gemSpeed: 0.025 gemSpeed: 0.00625
scoreSpeed: 1 scoreSpeed: 1
width: 7
height: 7

View File

@@ -130,29 +130,5 @@ PrefabInstance:
- {fileID: -7932498854989450506, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} - {fileID: -7932498854989450506, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3}
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: m_AddedComponents: []
- targetCorrespondingSourceObject: {fileID: 7667143225876670874, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec,
type: 3}
insertIndex: -1
addedObject: {fileID: 5350632371355805727}
m_SourcePrefab: {fileID: 100100000, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3}
--- !u!1 &1210587634127288510 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 7667143225876670874, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec,
type: 3}
m_PrefabInstance: {fileID: 8839428272799928612}
m_PrefabAsset: {fileID: 0}
--- !u!114 &5350632371355805727
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1210587634127288510}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7645dd1d371740729311dd834ab649f3, type: 3}
m_Name:
m_EditorClassIdentifier:
spawnScaleFrom: 0
spawnScaleDuration: 0.12

View File

@@ -8,15 +8,26 @@ using Views;
namespace ScriptableObjects { namespace ScriptableObjects {
[CreateAssetMenu(fileName = "GameVariables", menuName = "Game Variables")] [CreateAssetMenu(fileName = "GameVariables", menuName = "Game Variables")]
public class GameVariables : ScriptableObject { public class GameVariables : ScriptableObject {
[Header("Prefabs")]
public GameObject bgTilePrefabs; public GameObject bgTilePrefabs;
public GemTypeValues[] gemsPrefabs; public GemTypeValues[] gemsPrefabs;
public float bombDelay = 0.1f; [Header("Board Setup")]
public float bombSelfDelay = 0.05f;
public int bombRadius = 1;
public float dropHeight = 1;
public float gemSpeed = 0.1f;
public float scoreSpeed = 5;
public int width; public int width;
public int height; 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;
} }
} }

View File

@@ -98,11 +98,11 @@ namespace Services {
DestroyMatchedGems(position); DestroyMatchedGems(position);
GemView gemView = this.objectPool.Get(GemType.Bomb, position, 0); 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; int scoreValue = GemUtils.GetGemValues(color, this.gameVariables.gemsPrefabs).scoreValue;
Gem bombGem = new Gem(GemType.Bomb, position, scoreValue, color); Gem bombGem = new Gem(GemType.Bomb, position, scoreValue, color);
gemView.Bind(bombGem); gemView.Bind(bombGem, isBomb: true);
this.gemPresenters.Add(new GemPresenter(bombGem, gemView)); this.gemPresenters.Add(new GemPresenter(bombGem, gemView));
SetGem(position, bombGem); SetGem(position, bombGem);

View File

@@ -9,21 +9,40 @@ namespace Views {
public class GemView : MonoBehaviour { public class GemView : MonoBehaviour {
private Gem gem; private Gem gem;
public Gem Gem => this.gem; public Gem Gem => this.gem;
private SpriteRenderer spriteRenderer;
private bool isFalling; private bool isFalling;
[Header("Spawn Scale")] private const float SPAWN_SCALE_FROM = 0f;
[SerializeField] private float spawnScaleFrom = 0f; private const float SPAWN_SCALE_DURATION = 0.12f;
[SerializeField] private float spawnScaleDuration = 0.12f;
private CancellationTokenSource spawnScaleCts; private CancellationTokenSource spawnScaleCts;
public void Bind(Gem gem) { public void Bind(Gem gem, bool isBomb = false) {
this.gem = gem; this.gem = gem;
this.gameObject.SetActive(true); this.gameObject.SetActive(true);
SetupGem(isBomb);
PlaySpawnScale(); 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() { public void Unbind() {
this.spawnScaleCts?.Cancel(); this.spawnScaleCts?.Cancel();
this.spawnScaleCts?.Dispose(); this.spawnScaleCts?.Dispose();
@@ -39,27 +58,22 @@ namespace Views {
this.spawnScaleCts?.Dispose(); this.spawnScaleCts?.Dispose();
this.spawnScaleCts = new CancellationTokenSource(); this.spawnScaleCts = new CancellationTokenSource();
this.transform.localScale = Vector3.one * this.spawnScaleFrom; this.transform.localScale = Vector3.one * SPAWN_SCALE_FROM;
AnimateSpawnScaleAsync(this.spawnScaleCts.Token).Forget(); AnimateSpawnScaleAsync(this.spawnScaleCts.Token).Forget();
} }
private async UniTask AnimateSpawnScaleAsync(CancellationToken ct) { private async UniTask AnimateSpawnScaleAsync(CancellationToken ct) {
if (this.spawnScaleDuration <= 0f) {
this.transform.localScale = Vector3.one;
return;
}
float timer = 0f; float timer = 0f;
while (timer < this.spawnScaleDuration) { while (timer < SPAWN_SCALE_DURATION) {
ct.ThrowIfCancellationRequested(); ct.ThrowIfCancellationRequested();
timer += Time.deltaTime; timer += Time.deltaTime;
float scale = Mathf.Clamp01(timer / this.spawnScaleDuration); float scale = Mathf.Clamp01(timer / SPAWN_SCALE_DURATION);
scale = Mathf.SmoothStep(0f, 1f, scale); scale = Mathf.SmoothStep(0f, 1f, scale);
this.transform.localScale = Vector3.LerpUnclamped( this.transform.localScale = Vector3.LerpUnclamped(
Vector3.one * this.spawnScaleFrom, Vector3.one * SPAWN_SCALE_FROM,
Vector3.one, Vector3.one,
scale scale
); );