mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-11 16:33:55 +01: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")]
|
[Header("Soldiers values")]
|
||||||
|
|
||||||
|
[SerializeField] private Vector2Int allyBaseCoord = Vector2Int.zero;
|
||||||
[SerializeField] private Vector2Int[] soldierStartingPositions = null;
|
[SerializeField] private Vector2Int[] soldierStartingPositions = null;
|
||||||
|
|
||||||
[Header("Enemies values")]
|
[Header("Enemies values")]
|
||||||
|
|
||||||
|
[SerializeField] private Vector2Int enemyBaseCoord = Vector2Int.zero;
|
||||||
[SerializeField] private Vector2Int[] enemyStartingPositions = null;
|
[SerializeField] private Vector2Int[] enemyStartingPositions = null;
|
||||||
|
|
||||||
[Header("References")]
|
[Header("References")]
|
||||||
|
|
||||||
[SerializeField] private Tilemap tilemap = null;
|
[SerializeField] private Tilemap tilemap = null;
|
||||||
[SerializeField] private GameObject soldierPrefab = null;
|
[SerializeField] private GameObject soldierPrefab = null;
|
||||||
|
[SerializeField] private GameObject basePrefab = null;
|
||||||
|
|
||||||
// private (do not edit) variables
|
// private (do not edit) variables
|
||||||
|
|
||||||
@ -50,6 +53,11 @@ public class TilemapManager : MonoBehaviour
|
|||||||
|
|
||||||
private void Start()
|
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)
|
foreach (Vector2Int vec in soldierStartingPositions)
|
||||||
SpawnSoldier(vec.x, vec.y, true);
|
SpawnSoldier(vec.x, vec.y, true);
|
||||||
foreach (Vector2Int vec in enemyStartingPositions)
|
foreach (Vector2Int vec in enemyStartingPositions)
|
||||||
@ -85,12 +93,15 @@ public class TilemapManager : MonoBehaviour
|
|||||||
|
|
||||||
// ---------- public functions
|
// ---------- 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)
|
if (GetTileState(x, y) != TileState.free)
|
||||||
return false;
|
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)
|
if (isAlly)
|
||||||
tiles[x, y].standingSoldier.setOwnTag(Soldier.SoldierType.Ally);
|
tiles[x, y].standingSoldier.setOwnTag(Soldier.SoldierType.Ally);
|
||||||
|
|||||||
@ -2,6 +2,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
|
||||||
public class Soldier : MonoBehaviour
|
public class Soldier : MonoBehaviour
|
||||||
{
|
{
|
||||||
@ -44,9 +45,7 @@ public class Soldier : MonoBehaviour
|
|||||||
Ally,
|
Ally,
|
||||||
Enemy
|
Enemy
|
||||||
}
|
}
|
||||||
[SerializeField] private Soldier target;
|
[Header("Values")]
|
||||||
[SerializeField] private SoldierType enemyType;
|
|
||||||
[SerializeField] private SoldierType ourType;
|
|
||||||
[SerializeField] private float maxHealthPoints = 10;
|
[SerializeField] private float maxHealthPoints = 10;
|
||||||
[SerializeField] private float healthPoints = 1;
|
[SerializeField] private float healthPoints = 1;
|
||||||
[SerializeField] private float rangeAttack = 100;
|
[SerializeField] private float rangeAttack = 100;
|
||||||
@ -54,12 +53,22 @@ public class Soldier : MonoBehaviour
|
|||||||
[SerializeField] private float damageAttack = 1;
|
[SerializeField] private float damageAttack = 1;
|
||||||
[SerializeField] private int speedAttack = 1; // ticks between attacks
|
[SerializeField] private int speedAttack = 1; // ticks between attacks
|
||||||
[SerializeField] private int lastAttackTick = -1;
|
[SerializeField] private int lastAttackTick = -1;
|
||||||
|
[Header("References")]
|
||||||
[SerializeField] private TMP_Text nameText = null;
|
[SerializeField] private TMP_Text nameText = null;
|
||||||
[SerializeField] private TMP_Text healthPointsText = 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;
|
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// variables not visible in inspector
|
||||||
|
|
||||||
|
[HideInInspector] public UnityEvent onDeath = new UnityEvent();
|
||||||
|
|
||||||
public SoldierType GetOwnType()
|
public SoldierType GetOwnType()
|
||||||
{
|
{
|
||||||
return ourType;
|
return ourType;
|
||||||
@ -109,6 +118,7 @@ public class Soldier : MonoBehaviour
|
|||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
TickSystem.OnTick -= HandleTick;
|
TickSystem.OnTick -= HandleTick;
|
||||||
|
onDeath.Invoke();
|
||||||
|
|
||||||
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
|
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user