-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stats.cs
64 lines (49 loc) · 1.31 KB
/
Stats.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Godot;
using System;
public class Stats : Node
{
[Export]
public bool randomMaxHealth = false;
[Export]
public int maxHealth = 1;
private int health;
RandomNumberGenerator rng = new RandomNumberGenerator();
[Signal]
public delegate void noHitpoints();
[Signal]
public delegate void healthChanged(int healthValue);
[Signal]
public delegate void maxHealthChanged(int maxHealthValue);
public override void _Ready()
{
if (randomMaxHealth)
{
rng.Randomize();
maxHealth = rng.RandiRange(1,7);
}
health = maxHealth;
}
public void changeHealth(int value)
{
health = Math.Min(maxHealth, health + value);
EmitSignal("healthChanged", health);
if (health <= 0)
{
EmitSignal("noHitpoints");
}
}
public void setMaxHealth(int value)
{
this.maxHealth = Math.Max(value, 1); // maxhealth gelijkzetten aan ingevoerde waarde
changeHealth(0); // If maxHealth becomes lower than current health, this will correctly update it.
EmitSignal("maxHealthChanged", this.maxHealth);
}
public int getCurrentHealth()
{
return this.health;
}
public int getMaxHealth()
{
return this.maxHealth;
}
}