Skip to content

Commit

Permalink
add winner panel and update move camera
Browse files Browse the repository at this point in the history
  • Loading branch information
amm266 committed Apr 2, 2021
1 parent 09f0444 commit 6bdebce
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 43 deletions.
304 changes: 284 additions & 20 deletions Assets/Prefabs/UI.prefab

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions Assets/Scenes/MapScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ GameObject:
- component: {fileID: 123243331}
- component: {fileID: 123243330}
m_Layer: 5
m_Name: Close (1)
m_Name: setting_team1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -505,11 +505,11 @@ PrefabInstance:
objectReference: {fileID: 1778195490}
- target: {fileID: 1236313013, guid: c96875b7a845a7143be803fea0004d49, type: 3}
propertyPath: m_AnchorMax.x
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1236313013, guid: c96875b7a845a7143be803fea0004d49, type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1537088302, guid: c96875b7a845a7143be803fea0004d49, type: 3}
propertyPath: m_OnValueChanged.m_PersistentCalls.m_Calls.Array.data[0].m_Target
Expand All @@ -525,15 +525,15 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 897281234955408375, guid: c96875b7a845a7143be803fea0004d49, type: 3}
propertyPath: m_AnchorMax.x
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 897281234955408375, guid: c96875b7a845a7143be803fea0004d49, type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2495248660206519639, guid: c96875b7a845a7143be803fea0004d49, type: 3}
propertyPath: m_LocalPosition.x
value: 43.020386
value: 52
objectReference: {fileID: 0}
- target: {fileID: 2495248660206519639, guid: c96875b7a845a7143be803fea0004d49, type: 3}
propertyPath: m_LocalPosition.y
Expand Down Expand Up @@ -579,6 +579,10 @@ PrefabInstance:
propertyPath: m_Name
value: UI
objectReference: {fileID: 0}
- target: {fileID: 3241652078898949051, guid: c96875b7a845a7143be803fea0004d49, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4663512140528063356, guid: c96875b7a845a7143be803fea0004d49, type: 3}
propertyPath: m_LocalScale.x
value: 1.2
Expand Down Expand Up @@ -672,7 +676,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &1003224826
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1104,7 +1108,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0e6dda28b97103a4e89340af0863e0ed, type: 3}
m_Name:
m_EditorClassIdentifier:
dragSpeed: 0.5
ArrowMoveSpeed: 4
dragSpeed: 15
zoomSpeed: 1
myCamera: {fileID: 1509055357}
--- !u!1 &1539077790 stripped
Expand Down Expand Up @@ -1580,7 +1585,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!4 &2069621863
Transform:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/LogScripts/GameLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void MakeLog(string jsonStr)
}

Map map = new Map(cells, gameConfigDTO.base_health, gameConfigDTO.worker_health,
gameConfigDTO.soldier_health, gameConfigDTO.team0_name, gameConfigDTO.team1_name);
gameConfigDTO.soldier_health, gameConfigDTO.team0_name, gameConfigDTO.team1_name,gameConfigDTO.winner);

//making turns
Turn[] turns = new Turn[gameDTO.turns.Length];
Expand Down
4 changes: 3 additions & 1 deletion Assets/Scripts/LogScripts/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ public class Map
public int SoldierHealth { get; set; }
public string Team0Name { get; set; }
public string Team1Name { get; set; }
public int WinnerTeam { get; set; }

public Map(int[][] cells, int baseHealth, int workerHealth, int soldierHealth, string team0Name, string team1Name)
public Map(int[][] cells, int baseHealth, int workerHealth, int soldierHealth, string team0Name, string team1Name, int winnerTeam)
{
this.cells = cells;
this.BaseHealth = baseHealth;
this.WorkerHealth = workerHealth;
this.SoldierHealth = soldierHealth;
this.Team0Name = team0Name;
this.Team1Name = team1Name;
this.WinnerTeam = winnerTeam;
}
}
1 change: 1 addition & 0 deletions Assets/Scripts/LogScripts/dto/GameConfigDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class GameConfigDTO
public CellTypeDTO[] cells_type;
public string team0_name;
public string team1_name;
public int winner;
}
39 changes: 33 additions & 6 deletions Assets/Scripts/Map/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class GameManager : MonoBehaviour
{
public GameObject InGame;
public GameObject GameLogBrowser;

[SerializeField] private GameObject winnerPanel;
[SerializeField] private TextMeshProUGUI winnerText;
[SerializeField] private GameObject antPrefab;
[SerializeField] private GameObject cell_empty;
[SerializeField] private GameObject cell_wall;
Expand Down Expand Up @@ -53,14 +54,23 @@ public void StartGameManager(GameLog gameLog)
{
GameLogBrowser.SetActive(false);
InGame.SetActive(true);


winnerPanel.SetActive(false);
baseTime = UIManager.Instance.BaseTime;
this.gameLog = gameLog;
base1.GetComponent<BaseScript>().SetMaxHealth(gameLog.Map.BaseHealth);
base2.GetComponent<BaseScript>().SetMaxHealth(gameLog.Map.BaseHealth);
ShowMap();
FindObjectOfType<MoveCamera>().setMaid(gameLog.Map.cells.Length * width, gameLog.Map.cells[0].Length * haight);
MaxTurns = gameLog.Turns.Length;
if (gameLog.Map.WinnerTeam==0)
{
winnerText.text = gameLog.Map.Team0Name;
}
else
{
winnerText.text = gameLog.Map.Team1Name;
}
}

public void ApplyLog(int turn, bool isAnim)
Expand All @@ -69,19 +79,19 @@ public void ApplyLog(int turn, bool isAnim)
if (currTurn == turn - 1 && isAnim)
{
playAnime = true;
StartCoroutine(ApplyTurnAnim(gameLog.Turns[turn - 1]));
StartCoroutine(ApplyTurnAnim(gameLog.Turns[turn - 1],turn == MaxTurns));
}
else
{
playAnime = false;
ApplyTurnUnAnim(gameLog.Turns[turn - 1]);
ApplyTurnUnAnim(gameLog.Turns[turn - 1],turn == MaxTurns);
}

currTurn = turn;
}


private void ApplyTurnUnAnim(Turn turn)
private void ApplyTurnUnAnim(Turn turn, bool lastTurn)
{
team0_alive_workers.text = turn.team0_alive_workers.ToString();
team0_alive_soldiers.text = turn.team0_alive_soldiers.ToString();
Expand Down Expand Up @@ -119,9 +129,18 @@ private void ApplyTurnUnAnim(Turn turn)
antScript.Set(ant.Row, ant.Col, ant.Team, ant.Type, ant.Health, ant.Resource, ant.Id, numbers, n);
AntsTable.Add(ant.Id, antObject);
}

if (lastTurn)
{
winnerPanel.SetActive(true);
}
else
{
winnerPanel.SetActive(false);
}
}

private IEnumerator ApplyTurnAnim(Turn turn)
private IEnumerator ApplyTurnAnim(Turn turn,bool lastTurn)
{
team0_alive_workers.text = turn.team0_alive_workers.ToString();
team0_alive_soldiers.text = turn.team0_alive_soldiers.ToString();
Expand Down Expand Up @@ -220,6 +239,14 @@ private IEnumerator ApplyTurnAnim(Turn turn)

// Debug.Log("end phase1");
yield return new WaitForSecondsRealtime((baseTime / 2) * UIManager.Instance.Speed);
if (lastTurn)
{
winnerPanel.SetActive(true);
}
else
{
winnerPanel.SetActive(false);
}
if (playAnime)
{
//move ants time
Expand Down
38 changes: 34 additions & 4 deletions Assets/Scripts/MoveCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System;
using UnityEngine;
using System.Collections;
using UnityEngine.UIElements;

public class MoveCamera : MonoBehaviour
{
[SerializeField] private float ArrowMoveSpeed;
public float dragSpeed = 2;
private Vector3 dragOrigin;
public float zoomSpeed = 10.0f;
Expand Down Expand Up @@ -39,16 +41,44 @@ void Update()
{
myCamera.orthographicSize = 0;
}
if (Input.GetMouseButtonDown(2))

Vector3 pos;
Vector3 move;
if (Input.GetAxis("Vertical") < 0)
{
pos = Vector3.up;
move = new Vector3(-pos.x * ArrowMoveSpeed * Time.deltaTime, -pos.y * ArrowMoveSpeed * Time.deltaTime, 0);
transform.Translate(move, Space.World);
}
if (Input.GetAxis("Vertical") > 0)
{
pos = Vector3.down;
move = new Vector3(-pos.x * ArrowMoveSpeed * Time.deltaTime, -pos.y * ArrowMoveSpeed * Time.deltaTime, 0);
transform.Translate(move, Space.World);
}
if (Input.GetAxis("Horizontal") < 0)
{
pos = Vector3.right;
move = new Vector3(-pos.x * ArrowMoveSpeed * Time.deltaTime, -pos.y * ArrowMoveSpeed * Time.deltaTime, 0);
transform.Translate(move, Space.World);
}
if (Input.GetAxis("Horizontal") > 0)
{
pos = Vector3.left;
move = new Vector3(-pos.x * ArrowMoveSpeed * Time.deltaTime, -pos.y * ArrowMoveSpeed * Time.deltaTime, 0);
transform.Translate(move, Space.World);
}

if (Input.GetMouseButtonDown(0))
{
dragOrigin = Input.mousePosition;
return;
}

if (!Input.GetMouseButton(2)) return;
if (!Input.GetMouseButton(0)) return;

Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
Vector3 move = new Vector3(-pos.x * dragSpeed, -pos.y * dragSpeed, 0);
pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
move = new Vector3(-pos.x * dragSpeed * Time.deltaTime, -pos.y * dragSpeed * Time.deltaTime, 0);

transform.Translate(move, Space.World);
}
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/InputManager.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ InputManager:
positiveButton: right
altNegativeButton: a
altPositiveButton: d
gravity: 3
gravity: 50
dead: 0.001
sensitivity: 3
snap: 1
Expand All @@ -29,7 +29,7 @@ InputManager:
positiveButton: up
altNegativeButton: s
altPositiveButton: w
gravity: 3
gravity: 50
dead: 0.001
sensitivity: 3
snap: 1
Expand Down

0 comments on commit 6bdebce

Please sign in to comment.