summaryrefslogtreecommitdiffstats
path: root/Hex.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 /Hex.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 'Hex.gd')
-rw-r--r--Hex.gd51
1 files changed, 40 insertions, 11 deletions
diff --git a/Hex.gd b/Hex.gd
index f06c7bf..f6b615d 100644
--- a/Hex.gd
+++ b/Hex.gd
@@ -3,22 +3,51 @@ extends Tile
class_name Hex, "res://godot/Tile.png"
+var type : int = 0
+
+func _ready() -> void:
+ type = -1
+
func inspect() -> String:
- return "[%d;%d] %s" % [coords.x,coords.y,not blocked]
+ var s : String = 'plain'
+ if type == 2: s = 'city'
+ elif type == 3: s = 'wood'
+ elif type == 4: s = 'mountain'
+ return "%s e:%d h:%d c:%d\n -> [%d;%d]\n -> (%d;%d)" % [s, elevation(), height(), cost(), coords.x, coords.y, position.x, position.y]
+
+func change() -> void:
+ type += 1
+ if type < 2: type = 2
+ if type > 4: type = -1
+ for i in range(2, 5):
+ enable_overlay(i, i == type)
-func block(b : bool) -> void:
- enable_overlay(0, b)
+func cost() -> int:
+ if type == -1: return 1
+ return type - 1
-func is_blocked() -> bool:
- return is_overlay_on(0)
+func height() -> int:
+ if type == 2: return 2
+ elif type == 3: return 1
+ elif type == 4: return 0
+ return 0
+
+func elevation() -> int:
+ if type == 4: return 2
+ return 0
func block_los(from : Tile, to : Tile, d : float, dt : float) -> bool:
- return is_blocked()
+ var h : int = height() + elevation()
+ if h == 0: return false
+ var e : int = from.elevation()
+ if e > h:
+ if to.elevation() > h: return false
+ return (h * dt / (e - h)) >= (d - dt)
+ h -= e
+ return ((h * d / dt) >= to.elevation() - e)
func show_los(b) -> void:
- if not b:
- enable_overlay(1, false)
- enable_overlay(2, false)
+ if b: enable_overlay((1 if blocked else 0), true)
else:
- if blocked: enable_overlay(2, true)
- else: enable_overlay(1, true)
+ enable_overlay(0, false)
+ enable_overlay(1, false)