|
@@ -4,6 +4,7 @@ extends StaticBody2D
|
|
|
|
|
|
signal kace_broken
|
|
|
signal kace_damaged
|
|
|
+signal life_changed
|
|
|
|
|
|
|
|
|
var life: int
|
|
@@ -13,7 +14,7 @@ func setup(x: int, y: int, max_life: int):
|
|
|
position.x = x * 40
|
|
|
position.y = y * 20
|
|
|
life = randi() % max_life + 1
|
|
|
- _refresh_look()
|
|
|
+ emit_signal("life_changed", life)
|
|
|
|
|
|
|
|
|
func damage():
|
|
@@ -22,7 +23,7 @@ func damage():
|
|
|
if life < 1:
|
|
|
blow_up()
|
|
|
else:
|
|
|
- _refresh_look()
|
|
|
+ emit_signal("life_changed", life)
|
|
|
|
|
|
|
|
|
func blow_up():
|
|
@@ -32,19 +33,3 @@ func blow_up():
|
|
|
|
|
|
func impact(pos: Vector2):
|
|
|
damage()
|
|
|
-
|
|
|
-
|
|
|
-static func color_from_life(n: int) -> Color:
|
|
|
- var x = float(n % 256) / 255
|
|
|
- if n < 256:
|
|
|
- return Color(x, 1.0, 1.0 - x)
|
|
|
- elif n < 512:
|
|
|
- return Color(1.0, 1.0 - x, x)
|
|
|
- elif n < 768:
|
|
|
- return Color(1.0, 0.0, 1.0 - x)
|
|
|
- else:
|
|
|
- return Color(1.0, 0.0, 0.0)
|
|
|
-
|
|
|
-func _refresh_look() -> void:
|
|
|
- modulate = color_from_life(life)
|
|
|
- update() # For custom drawing
|