From 76e4d6be3477deb3c00a51f57b7ee49d4b99296d Mon Sep 17 00:00:00 2001 From: Sch1nken Date: Thu, 14 Mar 2024 21:17:16 +0100 Subject: [PATCH] Implemented most movement. TODO: Pillbug ability. And find and fix bugs witht he movement. TODO: Deselect when not movable --- BuildMenu.gd | 5 +- HexGrid3D/HexGrid3D.gd | 85 +++++++++--------- InsectTiles/Assets/Textures/ant_black.png | Bin 59063 -> 59063 bytes InsectTiles/Assets/Textures/ant_white.png | Bin 52078 -> 52078 bytes InsectTiles/Assets/Textures/bee_black.png | Bin 52460 -> 52460 bytes InsectTiles/Assets/Textures/bee_white.png | Bin 50891 -> 50891 bytes InsectTiles/Assets/Textures/beetle_black.png | Bin 50482 -> 50482 bytes InsectTiles/Assets/Textures/beetle_white.png | Bin 22733 -> 22733 bytes .../Assets/Textures/grasshopper_black.png | Bin 24584 -> 24584 bytes .../Assets/Textures/grasshopper_white.png | Bin 68848 -> 68848 bytes InsectTiles/Assets/Textures/ladybug_black.png | Bin 22825 -> 22825 bytes InsectTiles/Assets/Textures/ladybug_white.png | Bin 59499 -> 59499 bytes .../Assets/Textures/mosquito_black.png | Bin 24442 -> 24442 bytes .../Assets/Textures/mosquito_white.png | Bin 27175 -> 27175 bytes InsectTiles/Assets/Textures/pillbug_black.png | Bin 22616 -> 22616 bytes InsectTiles/Assets/Textures/pillbug_white.png | Bin 63513 -> 63513 bytes InsectTiles/Assets/Textures/spider_black.png | Bin 52156 -> 52156 bytes InsectTiles/Assets/Textures/spider_white.png | Bin 63387 -> 63387 bytes .../Prefabs/MovementBehaviourAnt.gd | 19 ++-- .../Prefabs/MovementBehaviourBee.gd | 2 + .../Prefabs/MovementBehaviourBeetle.gd | 31 +++++++ .../Prefabs/MovementBehaviourLadybug.gd | 38 ++++++++ .../Prefabs/MovementBehaviourMosquito.gd | 11 +++ .../Prefabs/MovementBehaviourPillbug.gd | 11 +++ .../Prefabs/MovementBehaviourSpider.gd | 1 - Tile/Prefabs/Ant.tres | 7 +- Tile/Prefabs/Beetle.tres | 10 ++- Tile/Prefabs/Ladybug.tres | 8 +- Tile/Prefabs/Mosquito.tres | 7 +- Tile/Prefabs/Pillbug.tres | 7 +- Tile/Tile.gd | 1 + hex_outline_bottom.res | Bin 1440 -> 1442 bytes hex_outline_material.tres | 2 +- 33 files changed, 184 insertions(+), 61 deletions(-) diff --git a/BuildMenu.gd b/BuildMenu.gd index 1cf6224..1952388 100644 --- a/BuildMenu.gd +++ b/BuildMenu.gd @@ -11,7 +11,10 @@ const default_insects = { preload("res://Tile/Prefabs/Ant.tres"): 3, preload("res://Tile/Prefabs/Beetle.tres"): 2, preload("res://Tile/Prefabs/Grasshopper.tres"): 3, - preload("res://Tile/Prefabs/Spider.tres"): 2 + preload("res://Tile/Prefabs/Spider.tres"): 2, + preload("res://Tile/Prefabs/Ladybug.tres"): 1, + preload("res://Tile/Prefabs/Mosquito.tres"): 1, + preload("res://Tile/Prefabs/Pillbug.tres"): 1 } # Called when the node enters the scene tree for the first time. diff --git a/HexGrid3D/HexGrid3D.gd b/HexGrid3D/HexGrid3D.gd index 0d792c3..264bd7d 100644 --- a/HexGrid3D/HexGrid3D.gd +++ b/HexGrid3D/HexGrid3D.gd @@ -26,26 +26,7 @@ var used_cells: Dictionary = {} @export var layer_height: float = 0.4 -# have all used_cells be saved as Vector4i (q, r, s, y) - -class TileStorage: - var tiles: Dictionary = {} - # we use a vector4i for coordinates - # q r s y (layer) - - func add_tile(tile: InsectTile, coords: Vector4i) -> void: - tiles[coords] = tile - pass - - func remove_tile(coords: Vector4i) -> void: - pass - - func has_tile(coords: Vector4i) -> bool: - return tiles.has(coords) - - func get_tile(coords: Vector4i) -> InsectTile: - return tiles[coords] - +# have all used_cells be saved as Vector4i (q, r, s, y) class AxialCoordinates: var q: float @@ -132,27 +113,31 @@ func is_cell_not_empty(coords: Vector4i) -> bool: func get_empty_neighbours(coords: Vector4i) -> Array[Vector4i]: return get_neighbours(coords).filter(is_cell_empty) -func get_neighbours(coords: Vector4i) -> Array[Vector4i]: +func get_neighbours(coords: Vector4i, ground_layer: bool = false) -> Array[Vector4i]: + var layer: int = coords.w + if ground_layer: + layer = 0 + return [ - Vector4i(coords.x + 1, coords.y, coords.z - 1, coords.w), - Vector4i(coords.x + 1, coords.y - 1, coords.z, coords.w), - Vector4i(coords.x, coords.y - 1, coords.z + 1, coords.w), - Vector4i(coords.x - 1, coords.y, coords.z + 1, coords.w), - Vector4i(coords.x - 1, coords.y + 1, coords.z, coords.w), - Vector4i(coords.x, coords.y + 1, coords.z - 1, coords.w) + Vector4i(coords.x + 1, coords.y, coords.z - 1, layer), + Vector4i(coords.x + 1, coords.y - 1, coords.z, layer), + Vector4i(coords.x, coords.y - 1, coords.z + 1, layer), + Vector4i(coords.x - 1, coords.y, coords.z + 1, layer), + Vector4i(coords.x - 1, coords.y + 1, coords.z, layer), + Vector4i(coords.x, coords.y + 1, coords.z - 1, layer) ] var current_tile: Node3D const HEX_OUTLINE = preload("res://hex_outline.tscn") -func get_placeable_positions(button: InsectButton) -> Array: +func get_placeable_positions(button: InsectButton) -> Array[Vector4i]: if used_cells.size() == 0: return [Vector4i.ZERO] elif used_cells.size() == 1: var single_cell = used_cells.keys().front() var neighbours = get_neighbours(single_cell) - var positions = [] + var positions: Array[Vector4i] = [] for neighbour in neighbours: #var hex_pos = cube_to_world_pos(neighbour) @@ -160,7 +145,7 @@ func get_placeable_positions(button: InsectButton) -> Array: return positions var possible_placements: Dictionary = {} - var positions = [] + var positions: Array[Vector4i] = [] for hex in used_cells.keys(): for neighbour in get_empty_neighbours(hex): @@ -190,7 +175,7 @@ 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: +func can_reach(start: Vector4i, target: Vector4i) -> bool: # if we have 5 potential spaces it can never be blocked var offset: Vector4i = Vector4i.ZERO @@ -201,14 +186,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, 0) - var right_coord = Vector4i(right.x + start.x, right.y + start.y, right.z + start.z, 0) + 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) return is_cell_empty(left_coord) or is_cell_empty(right_coord) func _on_insect_selected(button: InsectButton, is_black: bool) -> void: var positions = get_placeable_positions(button) - for p in positions: + for p in positions: var outline = HEX_OUTLINE.instantiate() var hex_pos = cube_to_world_pos(p) outline.position = Vector3(hex_pos.x, 0.0, hex_pos.y) @@ -320,19 +305,19 @@ 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 create_move_positions() -> void: - pass - func _on_insect_tile_selected(tile: InsectTile) -> void: if not can_hive_exist_without_tile(tile): + print("Would break hive") return if tile.resource.movement_behaviour == null: + print("no movement behaviour") return var spaces = tile.resource.movement_behaviour.get_available_spaces(tile.coordinates, self) if spaces.is_empty(): + print("empty?") #GameEvents.insect_tile_selection_request_failed.emit(tile) return @@ -341,13 +326,29 @@ func _on_insect_tile_selected(tile: InsectTile) -> void: var non_empty_neighbours = neighbours.filter(is_cell_not_empty) if non_empty_neighbours.size() == 1: + # NOTE: This is correct! But seemed wrong when testing the beetle movement + # If there are only two tiles (beetle + some other) the beetle can't climb ontop of the other + # tile. This fixes itself automatically when there are more than two tiles present + # And since you can't move unless you place the bee, there will always be at least 3 tiles + # before you can move your beetle var occupied_neighbour = non_empty_neighbours.front() if occupied_neighbour == tile.coordinates: continue + + var layer: int = 0 + var temp_tile: InsectTile = null + if is_cell_not_empty(space): + temp_tile = used_cells.get(space) + layer = 1 + while tile.hat != null: + layer += 1 + tile = tile.hat + + space.w = layer var outline = HEX_OUTLINE.instantiate() var hex_pos = cube_to_world_pos(space) # flat_hex_to_world_position(AxialCoordinates.new(space.x, space.y)) - outline.position = Vector3(hex_pos.x, 0.0, hex_pos.y) + outline.position = Vector3(hex_pos.x, layer * layer_height, hex_pos.y) outline.coordinates = space outline.visible = true outline.insect_tile = tile @@ -357,13 +358,15 @@ func _on_insect_tile_selected(tile: InsectTile) -> void: placement_visualizer.add_child(outline) placements[space] = outline +func get_tile(pos: Vector4i) -> InsectTile: + return used_cells.get(pos) func _on_insect_tile_moved(tile: InsectTile, target: Vector4i) -> void: used_cells.erase(tile.coordinates) var new_hex_pos = cube_to_world_pos(target) var sky_new_hex_pos = Vector3(new_hex_pos.x, 20.0, new_hex_pos.y) - var ground_new_hex_pos = Vector3(new_hex_pos.x, 0.0, new_hex_pos.y) + var ground_new_hex_pos = Vector3(new_hex_pos.x, target.w * layer_height, new_hex_pos.y) # var current_hex_pos = tile.position var sky_current_hex_pos = tile.position + Vector3(0.0, 20.0, 0.0) @@ -392,7 +395,7 @@ func get_same_neighbours(cell1: Vector4i, cell2: Vector4i) -> Array[Vector4i]: return shared_neighbours func is_position_on_hive(pos: Vector4i) -> bool: - return get_empty_neighbours(pos).size() > 0 + return get_empty_neighbours(pos).size() < 6 func can_hive_exist_without_tile(tile: InsectTile) -> bool: # TODO: BFS-Search from random cell to see if all other cells could still be reached when this @@ -402,7 +405,7 @@ func can_hive_exist_without_tile(tile: InsectTile) -> bool: # DO BFS var tiles_reached: Array = [] - var tiles_available: Array = used_cells.keys().filter(func(coords): return coords != tile.coordinates) + var tiles_available: Array = used_cells.keys().filter(func(coords): return coords != tile.coordinates).filter(func(coords): coords.w != tile.coordinates.w) if tiles_available.size() <= 1: # If we only have 1 or 2 total tiles, we can always move diff --git a/InsectTiles/Assets/Textures/ant_black.png b/InsectTiles/Assets/Textures/ant_black.png index d8c291618475d2b6f07cf24c84f7f95a6b699304..d62408cef522e434d92674657673b2dcb2847c04 100644 GIT binary patch delta 123 zcmdmfmU;VG<_Yy2d?Jh{n`}OO+1TFpRKzsI$k@uj(#pg@+rYrez+ml3Wx2_U&tyH& zCGJd_y@-KUO_Qmsldb5n~;5_1a}j0}uSbPbGk4NOCfjI9hTtxOCchIKdY Ks-4{S%n$%(mnEhE diff --git a/InsectTiles/Assets/Textures/ant_white.png b/InsectTiles/Assets/Textures/ant_white.png index 43c1dcb019928405cd34d51077cb35d2f30827d2..2077ac2c81ec37505a1804df12b2746e67a289d0 100644 GIT binary patch delta 73 zcmaDijrrX)<_Yy2d?Jh{n`}OO+1PG-YO>~O0T%9k8mlJXI3)|_R6U*`HktFZyr`i` ah>?MnfuWVDk+uPlVGy2vS81~CX+r=>yBkyh delta 84 zcmaDijrrX)<_Yy2tm2%SXO`&KZfv(bC1Mg{Xk=w%VP#^bZD3$!U{I#9Qe^UtQ?eKm b?4^P$CUc&apZw*NAdBv|jVCADo;Cyks?Z$X diff --git a/InsectTiles/Assets/Textures/bee_black.png b/InsectTiles/Assets/Textures/bee_black.png index 86c51daebf17f47cc22a71d595a1f98502ebb494..2bdd1468de6b487a860edf604e6571788529c22f 100644 GIT binary patch delta 88 zcmaDelljd|<_Yy2d?JjdN39PeZEW9tdh+r!0^(L-M&=9*45}rr5hW>!C8<`q`6-!c sm6PY5kz(=Y?&_Z0enwu@&?Lmjz{pF delta 121 zcmaDelljd|<_Yy2tm2$np=;}oZ*1Rv+SMe)(9p`n)XKn8+rYrez+lPhUsenZ45}rr z5hW>!C8<`q`6-!cl?+A(Mkcxj#<~XR8m@kGYMb1CMqbpwG{ndlXpWVM5yU7Nxz!<) Icb_o?0F(SCWB>pF diff --git a/InsectTiles/Assets/Textures/bee_white.png b/InsectTiles/Assets/Textures/bee_white.png index cc431a40806214a5c5f4c7d7e3188087ecb44566..93bebe7d965f89ca12f7ae178593b6675c9ac9b6 100644 GIT binary patch delta 88 zcmX@z%Y3?*c|tu0p9rJLCYujmHnz_?I=StbfH?O)ja3W`45}rr5hW>!C8<`q`6-!c sm6L0ZNwHKto**_k?U=l%p-G65ft7)wm8p@o0gz!3o_<$p@~mTq0P(~ie*gdg delta 121 zcmX@z%Y3?*c|tu0t2n3TnI-zQ8{20cbu|ewG_*1?wK6c&HZZU~e?swArb diff --git a/InsectTiles/Assets/Textures/beetle_black.png b/InsectTiles/Assets/Textures/beetle_black.png index 7b38196f8bbcea7700b62acda340556597e9dc20..9e46de1ac5b710d5d0c4d5dc2e1c68c133b30f74 100644 GIT binary patch delta 97 zcmdng#k{GDc|tu0p9rI|PDE<>#&*UdBBmim##RQFRwf481_o9J25V0$%T1nhL>5Eh i&Xn1UCZ9bbFKTEKVgyuaXk}^$(UR7GeE(#|qlN&dcOFFm delta 84 zcmdng#k{GDc|tu0t2n2|?#1%2H?}h#5itodG_o?Xure{zHZZUzm7AZEnO4bQWME{XYhbKvfUcqH@dPoT1`W7|lFZ!H;*!MN0=OPSlMo}I Z*@jl8Mi5KF)9)$)^+=YuPQDwj4FHkgD`Wrw delta 155 zcmeA;z}Rtsaf2um2dg-z=9wk>wVP#`9AoQELJWsekrd2W+85o)98W`&uple_+6+s2bXJ(4A^lkdiB0|4h&Duw_6 diff --git a/InsectTiles/Assets/Textures/grasshopper_white.png b/InsectTiles/Assets/Textures/grasshopper_white.png index c7442b54e07acb51e28f7a3213f298bbc1af4a52..b21b0a5986cc65e1ee6f9b6181f658920d4837d1 100644 GIT binary patch delta 105 zcmew`ljXxqmI?J7d?JjdN39PeHMVbUXWYjvYG@K-WME}rXk~1uZ2)8#w5ujddbY!#B@kdKg-78e(K@WngJ#VxVncU}a#i_N1~L0|SF< ziEBhjN@7W>Rc?MtW?ChKk%5tku7RR Znr&!hY6!6;t^fFbpdQH**UA4Pv;pk^Ei3>4 delta 155 zcmZ3viE-s7#tqY$I9SCwHFhtSf4zAg)5FkulMq8AD*DZ>*RkC+5iRMEV2Lq diff --git a/InsectTiles/Assets/Textures/ladybug_white.png b/InsectTiles/Assets/Textures/ladybug_white.png index b51bb44bfb1b95737072523e74d440f6adda233b..4227328ab9e5d2a0bd51815dd0a2fc50f64a8ee5 100644 GIT binary patch delta 121 zcmaETf%)|X<_Yy2d?Jh{n`}OO+1PIN+|@M1$k@uj(#ph8+rYrez<_(7#wrE|2GtVR zh?11Vl2ohQ{FKbJN(LhXBNJT%V_gGu4ONdPh)rgDAunoZ5@G~2!O+Uo2x3%t`dy{T HRxb>ure^TGBwgR05S~1)9)%x_KY_K0G?AFp8x;= delta 121 zcmeyhkMY+&#tGFNtm2%SXO`&KZfy3Ab2SMuG_o?Xure{zHZZU=|ze0J$t8+yDRo diff --git a/InsectTiles/Assets/Textures/mosquito_white.png b/InsectTiles/Assets/Textures/mosquito_white.png index e177a24b7eefe83fe4c4e5c05cb6247122f0fadf..b55ea79d1d2b4b339eac51171ddcd577cdddf0e2 100644 GIT binary patch delta 123 zcmZ2}g>m^6#tGFNd?JjdN39PeZEXIPAz~V0WNc+%X=P%hZD3#pL}5nelP6}%dZ0^q zb9Z$!FfeG8xJHzuB$lLFm1O3o7MCRE7BCnY7@6oA80#9Egct$MFtjo?h8Xry;M%mw H-!csWC72~0 delta 123 zcmZ2}g>m^6#tGFNtm2$np=;}oZ*2aRAz~6@Xk=w%VP#^bZD3$!U{I#9Qe^VPOj!?f z3HDOK6$}gv8YQj~B`Jv|sa7SKxv9k^iMa&~Mg~SEx(3F&2BslK##RQFRwhOe!(`-E KhfMyKX$Sy4VkABQ diff --git a/InsectTiles/Assets/Textures/pillbug_black.png b/InsectTiles/Assets/Textures/pillbug_black.png index b6ff31dfdb2f511dfc64d1620337f6f83f61bec2..c9e754bd4483235620c86125332cef3e0120b478 100644 GIT binary patch delta 155 zcmcbyf$_!$#touO9DE{-rbn$0ByE;uniyJd8e(K@WngJ#Vx(!C8<`q`6-!cl?+A(Mkcxj#<~XR8oar?x`7%r;2KIYb5n~;5_1dSdJIiMjDThv XTA3O{EcqyKZ5mLIWQpr!-3V;}KFlgV delta 155 zcmcbyf$_!$#touO9IWD;TA^#}j&GJ_niyJd5@Kj%Wn^JxVy10iU}a!Xrm<3lfq_A_ z#5JNMC9x#cDmOnRGp&-r$iT=%*T7iU09^xnso)Br1`W7|lFZ!H;*!MN0)!sZ5F=wN Z14}CtLx?51-!`5E>X9sQova(74FGPKD#HK( diff --git a/InsectTiles/Assets/Textures/pillbug_white.png b/InsectTiles/Assets/Textures/pillbug_white.png index 4f256264c9298a87471a94f0bc40f3407eb6ae25..8b0f51ac1e7db4427f12e733f7975a41dbb8f024 100644 GIT binary patch delta 114 zcmbRFfqCW!<_Yy2d?Jh{n`}OO+1UQ#+vF?X1;p2$RF-34U{Eb_jVMV;EJ?M>%}>cp ztDJo5yOhP9DYF*=dQ3x%jI9hT XtxOCcmUK7nss-wiEODLu?z=VsSBNc> diff --git a/InsectTiles/Assets/Textures/spider_black.png b/InsectTiles/Assets/Textures/spider_black.png index 2c7f086cda4c7b98501d1a4ddc21fb056302bbec..1311c511c9e0325178b05e8c12c8d392b91394ea 100644 GIT binary patch delta 88 zcmdlpoq5l6<_Yy2d?JjdN39PeZEWv8HM#t>fVfqdkvRhcgKCLuL`h0wNvc(DeoAIq s<>cJcQY_xwUEPzzPs@uMnuHh`SQ!{vnHp;w02u}!1+Gn-+*0Dom43jhEB delta 121 zcmdlpoq5l6<_Yy2tm2$np=;}oZ*1>A*0KnfO?EnA( diff --git a/InsectTiles/Assets/Textures/spider_white.png b/InsectTiles/Assets/Textures/spider_white.png index b029ada95972ba63266fcd6aef3c55bf1daf5171..f69d3c0dbb7052e0a483b11a56b563c71b54f9c5 100644 GIT binary patch delta 88 zcmV-e0H^<(?*p6f1CW0R4io`2vOMtgv4?8*lUDZ-7p=)79smFUC3HntbYx+4Wjbwd uWNBu3lT7y-1l*LHqLViF9~Ch)R5CC+FflqcGAl4JIxsL-XWb%`YWFcPMIo*L delta 121 zcmbRJo_Y3r<_Yy2tm2#+yBEv9-q@b?&DA8t(8$Wj!pg)<+rYrez@SWHr3eE9gKCLu zL`h0wNvc(DeoAIqC4-THk%_K>v91BS2KG|H6_d@r%ZnPAh8P)J8CY7G7(k5bZroKn IIqSP201bI0qW}N^ diff --git a/MovementBehaviour/Prefabs/MovementBehaviourAnt.gd b/MovementBehaviour/Prefabs/MovementBehaviourAnt.gd index de60368..3874897 100644 --- a/MovementBehaviour/Prefabs/MovementBehaviourAnt.gd +++ b/MovementBehaviour/Prefabs/MovementBehaviourAnt.gd @@ -6,29 +6,26 @@ class_name MovementBehaviourAnt # Maybe better: Get al "placecable tiles" from the map, go over those. Might be faster but more complicated func simulate_move_recursive(start: Vector4i, exclude: Array[Vector4i], map: HexGrid, visited_cells: Array[Vector4i] = []) -> Array[Vector4i]: - var visited = visited_cells var possible: Array[Vector4i] = [] - - #if max_num < 1: - # return [start] for neighbour in map.get_empty_neighbours(start): - if neighbour in visited: + if neighbour in visited_cells: + continue + + if not map.is_position_on_hive(neighbour): continue if not map.can_reach(start, neighbour): continue + visited_cells.push_back(neighbour) + simulate_move_recursive(neighbour, exclude, map, visited_cells) + var same_neighbours = map.get_same_neighbours(start, neighbour) for e in exclude: same_neighbours.erase(e) - - if same_neighbours.size() > 0: - visited.append(neighbour) - print("yay?") - possible.append_array(simulate_move_recursive(neighbour, exclude, map, visited)) - return possible + return visited_cells func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]: var possible_places: Array[Vector4i] = [] diff --git a/MovementBehaviour/Prefabs/MovementBehaviourBee.gd b/MovementBehaviour/Prefabs/MovementBehaviourBee.gd index c821460..7401d9e 100644 --- a/MovementBehaviour/Prefabs/MovementBehaviourBee.gd +++ b/MovementBehaviour/Prefabs/MovementBehaviourBee.gd @@ -3,6 +3,8 @@ class_name MovementBehaviourBee func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]: var potential_spaces = map.get_empty_neighbours(pos) + + print(potential_spaces) var target_spaces: Array[Vector4i] = [] diff --git a/MovementBehaviour/Prefabs/MovementBehaviourBeetle.gd b/MovementBehaviour/Prefabs/MovementBehaviourBeetle.gd index 10886ff..70c73fa 100644 --- a/MovementBehaviour/Prefabs/MovementBehaviourBeetle.gd +++ b/MovementBehaviour/Prefabs/MovementBehaviourBeetle.gd @@ -1,2 +1,33 @@ extends MovementBehaviour class_name MovementBehaviourBeetle + +@export var max_movement_reach: int = 1 + +func simulate_move_recursive(start: Vector4i, max_num: int, map: HexGrid, visited_cells: Array[Vector4i] = []) -> Array[Vector4i]: + var visited = visited_cells.duplicate() + var possible: Array[Vector4i] = [] + + visited.append(start) + + if max_num < 1: + return [start] + + for neighbour in map.get_neighbours(start, true): + if neighbour in visited: + continue + + # can reach... can_reach should only apply to our current level + if not map.can_reach(start, neighbour): + continue + + visited.append(neighbour) + possible.append_array(simulate_move_recursive(neighbour, max_num - 1, map, visited)) + + return possible + +func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]: + var possible_places: Array[Vector4i] = [] + + possible_places = simulate_move_recursive(pos, max_movement_reach, map) + + return possible_places diff --git a/MovementBehaviour/Prefabs/MovementBehaviourLadybug.gd b/MovementBehaviour/Prefabs/MovementBehaviourLadybug.gd index d632ca9..91509f1 100644 --- a/MovementBehaviour/Prefabs/MovementBehaviourLadybug.gd +++ b/MovementBehaviour/Prefabs/MovementBehaviourLadybug.gd @@ -1,2 +1,40 @@ extends MovementBehaviour class_name MovementBehaviourLadybug + +@export var max_movement_reach: int = 3 + +func simulate_move_recursive(start: Vector4i, max_num: int, exclude: Array[Vector4i], map: HexGrid, visited_cells: Array[Vector4i] = []) -> Array[Vector4i]: + var visited = visited_cells.duplicate() + var possible: Array[Vector4i] = [] + + visited.append(start) + + if max_num < 1: + return [start] + + var neighbours: Array[Vector4i] = [] + if max_num > 1: + neighbours = map.get_neighbours(start).filter(map.is_cell_not_empty) + else: + neighbours = map.get_empty_neighbours(start) + + for neighbour in neighbours: + if neighbour in visited: + continue + + #var same_neighbours = map.get_same_neighbours(start, neighbour) + #for e in exclude: + #same_neighbours.erase(e) + + #if same_neighbours.size() > 0: + visited.append(neighbour) + possible.append_array(simulate_move_recursive(neighbour, max_num - 1, exclude, map, visited)) + + return possible + +func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]: + var possible_places: Array[Vector4i] = [] + + possible_places = simulate_move_recursive(pos, max_movement_reach, [pos], map) + + return possible_places diff --git a/MovementBehaviour/Prefabs/MovementBehaviourMosquito.gd b/MovementBehaviour/Prefabs/MovementBehaviourMosquito.gd index 05380a3..c4b0ae6 100644 --- a/MovementBehaviour/Prefabs/MovementBehaviourMosquito.gd +++ b/MovementBehaviour/Prefabs/MovementBehaviourMosquito.gd @@ -1,2 +1,13 @@ extends MovementBehaviour class_name MovementBehaviourMosquito + +func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]: + var target_spaces: Array[Vector4i] = [] + + for neighbour in map.get_neighbours(pos): + if map.is_cell_empty(neighbour): + continue + + target_spaces.append_array(map.get_tile(neighbour).resource.movement_behaviour.get_available_spaces(pos, map)) + + return target_spaces diff --git a/MovementBehaviour/Prefabs/MovementBehaviourPillbug.gd b/MovementBehaviour/Prefabs/MovementBehaviourPillbug.gd index a314415..ae31f63 100644 --- a/MovementBehaviour/Prefabs/MovementBehaviourPillbug.gd +++ b/MovementBehaviour/Prefabs/MovementBehaviourPillbug.gd @@ -1,2 +1,13 @@ extends MovementBehaviour class_name MovementBehaviourPillbug + +func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]: + var potential_spaces = map.get_empty_neighbours(pos) + + var target_spaces: Array[Vector4i] = [] + + for neighbour in potential_spaces: + if map.can_reach(pos, neighbour): + target_spaces.append(neighbour) + + return target_spaces diff --git a/MovementBehaviour/Prefabs/MovementBehaviourSpider.gd b/MovementBehaviour/Prefabs/MovementBehaviourSpider.gd index 2e29953..975c1a2 100644 --- a/MovementBehaviour/Prefabs/MovementBehaviourSpider.gd +++ b/MovementBehaviour/Prefabs/MovementBehaviourSpider.gd @@ -25,7 +25,6 @@ func simulate_move_recursive(start: Vector4i, max_num: int, exclude: Array[Vecto if same_neighbours.size() > 0: visited.append(neighbour) - print("yay?") possible.append_array(simulate_move_recursive(neighbour, max_num - 1, exclude, map, visited)) return possible diff --git a/Tile/Prefabs/Ant.tres b/Tile/Prefabs/Ant.tres index 9d9d0ae..aa4b7de 100644 --- a/Tile/Prefabs/Ant.tres +++ b/Tile/Prefabs/Ant.tres @@ -1,13 +1,18 @@ -[gd_resource type="Resource" script_class="TileResource" load_steps=5 format=3 uid="uid://x25q4bbhxcp3"] +[gd_resource type="Resource" script_class="TileResource" load_steps=7 format=3 uid="uid://x25q4bbhxcp3"] [ext_resource type="Material" uid="uid://cxosyb7s454wj" path="res://InsectTiles/Materials/Ant_Black.tres" id="1_yunq4"] [ext_resource type="Material" uid="uid://cq13vo8hnk7k1" path="res://InsectTiles/Materials/Ant_White.tres" id="2_8sds4"] [ext_resource type="Script" path="res://Tile/TileResource.gd" id="3_n4n55"] +[ext_resource type="Script" path="res://MovementBehaviour/Prefabs/MovementBehaviourAnt.gd" id="3_thq0t"] [ext_resource type="Texture2D" uid="uid://0sqfwl6wjdtl" path="res://InsectTiles/Assets/UI/ant.png" id="4_canjv"] +[sub_resource type="Resource" id="Resource_m8bed"] +script = ExtResource("3_thq0t") + [resource] script = ExtResource("3_n4n55") tile_name = "Ant" +movement_behaviour = SubResource("Resource_m8bed") material_black = ExtResource("1_yunq4") material_white = ExtResource("2_8sds4") ui_texture = ExtResource("4_canjv") diff --git a/Tile/Prefabs/Beetle.tres b/Tile/Prefabs/Beetle.tres index 30f72f3..5c9adfc 100644 --- a/Tile/Prefabs/Beetle.tres +++ b/Tile/Prefabs/Beetle.tres @@ -1,13 +1,19 @@ -[gd_resource type="Resource" script_class="TileResource" load_steps=5 format=3 uid="uid://bn5na10diacrw"] +[gd_resource type="Resource" script_class="TileResource" load_steps=7 format=3 uid="uid://bn5na10diacrw"] [ext_resource type="Material" uid="uid://bbx3b1qialq3l" path="res://InsectTiles/Materials/Beetle_Black.tres" id="1_cbjw0"] [ext_resource type="Material" uid="uid://cas4k78kf1c0x" path="res://InsectTiles/Materials/Beetle_White.tres" id="2_txjyp"] [ext_resource type="Script" path="res://Tile/TileResource.gd" id="3_g4s7x"] +[ext_resource type="Script" path="res://MovementBehaviour/Prefabs/MovementBehaviourBeetle.gd" id="3_ik3ft"] [ext_resource type="Texture2D" uid="uid://dwewgsgd0gasi" path="res://InsectTiles/Assets/UI/beetle.png" id="4_iki3w"] +[sub_resource type="Resource" id="Resource_lc7ln"] +script = ExtResource("3_ik3ft") +max_movement_reach = 1 + [resource] script = ExtResource("3_g4s7x") -tile_name = "Spider" +tile_name = "Beetle" +movement_behaviour = SubResource("Resource_lc7ln") material_black = ExtResource("1_cbjw0") material_white = ExtResource("2_txjyp") ui_texture = ExtResource("4_iki3w") diff --git a/Tile/Prefabs/Ladybug.tres b/Tile/Prefabs/Ladybug.tres index 8881967..7930d6f 100644 --- a/Tile/Prefabs/Ladybug.tres +++ b/Tile/Prefabs/Ladybug.tres @@ -1,13 +1,19 @@ -[gd_resource type="Resource" script_class="TileResource" load_steps=5 format=3 uid="uid://daieqla4g6pnx"] +[gd_resource type="Resource" script_class="TileResource" load_steps=7 format=3 uid="uid://daieqla4g6pnx"] [ext_resource type="Material" uid="uid://ymfmmwtlmikl" path="res://InsectTiles/Materials/Ladybug_Black.tres" id="1_1577p"] [ext_resource type="Material" uid="uid://c5oxmuvm8ngp6" path="res://InsectTiles/Materials/Ladybug_White.tres" id="2_6ewhc"] +[ext_resource type="Script" path="res://MovementBehaviour/Prefabs/MovementBehaviourLadybug.gd" id="3_hgd41"] [ext_resource type="Script" path="res://Tile/TileResource.gd" id="3_kco06"] [ext_resource type="Texture2D" uid="uid://c8tm1giuiexap" path="res://InsectTiles/Assets/UI/ladybug.png" id="4_ad3wk"] +[sub_resource type="Resource" id="Resource_qjpfb"] +script = ExtResource("3_hgd41") +max_movement_reach = 3 + [resource] script = ExtResource("3_kco06") tile_name = "Ladybug" +movement_behaviour = SubResource("Resource_qjpfb") material_black = ExtResource("1_1577p") material_white = ExtResource("2_6ewhc") ui_texture = ExtResource("4_ad3wk") diff --git a/Tile/Prefabs/Mosquito.tres b/Tile/Prefabs/Mosquito.tres index 12d6239..182588f 100644 --- a/Tile/Prefabs/Mosquito.tres +++ b/Tile/Prefabs/Mosquito.tres @@ -1,13 +1,18 @@ -[gd_resource type="Resource" script_class="TileResource" load_steps=5 format=3 uid="uid://5gxoun8c6a2i"] +[gd_resource type="Resource" script_class="TileResource" load_steps=7 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://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_0j1qw"] +script = ExtResource("3_gkh5p") + [resource] script = ExtResource("3_5xhnv") tile_name = "Mosquito" +movement_behaviour = SubResource("Resource_0j1qw") material_black = ExtResource("1_lthri") material_white = ExtResource("2_qdl6y") ui_texture = ExtResource("4_rp6ff") diff --git a/Tile/Prefabs/Pillbug.tres b/Tile/Prefabs/Pillbug.tres index 6414ba0..80fa676 100644 --- a/Tile/Prefabs/Pillbug.tres +++ b/Tile/Prefabs/Pillbug.tres @@ -1,13 +1,18 @@ -[gd_resource type="Resource" script_class="TileResource" load_steps=5 format=3 uid="uid://dk0ndwv8i2rsb"] +[gd_resource type="Resource" script_class="TileResource" load_steps=7 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://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_5iy41"] +script = ExtResource("3_2v3p1") + [resource] script = ExtResource("3_j2ho1") tile_name = "Pillbug" +movement_behaviour = SubResource("Resource_5iy41") material_black = ExtResource("1_45nom") material_white = ExtResource("2_b3rd8") ui_texture = ExtResource("4_dg5at") diff --git a/Tile/Tile.gd b/Tile/Tile.gd index 6147fc2..5591022 100644 --- a/Tile/Tile.gd +++ b/Tile/Tile.gd @@ -102,6 +102,7 @@ func _process(delta): ##GameEvents.insect_tile_selection_request_failed.emit(tile) #return + print(resource) GameEvents.insect_tile_selected.emit(self) diff --git a/hex_outline_bottom.res b/hex_outline_bottom.res index 8d39613332a614e6d67575491a663fd890498439..b4acd1981e6285684af496ae12320b00d000f4b0 100644 GIT binary patch delta 1427 zcmV;E1#J4D3!)2uQd2`i0ssI201yBGn+^Z~iUj}wD77#BV4DpEECA*?u|W`Zk`AB} zL>pjei39@ii6H?%pb3D;EjqTXwMOJJ?!Bqan=~THCcQy25hj_b)or&4Ct3Ty0gMOs z8xxo{K1%_R0G0rn0B*sfw9!*Gm2rHrG0--z=YPvPaXRo9raJDihU=nA*}h081J-A? zm2;;xO-|~Ol_Gyf`J5_QgBFI`ada#huLM=TmBP&zZksGNd)ne-+t`Y8`M-nz)>&A% z9I+;(K=D7osktOV%KYK~$$yjoB>zkP?WzjU%~0Ke%RPC!C$?r}O&2xX4%BASy{W-L z`kt~%CU+$VQmdu@Cs>KvZKp|DREbinPkfVskc`}MI=Fvw(i$7E|cIg7~Pz%T9!E%QXMPuTL_hE>;Zza1aIy=?XCV7 z_$1AWDTote`LflZ?UY9yo@@p%FdZaRQKZVM*wboro3bg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mxQMyt zAw&Z88AiHT<{!Zgl_L!+-pAQiwU0@ur+)x@*jg<*v${^uRey2I5XgXtg z$o(vDpz-vWc;<(y^~aaZH4jQ*DJDs3+%J*|_Js?wL284!g@ON?|Dt~EBzHNaySgcuZWeM zUY#KWyS=vwL2T+S(aZmz+!#C6XG!BkDfKGN@WdVyXRMzFl%n=W!*1bAB%gC2DPaeJ z9sw(@(YvTypOGke+LG8%_kLJlUKf{tAc*cp6sPJ*w&OIR5YNfb8a9cE7JvRyQiX$& zv_3qRyQ|c>IZ6yfDvm!vfvI z0Pk2m=F})$==_YXwZnyxzH$I@Y${|u-C}vnfuo`d;CP{SdLrnrxp<9lqD6@Fg(!*y zXJF*Z#i$oU*=&5q_W&j;#*{)r+c42eLB2cn$QUsW66c)Br2C7BSB09(LV>|lxIkEI fE_3&ox{G*Bq}4^~E34<7t%CPDNweAkQd2`i&D^Is diff --git a/hex_outline_material.tres b/hex_outline_material.tres index 43d69c1..908825e 100644 --- a/hex_outline_material.tres +++ b/hex_outline_material.tres @@ -2,7 +2,7 @@ [sub_resource type="Gradient" id="Gradient_8056d"] offsets = PackedFloat32Array(0, 0.0549828, 0.945017) -colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 0.52549, 1, 1, 1, 0) +colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 0.772549, 1, 1, 1, 0) [sub_resource type="GradientTexture1D" id="GradientTexture1D_5kfu4"] gradient = SubResource("Gradient_8056d")