Skip to content

Commit

Permalink
feat(#5): add working upgrade panel
Browse files Browse the repository at this point in the history
feat(#10): simple hold money as variable and use to buy upgrades
fix(#6): smooth changing health bar
  • Loading branch information
dofranko committed Oct 1, 2021
1 parent a04e588 commit 5eb6037
Show file tree
Hide file tree
Showing 80 changed files with 13,970 additions and 28 deletions.
644 changes: 632 additions & 12 deletions Assets/Prefabs/Castle.prefab

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Assets/Prefabs/HealthBar.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ MonoBehaviour:
m_Direction: 0
m_MinValue: 0
m_MaxValue: 100
m_WholeNumbers: 1
m_WholeNumbers: 0
m_Value: 100
m_OnValueChanged:
m_PersistentCalls:
Expand Down Expand Up @@ -283,3 +283,4 @@ MonoBehaviour:
m_NumColorKeys: 3
m_NumAlphaKeys: 2
fill: {fileID: 6336234269027949233}
smoothing: 5
59 changes: 57 additions & 2 deletions Assets/Scripts/CastleScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ public class CastleScript : MonoBehaviour
{
public HealthBar healthBar;
public GameObject upgradesPanel;
public int defense;
public event System.EventHandler OnHideUpgrades;
public event System.EventHandler OnDie;
public event System.EventHandler OnShowUpgrades;

public int DefenseUpgradeLevel { get; private set; } = 0;
public int HealthUpgradeLevel { get; private set; } = 0;
public int ShieldUpgradeLevel { get; private set; } = 0;
public int MoneyUpgradeLevel { get; private set; } = 0;
public int Money { get; private set; } = 200;
private int defense = 5;
private int shield = 30; //zapewne zmaienione na to samo co health
private float moneyMultiplier = 1.0f;
void Start()
{
healthBar.SetMaxHealth(400);
healthBar.SetInitHealth(200);
upgradesPanel.SetActive(false);
}
public void TakeDamage(int damage)
Expand All @@ -34,6 +42,7 @@ void Die()
public void DisplayUpgrades()
{
upgradesPanel.SetActive(true);
OnShowUpgrades?.Invoke(this, System.EventArgs.Empty);
}

public void HideUpgrades(bool invokeHandler = true)
Expand All @@ -44,4 +53,50 @@ public void HideUpgrades(bool invokeHandler = true)
OnHideUpgrades?.Invoke(this, System.EventArgs.Empty);
}
}

public void UpgradeDefense(int moneyCost)
{
defense++;
DefenseUpgradeLevel++;
Money -= moneyCost;
}

public void UpgradeHealth(int moneyCost)
{
healthBar.SetMaxHealth(healthBar.GetMaxHealth() + 20);
healthBar.SetHealth(healthBar.GetHealth() + 40
> healthBar.GetMaxHealth() ? healthBar.GetMaxHealth() : healthBar.GetHealth() + 40);
HealthUpgradeLevel++;
Money -= moneyCost;
}

public void UpgradeShield(int moneyCost)
{
ShieldUpgradeLevel++;
shield += 10;
Money -= moneyCost;
}
public void UpgradeMoney(int moneyCost)
{
MoneyUpgradeLevel++;
moneyMultiplier += 0.1f;
Money -= moneyCost;
}

public int GetMaxHealth()
{
return healthBar.GetMaxHealth();
}
public int GetHealth()
{
return healthBar.GetHealth();
}
public float GetMoneyMultiplier()
{
return moneyMultiplier;
}
public int GetShield()
{
return shield;
}
}
3 changes: 2 additions & 1 deletion Assets/Scripts/Enemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void Awake()
}
void Start()
{
healthBar.SetMaxHealth(stats.HealthMax);
healthBar.SetInitHealth(stats.HealthMax);
Spawn();
}
public void Spawn()
Expand All @@ -51,6 +51,7 @@ public void Die()
{
OnDie?.Invoke(this, System.EventArgs.Empty);
Destroy(gameObject);
//TODO on die give money
}
public void TakeDamage(int damage)
{
Expand Down
28 changes: 24 additions & 4 deletions Assets/Scripts/HealthBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,41 @@ public class HealthBar : MonoBehaviour
public Slider slider;
public Gradient gradient;
public Image fill;
public void SetMaxHealth(int max)
private int health = 0;
[SerializeField] int smoothing;
private void Update()
{
if (slider.value != health)
{
slider.value = Mathf.Lerp(slider.value, health, smoothing * Time.deltaTime);
fill.color = gradient.Evaluate(slider.normalizedValue);
}
}
public void SetInitHealth(int max)
{
slider.maxValue = max;
slider.value = max;
health = max;

gradient.Evaluate(slider.normalizedValue);
}
public void SetHealth(int health)
{
slider.value = health;
this.health = health;
fill.color = gradient.Evaluate(slider.normalizedValue);
}

public void SetMaxHealth(int max)
{
slider.maxValue = max;
gradient.Evaluate(slider.normalizedValue);
}

public int GetHealth()
{
return (int)slider.value;
return (int)health;
}
public int GetMaxHealth()
{
return (int)slider.maxValue;
}
}
65 changes: 58 additions & 7 deletions Assets/Scripts/UpgradesSystemScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@ public class UpgradesSystemScript : MonoBehaviour
{

public CastleScript castle;
[SerializeField]
private Text timerText;
[SerializeField] private Text timerText;
[SerializeField] private Text defenseText;
[SerializeField] private Text healthText;
[SerializeField] private Text shieldText;
[SerializeField] private Text moneyText;
[SerializeField] private TMPro.TMP_Text infoText;
[SerializeField] private Text moneyInfoText;
private Camera cam;
private int masksToFilter;

private void Awake()
{
castle.OnShowUpgrades += OnCastleShowUpgrades;
}
void Start()
{
cam = Camera.main;
masksToFilter = LayerMask.GetMask("Raycastable UI");
}
private void OnCastleShowUpgrades(object? sender, System.EventArgs e)
{
moneyInfoText.text = $"Money: {castle.Money}";
infoText.text = "Upgrade equipement or start new wave...";
}

void Update()
{
Expand All @@ -27,22 +42,53 @@ void Update()
switch (hit.transform.name)
{
case "DefenseImage":
castle.defense += 1;
Debug.Log("upgraded defense");
if (castle.Money < 20)
{
ShowNotEnoughMoney();
break;
}
castle.UpgradeDefense(20); //TODO Parametrize
defenseText.text = $"Lvl {castle.DefenseUpgradeLevel}";
infoText.text = $"Upgraded defense from lvl {castle.DefenseUpgradeLevel - 1} to lvl {castle.DefenseUpgradeLevel}";
break;
case "HealthImage":
if (castle.Money < 20)
{
ShowNotEnoughMoney();
break;
}
castle.UpgradeHealth(20);
healthText.text = $"Lvl {castle.HealthUpgradeLevel}";
infoText.text = $"Upgraded health from lvl {castle.HealthUpgradeLevel - 1} to lvl {castle.HealthUpgradeLevel}\n";
infoText.text += $"Health: {castle.GetHealth()}/{castle.GetMaxHealth()}";
break;
// TODO
case "ShieldImage":
if (castle.Money < 20)
{
ShowNotEnoughMoney();
break;
}
castle.UpgradeShield(20);
shieldText.text = $"Lvl {castle.ShieldUpgradeLevel}";
infoText.text = $"Upgraded shield from lvl {castle.ShieldUpgradeLevel - 1} to lvl {castle.ShieldUpgradeLevel}\n";
infoText.text += $"Shield: {castle.GetShield()}";
break;
// TODO
case "MoneyImage":
if (castle.Money < 20)
{
ShowNotEnoughMoney();
break;
}
castle.UpgradeMoney(20);
moneyText.text = $"Lvl {castle.MoneyUpgradeLevel}";
infoText.text = $"Upgraded money bonus from lvl {castle.MoneyUpgradeLevel - 1} to lvl {castle.MoneyUpgradeLevel}\n";
infoText.text += $"Money multiplier: {castle.GetMoneyMultiplier()}";
break;
// TODO
case "SkipImage":
castle.HideUpgrades();
break;
}
moneyInfoText.text = $"Money: {castle.Money}";
}
}
}
Expand All @@ -51,4 +97,9 @@ public void SetTimerText(string text)
{
timerText.text = text;
}

private void ShowNotEnoughMoney()
{
infoText.text = "Not enough money to buy it";
}
}
8 changes: 8 additions & 0 deletions Assets/TextMesh Pro.meta

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

8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Documentation.meta

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

Binary file not shown.

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

8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Fonts.meta

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

46 changes: 46 additions & 0 deletions Assets/TextMesh Pro/Fonts/LiberationSans - OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Digitized data copyright (c) 2010 Google Corporation
with Reserved Font Arimo, Tinos and Cousine.
Copyright (c) 2012 Red Hat, Inc.
with Reserved Font Name Liberation.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL

-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.

The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the copyright statement(s).

"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.

"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.

5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Fonts/LiberationSans - OFL.txt.meta

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

Binary file added Assets/TextMesh Pro/Fonts/LiberationSans.ttf
Binary file not shown.
19 changes: 19 additions & 0 deletions Assets/TextMesh Pro/Fonts/LiberationSans.ttf.meta

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

8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Resources.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/TextMesh Pro/Resources/Fonts & Materials.meta

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

Loading

0 comments on commit 5eb6037

Please sign in to comment.