Skip to content
Snippets Groups Projects
Commit 85555c80 authored by Gard Aleksander Furre's avatar Gard Aleksander Furre
Browse files

Merge branch 'gardaf1' into 'main'

Added simple xp bar

See merge request !27
parents dbf34879 55c146e1
No related branches found
No related tags found
2 merge requests!29Updating master,!27Added simple xp bar
...@@ -56,6 +56,13 @@ namespace BigSock { ...@@ -56,6 +56,13 @@ namespace BigSock {
public float MaxHP => Stats.MaxHP; public float MaxHP => Stats.MaxHP;
public float baseMaxHP = 10; public float baseMaxHP = 10;
/*
Xp....
*/
public float dropXP;
public float xp;
public float maxXp;
public int level;
/* /*
...@@ -194,7 +201,11 @@ namespace BigSock { ...@@ -194,7 +201,11 @@ namespace BigSock {
Alive = false; Alive = false;
// Inform the attacker killed us. // Inform the attacker killed us.
if(attack.Actor != null) attack.Actor.TargetKilled(this, attack); if(attack.Actor != null) {
attack.Actor.TargetKilled(this, attack);
if(attack.Actor is PlayerController player)
player.GainXp(dropXP);
}
AfterDeath(); AfterDeath();
...@@ -239,7 +250,6 @@ namespace BigSock { ...@@ -239,7 +250,6 @@ namespace BigSock {
print($"[Character.AfterDeath()] start. | {HP}, {Alive}"); print($"[Character.AfterDeath()] start. | {HP}, {Alive}");
Destroy(gameObject); Destroy(gameObject);
} }
} }
...@@ -328,6 +338,12 @@ namespace BigSock { ...@@ -328,6 +338,12 @@ namespace BigSock {
public void TargetKilled(Character target, AttackStats attack) { public void TargetKilled(Character target, AttackStats attack) {
OnKill?.Invoke(this, target, attack); OnKill?.Invoke(this, target, attack);
} }
public void GiveXp(float xp) {
this.xp += xp;
OnGainedXP?.Invoke(this, xp);
}
/* /*
Triggers when character uses an attack. Triggers when character uses an attack.
...@@ -381,9 +397,9 @@ namespace BigSock { ...@@ -381,9 +397,9 @@ namespace BigSock {
/* /*
Triggers when character gains xp. Triggers when character gains xp.
Params: actor, amount. Params: sorce, amount.
*/ */
public event Action<Character, int> OnGainedXP; public event Action<Character, float> OnGainedXP;
/* /*
Triggers when character levels up. Triggers when character levels up.
......
...@@ -17,6 +17,9 @@ namespace BigSock { ...@@ -17,6 +17,9 @@ namespace BigSock {
{ {
public HPBar hpBar; public HPBar hpBar;
public XpBar xpBar;
public float collisionOffset = 0.05f; public float collisionOffset = 0.05f;
public ContactFilter2D movementFilter; public ContactFilter2D movementFilter;
...@@ -44,6 +47,10 @@ namespace BigSock { ...@@ -44,6 +47,10 @@ namespace BigSock {
protected override void Start() protected override void Start()
{ {
base.Start(); base.Start();
xpBar.SetMaxXp(maxXp);
xpBar.SetXp(xp);
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
spriteRenderer = GetComponent<SpriteRenderer>(); spriteRenderer = GetComponent<SpriteRenderer>();
hpBar.SetMaxHealth(Convert.ToInt32(MaxHP)); hpBar.SetMaxHealth(Convert.ToInt32(MaxHP));
...@@ -168,5 +175,21 @@ namespace BigSock { ...@@ -168,5 +175,21 @@ namespace BigSock {
base.AfterDamage(attack); base.AfterDamage(attack);
hpBar.SetHealth(Convert.ToInt32(HP)); hpBar.SetHealth(Convert.ToInt32(HP));
} }
public void GainXp(float xp){
GiveXp(xp);
CheckXp();
xpBar.SetXp(this.xp);
}
private void CheckXp(){
if(xp > maxXp){
level += 1;
xp -= maxXp;
maxXp = (level + 1) * 100;
xpBar.SetMaxXp(maxXp);
}
}
} }
} }
...@@ -9,6 +9,7 @@ namespace BigSock { ...@@ -9,6 +9,7 @@ namespace BigSock {
public partial class EnemyController : Character { public partial class EnemyController : Character {
public float collisionOffset = 0.05f; public float collisionOffset = 0.05f;
public ContactFilter2D movementFilter; public ContactFilter2D movementFilter;
protected List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); protected List<RaycastHit2D> castCollisions = new List<RaycastHit2D>();
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace BigSock.UI{
public class XpBar : MonoBehaviour
{
public Slider slider;
public TextMeshPro xpText;
protected void Start(){
slider = GetComponent<Slider>();
// xpText = GetComponent<TextMeshPro>();
}
public void SetXp(float xp){
slider.value = xp;
xpText.SetText($"{xp}/{slider.maxValue}");
}
public void SetMaxXp(float xp){
slider.maxValue = xp;
}
}
}
fileFormatVersion: 2
guid: a2ed0e7debd7bc7468e3a430508a7e71
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment