Implemented most movement. TODO: Pillbug ability. And find and fix bugs witht he movement. TODO: Deselect when not movable
This commit is contained in:
parent
11f8a71f52
commit
76e4d6be34
33 changed files with 184 additions and 61 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue