12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- class_name Brick
- extends StaticBody2D
- signal kace_broken
- signal kace_damaged
- signal life_changed
- signal impact
- const MAX_LIFE := 1999
- const Explosion = preload("res://effect/particle/explosion/Explosion.tscn")
- const EXPLOSION_OFFSET := Vector2(10, 5)
- var life: int
- func setup(x: int, y: int, max_life: int) -> void:
- position.x = x * 40
- position.y = y * 20
- life = randi() % max_life + 1
- life = min(life, MAX_LIFE)
- emit_signal("life_changed", life)
- func damage() -> void:
- life = life - 1
- emit_signal("kace_damaged")
- if life < 1:
- blow_up()
- else:
- emit_signal("life_changed", life)
- func blow_up() -> void:
- emit_signal("kace_broken")
- var explosion = Explosion.instance()
- explosion.position = to_global(EXPLOSION_OFFSET)
- get_parent().get_parent().add_child(explosion)
- queue_free()
- func impact(pos: Vector2) -> void:
- emit_signal("impact", to_local(pos))
- func bounce(pos: Vector2) -> void:
- damage()
|