Fixed Spider movement (it was not excluding itself after the first move

This commit is contained in:
Sch1nken 2024-03-14 22:13:33 +01:00
parent 76e4d6be34
commit 5722ffab48
9 changed files with 64 additions and 22 deletions

View 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
#

View file

@ -0,0 +1,2 @@
extends ActionBehaviour
class_name ActionBehaviourMosquito

View file

@ -0,0 +1,2 @@
extends ActionBehaviour
class_name ActionBehaviourPillbug

View file

@ -175,7 +175,27 @@ func get_left_neighbour(pos: Vector4i) -> Vector4i:
func get_right_neighbour(pos: Vector4i) -> Vector4i: func get_right_neighbour(pos: Vector4i) -> Vector4i:
return Vector4i(-pos.y, -pos.z, -pos.x, 0) 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 # if we have 5 potential spaces it can never be blocked
var offset: Vector4i = Vector4i.ZERO var offset: Vector4i = Vector4i.ZERO
@ -189,6 +209,11 @@ func can_reach(start: Vector4i, target: Vector4i) -> bool:
var left_coord = Vector4i(left.x + start.x, left.y + start.y, left.z + start.z, start.w) 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) 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) return is_cell_empty(left_coord) or is_cell_empty(right_coord)
func _on_insect_selected(button: InsectButton, is_black: bool) -> void: func _on_insect_selected(button: InsectButton, is_black: bool) -> void:

View file

@ -16,12 +16,12 @@ func simulate_move_recursive(start: Vector4i, max_num: int, exclude: Array[Vecto
if neighbour in visited: if neighbour in visited:
continue continue
if not map.can_reach(start, neighbour): if not map.can_reach(start, neighbour, exclude):
continue continue
var same_neighbours = map.get_same_neighbours(start, neighbour) var same_neighbours = map.get_same_neighbours(start, neighbour)
for e in exclude: #for e in exclude:
same_neighbours.erase(e) # same_neighbours.erase(e)
if same_neighbours.size() > 0: if same_neighbours.size() > 0:
visited.append(neighbour) visited.append(neighbour)

View file

@ -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="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="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://Tile/TileResource.gd" id="3_5xhnv"]
[ext_resource type="Script" path="res://MovementBehaviour/Prefabs/MovementBehaviourMosquito.gd" id="3_gkh5p"] [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"] [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"] [sub_resource type="Resource" id="Resource_0j1qw"]
script = ExtResource("3_gkh5p") script = ExtResource("3_gkh5p")
@ -13,6 +17,7 @@ script = ExtResource("3_gkh5p")
script = ExtResource("3_5xhnv") script = ExtResource("3_5xhnv")
tile_name = "Mosquito" tile_name = "Mosquito"
movement_behaviour = SubResource("Resource_0j1qw") movement_behaviour = SubResource("Resource_0j1qw")
action_behaviour = SubResource("Resource_sngyg")
material_black = ExtResource("1_lthri") material_black = ExtResource("1_lthri")
material_white = ExtResource("2_qdl6y") material_white = ExtResource("2_qdl6y")
ui_texture = ExtResource("4_rp6ff") ui_texture = ExtResource("4_rp6ff")

View file

@ -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="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="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://MovementBehaviour/Prefabs/MovementBehaviourPillbug.gd" id="3_2v3p1"]
[ext_resource type="Script" path="res://Tile/TileResource.gd" id="3_j2ho1"] [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"] [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"] [sub_resource type="Resource" id="Resource_5iy41"]
script = ExtResource("3_2v3p1") script = ExtResource("3_2v3p1")
@ -13,6 +17,7 @@ script = ExtResource("3_2v3p1")
script = ExtResource("3_j2ho1") script = ExtResource("3_j2ho1")
tile_name = "Pillbug" tile_name = "Pillbug"
movement_behaviour = SubResource("Resource_5iy41") movement_behaviour = SubResource("Resource_5iy41")
action_behaviour = SubResource("Resource_4oq6e")
material_black = ExtResource("1_45nom") material_black = ExtResource("1_45nom")
material_white = ExtResource("2_b3rd8") material_white = ExtResource("2_b3rd8")
ui_texture = ExtResource("4_dg5at") ui_texture = ExtResource("4_dg5at")

View file

@ -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

View file

@ -4,6 +4,7 @@ class_name TileResource
@export var tile_name: String = "DefaultName" @export var tile_name: String = "DefaultName"
@export var movement_behaviour: MovementBehaviour @export var movement_behaviour: MovementBehaviour
@export var action_behaviour: ActionBehaviour
@export var material_black: StandardMaterial3D @export var material_black: StandardMaterial3D
@export var material_white: StandardMaterial3D @export var material_white: StandardMaterial3D