Fixed more movement bugs, disabled expansions for now. Added turnendbehaviour (for bee, should add trigger by turn end signal)

This commit is contained in:
Sch1nken 2024-03-15 03:24:32 +01:00
parent 5722ffab48
commit 26fec25a6e
14 changed files with 154 additions and 37 deletions

View file

@ -4,6 +4,9 @@ class_name ActionBehaviour
func do_action() -> void: func do_action() -> void:
pass pass
func select_targets(source_pos: Vector4i, map: HexGrid) -> void:
pass
# NOTE: When selecting a tile, check if there is an action behaviour # 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) # If yes: In addition to showing moveable spaces (0 for the mosquito by default)
# also show action options (usually clicking other nearby tiles) # also show action options (usually clicking other nearby tiles)

View file

@ -1,2 +1,16 @@
extends ActionBehaviour extends ActionBehaviour
class_name ActionBehaviourMosquito class_name ActionBehaviourMosquito
# GameEvents.insect_tiles_selected_for_action
func select_targets(source_pos: Vector4i, map: HexGrid): # -> Array[InsectTile]:
var neighbours = map.get_neighbours(source_pos)
# Filter out other mosquitos
var possible_action_targets: Array[InsectTile] = []
for neighbour in neighbours:
var tile = map.get_tile(neighbour)
if tile != null:
# TODO: Find better way to see what tile we have...
if not tile.resource.movement_behaviour is MovementBehaviourMosquito:
possible_action_targets.push_back(tile)
GameEvents.insect_tiles_selected_for_action.emit(source_pos, possible_action_targets)

View file

@ -1,2 +1,12 @@
extends ActionBehaviour extends ActionBehaviour
class_name ActionBehaviourPillbug class_name ActionBehaviourPillbug
func select_targets(source_pos: Vector4i, map: HexGrid): # -> Array[InsectTile]:
var neighbours = map.get_neighbours(source_pos)
var possible_action_targets: Array[InsectTile] = []
for neighbour in neighbours:
var tile = map.get_tile(neighbour)
if tile != null:
possible_action_targets.push_back(tile)
GameEvents.insect_tiles_selected_for_action.emit(source_pos, possible_action_targets)

View file

@ -12,9 +12,9 @@ const default_insects = {
preload("res://Tile/Prefabs/Beetle.tres"): 2, preload("res://Tile/Prefabs/Beetle.tres"): 2,
preload("res://Tile/Prefabs/Grasshopper.tres"): 3, 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/Ladybug.tres"): 1,
preload("res://Tile/Prefabs/Mosquito.tres"): 1, #preload("res://Tile/Prefabs/Mosquito.tres"): 1,
preload("res://Tile/Prefabs/Pillbug.tres"): 1 #preload("res://Tile/Prefabs/Pillbug.tres"): 1
} }
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.

View file

@ -2,3 +2,4 @@ extends Node
var is_player_black: bool = false var is_player_black: bool = false
var debug: bool = true var debug: bool = true
var allow_selecting_in_stack: bool = false

View file

@ -8,5 +8,11 @@ signal insect_tile_selected(tile)
signal insect_tile_deselected(tile) signal insect_tile_deselected(tile)
signal insect_tile_moved(tile, to) signal insect_tile_moved(tile, to)
signal insect_tiles_selected_for_action(source_tile, target_tiles, action)
signal insect_action_cancelled()
signal insect_action_done() # ??? Maybe?
signal turn_started(turn_num) signal turn_started(turn_num)
signal turn_ended(turn_num) signal turn_ended(turn_num)
signal game_over(is_winner_black)

View file

@ -113,6 +113,19 @@ func is_cell_not_empty(coords: Vector4i) -> bool:
func get_empty_neighbours(coords: Vector4i) -> Array[Vector4i]: func get_empty_neighbours(coords: Vector4i) -> Array[Vector4i]:
return get_neighbours(coords).filter(is_cell_empty) return get_neighbours(coords).filter(is_cell_empty)
func get_highest_in_stack(coords: Vector4i) -> Vector4i:
if not used_cells.has(coords):
print("ground")
return coords
var top: InsectTile = used_cells[coords]
while top.hat != null:
top = top.hat
print("found top")
print(top.coordinates)
return top.coordinates
func get_neighbours(coords: Vector4i, ground_layer: bool = false) -> Array[Vector4i]: func get_neighbours(coords: Vector4i, ground_layer: bool = false) -> Array[Vector4i]:
var layer: int = coords.w var layer: int = coords.w
if ground_layer: if ground_layer:
@ -147,7 +160,13 @@ func get_placeable_positions(button: InsectButton) -> Array[Vector4i]:
var possible_placements: Dictionary = {} var possible_placements: Dictionary = {}
var positions: Array[Vector4i] = [] var positions: Array[Vector4i] = []
for hex in used_cells.keys(): for hex in used_cells.keys().filter(func(coords): return coords.w == 0):
# We filter here because we only want neighbours of ground level tiles
# Otherwise we spawn an oultine on ground level but with an internal
# Coordinate of somewhere higher up
# Visually everything will be correct but internally the resulting hex
# Will count as higher layer tile leading to nasty bugs
for neighbour in get_empty_neighbours(hex): for neighbour in get_empty_neighbours(hex):
if not used_cells.has(neighbour): if not used_cells.has(neighbour):
possible_placements[neighbour] = true possible_placements[neighbour] = true
@ -317,6 +336,7 @@ func _on_insect_placed(resource: TileResource, is_black: bool, pos: Vector4i) ->
tile_copy.resource = resource tile_copy.resource = resource
tile_copy.is_black = is_black tile_copy.is_black = is_black
tile_copy.coordinates = pos tile_copy.coordinates = pos
print(pos)
tile_copy.map_reference = self tile_copy.map_reference = self
var target_pos = Vector3(hex_pos.x, 0.0, hex_pos.y) var target_pos = Vector3(hex_pos.x, 0.0, hex_pos.y)
@ -339,6 +359,9 @@ func _on_insect_tile_selected(tile: InsectTile) -> void:
print("no movement behaviour") print("no movement behaviour")
return return
#if tile.resource.action_behaviour != null:
#tile.resource.action_behaviour.select_targets(tile.coordinates, self)
var spaces = tile.resource.movement_behaviour.get_available_spaces(tile.coordinates, self) var spaces = tile.resource.movement_behaviour.get_available_spaces(tile.coordinates, self)
if spaces.is_empty(): if spaces.is_empty():
@ -353,9 +376,14 @@ func _on_insect_tile_selected(tile: InsectTile) -> void:
if non_empty_neighbours.size() == 1: if non_empty_neighbours.size() == 1:
# NOTE: This is correct! But seemed wrong when testing the beetle movement # 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 # 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 # tile. (would not necessarily split the hive, but the simple logic I use thinks so).
# 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 # 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 # before you can move your beetle
# NOTE: This MIGHT result in a bug when you stack beetles... but no I don't think so
# You'd need to have a bee to be able to move, so yeah
var occupied_neighbour = non_empty_neighbours.front() var occupied_neighbour = non_empty_neighbours.front()
if occupied_neighbour == tile.coordinates: if occupied_neighbour == tile.coordinates:
continue continue
@ -365,9 +393,10 @@ func _on_insect_tile_selected(tile: InsectTile) -> void:
if is_cell_not_empty(space): if is_cell_not_empty(space):
temp_tile = used_cells.get(space) temp_tile = used_cells.get(space)
layer = 1 layer = 1
while tile.hat != null: while temp_tile.hat != null:
layer += 1 layer += 1
tile = tile.hat temp_tile = temp_tile.hat
print(layer)
space.w = layer space.w = layer
@ -387,15 +416,20 @@ func get_tile(pos: Vector4i) -> InsectTile:
return used_cells.get(pos) return used_cells.get(pos)
func _on_insect_tile_moved(tile: InsectTile, target: Vector4i) -> void: func _on_insect_tile_moved(tile: InsectTile, target: Vector4i) -> void:
# Remove from old stack
if tile.coordinates.w > 0:
var below: Vector4i = tile.coordinates + Vector4i(0, 0, 0, -1)
used_cells[below].hat = null
used_cells.erase(tile.coordinates) used_cells.erase(tile.coordinates)
var new_hex_pos = cube_to_world_pos(target) 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 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, target.w * layer_height, 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 current_hex_pos = tile.position
var sky_current_hex_pos = tile.position + Vector3(0.0, 20.0, 0.0) var sky_current_hex_pos = tile.position + Vector3(0.0, 20.0, 0.0)
#
var tween = get_tree().create_tween() var tween = get_tree().create_tween()
tween.tween_property(tile, "position", sky_current_hex_pos, 0.5).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_EXPO) tween.tween_property(tile, "position", sky_current_hex_pos, 0.5).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_EXPO)
tween.tween_property(tile, "position", sky_new_hex_pos, 0.0) tween.tween_property(tile, "position", sky_new_hex_pos, 0.0)
@ -405,6 +439,12 @@ func _on_insect_tile_moved(tile: InsectTile, target: Vector4i) -> void:
used_cells[tile.coordinates] = tile used_cells[tile.coordinates] = tile
if tile.coordinates.w > 0:
var below: Vector4i = tile.coordinates + Vector4i(0, 0, 0, -1)
used_cells[below].hat = tile
# Add to new stack
func get_same_neighbours(cell1: Vector4i, cell2: Vector4i) -> Array[Vector4i]: func get_same_neighbours(cell1: Vector4i, cell2: Vector4i) -> Array[Vector4i]:
var neighbours1 = get_neighbours(cell1).filter(is_cell_not_empty) var neighbours1 = get_neighbours(cell1).filter(is_cell_not_empty)
var neighbours2 = get_neighbours(cell2).filter(is_cell_not_empty) var neighbours2 = get_neighbours(cell2).filter(is_cell_not_empty)
@ -423,6 +463,9 @@ func is_position_on_hive(pos: Vector4i) -> bool:
return get_empty_neighbours(pos).size() < 6 return get_empty_neighbours(pos).size() < 6
func can_hive_exist_without_tile(tile: InsectTile) -> bool: func can_hive_exist_without_tile(tile: InsectTile) -> bool:
if tile.coordinates.w != 0:
return true
# TODO: BFS-Search from random cell to see if all other cells could still be reached when this # TODO: BFS-Search from random cell to see if all other cells could still be reached when this
# tile would be empty space # tile would be empty space
if get_empty_neighbours(tile.coordinates).size() == 5: # we only have one real neighbour, so can't break anything if get_empty_neighbours(tile.coordinates).size() == 5: # we only have one real neighbour, so can't break anything
@ -430,7 +473,7 @@ func can_hive_exist_without_tile(tile: InsectTile) -> bool:
# DO BFS # DO BFS
var tiles_reached: Array = [] var tiles_reached: Array = []
var tiles_available: Array = used_cells.keys().filter(func(coords): return coords != tile.coordinates).filter(func(coords): coords.w != tile.coordinates.w) var tiles_available: Array = used_cells.keys().filter(func(coords): return coords != tile.coordinates).filter(func(coords): return coords.w == 0)
if tiles_available.size() <= 1: if tiles_available.size() <= 1:
# If we only have 1 or 2 total tiles, we can always move # If we only have 1 or 2 total tiles, we can always move

View file

@ -0,0 +1,11 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://cjoq705fsnga5"]
[ext_resource type="Shader" path="res://InsectTiles/HoverShader.gdshader" id="1_rk2jr"]
[resource]
render_priority = 0
shader = ExtResource("1_rk2jr")
shader_parameter/albedo = Color(0, 0.392157, 0, 1)
shader_parameter/emission_color = Color(0, 0.552941, 0, 0.886275)
shader_parameter/emission_amount = 5.0
shader_parameter/rim_steepness = 0.214

View file

@ -72,7 +72,7 @@ func _set_zoom_level(value: float) -> void:
self, self,
"camera_distance", "camera_distance",
_camera_distance, _camera_distance,
0.3 0.15
) )
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:

View file

@ -17,8 +17,8 @@ func simulate_move_recursive(start: Vector4i, max_num: int, map: HexGrid, visite
continue continue
# can reach... can_reach should only apply to our current level # can reach... can_reach should only apply to our current level
if not map.can_reach(start, neighbour): #if not map.can_reach(start, neighbour):
continue # continue
visited.append(neighbour) visited.append(neighbour)
possible.append_array(simulate_move_recursive(neighbour, max_num - 1, map, visited)) possible.append_array(simulate_move_recursive(neighbour, max_num - 1, map, visited))
@ -30,4 +30,10 @@ func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]:
possible_places = simulate_move_recursive(pos, max_movement_reach, map) possible_places = simulate_move_recursive(pos, max_movement_reach, map)
var possible_with_hats: Array[Vector4i] = []
for p in possible_places:
possible_with_hats.push_back(map.get_highest_in_stack(p))
return possible_places return possible_places

View file

@ -27,6 +27,7 @@ var selected: bool = false
var hover_shader: ShaderMaterial = preload("res://InsectTiles/HoverShader.tres") var hover_shader: ShaderMaterial = preload("res://InsectTiles/HoverShader.tres")
const SELECTION_FAILED_MAT: ShaderMaterial = preload("res://InsectTiles/SelectionFailedMat.tres") const SELECTION_FAILED_MAT: ShaderMaterial = preload("res://InsectTiles/SelectionFailedMat.tres")
const ACTION_SHADER = preload("res://InsectTiles/ActionShader.tres")
var mat: StandardMaterial3D var mat: StandardMaterial3D
@ -34,6 +35,8 @@ var tween: Tween
var tweening: bool = false var tweening: bool = false
var selected_for_action: bool = false
func _ready() -> void: func _ready() -> void:
if is_black: if is_black:
hexagon_small.set_surface_override_material(0, resource.material_black.duplicate()) hexagon_small.set_surface_override_material(0, resource.material_black.duplicate())
@ -50,6 +53,16 @@ func _ready() -> void:
GameEvents.insect_tile_selected.connect(_on_insect_tile_selected) GameEvents.insect_tile_selected.connect(_on_insect_tile_selected)
GameEvents.insect_tile_deselected.connect(_on_insect_tile_deselected) GameEvents.insect_tile_deselected.connect(_on_insect_tile_deselected)
GameEvents.insect_tile_moved.connect(_on_insect_tile_moved) GameEvents.insect_tile_moved.connect(_on_insect_tile_moved)
GameEvents.insect_tiles_selected_for_action.connect(_on_tiles_selected_for_action)
func _on_tiles_selected_for_action(source_pos: Vector4i, targets: Array[InsectTile]) -> void:
if self in targets:
selected_for_action = true
print("meme")
mat.next_pass = ACTION_SHADER
return
deactivated = true
func _on_insect_tile_moved(tile: InsectTile, to: Vector4i) -> void: func _on_insect_tile_moved(tile: InsectTile, to: Vector4i) -> void:
@ -66,7 +79,6 @@ func _on_insect_tile_deselected(tile: InsectTile) -> void:
selected = false selected = false
func _on_insect_tile_selected(tile: InsectTile) -> void: func _on_insect_tile_selected(tile: InsectTile) -> void:
move_in_progress = true
if tile == self: if tile == self:
selected = true selected = true
@ -87,23 +99,19 @@ func _process(delta):
if not hovered: if not hovered:
return return
## Check with map if we can be placed # Move up the insect stack.... or just do not react while we have something on top of us?
#if not map_reference.can_move(self):
#return
#
#
#if resource.movement_behaviour == null:
## TODO: Play fail animation/tween
#return
#
#var spaces = resource.movement_behaviour.get_available_spaces(coordinates, map_reference)
#
#if spaces.is_empty():
##GameEvents.insect_tile_selection_request_failed.emit(tile)
#return
print(resource) if GameData.allow_selecting_in_stack:
var top: InsectTile = self
while top.hat != null:
top = top.hat
if top.is_black == GameData.is_player_black or GameData.debug:
GameEvents.insect_tile_selected.emit(top)
else:
if hat != null:
return
else:
GameEvents.insect_tile_selected.emit(self) GameEvents.insect_tile_selected.emit(self)
func hover() -> void: func hover() -> void:
@ -138,11 +146,11 @@ func unhover() -> void:
func _on_mouse_entered(): func _on_mouse_entered():
hovered = true hovered = true
if not deactivated: if not deactivated and not selected_for_action:
hover() hover()
func _on_mouse_exited(): func _on_mouse_exited():
hovered = false hovered = false
if not selected: if not selected and not selected_for_action:
unhover() unhover()

View file

@ -5,6 +5,8 @@ class_name TileResource
@export var movement_behaviour: MovementBehaviour @export var movement_behaviour: MovementBehaviour
@export var action_behaviour: ActionBehaviour @export var action_behaviour: ActionBehaviour
@export var turn_end_behaviour: TurnEndBehaviour
@export var material_black: StandardMaterial3D @export var material_black: StandardMaterial3D
@export var material_white: StandardMaterial3D @export var material_white: StandardMaterial3D

View file

@ -0,0 +1,8 @@
extends TurnEndBehaviour
class_name TurnEndBehaviourBee
func trigger(tile: InsectTile, map: HexGrid, was_turn_black: bool = false) -> void:
if map.get_empty_neighbours(tile.coordinates).size() == 0:
# Game Over for this player
GameEvents.game_over.emit(!tile.is_black)
pass

View file

@ -0,0 +1,5 @@
extends Resource
class_name TurnEndBehaviour
func trigger(tile: InsectTile, map: HexGrid, was_turn_black: bool = false) -> void:
pass