summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-07-19 21:49:00 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-07-19 21:49:00 +0200
commit97629c24f4ba40ddbb1c2bc5ffd52ff74eea68b7 (patch)
treee82117567a41629604dcb12746d28442cd25e48b
parentdc4c8275bf7fe7b22783b5ed366e3eb9c0b83a5b (diff)
downloadgodot-hexgrid-97629c24f4ba40ddbb1c2bc5ffd52ff74eea68b7.zip
godot-hexgrid-97629c24f4ba40ddbb1c2bc5ffd52ff74eea68b7.tar.gz
implement Range Of Influence Demo
-rw-r--r--Hex.gd17
-rw-r--r--Main.gd3
-rw-r--r--Main.tscn17
-rw-r--r--Map.gd14
-rw-r--r--README.md3
-rw-r--r--assets/red.pngbin0 -> 4526 bytes
-rw-r--r--data/influence.gifbin0 -> 770118 bytes
7 files changed, 39 insertions, 15 deletions
diff --git a/Hex.gd b/Hex.gd
index 77b867e..99bdbd2 100644
--- a/Hex.gd
+++ b/Hex.gd
@@ -23,7 +23,7 @@ func has_road(o : int) -> bool:
func change() -> void:
type = (type + 2) % 5 - 1
for i in range(4):
- enable_overlay(i + 2, i == type)
+ enable_overlay(i + 3, i == type)
func cost() -> int:
if type == -1: return 1
@@ -63,15 +63,18 @@ func block_los(from : Tile, to : Tile, d : float, dt : float) -> bool:
return ((h * d / dt) >= to.elevation() - e)
func show_los(b) -> void:
- if b: enable_overlay((1 if blocked else 0), true)
+ if b: enable_overlay((2 if blocked else 1), true)
else:
- enable_overlay(0, false)
enable_overlay(1, false)
+ enable_overlay(2, false)
func show_move(b) -> void:
- if 6 < get_child_count():
- enable_overlay(6, b)
+ enable_overlay(7, b)
func show_short(b) -> void:
- if 7 < get_child_count():
- enable_overlay(7, b)
+ enable_overlay(8, b)
+
+func show_influence(b) -> void:
+ var s : Sprite = get_child(0)
+ s.modulate = Color(f/10.0, 0, 0)
+ enable_overlay(0, b)
diff --git a/Main.gd b/Main.gd
index 432baba..42b52a9 100644
--- a/Main.gd
+++ b/Main.gd
@@ -14,6 +14,7 @@ func _ready():
UI.get_node("zout").connect("pressed", self, "on_zoom", [false])
UI.get_node("LOS").connect("pressed", self, "on_toggle")
UI.get_node("Move").connect("pressed", self, "on_toggle")
+ UI.get_node("Influence").connect("pressed", self, "on_toggle")
Map.connect("hex_touched", self, "on_hex_touched")
$CanvasLayer/HBOX/ViewportContainer.connect("resized", self, "on_viewport_resized")
on_toggle()
@@ -32,7 +33,7 @@ func on_zoom(b : bool) -> void:
Camera.update_camera(0, 0, -0.05 if b else 0.05)
func on_toggle() -> void:
- Map.set_mode(UI.get_node("LOS").pressed, UI.get_node("Move").pressed)
+ Map.set_mode(UI.get_node("LOS").pressed, UI.get_node("Move").pressed, UI.get_node("Influence").pressed)
func on_hex_touched(pos : Vector2, hex : Hex, key : int) -> void:
var s : String = ("offmap" if key == -1 else hex.inspect())
diff --git a/Main.tscn b/Main.tscn
index ab3f410..27a5ce9 100644
--- a/Main.tscn
+++ b/Main.tscn
@@ -129,18 +129,27 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="Info" type="Label" parent="CanvasLayer/HBOX/UI"]
+[node name="Influence" type="CheckBox" parent="CanvasLayer/HBOX/UI"]
margin_top = 538.0
margin_right = 250.0
-margin_bottom = 574.0
+margin_bottom = 582.0
+text = "Influence"
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="Info" type="Label" parent="CanvasLayer/HBOX/UI"]
+margin_top = 612.0
+margin_right = 250.0
+margin_bottom = 648.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="OSInfo" type="Label" parent="CanvasLayer/HBOX/UI"]
-margin_top = 604.0
+margin_top = 678.0
margin_right = 250.0
-margin_bottom = 640.0
+margin_bottom = 714.0
__meta__ = {
"_edit_use_anchors_": false
}
diff --git a/Map.gd b/Map.gd
index d23ea5a..81c5c36 100644
--- a/Map.gd
+++ b/Map.gd
@@ -8,6 +8,7 @@ const BLOCK : String = "res://assets/block.png"
const BLACK : String = "res://assets/black.png"
const MOVE : String = "res://assets/move.png"
const SHORT : String = "res://assets/short.png"
+const RED : String = "res://assets/red.png"
const GREEN : String = "res://assets/green.png"
const TREE : String = "res://assets/tree.png"
const CITY : String = "res://assets/city.png"
@@ -24,9 +25,11 @@ var p1 : Vector2
var los : Array
var move : Array
var short : Array
+var influence : Array
var unit : Unit
var show_los : bool
var show_move : bool
+var show_influence : bool
func _ready():
drag = null
@@ -40,6 +43,7 @@ func reset() -> void:
los.clear()
move.clear()
short.clear()
+ influence.clear()
hexes.clear()
hexes[-1] = Hex.new() # off map
p0 = Vector2(0, 0)
@@ -56,9 +60,10 @@ func rotate_map() -> void:
configure()
reset()
-func set_mode(l : bool, m : bool) -> void:
+func set_mode(l : bool, m : bool, i : bool) -> void:
show_los = l
show_move = m
+ show_influence = i
compute()
func configure() -> void:
@@ -126,7 +131,7 @@ func get_tile(coords : Vector2, k : int) -> Tile:
var hex : Hex = Hex.new()
hex.roads = get_road(k)
hex.rotation_degrees = hex_rotation
- hex.configure(board.center_of(coords), coords, [GREEN, BLACK, CITY, TREE, MOUNT, BLOCK, MOVE, SHORT])
+ hex.configure(board.center_of(coords), coords, [RED, GREEN, BLACK, CITY, TREE, MOUNT, BLOCK, MOVE, SHORT])
hexes[k] = hex
$Hexes.add_child(hex)
return hex
@@ -162,3 +167,8 @@ func compute() -> void:
board.shortest_path(unit, board.get_tile(p0), board.get_tile(p1), short)
for hex in move: hex.show_move(true)
for i in range(1, short.size() -1): short[i].show_short(true)
+ for hex in influence: hex.show_influence(false)
+ if show_influence:
+ # warning-ignore:return_value_discarded
+ board.range_of_influence(unit, board.get_tile(p0), 0, influence)
+ for hex in influence: hex.show_influence(true)
diff --git a/README.md b/README.md
index 3381d40..2f8f07c 100644
--- a/README.md
+++ b/README.md
@@ -14,10 +14,11 @@ test maps made with [hexmap](https://github.com/jeremyz/hexmap) a [gimp](https:/
- [x] 3D Line Of Sight
- [x] Reachable Tiles ::: BFS
- [x] Shortest Path ::: A*
- - [ ] Range Of Influence (LOS - Fire Power)
+ - [x] Range Of Influence (LOS - Fire Power)
- [ ] Battle lines (Kruskal + farthest apart units are the flank units)
## screenshots
![Line Of Sight](data/los.gif)
![Possible Move - Shortest Path](data/move.gif)
+![Range Of Influence Path](data/influence.gif)
diff --git a/assets/red.png b/assets/red.png
new file mode 100644
index 0000000..0bf4075
--- /dev/null
+++ b/assets/red.png
Binary files differ
diff --git a/data/influence.gif b/data/influence.gif
new file mode 100644
index 0000000..7d73cea
--- /dev/null
+++ b/data/influence.gif
Binary files differ