Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
squiig committed Jun 9, 2017
2 parents e9fde59 + 9022c9f commit afeee0e
Show file tree
Hide file tree
Showing 62 changed files with 2,599 additions and 8 deletions.
Binary file added Assets/Game/Fonts/Supercell-magic-webfont.ttf
Binary file not shown.
21 changes: 21 additions & 0 deletions Assets/Game/Fonts/Supercell-magic-webfont.ttf.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Game/Graphics/Textures/UI/4x4white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions Assets/Game/Graphics/Textures/UI/4x4white.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Game/Prefabs/Gameplay/BasicUnit.prefab
Binary file not shown.
2 changes: 1 addition & 1 deletion Assets/Game/Prefabs/Gameplay/BasicUnit.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Game/Prefabs/Gameplay/Towers/ArenaTower.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Gameplay/Towers/KingTower.prefab
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Game/Prefabs/UI.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Game/Prefabs/UI/HUD.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Game/Prefabs/UI/HUD/TowerHealthPanel.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Game/Prefabs/UI/HUD/UnitHealthPanel.prefab
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Game/Prefabs/UI/HUD/UnitHealthPanel.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Game/Scenes/Levels/Level.unity
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed Assets/Game/Scenes/Levels/Level/NavMesh.asset
Binary file not shown.
Binary file modified Assets/Game/ScriptableObjects/Players/Player1.asset
Binary file not shown.
Binary file modified Assets/Game/ScriptableObjects/Players/Player2.asset
Binary file not shown.
4 changes: 3 additions & 1 deletion Assets/Game/Scripts/Gameplay/ArenaTower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ public class ArenaTower : Tower
[SerializeField]
private Renderer m_Renderer;

void Awake()
protected override void Awake()
{
base.Awake();

m_Renderer.material.color = m_Owner.Definition.Color;
}
}
Expand Down
4 changes: 3 additions & 1 deletion Assets/Game/Scripts/Gameplay/KingTower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public class KingTower : Tower
[SerializeField]
private Renderer m_Renderer;

void Awake()
protected override void Awake()
{
base.Awake();

m_Renderer.material.color = m_Definition.Color;
}
}
Expand Down
21 changes: 19 additions & 2 deletions Assets/Game/Scripts/Gameplay/Modules/IDamageable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace CRC
{
public delegate void DeathEventHandler();
public delegate void HealthChangeEventHandler();
public interface IDamageable
{
event DeathEventHandler DeathEvent;
event HealthChangeEventHandler HealthChangeEvent;

KingTower Owner { get; }

Expand All @@ -22,6 +25,7 @@ public interface IDamageable
public abstract class Damageable : MonoBehaviour, IDamageable
{
public event DeathEventHandler DeathEvent;
public event HealthChangeEventHandler HealthChangeEvent;

[SerializeField]
protected KingTower m_Owner;
Expand All @@ -37,23 +41,36 @@ public abstract class Damageable : MonoBehaviour, IDamageable
public virtual void Hurt(float amount)
{
m_CurrentHealth -= amount;

if (m_CurrentHealth <= .0f)
{
m_CurrentHealth = .0f;
FireDeathEvent();
}

FireHealthChangeEvent();
}

public virtual void Heal(float amount)
{
m_CurrentHealth += amount;
if (m_CurrentHealth > m_MaxHealth) m_CurrentHealth = m_MaxHealth;

if (m_CurrentHealth > m_MaxHealth)
m_CurrentHealth = m_MaxHealth;

FireHealthChangeEvent();
}

protected virtual void FireDeathEvent()
protected void FireDeathEvent()
{
if (DeathEvent != null)
DeathEvent();
}

protected void FireHealthChangeEvent()
{
if (HealthChangeEvent != null)
HealthChangeEvent();
}
}
}
8 changes: 7 additions & 1 deletion Assets/Game/Scripts/Gameplay/SpawningHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ void Update()

if (hitSuccess)
{
Unit unit = Instantiate(m_UnitPrefab.gameObject, hitInfo.point, Quaternion.identity).GetComponent<Unit>();
Unit unit = Instantiate
(
m_UnitPrefab.gameObject,
hitInfo.point + Vector3.up * m_UnitPrefab.transform.lossyScale.y,
Quaternion.identity
)
.GetComponent<Unit>();

if (unit == null)
return;
Expand Down
24 changes: 24 additions & 0 deletions Assets/Game/Scripts/Gameplay/Tower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace CRC
{
public class Tower : Damageable
{
[SerializeField]
private Text m_HPText;

protected virtual void Awake()
{
m_CurrentHealth = m_MaxHealth;

m_HPText.text = m_CurrentHealth.ToString();
}

protected virtual void Start()
{
HealthChangeEvent += OnHealthChange;
}

protected virtual void OnDestroy()
{
HealthChangeEvent -= OnHealthChange;
}

protected virtual void OnHealthChange()
{
m_HPText.text = m_CurrentHealth.ToString();
}
}
}
36 changes: 36 additions & 0 deletions Assets/Game/Scripts/Gameplay/Units/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;

namespace CRC
{
Expand Down Expand Up @@ -45,6 +46,16 @@ public enum UnitState
[SerializeField]
private NavMeshAgent m_Agent;

[Header("Healthbar")]

[SerializeField]
private GameObject m_HealthPanelPrefab;

[SerializeField]
private float m_HPBarYOffPx = 50.0f;

private Image m_HPBarForeground;

private bool m_Enabled;

private UnitState m_State;
Expand All @@ -63,6 +74,21 @@ public void Initialize(KingTower owner)
m_State = UnitState.Idle;
m_CurrentHealth = m_MaxHealth;

GameObject healthPanel = Instantiate
(
m_HealthPanelPrefab,
Camera.main.WorldToScreenPoint(this.transform.position) + Vector3.up * m_HPBarYOffPx,
Quaternion.identity,
GameObject.Find("HUD").transform
);

healthPanel.GetComponent<UnitHealthPanel>().Initialize(this, m_HPBarYOffPx);

m_HPBarForeground = healthPanel.transform.GetChild(1).GetComponent<Image>();
m_HPBarForeground.color = m_Owner.Definition.Color;

HealthChangeEvent += OnHealthChange;

m_Enabled = true;
}

Expand All @@ -74,6 +100,16 @@ void Update()
StartCoroutine(Walk());
}

void OnDestroy()
{
HealthChangeEvent -= OnHealthChange;
}

private void OnHealthChange()
{
m_HPBarForeground.fillAmount = m_CurrentHealth / m_MaxHealth;
}

private IEnumerator Walk()
{
yield return new WaitForSeconds(0.5f);
Expand Down
9 changes: 9 additions & 0 deletions Assets/Game/Scripts/UI.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit afeee0e

Please sign in to comment.