Fixed Spider movement (it was not excluding itself after the first move
This commit is contained in:
parent
76e4d6be34
commit
5722ffab48
9 changed files with 64 additions and 22 deletions
15
ActionBehaviour/ActionBehaviourResource.gd
Normal file
15
ActionBehaviour/ActionBehaviourResource.gd
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
extends Resource
|
||||
class_name ActionBehaviour
|
||||
|
||||
func do_action() -> void:
|
||||
pass
|
||||
|
||||
# NOTE: When selecting a tile, check if there is an action behaviour
|
||||
# If yes: In addition to showing moveable spaces (0 for the mosquito by default)
|
||||
# also show action options (usually clicking other nearby tiles)
|
||||
|
||||
# For pillbug this "select" the tile, then create some sort of movement-outline
|
||||
# to move thant unit there
|
||||
# Check if unit was recently moved etc
|
||||
|
||||
#
|
||||
2
ActionBehaviour/Prefabs/ActionBehaviourMosquito.gd
Normal file
2
ActionBehaviour/Prefabs/ActionBehaviourMosquito.gd
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
extends ActionBehaviour
|
||||
class_name ActionBehaviourMosquito
|
||||
2
ActionBehaviour/Prefabs/ActionBehaviourPillbug.gd
Normal file
2
ActionBehaviour/Prefabs/ActionBehaviourPillbug.gd
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
extends ActionBehaviour
|
||||
class_name ActionBehaviourPillbug
|
||||
|
|
@ -175,7 +175,27 @@ func get_left_neighbour(pos: Vector4i) -> Vector4i:
|
|||
func get_right_neighbour(pos: Vector4i) -> Vector4i:
|
||||
return Vector4i(-pos.y, -pos.z, -pos.x, 0)
|
||||
|
||||
func can_reach(start: Vector4i, target: Vector4i) -> bool:
|
||||
var debug_labels = []
|
||||
|
||||
func debug_label(pos, text) -> void:
|
||||
var label = Label3D.new()
|
||||
label.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
||||
label.text = text
|
||||
var p = cube_to_world_pos(pos)
|
||||
label.position = Vector3(p.x, 0.2, p.y)
|
||||
add_child(label)
|
||||
debug_labels.push_back(label)
|
||||
|
||||
func clear_debug_labels() -> void:
|
||||
for label in debug_labels:
|
||||
label.queue_free()
|
||||
|
||||
debug_labels.clear()
|
||||
|
||||
func can_reach(start: Vector4i, target: Vector4i, exclude: Array[Vector4i] = []) -> bool:
|
||||
if start.w != target.w:
|
||||
return true
|
||||
|
||||
# if we have 5 potential spaces it can never be blocked
|
||||
var offset: Vector4i = Vector4i.ZERO
|
||||
|
||||
|
|
@ -185,9 +205,14 @@ func can_reach(start: Vector4i, target: Vector4i) -> bool:
|
|||
|
||||
var left = get_left_neighbour(offset)
|
||||
var right = get_right_neighbour(offset)
|
||||
|
||||
|
||||
var left_coord = Vector4i(left.x + start.x, left.y + start.y, left.z + start.z, start.w)
|
||||
var right_coord = Vector4i(right.x + start.x, right.y + start.y, right.z + start.z, start.w)
|
||||
|
||||
if left_coord in exclude or right_coord in exclude:
|
||||
print("excluded?")
|
||||
return true
|
||||
|
||||
|
||||
return is_cell_empty(left_coord) or is_cell_empty(right_coord)
|
||||
|
||||
|
|
@ -305,7 +330,7 @@ func _on_insect_placed(resource: TileResource, is_black: bool, pos: Vector4i) ->
|
|||
func can_move(tile: InsectTile) -> bool:
|
||||
return can_hive_exist_without_tile(tile)
|
||||
|
||||
func _on_insect_tile_selected(tile: InsectTile) -> void:
|
||||
func _on_insect_tile_selected(tile: InsectTile) -> void:
|
||||
if not can_hive_exist_without_tile(tile):
|
||||
print("Would break hive")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ func simulate_move_recursive(start: Vector4i, max_num: int, exclude: Array[Vecto
|
|||
for neighbour in map.get_empty_neighbours(start):
|
||||
if neighbour in visited:
|
||||
continue
|
||||
|
||||
if not map.can_reach(start, neighbour):
|
||||
|
||||
if not map.can_reach(start, neighbour, exclude):
|
||||
continue
|
||||
|
||||
var same_neighbours = map.get_same_neighbours(start, neighbour)
|
||||
for e in exclude:
|
||||
same_neighbours.erase(e)
|
||||
#for e in exclude:
|
||||
# same_neighbours.erase(e)
|
||||
|
||||
if same_neighbours.size() > 0:
|
||||
visited.append(neighbour)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
[gd_resource type="Resource" script_class="TileResource" load_steps=7 format=3 uid="uid://5gxoun8c6a2i"]
|
||||
[gd_resource type="Resource" script_class="TileResource" load_steps=9 format=3 uid="uid://5gxoun8c6a2i"]
|
||||
|
||||
[ext_resource type="Material" uid="uid://c3cgwluy7660h" path="res://InsectTiles/Materials/Mosquito_Black.tres" id="1_lthri"]
|
||||
[ext_resource type="Script" path="res://ActionBehaviour/Prefabs/ActionBehaviourMosquito.gd" id="1_v5wo0"]
|
||||
[ext_resource type="Material" uid="uid://4d8v7sxf1udv" path="res://InsectTiles/Materials/Mosquito_White.tres" id="2_qdl6y"]
|
||||
[ext_resource type="Script" path="res://Tile/TileResource.gd" id="3_5xhnv"]
|
||||
[ext_resource type="Script" path="res://MovementBehaviour/Prefabs/MovementBehaviourMosquito.gd" id="3_gkh5p"]
|
||||
[ext_resource type="Texture2D" uid="uid://sw4ar13a5qxx" path="res://InsectTiles/Assets/UI/mosquito.png" id="4_rp6ff"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_sngyg"]
|
||||
script = ExtResource("1_v5wo0")
|
||||
|
||||
[sub_resource type="Resource" id="Resource_0j1qw"]
|
||||
script = ExtResource("3_gkh5p")
|
||||
|
||||
|
|
@ -13,6 +17,7 @@ script = ExtResource("3_gkh5p")
|
|||
script = ExtResource("3_5xhnv")
|
||||
tile_name = "Mosquito"
|
||||
movement_behaviour = SubResource("Resource_0j1qw")
|
||||
action_behaviour = SubResource("Resource_sngyg")
|
||||
material_black = ExtResource("1_lthri")
|
||||
material_white = ExtResource("2_qdl6y")
|
||||
ui_texture = ExtResource("4_rp6ff")
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
[gd_resource type="Resource" script_class="TileResource" load_steps=7 format=3 uid="uid://dk0ndwv8i2rsb"]
|
||||
[gd_resource type="Resource" script_class="TileResource" load_steps=9 format=3 uid="uid://dk0ndwv8i2rsb"]
|
||||
|
||||
[ext_resource type="Material" uid="uid://4vol6qmah4dx" path="res://InsectTiles/Materials/Pillbug_Black.tres" id="1_45nom"]
|
||||
[ext_resource type="Script" path="res://ActionBehaviour/Prefabs/ActionBehaviourPillbug.gd" id="1_mp5qe"]
|
||||
[ext_resource type="Material" uid="uid://drmm6ppt50j7s" path="res://InsectTiles/Materials/Pillbug_White.tres" id="2_b3rd8"]
|
||||
[ext_resource type="Script" path="res://MovementBehaviour/Prefabs/MovementBehaviourPillbug.gd" id="3_2v3p1"]
|
||||
[ext_resource type="Script" path="res://Tile/TileResource.gd" id="3_j2ho1"]
|
||||
[ext_resource type="Texture2D" uid="uid://evg5tvmw8ehl" path="res://InsectTiles/Assets/UI/pillbug.png" id="4_dg5at"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_4oq6e"]
|
||||
script = ExtResource("1_mp5qe")
|
||||
|
||||
[sub_resource type="Resource" id="Resource_5iy41"]
|
||||
script = ExtResource("3_2v3p1")
|
||||
|
||||
|
|
@ -13,6 +17,7 @@ script = ExtResource("3_2v3p1")
|
|||
script = ExtResource("3_j2ho1")
|
||||
tile_name = "Pillbug"
|
||||
movement_behaviour = SubResource("Resource_5iy41")
|
||||
action_behaviour = SubResource("Resource_4oq6e")
|
||||
material_black = ExtResource("1_45nom")
|
||||
material_white = ExtResource("2_b3rd8")
|
||||
ui_texture = ExtResource("4_dg5at")
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
extends Marker3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
print(position)
|
||||
print(global_position)
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
|
@ -4,6 +4,7 @@ class_name TileResource
|
|||
@export var tile_name: String = "DefaultName"
|
||||
|
||||
@export var movement_behaviour: MovementBehaviour
|
||||
@export var action_behaviour: ActionBehaviour
|
||||
@export var material_black: StandardMaterial3D
|
||||
@export var material_white: StandardMaterial3D
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue