|
@@ -1,3 +1,4 @@
|
|
|
+class_name Brick
|
|
|
extends StaticBody2D
|
|
|
|
|
|
|
|
@@ -12,15 +13,16 @@ func setup(x: int, y: int, max_life: int):
|
|
|
position.x = x * 40
|
|
|
position.y = y * 20
|
|
|
life = randi() % max_life + 1
|
|
|
- update() # For custom drawing
|
|
|
+ _refresh_look()
|
|
|
|
|
|
|
|
|
func damage():
|
|
|
life = life - 1
|
|
|
emit_signal("kace_damaged")
|
|
|
- update() # For custom drawing
|
|
|
if life < 1:
|
|
|
blow_up()
|
|
|
+ else:
|
|
|
+ _refresh_look()
|
|
|
|
|
|
|
|
|
func blow_up():
|
|
@@ -30,3 +32,19 @@ 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
|