-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brick.cs
41 lines (36 loc) · 933 Bytes
/
Brick.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
using Godot;
[Tool]
public partial class Brick : StaticBody2D
{
static readonly string[] colors = {"slate blue", "light sky blue", "MediumSeaGreen", "orange", "IndianRed"};
[Export(PropertyHint.Range, "1, 5,")]
public uint MaxHealth
{
get => maxHealth;
set
{
maxHealth = value;
GetNode<ColorRect>("ColorRect").Color = new Color(colors[maxHealth-1]);
}
}
uint maxHealth = 1;
uint health;
[Signal]
public delegate void OnBreakEventHandler(uint maxHealth);
public override void _Ready()
{
health = maxHealth;
GetNode<ColorRect>("ColorRect").Color = new Color(colors[health-1]);
}
//returns true if the brick is broken
public bool Hit() {
health--;
if(health <= 0) {
EmitSignal("OnBreak", maxHealth);
QueueFree();
return true;
}
GetNode<ColorRect>("ColorRect").Color = new Color(colors[health-1]);
return false;
}
}