123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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_rect(Rect2(p * Vector2(40, 20) + Vector2(2, 2), Vector2(36, 16)), Color.red, true)
- draw_string(default_font, p * Vector2(40, 20) + print_offset, str(living_cells[p]))
|