1234567891011121314151617181920212223242526272829303132333435363738394041 |
- extends Node2D
- var living_cells = {}
- var default_font
- const print_offset = Vector2(1.0, 15.0)
- func spawn_brick(x, y, maximum_life):
- living_cells[Vector2(x, y)] = maximum_life
- update()
- func may_die_by_taking_this(pos, damage):
- var has_died = false
- if damage > 0 and living_cells.has(pos):
- living_cells[pos] -= damage
- update()
- has_died = living_cells[pos] <= 0
- if has_died:
- living_cells.erase(pos)
- return has_died
- func create_font():
- var label = Label.new()
- default_font = label.get_font("font")
- func _ready():
- create_font()
- func _draw():
- for p in living_cells:
- draw_string(default_font, p * Vector2(40, 20) + print_offset, str(living_cells[p]), Color.red)
|