mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 17:43:12 +02:00
Merge branch 'Development' into SpartaqS-AddingSoldiersToSquad
This commit is contained in:
commit
81cb9f5489
@ -24,16 +24,19 @@ public class TilemapManager : MonoBehaviour
|
||||
|
||||
[Header("Soldiers values")]
|
||||
|
||||
[SerializeField] private Vector2Int allyBaseCoord = Vector2Int.zero;
|
||||
[SerializeField] private Vector2Int[] soldierStartingPositions = null;
|
||||
|
||||
[Header("Enemies values")]
|
||||
|
||||
[SerializeField] private Vector2Int enemyBaseCoord = Vector2Int.zero;
|
||||
[SerializeField] private Vector2Int[] enemyStartingPositions = null;
|
||||
|
||||
[Header("References")]
|
||||
|
||||
[SerializeField] private Tilemap tilemap = null;
|
||||
[SerializeField] private GameObject soldierPrefab = null;
|
||||
[SerializeField] private GameObject basePrefab = null;
|
||||
|
||||
// private (do not edit) variables
|
||||
|
||||
@ -50,6 +53,11 @@ public class TilemapManager : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//spawn bases
|
||||
SpawnSoldier(allyBaseCoord.x, allyBaseCoord.y, true, true);
|
||||
SpawnSoldier(enemyBaseCoord.x, enemyBaseCoord.y, false, true);
|
||||
|
||||
//spawn soldiers
|
||||
foreach (Vector2Int vec in soldierStartingPositions)
|
||||
SpawnSoldier(vec.x, vec.y, true);
|
||||
foreach (Vector2Int vec in enemyStartingPositions)
|
||||
@ -85,12 +93,15 @@ public class TilemapManager : MonoBehaviour
|
||||
|
||||
// ---------- public functions
|
||||
|
||||
public bool SpawnSoldier(int x, int y, bool isAlly)
|
||||
public bool SpawnSoldier(int x, int y, bool isAlly, bool isBase=false)
|
||||
{
|
||||
if (GetTileState(x, y) != TileState.free)
|
||||
return false;
|
||||
|
||||
tiles[x, y].standingSoldier = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
|
||||
if (isBase)
|
||||
tiles[x, y].standingSoldier = Instantiate(basePrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
|
||||
if (isBase)
|
||||
tiles[x, y].standingSoldier = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
|
||||
|
||||
if (isAlly)
|
||||
tiles[x, y].standingSoldier.setOwnTag(Soldier.SoldierType.Ally);
|
||||
|
||||
@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class Soldier : MonoBehaviour
|
||||
{
|
||||
@ -43,10 +44,8 @@ public class Soldier : MonoBehaviour
|
||||
{
|
||||
Ally,
|
||||
Enemy
|
||||
}
|
||||
[SerializeField] private Soldier target;
|
||||
[SerializeField] private SoldierType enemyType;
|
||||
[SerializeField] private SoldierType ourType;
|
||||
}
|
||||
[Header("Values")]
|
||||
[SerializeField] private float maxHealthPoints = 10;
|
||||
[SerializeField] private float healthPoints = 1;
|
||||
[SerializeField] private float rangeAttack = 100;
|
||||
@ -54,12 +53,22 @@ public class Soldier : MonoBehaviour
|
||||
[SerializeField] private float damageAttack = 1;
|
||||
[SerializeField] private int speedAttack = 1; // ticks between attacks
|
||||
[SerializeField] private int lastAttackTick = -1;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private TMP_Text nameText = null;
|
||||
[SerializeField] private TMP_Text healthPointsText = null;
|
||||
[Header("Do-not-change-in-game values")]
|
||||
[SerializeField] private Soldier target;
|
||||
[SerializeField] private SoldierType enemyType;
|
||||
[SerializeField] private SoldierType ourType;
|
||||
|
||||
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
|
||||
|
||||
|
||||
|
||||
// variables not visible in inspector
|
||||
|
||||
[HideInInspector] public UnityEvent onDeath = new UnityEvent();
|
||||
|
||||
public SoldierType GetOwnType()
|
||||
{
|
||||
return ourType;
|
||||
@ -109,6 +118,7 @@ public class Soldier : MonoBehaviour
|
||||
private void OnDestroy()
|
||||
{
|
||||
TickSystem.OnTick -= HandleTick;
|
||||
onDeath.Invoke();
|
||||
|
||||
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user