LifeContainer.gd 694 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. extends Node2D
  2. var living_cells = {}
  3. var default_font
  4. const print_offset = Vector2(1.0, 15.0)
  5. func spawn_brick(x, y, maximum_life):
  6. living_cells[Vector2(x, y)] = maximum_life
  7. update()
  8. func may_die_by_taking_this(pos, damage):
  9. var has_died = false
  10. if damage > 0 and living_cells.has(pos):
  11. living_cells[pos] -= damage
  12. update()
  13. has_died = living_cells[pos] <= 0
  14. if has_died:
  15. living_cells.erase(pos)
  16. return has_died
  17. func create_font():
  18. var label = Label.new()
  19. default_font = label.get_font("font")
  20. func _ready():
  21. create_font()
  22. func _draw():
  23. for p in living_cells:
  24. draw_string(default_font, p * Vector2(40, 20) + print_offset, str(living_cells[p]), Color.red)