summaryrefslogtreecommitdiffstats
path: root/Map.gd
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-07-09 17:03:28 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-07-09 17:03:28 +0200
commitdf57b3be4e9a8c3ed3d5d14b4b4f1e2ef7629cd3 (patch)
tree7a2a8e9f8f6c3a548442229e58168f1293db4baa /Map.gd
parent857e8831cf4e25b487a1c390e1f32cef2ca2554d (diff)
downloadgodot-hexgrid-df57b3be4e9a8c3ed3d5d14b4b4f1e2ef7629cd3.zip
godot-hexgrid-df57b3be4e9a8c3ed3d5d14b4b4f1e2ef7629cd3.tar.gz
implement different terrain type, use elevation, and height to compute LOS
Diffstat (limited to 'Map.gd')
-rw-r--r--Map.gd24
1 files changed, 11 insertions, 13 deletions
diff --git a/Map.gd b/Map.gd
index 1300304..76edb86 100644
--- a/Map.gd
+++ b/Map.gd
@@ -1,13 +1,16 @@
extends Sprite
signal configure(center, texture_size)
-signal touched(msg)
+signal hex_touched(pos, hex, key)
const MAPH : String = "res://assets/map-h.png"
const MAPV : String = "res://assets/map-v.png"
const BLOCK : String = "res://assets/block.png"
const BLACK : String = "res://assets/black.png"
const GREEN : String = "res://assets/green.png"
+const TREE : String = "res://assets/tree.png"
+const CITY : String = "res://assets/city.png"
+const MOUNT : String = "res://assets/mountain.png"
var drag : Sprite
@@ -35,7 +38,7 @@ func get_tile(coords : Vector2, k : int) -> Tile:
if hexes.has(k): return hexes[k]
var hex : Hex = Hex.new()
hex.rotation_degrees = hex_rotation
- hex.configure(board.center_of(coords), coords, [BLOCK, GREEN, BLACK])
+ hex.configure(board.center_of(coords), coords, [GREEN, BLACK, CITY, TREE, MOUNT])
hexes[k] = hex
$Hexes.add_child(hex)
return hex
@@ -77,7 +80,7 @@ func on_mouse_1(pressed : bool) -> void:
var pos : Vector2 = get_local_mouse_position()
var coords : Vector2 = board.to_map(pos)
if pressed:
- notify(pos, coords)
+ notify(board.get_tile(coords), pos, coords)
if drag == null:
prev = coords
if board.to_map($Tank.position) == coords:
@@ -99,19 +102,14 @@ func on_mouse_2(pressed : bool) -> void:
var pos : Vector2 = get_local_mouse_position()
var coords : Vector2 = board.to_map(pos)
if pressed:
- notify(pos, coords)
var hex : Hex = board.get_tile(coords)
- if not hex.is_blocked(): hex.block(true)
- else: hex.block(false)
+ hex.change()
+ notify(hex, pos, coords)
update_los()
-func notify(pos : Vector2, coords : Vector2) -> void:
- if board.is_on_map(coords):
- var center : Vector2 = board.center_of(coords)
- var key : int = board.key(coords)
- emit_signal("touched","%s\n -> %s\n -> %s\n -> %d" % [pos, coords, center, key])
- else:
- emit_signal("touched", "off board")
+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:
for hex in los: