Commit 45b90dea authored by KenzyAshour2's avatar KenzyAshour2

ai better seka now

parent b9510b9b
This diff is collapsed.
...@@ -4,19 +4,19 @@ using System.Collections.Generic; ...@@ -4,19 +4,19 @@ using System.Collections.Generic;
public class DeepSeaSpawner : MonoBehaviour public class DeepSeaSpawner : MonoBehaviour
{ {
[Header("Game Logic")]
public Button nextButton;
public int rocksNeededToWin = 3;
[SerializeField] SpriteRenderer zoneRenderer;
[SerializeField] Color highlightColor = new Color(0f, 1f, 0f, 0.4f);
private Color hiddenColor = new Color(0f, 0f, 0f, 0f);
[SerializeField] Button nextButton;
public int rocksNeededToWin = 3;
private int currentPlacedRocks = 0; private int currentPlacedRocks = 0;
[Header("Bubble Settings")] [SerializeField] GameObject bubblePrefab;
public GameObject bubblePrefab; [SerializeField] Transform[] bubbleSpawnPoints;
public Transform[] bubbleSpawnPoints; [SerializeField] float bubbleInterval = 1.5f;
public float bubbleInterval = 1.5f;
[Header("Floating Rock Settings")] [SerializeField] GameObject[] rockPrefabs;
public GameObject[] rockPrefabs;
public int initialRockCount = 12; public int initialRockCount = 12;
public float spawnPadding = 0.5f; public float spawnPadding = 0.5f;
...@@ -26,46 +26,47 @@ public class DeepSeaSpawner : MonoBehaviour ...@@ -26,46 +26,47 @@ public class DeepSeaSpawner : MonoBehaviour
void Start() void Start()
{ {
cam = Camera.main; cam = Camera.main;
if (zoneRenderer != null) zoneRenderer.color = hiddenColor;
} }
void OnEnable() void OnEnable()
{ {
if (cam == null) cam = Camera.main; if (cam == null) cam = Camera.main;
// Reset the game logic
currentPlacedRocks = 0; currentPlacedRocks = 0;
// --- THE FIX ---
// We wait 0.1 seconds to make sure we override the ImageSwitcher
Invoke(nameof(LockButton), 0.1f); Invoke(nameof(LockButton), 0.1f);
// ----------------
SpawnInitialRocks(); SpawnInitialRocks();
InvokeRepeating(nameof(SpawnBubble), 0f, bubbleInterval); InvokeRepeating(nameof(SpawnBubble), 0f, bubbleInterval);
} }
public void SetZoneHighlight(bool isActive)
void LockButton()
{ {
if (nextButton != null) if (zoneRenderer != null)
{ {
nextButton.interactable = false; zoneRenderer.color = isActive ? highlightColor : hiddenColor;
} }
} }
void LockButton()
{
if (nextButton != null) nextButton.interactable = false;
}
void OnDisable() void OnDisable()
{ {
CancelInvoke(); CancelInvoke();
CleanupObjects(); CleanupObjects();
if (zoneRenderer != null) zoneRenderer.color = hiddenColor;
} }
public void RockPlaced() public void RockPlaced()
{ {
currentPlacedRocks++; currentPlacedRocks++;
SetZoneHighlight(false);
if (currentPlacedRocks >= rocksNeededToWin) if (currentPlacedRocks >= rocksNeededToWin)
{ {
if (nextButton != null) nextButton.interactable = true; if (nextButton != null) nextButton.interactable = true;
Debug.Log("Deposition Complete! Next button unlocked."); Debug.Log("Deposition Complete!");
} }
} }
...@@ -73,22 +74,17 @@ public class DeepSeaSpawner : MonoBehaviour ...@@ -73,22 +74,17 @@ public class DeepSeaSpawner : MonoBehaviour
{ {
Vector2 minScreen = cam.ViewportToWorldPoint(new Vector3(0, 0, 0)); Vector2 minScreen = cam.ViewportToWorldPoint(new Vector3(0, 0, 0));
Vector2 maxScreen = cam.ViewportToWorldPoint(new Vector3(1, 1, 0)); Vector2 maxScreen = cam.ViewportToWorldPoint(new Vector3(1, 1, 0));
float bottomLimit = minScreen.y + 2.0f; float bottomLimit = minScreen.y + 2.0f;
for (int i = 0; i < initialRockCount; i++) for (int i = 0; i < initialRockCount; i++)
{ {
if (rockPrefabs.Length == 0) return; if (rockPrefabs.Length == 0) return;
GameObject randomPrefab = rockPrefabs[Random.Range(0, rockPrefabs.Length)]; GameObject randomPrefab = rockPrefabs[Random.Range(0, rockPrefabs.Length)];
float randomX = Random.Range(minScreen.x + spawnPadding, maxScreen.x - spawnPadding); float randomX = Random.Range(minScreen.x + spawnPadding, maxScreen.x - spawnPadding);
float randomY = Random.Range(bottomLimit, maxScreen.y - spawnPadding); float randomY = Random.Range(bottomLimit, maxScreen.y - spawnPadding);
Vector3 spawnPos = new Vector3(randomX, randomY, 0); GameObject rock = Instantiate(randomPrefab, new Vector3(randomX, randomY, 0), Quaternion.identity);
GameObject rock = Instantiate(randomPrefab, spawnPos, Quaternion.identity);
rock.transform.SetParent(this.transform); rock.transform.SetParent(this.transform);
spawnedObjects.Add(rock); spawnedObjects.Add(rock);
} }
...@@ -97,11 +93,8 @@ public class DeepSeaSpawner : MonoBehaviour ...@@ -97,11 +93,8 @@ public class DeepSeaSpawner : MonoBehaviour
void SpawnBubble() void SpawnBubble()
{ {
if (bubblePrefab == null || bubbleSpawnPoints.Length == 0) return; if (bubblePrefab == null || bubbleSpawnPoints.Length == 0) return;
Transform spawnPoint = bubbleSpawnPoints[Random.Range(0, bubbleSpawnPoints.Length)]; Transform spawnPoint = bubbleSpawnPoints[Random.Range(0, bubbleSpawnPoints.Length)];
Vector3 spawnPos = spawnPoint.position + new Vector3(Random.Range(-0.2f, 0.2f), 0.5f, 0); GameObject bubble = Instantiate(bubblePrefab, spawnPoint.position, Quaternion.identity);
GameObject bubble = Instantiate(bubblePrefab, spawnPos, Quaternion.identity);
bubble.transform.SetParent(this.transform); bubble.transform.SetParent(this.transform);
spawnedObjects.Add(bubble); spawnedObjects.Add(bubble);
} }
......
...@@ -7,8 +7,8 @@ public class FloatingDraggableRock : MonoBehaviour ...@@ -7,8 +7,8 @@ public class FloatingDraggableRock : MonoBehaviour
private Vector3 targetPos; private Vector3 targetPos;
private bool isDragging = false; private bool isDragging = false;
private bool isPlaced = false; // Is it stuck to the ground? private bool isPlaced = false;
private bool isHoveringGround = false; // Are we currently over the zone? private bool isHoveringGround = false;
private Vector3 dragOffset; private Vector3 dragOffset;
private float zCoord; private float zCoord;
...@@ -18,46 +18,35 @@ public class FloatingDraggableRock : MonoBehaviour ...@@ -18,46 +18,35 @@ public class FloatingDraggableRock : MonoBehaviour
void Start() void Start()
{ {
cam = Camera.main; cam = Camera.main;
// Find the spawner so we can tell it when we are placed
mySpawner = GetComponentInParent<DeepSeaSpawner>(); mySpawner = GetComponentInParent<DeepSeaSpawner>();
PickNewScreenTarget(); PickNewScreenTarget();
} }
void Update() void Update()
{ {
// If placed, do nothing (stay stuck)
if (isPlaced) return; if (isPlaced) return;
if (!isDragging) if (!isDragging)
{ {
// Move slowly towards the target
transform.position = Vector3.MoveTowards(transform.position, targetPos, floatSpeed * Time.deltaTime); transform.position = Vector3.MoveTowards(transform.position, targetPos, floatSpeed * Time.deltaTime);
if (Vector3.Distance(transform.position, targetPos) < 0.1f) PickNewScreenTarget();
if (Vector3.Distance(transform.position, targetPos) < 0.1f)
{
PickNewScreenTarget();
}
} }
} }
void PickNewScreenTarget() void PickNewScreenTarget()
{ {
// Keep floating targets high up so they don't accidentally float into the ground zone Vector2 minScreen = cam.ViewportToWorldPoint(new Vector3(0.1f, 0.3f, 0));
Vector2 minScreen = cam.ViewportToWorldPoint(new Vector3(0.1f, 0.3f, 0)); // Start 30% up the screen
Vector2 maxScreen = cam.ViewportToWorldPoint(new Vector3(0.9f, 0.9f, 0)); Vector2 maxScreen = cam.ViewportToWorldPoint(new Vector3(0.9f, 0.9f, 0));
targetPos = new Vector3(Random.Range(minScreen.x, maxScreen.x), Random.Range(minScreen.y, maxScreen.y), transform.position.z);
float x = Random.Range(minScreen.x, maxScreen.x);
float y = Random.Range(minScreen.y, maxScreen.y);
targetPos = new Vector3(x, y, transform.position.z);
} }
void OnMouseDown() void OnMouseDown()
{ {
// You cannot drag it anymore if it is already placed!
if (isPlaced) return; if (isPlaced) return;
isDragging = true; isDragging = true;
if (mySpawner != null) mySpawner.SetZoneHighlight(true);
zCoord = cam.WorldToScreenPoint(gameObject.transform.position).z; zCoord = cam.WorldToScreenPoint(gameObject.transform.position).z;
dragOffset = gameObject.transform.position - GetMouseAsWorldPoint(); dragOffset = gameObject.transform.position - GetMouseAsWorldPoint();
} }
...@@ -72,7 +61,10 @@ public class FloatingDraggableRock : MonoBehaviour ...@@ -72,7 +61,10 @@ public class FloatingDraggableRock : MonoBehaviour
{ {
isDragging = false; isDragging = false;
// CHECK: Did we drop it on the ground? // --- NEW: Tell Spawner to Turn OFF Highlight ---
if (mySpawner != null) mySpawner.SetZoneHighlight(false);
// -----------------------------------------------
if (isHoveringGround) if (isHoveringGround)
{ {
StickToGround(); StickToGround();
...@@ -86,12 +78,7 @@ public class FloatingDraggableRock : MonoBehaviour ...@@ -86,12 +78,7 @@ public class FloatingDraggableRock : MonoBehaviour
void StickToGround() void StickToGround()
{ {
isPlaced = true; isPlaced = true;
if (mySpawner != null) mySpawner.RockPlaced();
// Tell the Spawner we did it
if (mySpawner != null)
{
mySpawner.RockPlaced();
}
} }
private Vector3 GetMouseAsWorldPoint() private Vector3 GetMouseAsWorldPoint()
...@@ -101,21 +88,13 @@ public class FloatingDraggableRock : MonoBehaviour ...@@ -101,21 +88,13 @@ public class FloatingDraggableRock : MonoBehaviour
return cam.ScreenToWorldPoint(mousePoint); return cam.ScreenToWorldPoint(mousePoint);
} }
// --- COLLISION DETECTION ---
void OnTriggerEnter2D(Collider2D other) void OnTriggerEnter2D(Collider2D other)
{ {
// Make sure your Ground object has the Tag "Ground" if (other.CompareTag("Ground")) isHoveringGround = true;
if (other.CompareTag("Ground"))
{
isHoveringGround = true;
}
} }
void OnTriggerExit2D(Collider2D other) void OnTriggerExit2D(Collider2D other)
{ {
if (other.CompareTag("Ground")) if (other.CompareTag("Ground")) isHoveringGround = false;
{
isHoveringGround = false;
}
} }
} }
\ No newline at end of file
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using AL_Arcade.DialogueSystem.Scripts;
public class ImageSwitcher : MonoBehaviour public class ImageSwitcher : MonoBehaviour
{ {
...@@ -13,6 +14,7 @@ public class ImageSwitcher : MonoBehaviour ...@@ -13,6 +14,7 @@ public class ImageSwitcher : MonoBehaviour
private int currentIndex = 0; private int currentIndex = 0;
[SerializeField] string[] gameobjectives;
void Start() void Start()
{ {
if (pictures.Length > 0) if (pictures.Length > 0)
...@@ -45,9 +47,12 @@ public class ImageSwitcher : MonoBehaviour ...@@ -45,9 +47,12 @@ public class ImageSwitcher : MonoBehaviour
if (currentIndex >= pictures.Length) if (currentIndex >= pictures.Length)
{ {
currentIndex = pictures.Length - 1; currentIndex = pictures.Length - 1;
} }
pictures[currentIndex].SetActive(true); pictures[currentIndex].SetActive(true);
GameContextBuilder.Instance.SetCurrentObjective(gameobjectives[currentIndex]);
if (currentIndex == pictures.Length - 1) if (currentIndex == pictures.Length - 1)
{ {
if (nextButton != null) nextButton.interactable = false; if (nextButton != null) nextButton.interactable = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment