From ee1703b69b7977a8cd6d37dd097f425c8c905882 Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Thu, 03 Apr 2025 22:24:35 +0000 Subject: [PATCH] #42 added jobs for tile generation --- Assets/Scripts/Managers/GameManager.cs | 32 +++++++++++++++++++++++++++++--- 1 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index e0670dd..9f4d5ed 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -14,8 +14,10 @@ public GameObject damageTextPrefab; public GameObject healthTextPrefab; + public GameObject lootTextPrefab; public Canvas playerUI; public Canvas pauseMenuUI; + public Canvas worldSpaceUI; public GameObject levelChanger; public Tilemap tilemap; [NonSerialized] @@ -23,6 +25,8 @@ [NonSerialized] public List<Vector3Int> destroyedTiles = new List<Vector3Int>(); public GameObject pickups; + public Tilemap fogTilemap; + public FogOfWar fogOfWar; private void Awake() { @@ -50,6 +54,7 @@ SaveDataMap mapState = SaveSystem.LoadMapState(); if (mapState != null) { + //fogOfWar.LoadFromSaveData(mapState.fogOfWarData); generateTileMap.SetSettingsFromSeed(mapState.seed); if (mapState.destroyedTiles != null && mapState.destroyedTiles.Count > 0) { @@ -112,6 +117,20 @@ tmpText.text = healthRestored.ToString(); } + public void CharacterLootObtained(Vector3 position, Item itemReceived, int quantity) + { + // Offset the position slightly up so it doesn't spawn inside the ground/player + position += Vector3.up * 0.5f; + + // Create text in world space (no parent needed) + GameObject textObj = Instantiate(lootTextPrefab, position, Quaternion.identity, worldSpaceUI.transform); + TextMeshProUGUI tmpText = textObj.GetComponent<TextMeshProUGUI>(); + tmpText.text = $"+{quantity} ({itemReceived.itemName})"; + + // Ensure it's visible to the camera + textObj.transform.rotation = Camera.main.transform.rotation; + + } public void CharacterDrill(ContactPoint2D contact, DrillDirection drillDirection) { GridLayout grid = tilemap.transform.GetComponentInParent<GridLayout>(); @@ -125,7 +144,10 @@ cellCoord.x = cellCoord.x + 1; break; case DrillDirection.Down: - cellCoord.y = cellCoord.y - 1; + // Use player's center position for downward drilling + Vector3 playerCenter = contact.rigidbody.transform.position; + cellCoord = grid.WorldToCell(playerCenter); + cellCoord.y = grid.WorldToCell(contact.point).y - 1; // Keep the vertical position from contact point break; } @@ -140,14 +162,18 @@ // middle of tile cellWorldPosition.x += 0.5f; cellWorldPosition.y += 0.5f; - if (tileGameObject?.GetComponent<Dropable>()?.isDropable ?? false) + Dropable dropable = tileGameObject?.GetComponent<Dropable>(); + if (dropable?.isDropable ?? false) { // Change no drops, only inventory //Instantiate(tileGameObject?.GetComponent<Dropable>().dropable, cellWorldPosition, Quaternion.identity, pickups.transform); Inventory playerInventory = contact.rigidbody.gameObject.GetComponent<Inventory>(); if (playerInventory != null) { - playerInventory.AddItem(tileGameObject?.GetComponent<Dropable>().dropable); + Item item = dropable.dropable; + int dropAmount = dropable.GetRandomDropAmount(); + playerInventory.AddItem(item, dropAmount); + CharacterLootObtained(tileGameObject.transform.position, item, dropAmount); } } tilemap.SetTile(cellCoord, null); -- Gitblit v1.9.3