diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-10 14:46:13 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-10 14:46:13 +0200 |
commit | e0a6d318be7570152eef053ad0dbc67608a981de (patch) | |
tree | f9818a3777ad6e513750eba33365a859e004a6eb /Map.gd | |
parent | ed517bbfd0e10abd9bc571131188061a7221d103 (diff) | |
download | godot-hexgrid-e0a6d318be7570152eef053ad0dbc67608a981de.zip godot-hexgrid-e0a6d318be7570152eef053ad0dbc67608a981de.tar.gz |
add check boxes
Diffstat (limited to 'Map.gd')
-rw-r--r-- | Map.gd | 30 |
1 files changed, 20 insertions, 10 deletions
@@ -24,6 +24,8 @@ var p1 : Vector2 var los : Array var move : Array var unit : Unit +var show_los : bool +var show_move : bool func _ready(): board = HexBoard.new() @@ -47,6 +49,10 @@ func get_tile(coords : Vector2, k : int) -> Tile: $Hexes.add_child(hex) return hex +func config(l : bool, m : bool) -> void: + show_los = l + show_move = m + func on_rotate() -> void: texture = load(MAPH if board.v else MAPV) var ts : Vector2 = texture.get_size() @@ -74,7 +80,7 @@ func on_rotate() -> void: $Hexes.remove_child(hex) hex.queue_free() reset() - update_los() + update() func on_mouse_move() -> void: if drag != null: @@ -97,7 +103,7 @@ func on_mouse_1(pressed : bool) -> void: drag.position = board.center_of(coords) if drag == $Tank: p0 = coords else: p1 = coords - update_los() + update() else: drag.position = board.center_of(prev) drag = null @@ -109,18 +115,22 @@ func on_mouse_2(pressed : bool) -> void: var hex : Hex = board.get_tile(coords) hex.change() notify(hex, pos, coords) - update_los() + update() func notify(hex : Hex, pos : Vector2, coords : Vector2) -> void: if board.is_on_map(coords): emit_signal("hex_touched",pos, hex, board.key(coords)) else: emit_signal("hex_touched", pos, hex, -1) -func update_los() -> void: +func update() -> void: + $Los.visible = false for hex in los: hex.show_los(false) - var ct : Vector2 = board.line_of_sight(p0, p1, los) - $Los.setup($Tank.position, $Target.position, ct) - for hex in los: hex.show_los(true) + if show_los: + $Los.visible = true + var ct : Vector2 = board.line_of_sight(p0, p1, los) + $Los.setup($Tank.position, $Target.position, ct) + for hex in los: hex.show_los(true) for hex in move: hex.show_move(false) - # warning-ignore:return_value_discarded - board.possible_moves(unit, board.get_tile(p0), move) - for hex in move: hex.show_move(true) + if show_move: + # warning-ignore:return_value_discarded + board.possible_moves(unit, board.get_tile(p0), move) + for hex in move: hex.show_move(true) |