commit
afa6c0ab6f
8 changed files with 137 additions and 37 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -140,6 +140,9 @@ fabric.properties
|
|||
# Uncomment this line if you wish to ignore the asset store tools plugin
|
||||
# [Aa]ssets/AssetStoreTools*
|
||||
|
||||
# Ignore Rider Plugin
|
||||
[Aa]ssets/Plugins/Editor/JetBrains/*
|
||||
|
||||
# TextMesh Pro files
|
||||
[Aa]ssets/TextMesh*Pro/
|
||||
|
||||
|
|
Binary file not shown.
|
@ -8215,9 +8215,10 @@ GameObject:
|
|||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 840487112}
|
||||
- component: {fileID: 840487113}
|
||||
- component: {fileID: 840487111}
|
||||
m_Layer: 0
|
||||
m_Name: LevelManager
|
||||
m_Name: GameManager
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
|
@ -8235,14 +8236,12 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 308dfc6b26c3b422faf1717231fc888b, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
columns: 30
|
||||
rows: 20
|
||||
boardHolder: {fileID: 585332173}
|
||||
startPosition: {fileID: 185746015}
|
||||
indestructibleWallPrefab: {fileID: 5959564480851182330, guid: dd25aabed7c6c491eb405f1e5c5f4d99,
|
||||
type: 3}
|
||||
destructibleWallPrefab: {fileID: 4177940729222266681, guid: da559e681f8d34d58bb5f3457045664a,
|
||||
type: 3}
|
||||
boardHolder: {fileID: 585332173}
|
||||
--- !u!4 &840487112
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -8257,6 +8256,18 @@ Transform:
|
|||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 6
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &840487113
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 840487110}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 697f5ae5656c74dcd8d7f5d619adb0ac, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1135949884
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
34
Assets/Scripts/src/Managers/GameManager.cs
Normal file
34
Assets/Scripts/src/Managers/GameManager.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace src.Managers
|
||||
{
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager Instance = null;
|
||||
private LevelManager _levelManager;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else if (Instance != null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
/* Don't destroy when reloading the scene */
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
_levelManager = GetComponent<LevelManager>();
|
||||
|
||||
InitGame();
|
||||
}
|
||||
|
||||
private void InitGame()
|
||||
{
|
||||
_levelManager.InitLevel();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/src/Managers/GameManager.cs.meta
Normal file
11
Assets/Scripts/src/Managers/GameManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 697f5ae5656c74dcd8d7f5d619adb0ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using src.Base;
|
||||
using src.Helpers;
|
||||
using src.Wall;
|
||||
|
@ -11,75 +12,101 @@ namespace src.Managers
|
|||
{
|
||||
public class Count
|
||||
{
|
||||
public readonly int Min;
|
||||
public readonly int Max;
|
||||
private readonly int _min;
|
||||
private readonly int _max;
|
||||
|
||||
public Count(int min, int max)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
_min = min;
|
||||
_max = max;
|
||||
}
|
||||
|
||||
public int RandomIntRange()
|
||||
{
|
||||
return Mathf.FloorToInt(Random.Range(Min, Max));
|
||||
return Mathf.FloorToInt(Random.Range(_min, _max));
|
||||
}
|
||||
}
|
||||
|
||||
public int columns = 30;
|
||||
public int rows = 20;
|
||||
public Count DestructibleWallCount
|
||||
{
|
||||
get => _destructibleWallCount;
|
||||
set => _destructibleWallCount = value;
|
||||
}
|
||||
|
||||
/* Specifies how many objects we want per level. */
|
||||
public Count destructibleWallCount = new Count(150, 350);
|
||||
public Count upgradesCount = new Count(0, 5);
|
||||
public Count enemyCount = new Count(20, 50);
|
||||
public Count UpgradesCount
|
||||
{
|
||||
get => _upgradesCount;
|
||||
set => _upgradesCount = value;
|
||||
}
|
||||
|
||||
public Count EnemyCount
|
||||
{
|
||||
get => _enemyCount;
|
||||
set => _enemyCount = value;
|
||||
}
|
||||
|
||||
/* Used to group spawned objects */
|
||||
public Transform boardHolder;
|
||||
|
||||
/* Holds the starting position of the player */
|
||||
public Transform startPosition;
|
||||
public GameObject indestructibleWallPrefab;
|
||||
public GameObject destructibleWallPrefab;
|
||||
|
||||
/* Used to group spawned objects */
|
||||
public Transform boardHolder;
|
||||
/* Specifies how many objects we want per level. */
|
||||
private Count _destructibleWallCount = new Count(150, 350);
|
||||
private Count _upgradesCount = new Count(0, 5);
|
||||
private Count _enemyCount = new Count(20, 50);
|
||||
|
||||
/* The size of the board. */
|
||||
private const int Columns = 30;
|
||||
private const int Rows = 20;
|
||||
|
||||
/* Holds the available positions */
|
||||
private readonly List<Vector3> _freeGridPositions = new List<Vector3>();
|
||||
private readonly List<GameObject> _destructibleWalls = new List<GameObject>();
|
||||
|
||||
/* Test only */
|
||||
public void Awake()
|
||||
{
|
||||
InitBoard();
|
||||
SetupLevel();
|
||||
SetupExit();
|
||||
SetupUpgrades();
|
||||
}
|
||||
|
||||
private void SetupUpgrades()
|
||||
{
|
||||
var count = upgradesCount.RandomIntRange();
|
||||
var count = _upgradesCount.RandomIntRange();
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
if (_destructibleWalls.Count == 0)
|
||||
{
|
||||
Debug.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<DestructibleWall>();
|
||||
Debug.Log($"Spawned upgrade at: x:{wall.XCoordinate} y:{wall.YCoordinate}");
|
||||
wall.SpawnsUpgrade();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupExit()
|
||||
{
|
||||
if (_destructibleWalls.Count == 0)
|
||||
{
|
||||
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<DestructibleWall>();
|
||||
Debug.Log($"Spawned exit at: x:{wall.XCoordinate} y:{wall.YCoordinate}");
|
||||
wall.SpawnsExit();
|
||||
}
|
||||
|
||||
public void InitBoard()
|
||||
/* Place the indestructible tiles on the board and saves the
|
||||
* unused positions in a list. */
|
||||
private 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++)
|
||||
for (var x = startPosition.position.x; x < Columns; x++)
|
||||
{
|
||||
for (var y = startPosition.position.y; y > rows * -1; y--)
|
||||
for (var y = startPosition.position.y; y > Rows * -1; y--)
|
||||
{
|
||||
/* We want the following positions to be a safe zone. */
|
||||
/* Don't place anything on starting position */
|
||||
|
@ -112,10 +139,10 @@ namespace src.Managers
|
|||
}
|
||||
}
|
||||
|
||||
public void SetupLevel()
|
||||
/* Randomly places destructible tiles on the level. */
|
||||
private void SetupLevelDestructibleWalls()
|
||||
{
|
||||
var random = new Random();
|
||||
var numberOfDestructilbeWallsToPlace = destructibleWallCount.RandomIntRange();
|
||||
var numberOfDestructilbeWallsToPlace = _destructibleWallCount.RandomIntRange();
|
||||
|
||||
_freeGridPositions.ShuffleList();
|
||||
foreach (var nextPosition in _freeGridPositions)
|
||||
|
@ -132,6 +159,7 @@ namespace src.Managers
|
|||
|
||||
private void PlaceDestructibleTile(Vector3 position)
|
||||
{
|
||||
Debug.Log($"PlaceDestructibleTile: x:{position.x} y:{position.y}");
|
||||
var instance = Instantiate(destructibleWallPrefab, position, Quaternion.identity);
|
||||
_destructibleWalls.Add(instance);
|
||||
instance.transform.SetParent(boardHolder);
|
||||
|
@ -150,5 +178,14 @@ namespace src.Managers
|
|||
instance.transform.SetParent(boardHolder);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Initializes the level. */
|
||||
public void InitLevel()
|
||||
{
|
||||
InitBoard();
|
||||
SetupLevelDestructibleWalls();
|
||||
SetupExit();
|
||||
SetupUpgrades();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,12 +17,16 @@ namespace src.Wall
|
|||
_spawnUpgrade = true;
|
||||
}
|
||||
|
||||
public float XCoordinate => transform.position.x;
|
||||
public float YCoordinate => transform.position.y;
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (_spawnExit)
|
||||
{
|
||||
// TODO Spawn an exit
|
||||
} else if (_spawnUpgrade)
|
||||
}
|
||||
else if (_spawnUpgrade)
|
||||
{
|
||||
// TODO Spawn an upgrade, use composition to UpgradeManager
|
||||
// to get random / desired upgrade
|
||||
|
|
|
@ -6,7 +6,7 @@ AnimatorController:
|
|||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: MockPlayer
|
||||
m_Name: PlayerAnimator
|
||||
serializedVersion: 5
|
||||
m_AnimatorParameters: []
|
||||
m_AnimatorLayers:
|
||||
|
|
Loading…
Reference in a new issue