diff --git a/Assets/GameVariables.asset b/Assets/GameVariables.asset index a2f18b2..813415d 100644 --- a/Assets/GameVariables.asset +++ b/Assets/GameVariables.asset @@ -51,11 +51,22 @@ MonoBehaviour: explosionPrefab: {fileID: 8968486364681163996, guid: 05c754e3d4f9fd349ac1def58d17670f, type: 3} 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 bombSelfDelay: 0.25 bombRadius: 2 dropHeight: 2 - gemSpeed: 0.025 + gemSpeed: 0.00625 scoreSpeed: 1 - width: 7 - height: 7 diff --git a/Assets/Prefabs/Gems/Bomb Variant.prefab b/Assets/Prefabs/Gems/Bomb Variant.prefab index e68795e..da9cc14 100644 --- a/Assets/Prefabs/Gems/Bomb Variant.prefab +++ b/Assets/Prefabs/Gems/Bomb Variant.prefab @@ -130,29 +130,5 @@ PrefabInstance: - {fileID: -7932498854989450506, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 7667143225876670874, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, - type: 3} - insertIndex: -1 - addedObject: {fileID: 5350632371355805727} + m_AddedComponents: [] 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 diff --git a/Assets/Scripts/ScriptableObjects/GameVariables.cs b/Assets/Scripts/ScriptableObjects/GameVariables.cs index c7511ed..ff9c2da 100644 --- a/Assets/Scripts/ScriptableObjects/GameVariables.cs +++ b/Assets/Scripts/ScriptableObjects/GameVariables.cs @@ -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; } } \ No newline at end of file diff --git a/Assets/Scripts/Services/GameBoardService.cs b/Assets/Scripts/Services/GameBoardService.cs index c958542..71fc820 100644 --- a/Assets/Scripts/Services/GameBoardService.cs +++ b/Assets/Scripts/Services/GameBoardService.cs @@ -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); diff --git a/Assets/Scripts/Views/GemView.cs b/Assets/Scripts/Views/GemView.cs index 00d2557..625d158 100644 --- a/Assets/Scripts/Views/GemView.cs +++ b/Assets/Scripts/Views/GemView.cs @@ -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(); + + 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 );