From d3243016f99a4c044bff5346861908f4f9464626 Mon Sep 17 00:00:00 2001 From: Denis NUTIU Date: Sat, 13 Jul 2019 18:10:32 +0300 Subject: [PATCH 1/7] Implement exit strategy --- Assets/DevMocks/exitDoorPrefab.prefab | 40 +++++ Assets/Prefabs/Managers/GameManager.prefab | 2 + Assets/Prefabs/UI/MobileInputControls.prefab | 2 +- Assets/Prefabs/UI/PreStageUI.prefab | 6 +- Assets/Scenes/SampleScene.unity | 149 ++---------------- Assets/Scripts/src/Base/UpgradeBase.cs | 10 +- Assets/Scripts/src/Managers/GameManager.cs | 41 +++-- Assets/Scripts/src/Managers/LevelManager.cs | 74 +++++---- Assets/Scripts/src/Managers/UpgradeManager.cs | 36 +++++ Assets/Scripts/src/Player/PlayerController.cs | 8 +- .../{PreLevelLoad.cs => PreStageUiScript.cs} | 3 +- ...lLoad.cs.meta => PreStageUiScript.cs.meta} | 0 .../Scripts/src/Upgrade/BombFlamesUpgrade.cs | 4 +- .../src/Upgrade/BombPlacementUpgrade.cs | 4 +- .../Scripts/src/Upgrade/PlayerSpeedUpgrade.cs | 1 + Assets/Scripts/src/Wall/DestructibleWall.cs | 11 +- Assets/Scripts/src/Wall/ExitDoor.cs | 30 ++++ Assets/Scripts/src/Wall/ExitDoor.cs.meta | 3 + ProjectSettings/ProjectSettings.asset | 6 +- 19 files changed, 228 insertions(+), 202 deletions(-) rename Assets/Scripts/src/UI/{PreLevelLoad.cs => PreStageUiScript.cs} (81%) rename Assets/Scripts/src/UI/{PreLevelLoad.cs.meta => PreStageUiScript.cs.meta} (100%) create mode 100644 Assets/Scripts/src/Wall/ExitDoor.cs create mode 100644 Assets/Scripts/src/Wall/ExitDoor.cs.meta diff --git a/Assets/DevMocks/exitDoorPrefab.prefab b/Assets/DevMocks/exitDoorPrefab.prefab index 702df4e..469ff13 100644 --- a/Assets/DevMocks/exitDoorPrefab.prefab +++ b/Assets/DevMocks/exitDoorPrefab.prefab @@ -10,6 +10,8 @@ GameObject: m_Component: - component: {fileID: 3243993883904879596} - component: {fileID: 3212428174306319952} + - component: {fileID: 3858379993772342456} + - component: {fileID: 1949159407646367785} m_Layer: 0 m_Name: exitDoorPrefab m_TagString: Untagged @@ -79,3 +81,41 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!114 &3858379993772342456 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1538214466168189615} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d5d5847c8fef4a91bafe88cc2ccf43ec, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!61 &1949159407646367785 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1538214466168189615} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0.5, y: 0.5} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 1, y: 1} + newSize: {x: 0.32, y: 0.32} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 0.1, y: 0.8} + m_EdgeRadius: 0 diff --git a/Assets/Prefabs/Managers/GameManager.prefab b/Assets/Prefabs/Managers/GameManager.prefab index 3af0897..c1c56c7 100644 --- a/Assets/Prefabs/Managers/GameManager.prefab +++ b/Assets/Prefabs/Managers/GameManager.prefab @@ -45,6 +45,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 697f5ae5656c74dcd8d7f5d619adb0ac, type: 3} m_Name: m_EditorClassIdentifier: + preStageUiPrefab: {fileID: 4994633962466276707, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} --- !u!114 &158905820630581596 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/UI/MobileInputControls.prefab b/Assets/Prefabs/UI/MobileInputControls.prefab index 671ce55..99330e4 100644 --- a/Assets/Prefabs/UI/MobileInputControls.prefab +++ b/Assets/Prefabs/UI/MobileInputControls.prefab @@ -553,7 +553,7 @@ MonoBehaviour: m_FloatArgument: 1 m_StringArgument: Jump m_BoolArgument: 0 - m_CallState: 2 + m_CallState: 1 m_TypeName: UnityEngine.EventSystems.EventTrigger+TriggerEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null delegates: diff --git a/Assets/Prefabs/UI/PreStageUI.prefab b/Assets/Prefabs/UI/PreStageUI.prefab index dfaf195..ccefa2c 100644 --- a/Assets/Prefabs/UI/PreStageUI.prefab +++ b/Assets/Prefabs/UI/PreStageUI.prefab @@ -78,7 +78,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: Stage 1 + m_Text: --- !u!1 &2251350585563921972 GameObject: m_ObjectHideFlags: 0 @@ -165,7 +165,7 @@ GameObject: - component: {fileID: 2152024136797500473} - component: {fileID: 936482196064115039} - component: {fileID: 826719949318333507} - - component: {fileID: 2684488013186753063} + - component: {fileID: 4764158450672019134} m_Layer: 5 m_Name: PreStageUI m_TagString: Untagged @@ -254,7 +254,7 @@ MonoBehaviour: m_BlockingMask: serializedVersion: 2 m_Bits: 4294967295 ---- !u!114 &2684488013186753063 +--- !u!114 &4764158450672019134 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index bb21ab0..2d89179 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -271,7 +271,7 @@ Transform: m_Children: - {fileID: 97386695} m_Father: {fileID: 0} - m_RootOrder: 3 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &266944717 MonoBehaviour: @@ -404,7 +404,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 519420028} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 11.456655, y: -4.0430503, z: -10} + m_LocalPosition: {x: 13.828903, y: -4.0430503, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -478,137 +478,8 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 5 + m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1001 &1152312890 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 4994633962466276707, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_Name - value: PreStageUI - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_RootOrder - value: 9 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_AnchoredPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_AnchoredPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_SizeDelta.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_SizeDelta.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_AnchorMin.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_AnchorMin.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_AnchorMax.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_AnchorMax.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_Pivot.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_Pivot.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 2152024136797500473, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_Enabled - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 4935993846136593301, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, - type: 3} - propertyPath: m_Text - value: - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, type: 3} --- !u!4 &1352658977 stripped Transform: m_CorrespondingSourceObject: {fileID: 6843575828445418654, guid: d3055091a17dc4aa1accf2e33ccef144, @@ -734,7 +605,7 @@ PrefabInstance: - target: {fileID: 158905820630581587, guid: fdaa7451ab31b477b930076bbc888bab, type: 3} propertyPath: m_RootOrder - value: 6 + value: 5 objectReference: {fileID: 0} - target: {fileID: 158905820630581587, guid: fdaa7451ab31b477b930076bbc888bab, type: 3} @@ -882,27 +753,27 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 311312839, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8007755715420797612, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2219516564249810540, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1533625511004221075, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 7551096532728223647, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3} @@ -1099,7 +970,7 @@ PrefabInstance: - target: {fileID: 9082059503774285365, guid: fd1ddd924c55b4f9694b98102c91a0a6, type: 3} propertyPath: m_RootOrder - value: 4 + value: 3 objectReference: {fileID: 0} - target: {fileID: 9082059503774285365, guid: fd1ddd924c55b4f9694b98102c91a0a6, type: 3} diff --git a/Assets/Scripts/src/Base/UpgradeBase.cs b/Assets/Scripts/src/Base/UpgradeBase.cs index 2286e75..5aa312e 100644 --- a/Assets/Scripts/src/Base/UpgradeBase.cs +++ b/Assets/Scripts/src/Base/UpgradeBase.cs @@ -1,17 +1,18 @@ -using src.Base; using src.Interfaces; using src.Managers; using UnityEngine; -namespace src.Upgrade +namespace src.Base { public class UpgradeBase : GameplayComponent, IUpgrade { - protected GameManager gameManager; + protected GameManager GameManager; + private UpgradeManager _upgradeManager; public void Start() { - gameManager = GameManager.Instance; + GameManager = GameManager.Instance; + _upgradeManager = UpgradeManager.Instance; } public virtual void PerformUpgrade() @@ -23,6 +24,7 @@ namespace src.Upgrade { if (!other.CompareTag("Player")) return; PerformUpgrade(); + _upgradeManager.ClaimUpgrade(gameObject); Destroy(gameObject); } } diff --git a/Assets/Scripts/src/Managers/GameManager.cs b/Assets/Scripts/src/Managers/GameManager.cs index 47db7ef..c22bb1e 100644 --- a/Assets/Scripts/src/Managers/GameManager.cs +++ b/Assets/Scripts/src/Managers/GameManager.cs @@ -1,5 +1,6 @@ using System.Collections; using src.Helpers; +using src.Player; using UnityEngine; namespace src.Managers @@ -10,7 +11,11 @@ namespace src.Managers private LevelManager _levelManager; private UpgradeManager _upgradeManager; private BombsUtilManager _bombsUtilManager; - private GameObject _preStageUi; + + // External Components + public GameObject preStageUiPrefab; + private PlayerController _playerController; + private readonly GameStateManager _gameStateManager = GameStateManager.Instance; public void Awake() { @@ -26,16 +31,26 @@ namespace src.Managers /* Don't destroy when reloading the scene */ DontDestroyOnLoad(gameObject); + // Load inner components _levelManager = GetComponent(); _upgradeManager = GetComponent(); _bombsUtilManager = BombsUtilManager.Instance; - _preStageUi = GameObject.Find("PreStageUI"); + + // Load external components + _playerController = GameObject.Find("Player").GetComponent(); } public void Start() { + _levelManager.InitBoard(); + StartLevel(); + } + + private void StartLevel() + { + _playerController.Respawn(); StartCoroutine(PreInitGame()); - InitGame(); + _levelManager.InitLevel(); } public UpgradeManager GetUpgradeManager() @@ -47,16 +62,13 @@ namespace src.Managers { return _bombsUtilManager; } - - private void InitGame() - { - _levelManager.InitLevel(); - } + private IEnumerator PreInitGame() { - _preStageUi.SetActive(true); + var preStageUi = Instantiate(preStageUiPrefab); // Will destroy itself. + preStageUi.SetActive(true); yield return new WaitForSeconds(1f); - _preStageUi.SetActive(false); + Destroy(preStageUi); } private void Update() @@ -75,5 +87,14 @@ namespace src.Managers ApplicationActions.HandlePauseKey(); } } + + public void StartNextLevel() + { + DebugHelper.LogInfo("Initializing next level!"); + _levelManager.DestroyLevel(); + _upgradeManager.DestroyUnclaimedUpgrades(); + _gameStateManager.IncreaseLevel(); + StartLevel(); + } } } \ No newline at end of file diff --git a/Assets/Scripts/src/Managers/LevelManager.cs b/Assets/Scripts/src/Managers/LevelManager.cs index b50f212..ee08e68 100644 --- a/Assets/Scripts/src/Managers/LevelManager.cs +++ b/Assets/Scripts/src/Managers/LevelManager.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using src.Base; using src.Helpers; using src.Wall; @@ -63,47 +64,46 @@ namespace src.Managers private const int Rows = 20; /* Holds the available positions */ - private readonly List _freeGridPositions = new List(); - private readonly List _destructibleWalls = new List(); - private readonly List _enemies = new List(); + private readonly List _freeGridPositionsBoard = new List(); + private List _freeGridPositions; + private List _destructibleWalls; + private List _enemies; - private void SetupUpgrades() + /* Modifies walls from _destructibleWalls in order to setup upgrades*/ + private void SetupSpawnables() { var count = _upgradesCount.RandomIntRange(); + var wallsSize = _destructibleWalls.Count; + _destructibleWalls.ShuffleList(); for (var i = 0; i < count; i++) { - if (_destructibleWalls.Count == 0) + if (i > wallsSize - 1) { DebugHelper.LogWarning("No destructible walls left, cannot spawn upgrade."); continue; } /* Get the destructible wall script and make it to spawn the upgrade */ - var wall = _destructibleWalls.PopRandom().GetComponent(); + var wall = _destructibleWalls[i].GetComponent(); DebugHelper.LogInfo($"Spawned upgrade at: x:{wall.XCoordinate} y:{wall.YCoordinate}"); wall.SpawnsUpgrade(); } - } - - private void SetupExit() - { - if (_destructibleWalls.Count == 0) + + if (count > wallsSize - 2) { Debug.LogWarning("No destructible walls found, cannot spawn exit!"); return; } - - /* Get the destructible wall script and make it to spawn the exit */ - var wall = _destructibleWalls.PopRandom().GetComponent(); - DebugHelper.LogInfo($"Spawned exit at: x:{wall.XCoordinate} y:{wall.YCoordinate}"); - wall.SpawnsExit(); + + var exitWall = _destructibleWalls[count + 1].GetComponent(); + DebugHelper.LogInfo($"Spawned exit at: x:{exitWall.XCoordinate} y:{exitWall.YCoordinate}"); + exitWall.SpawnsExit(); } /* Place the indestructible tiles on the board and saves the * unused positions in a list. */ - private void InitBoard() + public void InitBoard() { - _freeGridPositions.Clear(); /* We want to iterate over the X axis taking into consideration the startPosition's offset */ for (var x = startPosition.position.x; x < Columns; x++) { @@ -135,7 +135,7 @@ namespace src.Managers } /* Add position to _gridPositions */ - _freeGridPositions.Add(new Vector3(x, y, 0f)); + _freeGridPositionsBoard.Add(new Vector3(x, y, 0f)); } } } @@ -143,18 +143,18 @@ namespace src.Managers /* Randomly places destructible tiles on the level. */ private void SetupLevelDestructibleWalls() { - var numberOfDestructilbeWallsToPlace = _destructibleWallCount.RandomIntRange(); + var numberOfWallsRemaining = _destructibleWallCount.RandomIntRange(); List usedPositions = new List(); _freeGridPositions.ShuffleList(); foreach (var nextPosition in _freeGridPositions) { - if (numberOfDestructilbeWallsToPlace == 0) + if (numberOfWallsRemaining == 0) { break; } usedPositions.Add(nextPosition); PlaceDestructibleTile(nextPosition); - numberOfDestructilbeWallsToPlace -= 1; + numberOfWallsRemaining -= 1; } foreach (var usedPosition in usedPositions) { @@ -164,7 +164,8 @@ namespace src.Managers private void PlaceDestructibleTile(Vector3 position) { - DebugHelper.LogInfo($"PlaceDestructibleTile: x:{position.x} y:{position.y}"); + // TODO ADD ENUMS AND DEFINES TO THE LOGGING SYSTEM +// DebugHelper.LogInfo($"PlaceDestructibleTile: x:{position.x} y:{position.y}"); var randomWall = destructibleWallPrefabs.ChoseRandom(); var instance = Instantiate(randomWall, position, Quaternion.identity); _destructibleWalls.Add(instance); @@ -173,7 +174,7 @@ namespace src.Managers private bool PlaceIndestructibleTile(float x, float y) { - DebugHelper.LogInfo($"PlaceIndestructibleTile: x:{x} y:{y}"); +// DebugHelper.LogInfo($"PlaceIndestructibleTile: x:{x} y:{y}"); var absX = Mathf.RoundToInt(x); var absY = Mathf.RoundToInt(y); @@ -207,7 +208,7 @@ namespace src.Managers private bool PlaceEnemy(Vector3 position) { - DebugHelper.LogInfo($"PlaceEnemy: x:{position.x} y:{position.y}"); +// DebugHelper.LogInfo($"PlaceEnemy: x:{position.x} y:{position.y}"); var randomEnemy = enemiesPrefab.ChoseRandom(); var instance = Instantiate(randomEnemy, position, Quaternion.identity); _enemies.Add(instance); @@ -218,11 +219,26 @@ namespace src.Managers /* Initializes the level. */ public void InitLevel() { - InitBoard(); + _freeGridPositions = new List(_freeGridPositionsBoard); + _destructibleWalls = new List(); + _enemies = new List(); SetupLevelDestructibleWalls(); SetupLevelEnemies(); - SetupExit(); - SetupUpgrades(); + SetupSpawnables(); + } + + public void DestroyLevel() + { + foreach (var enemy in _enemies) + { + Destroy(enemy); + } + + foreach (var wall in _destructibleWalls) + { + Destroy(wall); + } + DebugHelper.LogInfo("LevelManager: Cleared level!"); } } } \ No newline at end of file diff --git a/Assets/Scripts/src/Managers/UpgradeManager.cs b/Assets/Scripts/src/Managers/UpgradeManager.cs index 9bbb09a..0337d83 100644 --- a/Assets/Scripts/src/Managers/UpgradeManager.cs +++ b/Assets/Scripts/src/Managers/UpgradeManager.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using src.Base; using src.Helpers; using UnityEngine; @@ -6,11 +8,45 @@ namespace src.Managers { public class UpgradeManager : GameplayComponent { + public static UpgradeManager Instance; + private List _unclaimedUpgrades = new List(); public GameObject[] upgradePrefabs; + private void Awake() + { + if (Instance == null) + { + Instance = this; + } + else if (Instance != null) + { + Destroy(gameObject); + } + } + public GameObject GetUpgradePrefab() { return upgradePrefabs.ChoseRandom(); } + + /* Register unclaimed upgrades so then can be destroyed on level changed or other events. */ + public void RegisterUpgradeAsUnclaimed(GameObject instance) + { + _unclaimedUpgrades.Add(instance); + } + + public void ClaimUpgrade(GameObject instance) + { + _unclaimedUpgrades.Remove(instance); + } + + public void DestroyUnclaimedUpgrades() + { + foreach (var upgrade in _unclaimedUpgrades) + { + Destroy(upgrade); + } + _unclaimedUpgrades = new List(); + } } } \ No newline at end of file diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index 542d9f3..53dee5d 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -29,10 +29,6 @@ namespace src.Player movementSpeed = _playerUpgrade.GetMovementSpeed(); _playerUpgrade.PlayerSpeed += IncreaseSpeed; - - - /* Always start at the starting point. */ - Respawn(); } private void FixedUpdate() @@ -106,9 +102,11 @@ namespace src.Player #endif } - private void Respawn() + public void Respawn() { + DebugHelper.LogInfo("Player is respawning!"); transform.SetPositionAndRotation(_respawnPosition.position, Quaternion.identity); + _animator.Play("IdleDown"); } public void OnTriggerExit2D(Collider2D other) diff --git a/Assets/Scripts/src/UI/PreLevelLoad.cs b/Assets/Scripts/src/UI/PreStageUiScript.cs similarity index 81% rename from Assets/Scripts/src/UI/PreLevelLoad.cs rename to Assets/Scripts/src/UI/PreStageUiScript.cs index 720626d..aefde31 100644 --- a/Assets/Scripts/src/UI/PreLevelLoad.cs +++ b/Assets/Scripts/src/UI/PreStageUiScript.cs @@ -1,10 +1,11 @@ +using src.Base; using src.Managers; using UnityEngine; using UnityEngine.UI; namespace src.UI { - public class PreLevelLoad : MonoBehaviour + public class PreStageUiScript : GameplayComponent { private readonly GameStateManager _gameStateManager = GameStateManager.Instance; private Text _stageText; diff --git a/Assets/Scripts/src/UI/PreLevelLoad.cs.meta b/Assets/Scripts/src/UI/PreStageUiScript.cs.meta similarity index 100% rename from Assets/Scripts/src/UI/PreLevelLoad.cs.meta rename to Assets/Scripts/src/UI/PreStageUiScript.cs.meta diff --git a/Assets/Scripts/src/Upgrade/BombFlamesUpgrade.cs b/Assets/Scripts/src/Upgrade/BombFlamesUpgrade.cs index 110f877..9402172 100644 --- a/Assets/Scripts/src/Upgrade/BombFlamesUpgrade.cs +++ b/Assets/Scripts/src/Upgrade/BombFlamesUpgrade.cs @@ -1,10 +1,12 @@ +using src.Base; + namespace src.Upgrade { public class BombFlamesUpgrade : UpgradeBase { public override void PerformUpgrade() { - var bombManager = gameManager.GetBombsUtilManager(); + var bombManager = GameManager.GetBombsUtilManager(); bombManager.IncreasePower(); } } diff --git a/Assets/Scripts/src/Upgrade/BombPlacementUpgrade.cs b/Assets/Scripts/src/Upgrade/BombPlacementUpgrade.cs index 3e7b770..89497ab 100644 --- a/Assets/Scripts/src/Upgrade/BombPlacementUpgrade.cs +++ b/Assets/Scripts/src/Upgrade/BombPlacementUpgrade.cs @@ -1,10 +1,12 @@ +using src.Base; + namespace src.Upgrade { public class BombPlacementUpgrade : UpgradeBase { public override void PerformUpgrade() { - var bombManager = gameManager.GetBombsUtilManager(); + var bombManager = GameManager.GetBombsUtilManager(); bombManager.IncreaseAllowedBombs(); } } diff --git a/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs b/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs index 4f1f5b3..013a47b 100644 --- a/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs +++ b/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs @@ -1,3 +1,4 @@ +using src.Base; using src.Player; namespace src.Upgrade diff --git a/Assets/Scripts/src/Wall/DestructibleWall.cs b/Assets/Scripts/src/Wall/DestructibleWall.cs index 6c27b55..b839da3 100644 --- a/Assets/Scripts/src/Wall/DestructibleWall.cs +++ b/Assets/Scripts/src/Wall/DestructibleWall.cs @@ -36,7 +36,7 @@ namespace src.Wall public float XCoordinate => transform.position.x; public float YCoordinate => transform.position.y; - private void BeforeDestroy() + private void SpawnSomething() { var currentPosition = transform.position; Destroy(GetComponent()); @@ -50,12 +50,12 @@ namespace src.Wall { DebugHelper.LogInfo($"Destructible spawned upgrade {transform.position}"); var upgrade = _upgradeManager.GetUpgradePrefab(); - Instantiate(upgrade, currentPosition, Quaternion.identity); + var instance = Instantiate(upgrade, currentPosition, Quaternion.identity); + _upgradeManager.RegisterUpgradeAsUnclaimed(instance); } - SwapToPulverise(); } - private void SwapToPulverise() + private void PlayDestroyAnimation() { // _animator.speed = 10; } @@ -63,7 +63,8 @@ namespace src.Wall public void onExplosion() { DebugHelper.LogInfo($"Destructible wall hit by explosion {transform.position}"); - BeforeDestroy(); + PlayDestroyAnimation(); + SpawnSomething(); Destroy(gameObject); } } diff --git a/Assets/Scripts/src/Wall/ExitDoor.cs b/Assets/Scripts/src/Wall/ExitDoor.cs new file mode 100644 index 0000000..829bbd2 --- /dev/null +++ b/Assets/Scripts/src/Wall/ExitDoor.cs @@ -0,0 +1,30 @@ +using System; +using src.Base; +using src.Managers; +using UnityEngine; + +namespace src.Wall +{ + public class ExitDoor : GameplayComponent + { + private GameManager _gameManager; + private Collider2D _collider2D; + + private void Start() + { + _gameManager = GameManager.Instance; + _collider2D = GetComponent(); + } + + /* Trigger the next level and destroy itself. */ + private void OnTriggerStay2D(Collider2D other) + { + if (!other.CompareTag("Player")) + { + return; + } + Destroy(this); + _gameManager.StartNextLevel(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/src/Wall/ExitDoor.cs.meta b/Assets/Scripts/src/Wall/ExitDoor.cs.meta new file mode 100644 index 0000000..aa2631a --- /dev/null +++ b/Assets/Scripts/src/Wall/ExitDoor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d5d5847c8fef4a91bafe88cc2ccf43ec +timeCreated: 1563024607 \ No newline at end of file diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index f76ea9b..8887fbb 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -591,9 +591,9 @@ PlayerSettings: webGLThreadsSupport: 0 scriptingDefineSymbols: 1: CROSS_PLATFORM_INPUT - 4: CROSS_PLATFORM_INPUT;MOBILE_INPUT - 7: CROSS_PLATFORM_INPUT;MOBILE_INPUT - 14: MOBILE_INPUT + 4: CROSS_PLATFORM_INPUT + 7: CROSS_PLATFORM_INPUT + 14: platformArchitecture: {} scriptingBackend: {} il2cppCompilerConfiguration: {} From 73f3ff25daf9a96b7328d8492cec5d63d0c2eee7 Mon Sep 17 00:00:00 2001 From: Denis NUTIU Date: Sat, 13 Jul 2019 18:15:22 +0300 Subject: [PATCH 2/7] Fix exitDoorPrefab not destroying itself --- Assets/Scripts/src/Wall/ExitDoor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/src/Wall/ExitDoor.cs b/Assets/Scripts/src/Wall/ExitDoor.cs index 829bbd2..07709d4 100644 --- a/Assets/Scripts/src/Wall/ExitDoor.cs +++ b/Assets/Scripts/src/Wall/ExitDoor.cs @@ -23,7 +23,7 @@ namespace src.Wall { return; } - Destroy(this); + Destroy(gameObject, 1f); _gameManager.StartNextLevel(); } } From ffa46c242675a6d3005a1b2e6bda69998c89ccd1 Mon Sep 17 00:00:00 2001 From: Denis NUTIU Date: Sat, 13 Jul 2019 18:26:06 +0300 Subject: [PATCH 3/7] Add back respawn player --- Assets/Scripts/src/Player/PlayerController.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index 53dee5d..5314ab4 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -29,6 +29,8 @@ namespace src.Player movementSpeed = _playerUpgrade.GetMovementSpeed(); _playerUpgrade.PlayerSpeed += IncreaseSpeed; + + Respawn(); } private void FixedUpdate() From 66a91cb6188c27b8835d14b2f3660bfe3a043efb Mon Sep 17 00:00:00 2001 From: Denis NUTIU Date: Sat, 13 Jul 2019 18:35:29 +0300 Subject: [PATCH 4/7] Implement LogVerbose & update level manager's logging --- Assets/Scripts/src/Helpers/DebugHelper.cs | 10 ++++++++++ Assets/Scripts/src/Managers/LevelManager.cs | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/src/Helpers/DebugHelper.cs b/Assets/Scripts/src/Helpers/DebugHelper.cs index d23b438..d252efc 100644 --- a/Assets/Scripts/src/Helpers/DebugHelper.cs +++ b/Assets/Scripts/src/Helpers/DebugHelper.cs @@ -8,6 +8,16 @@ namespace src.Helpers { public static class DebugHelper { + public static void LogVerbose(string message) + { +#if LOG_VERBOSE + if (Debug.isDebugBuild) + { + Debug.Log(message); + } +#endif + } + public static void LogInfo(string message) { if (Debug.isDebugBuild) diff --git a/Assets/Scripts/src/Managers/LevelManager.cs b/Assets/Scripts/src/Managers/LevelManager.cs index ee08e68..ac35ea2 100644 --- a/Assets/Scripts/src/Managers/LevelManager.cs +++ b/Assets/Scripts/src/Managers/LevelManager.cs @@ -164,8 +164,7 @@ namespace src.Managers private void PlaceDestructibleTile(Vector3 position) { - // TODO ADD ENUMS AND DEFINES TO THE LOGGING SYSTEM -// DebugHelper.LogInfo($"PlaceDestructibleTile: x:{position.x} y:{position.y}"); + DebugHelper.LogVerbose($"PlaceDestructibleTile: x:{position.x} y:{position.y}"); var randomWall = destructibleWallPrefabs.ChoseRandom(); var instance = Instantiate(randomWall, position, Quaternion.identity); _destructibleWalls.Add(instance); @@ -174,7 +173,7 @@ namespace src.Managers private bool PlaceIndestructibleTile(float x, float y) { -// DebugHelper.LogInfo($"PlaceIndestructibleTile: x:{x} y:{y}"); + DebugHelper.LogVerbose($"PlaceIndestructibleTile: x:{x} y:{y}"); var absX = Mathf.RoundToInt(x); var absY = Mathf.RoundToInt(y); @@ -208,7 +207,7 @@ namespace src.Managers private bool PlaceEnemy(Vector3 position) { -// DebugHelper.LogInfo($"PlaceEnemy: x:{position.x} y:{position.y}"); + DebugHelper.LogVerbose($"PlaceEnemy: x:{position.x} y:{position.y}"); var randomEnemy = enemiesPrefab.ChoseRandom(); var instance = Instantiate(randomEnemy, position, Quaternion.identity); _enemies.Add(instance); From d9bdd30ab6f7ec455829fe5e00071988105c5936 Mon Sep 17 00:00:00 2001 From: Denis NUTIU Date: Sun, 14 Jul 2019 11:04:22 +0300 Subject: [PATCH 5/7] Fix place bomb button sprite --- Assets/Sprites/UI/Controls/PlaceBombButton.png | Bin 496 -> 442 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Assets/Sprites/UI/Controls/PlaceBombButton.png b/Assets/Sprites/UI/Controls/PlaceBombButton.png index a39e5b5c8d327a1e73ce4a1577368a3d33962aa4..9bc50969ea7a1d0ac654b6595e9669c114cec3ad 100644 GIT binary patch delta 403 zcmV;E0c`&81G)o{F@JPPL_t(og~eC9Zo)7Wy+-{CSV}uoNL@hfz{JeVH&Cf_KBvkb zv~$<)?be|zEiCj8NH7fUP~FIw#6H(J;z&_IxjyIIM;uv^5Kk|!#`kYf5#1Dw6x^M4p|UlrgA#9+G*4{NIi5CjdNubc}cd&ofB2yVs5X5zxl{&)R##Lb## zuRzcMvY*>PvOhB5ej;PA-EZK*vsXM6B#6lAG_GV{i_Hy9Y+>z|g@0;0db`n9L^UJGJ zGS1e)-frX@!wv`qYm7K=xZti}oupmv6cN6UPE{tzixiy8qJNXL%U=I};=VM-)CGH@ zWF093(s-=vS>ckn@hotu>{uo%3WayO-Fi-z=lCfKq-m~2({U- zuWggtGb@Jm|F@4j@%ElDz`<>>33SP2#AHq_K~r!5SXtWizDa8X(zSnlz81kbk=xKE zGy4ku`hF{hEq^Sw*eZyY0Qf8W>hcx<)W1!LHBe=5u6YQYtAe-!AsUVS59?eFNaQsj z-Ey`h*^3O!Th7xE0G?iMf=)y``>)S|^ECWF6#(cea0d$|P4)l~H`REI#zXOgSBdNg zv{m51zU%>`CzSRD)d|OCYlFG?!A&XkdZoa=xQ(>soI+G>xoc90k>C##E`Y>{b{-pS z|M;u~fMlb^4RfmhFaQ8toE+*uPAMZ=ao|e7qzDe!*9m(F00000NkvXXu0mjfkSgLv From 6cc8a4e6b3118a9a0ace411b6970d4ec0c0771a8 Mon Sep 17 00:00:00 2001 From: Denis NUTIU Date: Sun, 14 Jul 2019 11:11:44 +0300 Subject: [PATCH 6/7] Increase pre-stage font-size when on mobile --- Assets/Prefabs/UI/PreStageUI.prefab | 6 +++--- Assets/Scripts/src/UI/PreStageUiScript.cs | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Assets/Prefabs/UI/PreStageUI.prefab b/Assets/Prefabs/UI/PreStageUI.prefab index ccefa2c..02e891f 100644 --- a/Assets/Prefabs/UI/PreStageUI.prefab +++ b/Assets/Prefabs/UI/PreStageUI.prefab @@ -34,8 +34,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 160, y: 30} + m_AnchoredPosition: {x: 70.3, y: -35.5} + m_SizeDelta: {x: 300.5, y: 101.1} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &5829552964612260718 CanvasRenderer: @@ -71,7 +71,7 @@ MonoBehaviour: m_FontStyle: 1 m_BestFit: 0 m_MinSize: 1 - m_MaxSize: 40 + m_MaxSize: 50 m_Alignment: 0 m_AlignByGeometry: 0 m_RichText: 0 diff --git a/Assets/Scripts/src/UI/PreStageUiScript.cs b/Assets/Scripts/src/UI/PreStageUiScript.cs index aefde31..d05826e 100644 --- a/Assets/Scripts/src/UI/PreStageUiScript.cs +++ b/Assets/Scripts/src/UI/PreStageUiScript.cs @@ -13,6 +13,9 @@ namespace src.UI public void Start() { _stageText = GetComponentInChildren(); +#if UNITY_ANDROID || UNITY_IOS + _stageText.fontSize = 50; +#endif _stageText.text = $"Stage {_gameStateManager.Level}"; } } From 7031e027788a7cb62032a973f407354569dfcddc Mon Sep 17 00:00:00 2001 From: Denis NUTIU Date: Sun, 14 Jul 2019 14:15:14 +0300 Subject: [PATCH 7/7] Add levelnumber in level initialization log --- Assets/Scripts/src/Managers/GameManager.cs | 1 - Assets/Scripts/src/Managers/LevelManager.cs | 4 ++++ ProjectSettings/ProjectSettings.asset | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/src/Managers/GameManager.cs b/Assets/Scripts/src/Managers/GameManager.cs index c22bb1e..16ec65c 100644 --- a/Assets/Scripts/src/Managers/GameManager.cs +++ b/Assets/Scripts/src/Managers/GameManager.cs @@ -90,7 +90,6 @@ namespace src.Managers public void StartNextLevel() { - DebugHelper.LogInfo("Initializing next level!"); _levelManager.DestroyLevel(); _upgradeManager.DestroyUnclaimedUpgrades(); _gameStateManager.IncreaseLevel(); diff --git a/Assets/Scripts/src/Managers/LevelManager.cs b/Assets/Scripts/src/Managers/LevelManager.cs index ac35ea2..ab9e24e 100644 --- a/Assets/Scripts/src/Managers/LevelManager.cs +++ b/Assets/Scripts/src/Managers/LevelManager.cs @@ -68,6 +68,9 @@ namespace src.Managers private List _freeGridPositions; private List _destructibleWalls; private List _enemies; + + /* Singletons */ + private GameStateManager _gameStateManager = GameStateManager.Instance; /* Modifies walls from _destructibleWalls in order to setup upgrades*/ private void SetupSpawnables() @@ -218,6 +221,7 @@ namespace src.Managers /* Initializes the level. */ public void InitLevel() { + DebugHelper.LogInfo($"Initializing level: #{_gameStateManager.Level}"); _freeGridPositions = new List(_freeGridPositionsBoard); _destructibleWalls = new List(); _enemies = new List(); diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 8887fbb..f76ea9b 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -591,9 +591,9 @@ PlayerSettings: webGLThreadsSupport: 0 scriptingDefineSymbols: 1: CROSS_PLATFORM_INPUT - 4: CROSS_PLATFORM_INPUT - 7: CROSS_PLATFORM_INPUT - 14: + 4: CROSS_PLATFORM_INPUT;MOBILE_INPUT + 7: CROSS_PLATFORM_INPUT;MOBILE_INPUT + 14: MOBILE_INPUT platformArchitecture: {} scriptingBackend: {} il2cppCompilerConfiguration: {}