TO SQUASH: Started map covering.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Foreground : MonoBehaviour
|
||||
{
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
ResetBoard();
|
||||
}
|
||||
|
||||
public void ResetBoard()
|
||||
{
|
||||
// Reset the game board to its initial state
|
||||
int currentLevel = PlayerPrefs.GetInt("CurrentLevel");
|
||||
currentLevel = currentLevel == 0 ? 1 : currentLevel; // Ensure currentLevel is at least 1
|
||||
currentLevel = (((currentLevel - 1) / 5) % 10 + 10) % 10 + 1;
|
||||
|
||||
Debug.Log($"Current Level: {currentLevel}");
|
||||
|
||||
string resourcePath = $"Patterns/back_{currentLevel}";
|
||||
|
||||
Texture2D texture = Resources.Load<Texture2D>(resourcePath);
|
||||
if (texture == null)
|
||||
{
|
||||
Debug.LogWarning($"Could not load Sprite or Texture2D at Resources/{resourcePath}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback if the asset is imported as Texture instead of Sprite.
|
||||
Sprite runtimeSprite = Sprite.Create(
|
||||
texture,
|
||||
new Rect(0, 0, texture.width, texture.height),
|
||||
new Vector2(0.5f, 0.5f),
|
||||
100f
|
||||
);
|
||||
|
||||
spriteRenderer.sprite = runtimeSprite;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83f9939f8fdda54efa78f609f9bceff5
|
||||
@@ -12,12 +12,6 @@ public class GameBoard : MonoBehaviour
|
||||
ResetBoard();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ResetBoard()
|
||||
{
|
||||
// Reset the game board to its initial state
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5262a150f7acbf5f8869006f848a443d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BarBase : MonoBehaviour
|
||||
{
|
||||
public float firingSpeed = 0.03f;
|
||||
|
||||
public bool canFireLeft = true;
|
||||
|
||||
public bool canFireRight = true;
|
||||
|
||||
public bool canFireTop = true;
|
||||
|
||||
public bool canFireBottom = true;
|
||||
|
||||
protected float firingTimer = 0.0f;
|
||||
|
||||
protected Bounds bounds;
|
||||
|
||||
protected bool canFire = true;
|
||||
|
||||
protected void Initialize()
|
||||
{
|
||||
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
bounds = spriteRenderer.bounds;
|
||||
|
||||
var walls = GameObject.FindGameObjectsWithTag("Wall");
|
||||
|
||||
if (walls.Length > 0)
|
||||
{
|
||||
// Cap the firing ability if the bar is already intersecting with a wall.
|
||||
foreach (var wall in walls)
|
||||
{
|
||||
var wallBounds = wall.GetComponent<SpriteRenderer>().bounds;
|
||||
if (wallBounds.Intersects(bounds))
|
||||
{
|
||||
canFire = false;
|
||||
|
||||
// Register the intersection with the WorldFiller.
|
||||
var worldFiller = GameObject.FindAnyObjectByType<WorldFiller>();
|
||||
|
||||
if (worldFiller != null)
|
||||
{
|
||||
var intersectionBounds = GetIntersectionBounds(wallBounds, bounds);
|
||||
worldFiller.SetWallPosition(intersectionBounds.center);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Bounds GetIntersectionBounds(Bounds wallBounds, Bounds barBounds)
|
||||
{
|
||||
Bounds intersectionBounds = new Bounds();
|
||||
|
||||
intersectionBounds.SetMinMax(
|
||||
Vector3.Max(wallBounds.min, barBounds.min),
|
||||
Vector3.Min(wallBounds.max, barBounds.max)
|
||||
);
|
||||
|
||||
return intersectionBounds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc658019d9b712031b48788b92920756
|
||||
@@ -1,41 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class HorizontalBar : MonoBehaviour
|
||||
public class HorizontalBar : BarBase
|
||||
{
|
||||
public float firingSpeed = 0.03f;
|
||||
|
||||
public GameObject horizontalBarrierPrefab;
|
||||
|
||||
public bool canFireLeft = true;
|
||||
|
||||
public bool canFireRight = true;
|
||||
|
||||
private float firingTimer = 0.0f;
|
||||
|
||||
private Bounds bounds;
|
||||
|
||||
private bool canFire = true;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
bounds = spriteRenderer.bounds;
|
||||
|
||||
var walls = GameObject.FindGameObjectsWithTag("Wall");
|
||||
|
||||
if (walls.Length > 0)
|
||||
{
|
||||
// Cap the firing ability if the bar is already intersecting with a wall.
|
||||
foreach (var wall in walls)
|
||||
{
|
||||
if (wall.GetComponent<Collider2D>().bounds.Intersects(bounds))
|
||||
{
|
||||
canFire = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Initialize();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
+2
-26
@@ -1,37 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class HorizontalLaser : MonoBehaviour
|
||||
public class HorizontalLaser : BarBase
|
||||
{
|
||||
public GameObject horizontalLaserPrefab;
|
||||
|
||||
public bool canFireLeft = true;
|
||||
|
||||
public bool canFireRight = true;
|
||||
|
||||
private Bounds bounds;
|
||||
|
||||
private bool canFire = true;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
bounds = spriteRenderer.bounds;
|
||||
|
||||
var walls = GameObject.FindGameObjectsWithTag("Wall");
|
||||
|
||||
if (walls.Length > 0)
|
||||
{
|
||||
// Cap the firing ability if the bar is already intersecting with a wall.
|
||||
foreach (var wall in walls)
|
||||
{
|
||||
if (wall.GetComponent<Collider2D>().bounds.Intersects(bounds))
|
||||
{
|
||||
canFire = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Initialize();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -72,6 +72,8 @@ public class Player : MonoBehaviour
|
||||
|
||||
public BallSpawner ballSpawner;
|
||||
|
||||
public int percentCovered = 0;
|
||||
|
||||
private bool flipped = false;
|
||||
|
||||
private bool gameOver = false;
|
||||
@@ -150,16 +152,19 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
void Update()
|
||||
{
|
||||
// Foce reset the rotation.
|
||||
transform.rotation = Quaternion.identity;
|
||||
transform.eulerAngles = new Vector3(0, 0, flipped ? 90 : 0);
|
||||
|
||||
// Update the damage timer.
|
||||
if (damageTimer > 0.0f)
|
||||
{
|
||||
damageTimer -= Time.fixedDeltaTime;
|
||||
damageTimer -= Time.deltaTime;
|
||||
}
|
||||
|
||||
// Player movement is based on the mouse position, clamped to the game board bounds.
|
||||
if (!exploding)
|
||||
{
|
||||
Vector2 mouseScreen = Mouse.current.position.ReadValue();
|
||||
@@ -176,12 +181,13 @@ public class Player : MonoBehaviour
|
||||
transform.position = new Vector3(clampedX, clampedY, transform.position.z);
|
||||
}
|
||||
|
||||
// Handle keyboard input for flipping, game over, and toggling laser/magnet modes.
|
||||
if (Keyboard.current != null)
|
||||
{
|
||||
if (Keyboard.current.spaceKey.wasPressedThisFrame)
|
||||
{
|
||||
flipped = !flipped;
|
||||
transform.eulerAngles = new Vector3(0, 0, flipped ? 90 : 0);
|
||||
// transform.eulerAngles = new Vector3(0, 0, flipped ? 90 : 0);
|
||||
audioSource.PlayOneShot(flip);
|
||||
}
|
||||
|
||||
@@ -216,6 +222,7 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Mouse input handling for firing lasers, magnets, or normal barriers.
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame && canFire && !exploding)
|
||||
{
|
||||
if (laserActive)
|
||||
@@ -232,6 +239,7 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Check for game over or revival conditions.
|
||||
if (gameOver)
|
||||
{
|
||||
StartCoroutine(EndGame());
|
||||
@@ -244,6 +252,7 @@ public class Player : MonoBehaviour
|
||||
StartCoroutine(Revive());
|
||||
}
|
||||
|
||||
// Handle magnet timer countdown and deactivation.
|
||||
if (magnetTimer > 0.0f)
|
||||
{
|
||||
magnetTimer -= Time.deltaTime;
|
||||
@@ -487,7 +496,7 @@ public class Player : MonoBehaviour
|
||||
StartCoroutine(SetGameOver());
|
||||
}
|
||||
|
||||
canFire = true; // Allow firing again after bar hit
|
||||
canFire = true; // Allow firing again after bar hit.
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision)
|
||||
@@ -1,41 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class VerticalBar : MonoBehaviour
|
||||
public class VerticalBar : BarBase
|
||||
{
|
||||
public float firingSpeed = 0.03f;
|
||||
|
||||
public GameObject verticalBarrierPrefab;
|
||||
|
||||
public bool canFireTop = true;
|
||||
|
||||
public bool canFireBottom = true;
|
||||
|
||||
private float firingTimer = 0.0f;
|
||||
|
||||
private Bounds bounds;
|
||||
|
||||
private bool canFire = true;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
bounds = spriteRenderer.bounds;
|
||||
|
||||
var walls = GameObject.FindGameObjectsWithTag("Wall");
|
||||
|
||||
if (walls.Length > 0)
|
||||
{
|
||||
// Cap the firing ability if the bar is already intersecting with a wall.
|
||||
foreach (var wall in walls)
|
||||
{
|
||||
if (wall.GetComponent<Collider2D>().bounds.Intersects(bounds))
|
||||
{
|
||||
canFire = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Initialize();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -1,37 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class VerticalLaser : MonoBehaviour
|
||||
public class VerticalLaser : BarBase
|
||||
{
|
||||
public GameObject verticalLaserPrefab;
|
||||
|
||||
public bool canFireTop = true;
|
||||
|
||||
public bool canFireBottom = true;
|
||||
|
||||
private Bounds bounds;
|
||||
|
||||
private bool canFire = true;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
bounds = spriteRenderer.bounds;
|
||||
|
||||
var walls = GameObject.FindGameObjectsWithTag("Wall");
|
||||
|
||||
if (walls.Length > 0)
|
||||
{
|
||||
// Cap the firing ability if the bar is already intersecting with a wall.
|
||||
foreach (var wall in walls)
|
||||
{
|
||||
if (wall.GetComponent<Collider2D>().bounds.Intersects(bounds))
|
||||
{
|
||||
canFire = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Initialize();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -200,4 +200,9 @@ public class BallSpawner : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Queue<GameObject> GetBalls()
|
||||
{
|
||||
return balls;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class SharkSpawner : MonoBehaviour
|
||||
|
||||
private bool isActive = true;
|
||||
|
||||
private static float spawnProbability = 0.5f;
|
||||
private static float spawnProbability = 0.1f;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class WorldFiller : MonoBehaviour
|
||||
{
|
||||
public Player player;
|
||||
|
||||
public SpriteRenderer gameBoardSpriteRenderer;
|
||||
|
||||
public GameObject wallPrefab;
|
||||
|
||||
private Bounds gameBoardBounds;
|
||||
|
||||
private Vector2?[] wallPositions;
|
||||
|
||||
private int wallCount = 0;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
gameBoardBounds = gameBoardSpriteRenderer.bounds;
|
||||
ClearWalls();
|
||||
}
|
||||
|
||||
public void ClearWalls()
|
||||
{
|
||||
wallPositions = new Vector2?[2];
|
||||
wallPositions[0] = null;
|
||||
wallPositions[1] = null;
|
||||
wallCount = 0;
|
||||
}
|
||||
|
||||
public void SetWallPosition(Vector2 position)
|
||||
{
|
||||
if (wallCount >= wallPositions.Length)
|
||||
{
|
||||
Debug.LogError("Index out of bounds for wall positions.");
|
||||
return;
|
||||
}
|
||||
|
||||
wallPositions[wallCount] = position;
|
||||
wallCount++;
|
||||
|
||||
SpawnWall();
|
||||
}
|
||||
|
||||
public void SpawnWall()
|
||||
{
|
||||
// If both wall positions are set, spawn a wall.
|
||||
if (wallPositions[0] != null && wallPositions[1] != null)
|
||||
{
|
||||
Debug.Log($"Spawning wall with wall line: ({wallPositions[0]}, {wallPositions[1]})");
|
||||
|
||||
// Get all the balls in the scene.
|
||||
var ballSpawner = FindAnyObjectByType<BallSpawner>();
|
||||
var balls = ballSpawner.GetBalls();
|
||||
|
||||
// There are three possible scenarios for the wall positions:
|
||||
// 1. Only one side of the wall line is empty (either left or right).
|
||||
// 2. All sides of the wall line are occupied.
|
||||
// 3. All sides of the wall line are empty.
|
||||
|
||||
|
||||
// Destroy all bar segments after we are done.
|
||||
GameObject[] barSegments = GameObject.FindGameObjectsWithTag("Bar");
|
||||
|
||||
foreach (GameObject barSegment in barSegments)
|
||||
{
|
||||
Destroy(barSegment);
|
||||
}
|
||||
|
||||
// Clear the pending wall line.
|
||||
ClearWalls();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85b8e4c52283a887494c3424f55c5bd2
|
||||
Reference in New Issue
Block a user