fixed the path rebuilding lag
This commit is contained in:
@@ -138,7 +138,7 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
|
||||
func consider_leap(direction: Vector3) -> void:
|
||||
var node: FlowNode = check_jump(character.global_position + (direction * jump_distance))
|
||||
var node: FlowNodeData = check_jump(character.global_position + (direction * jump_distance))
|
||||
if node:
|
||||
var expected_distance_remaining: float = calculate_distance_to_goal(node)
|
||||
expected_distance_remaining += (character.global_position + (direction * jump_distance)).distance_to(node.global_position)
|
||||
@@ -153,8 +153,8 @@ func finish_jump() -> void:
|
||||
jumping = false
|
||||
|
||||
|
||||
func check_jump(destination: Vector3) -> FlowNode:
|
||||
var closest_point: FlowNode = flow_field.get_closest_traversable_point(destination)
|
||||
func check_jump(destination: Vector3) -> FlowNodeData:
|
||||
var closest_point: FlowNodeData = flow_field.get_closest_point(destination, true, false)
|
||||
if !closest_point.best_path or closest_point.global_position.distance_to(destination) > 1.2:
|
||||
return null
|
||||
return closest_point.best_path
|
||||
|
||||
@@ -4,7 +4,7 @@ extends EnemyMovement
|
||||
#var path: Curve3D
|
||||
#var path_progress: float = 0.0
|
||||
var flow_field: FlowField
|
||||
var next_node: FlowNode :
|
||||
var next_node: FlowNodeData :
|
||||
get():
|
||||
return next_node
|
||||
set(value):
|
||||
@@ -16,16 +16,16 @@ var next_node: FlowNode :
|
||||
#TODO: make deterministic random
|
||||
var x: float = randf_range(-1, 1)
|
||||
var y: float = randf_range(-1, 1)
|
||||
if Vector3(next_node.global_position.x + x, next_node.global_position.y, next_node.global_position.z + y).distance_to(next_node.global_position) <= 1.0:
|
||||
if Vector3(next_node.position.x + x, next_node.position.y, next_node.position.z + y).distance_to(next_node.position) <= 1.0:
|
||||
found_point = true
|
||||
next_pos = Vector3(next_node.global_position.x + x, next_node.global_position.y, next_node.global_position.z + y)
|
||||
next_pos = Vector3(next_node.position.x + x, next_node.position.y, next_node.position.z + y)
|
||||
var next_pos: Vector3
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
if flow_field:
|
||||
next_node = flow_field.get_closest_traversable_point(character.global_position)
|
||||
next_node = flow_field.get_closest_point(character.global_position, true, false)
|
||||
#We skip one node so the "start" nodes placed near
|
||||
#spawners are just usefull for "catching" enemies that are looking
|
||||
#for a way into the pathfinding graph
|
||||
@@ -33,14 +33,14 @@ func _ready() -> void:
|
||||
distance_remaining += calculate_distance_to_goal(next_node)
|
||||
|
||||
|
||||
func calculate_distance_to_goal(node: FlowNode) -> float:
|
||||
func calculate_distance_to_goal(node: FlowNodeData) -> float:
|
||||
var distance: float = 0.0
|
||||
distance += character.global_position.distance_to(node.global_position)
|
||||
distance += character.global_position.distance_to(node.position)
|
||||
if node.best_path:
|
||||
var then_next_node: FlowNode = node.best_path
|
||||
distance += node.global_position.distance_to(then_next_node.global_position)
|
||||
var then_next_node: FlowNodeData = node.best_path
|
||||
distance += node.position.distance_to(then_next_node.position)
|
||||
while then_next_node.best_path:
|
||||
distance += then_next_node.global_position.distance_to(then_next_node.best_path.global_position)
|
||||
distance += then_next_node.position.distance_to(then_next_node.best_path.position)
|
||||
then_next_node = then_next_node.best_path
|
||||
return distance
|
||||
|
||||
|
||||
@@ -21,9 +21,8 @@ var enemies_spawned: Dictionary = {}
|
||||
var enemies_to_spawn: int = 0
|
||||
var done_spawning: bool = true
|
||||
var enemy_id: int = 0
|
||||
var path: Path3D
|
||||
var path_polygon: PackedScene = preload("res://path_polygon.tscn")
|
||||
var game_manager: GameManager
|
||||
var path_vfx: PathVFX
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
@@ -84,27 +83,27 @@ func networked_spawn_land_enemy(enemy_num: int, id1: int, id2: int) -> void:
|
||||
func create_path() -> void:
|
||||
if type != Data.EnemyType.LAND:
|
||||
return
|
||||
path = Path3D.new()
|
||||
path.curve = Curve3D.new()
|
||||
add_child(path)
|
||||
var polygon: CSGPolygon3D = path_polygon.instantiate()
|
||||
path.add_child(polygon)
|
||||
polygon.mode = CSGPolygon3D.MODE_PATH
|
||||
polygon.path_node = path.get_path()
|
||||
path.global_position = Vector3.ZERO
|
||||
if path_vfx:
|
||||
path_vfx.queue_free()
|
||||
path_vfx = PathVFX.new()
|
||||
path_vfx.line_width = 0.2
|
||||
path_vfx.material = load("res://path_material.tres")
|
||||
add_child(path_vfx)
|
||||
path_vfx.global_position = Vector3.ZERO
|
||||
update_path()
|
||||
|
||||
|
||||
|
||||
func update_path() -> void:
|
||||
if type != Data.EnemyType.LAND or !flow_field.nodes:
|
||||
if type != Data.EnemyType.LAND or !flow_field.data.nodes:
|
||||
return
|
||||
path.curve = Curve3D.new()
|
||||
var node: FlowNode = flow_field.get_closest_traversable_point(global_position)
|
||||
path.curve.add_point(node.global_position + Vector3(0, 0.5, 0))
|
||||
var points: Array[Vector3] = []
|
||||
var node: FlowNodeData = flow_field.get_closest_point(flow_field.start_nodes[0].position, true, false)
|
||||
points.append(node.position + Vector3(0, 0.15, 0))
|
||||
while node.best_path:
|
||||
node = node.best_path
|
||||
path.curve.add_point(node.global_position + Vector3(0, 0.5, 0))
|
||||
points.append(node.position + Vector3(0, 0.15, 0))
|
||||
path_vfx.path(points)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ func spawn_level(scene: PackedScene) -> void:
|
||||
var flow_field: FlowField = FlowField.new()
|
||||
level.flow_field = flow_field
|
||||
level.add_child(flow_field)
|
||||
flow_field.load_from_data(FlowFieldTool.load_flow_field_from_disc(level_config.zone.flow_field_data_path))
|
||||
flow_field.data = FlowFieldTool.load_flow_field_from_disc(level_config.zone.flow_field_data_path)
|
||||
level.load_flow_field()
|
||||
level.game_manager = self
|
||||
for x: EnemySpawner in level.enemy_spawns:
|
||||
@@ -121,7 +121,7 @@ func spawn_level(scene: PackedScene) -> void:
|
||||
root_scene.add_child(level)
|
||||
for spawner: EnemySpawner in level.enemy_spawns:
|
||||
spawner.create_path()
|
||||
level.generate_obstacle(level_config.points_blocked)
|
||||
level.generate_obstacles(level_config.points_blocked)
|
||||
|
||||
|
||||
func spawn_players() -> void:
|
||||
@@ -214,7 +214,9 @@ func temp_set_upcoming_wave(new_wave: WaveConfig, coins: int) -> void:
|
||||
pot = coins
|
||||
var dict: Dictionary[String, int] = {}
|
||||
for enemy_group: EnemyGroup in new_wave.enemy_groups.keys():
|
||||
dict[enemy_group.enemy.title] = enemy_group.count
|
||||
if !dict.has(enemy_group.enemy.title):
|
||||
dict[enemy_group.enemy.title] = 0
|
||||
dict[enemy_group.enemy.title] += enemy_group.count
|
||||
connected_players_nodes[multiplayer.get_unique_id()].hud.set_upcoming_wave(dict)
|
||||
|
||||
|
||||
@@ -351,7 +353,6 @@ func start() -> void:
|
||||
set_upcoming_wave()
|
||||
level.flow_field.calculate()
|
||||
level.enemy_spawns[0].update_path()
|
||||
level.generate_obstacles()
|
||||
|
||||
#Start game
|
||||
game_active = true
|
||||
|
||||
@@ -11,22 +11,22 @@ extends Node3D
|
||||
@export var printer: CardPrinter
|
||||
@export var shop: ShopStand
|
||||
@export var obstacles: Array[PackedScene]
|
||||
var walls: Dictionary[FlowNode, TowerBase] = {}
|
||||
|
||||
var walls: Dictionary[FlowNodeData, TowerBase] = {}
|
||||
var wall_id: int = 0
|
||||
var tower_base_scene: PackedScene = load("res://Scenes/TowerBase/tower_base.tscn")
|
||||
var tower_frame_scene: PackedScene = load("res://Scenes/tower_frame.tscn")
|
||||
var tower_frames: Dictionary[FlowNode, Node3D] = {}
|
||||
var tower_frames: Dictionary[FlowNodeData, Node3D] = {}
|
||||
var game_manager: GameManager
|
||||
var flow_field: FlowField
|
||||
|
||||
|
||||
func load_flow_field() -> void:
|
||||
var x: int = 0
|
||||
for spawn: EnemySpawner in enemy_spawns:
|
||||
flow_field.path_updated.connect(spawn.update_path)
|
||||
for node: FlowNode in flow_field.nodes:
|
||||
|
||||
for node: FlowNodeData in flow_field.data.nodes:
|
||||
if node.buildable:
|
||||
x += 1
|
||||
var frame: Node3D = tower_frame_scene.instantiate()
|
||||
tower_frames[node] = frame
|
||||
add_child(frame)
|
||||
@@ -34,23 +34,23 @@ func load_flow_field() -> void:
|
||||
|
||||
|
||||
func disable_all_tower_frames() -> void:
|
||||
for node: FlowNode in tower_frames:
|
||||
for node: FlowNodeData in tower_frames:
|
||||
tower_frames[node].visible = false
|
||||
|
||||
|
||||
func enable_non_path_tower_frames() -> void:
|
||||
for node: FlowNode in tower_frames:
|
||||
for node: FlowNodeData in tower_frames:
|
||||
tower_frames[node].visible = true
|
||||
disable_path_tower_frames()
|
||||
|
||||
|
||||
func disable_path_tower_frames() -> void:
|
||||
for node: FlowNode in tower_frames:
|
||||
for node: FlowNodeData in tower_frames:
|
||||
if node.traversable and !flow_field.traversable_after_blocking_point(node):
|
||||
tower_frames[node].visible = false
|
||||
|
||||
|
||||
func set_wall(point: FlowNode, caller_id: int) -> void:
|
||||
func set_wall(point: FlowNodeData, caller_id: int) -> void:
|
||||
point.traversable = false
|
||||
flow_field.calculate()
|
||||
flow_field.path_updated.emit()
|
||||
@@ -59,7 +59,7 @@ func set_wall(point: FlowNode, caller_id: int) -> void:
|
||||
wall_id += 1
|
||||
|
||||
|
||||
func remove_wall(point: FlowNode) -> void:
|
||||
func remove_wall(point: FlowNodeData) -> void:
|
||||
var wall: TowerBase = walls[point]
|
||||
#game_manager.connected_players_nodes[wall.owner_id].currency += Data.wall_cost
|
||||
game_manager.connected_players_nodes[wall.owner_id].unready_self()
|
||||
@@ -71,10 +71,10 @@ func remove_wall(point: FlowNode) -> void:
|
||||
enable_non_path_tower_frames()
|
||||
|
||||
|
||||
func spawn_wall(point: FlowNode, name_id: int, caller_id: int) -> void:
|
||||
func spawn_wall(point: FlowNodeData, name_id: int, caller_id: int) -> void:
|
||||
var base: TowerBase = tower_base_scene.instantiate() as TowerBase
|
||||
base.game_manager = game_manager
|
||||
base.position = point.global_position
|
||||
base.position = point.position
|
||||
base.name = "Wall" + str(name_id)
|
||||
base.owner_id = caller_id
|
||||
base.point = point
|
||||
@@ -83,59 +83,15 @@ func spawn_wall(point: FlowNode, name_id: int, caller_id: int) -> void:
|
||||
disable_path_tower_frames()
|
||||
|
||||
|
||||
func generate_obstacle(ids: Array[int]) -> void:
|
||||
var points: Array[FlowNode] = []
|
||||
for node: FlowNode in flow_field.nodes:
|
||||
func generate_obstacles(ids: Array[int]) -> void:
|
||||
var points: Array[FlowNodeData] = []
|
||||
for node: FlowNodeData in flow_field.data.nodes:
|
||||
if ids.has(node.node_id):
|
||||
points.append(node)
|
||||
for node: FlowNode in points:
|
||||
for node: FlowNodeData in points:
|
||||
var obstacle: Node3D = obstacles[0].instantiate()
|
||||
obstacle.position = node.position
|
||||
flow_field.toggle_buildable(node)
|
||||
if node.traversable:
|
||||
flow_field.toggle_traversable(node)
|
||||
add_child(obstacle)
|
||||
|
||||
|
||||
func generate_obstacles() -> void:
|
||||
pass
|
||||
#print(str(multiplayer.get_unique_id()) + " spawning obstacles with seed: " + str(Game.rng.seed))
|
||||
#var obstacle_count: int = NoiseRandom.randi_in_range(1, 0, 5)
|
||||
#obstacle_count = 0
|
||||
# for index: int in obstacle_count:
|
||||
# #var x: int = Game.randi_in_range(10 * index, 1 - a_star_graph_3d.grid_size.x, a_star_graph_3d.grid_size.x - 1)
|
||||
#var y: int = Game.randi_in_range(32 * index, 1 - a_star_graph_3d.grid_size.y, a_star_graph_3d.grid_size.y - 1)
|
||||
# var chosen_obstacle: int = Game.randi_in_range(4 * index, 0, obstacle_scenes.size() - 1)
|
||||
# var obstacle: GridMap = obstacle_scenes[chosen_obstacle].instantiate() as GridMap
|
||||
# var orientations: Array[int] = [0, 90, 180, 270]
|
||||
# var chosen_orientation: int = Game.randi_in_range(15 * index, 0, orientations.size() - 1)
|
||||
# #obstacle.position = Vector3(x, 0, y)
|
||||
# obstacle.set_rotation_degrees(Vector3(0, chosen_orientation, 0))
|
||||
# add_child(obstacle)
|
||||
# for cell: Vector3i in obstacle.get_used_cells():
|
||||
# var cell_coord: Vector3 = obstacle.to_global(obstacle.map_to_local(cell))
|
||||
# remove_world_tile(round(cell_coord.x), round(cell_coord.z))
|
||||
# obstacle.queue_free()
|
||||
|
||||
|
||||
#func cell_coord_to_astar_point(x: int, y: int) -> int:
|
||||
# var center_point_x: int = floori(a_star_graph_3d.grid_size.x / 2.0) * a_star_graph_3d.grid_size.y
|
||||
# var center_point_y: int = floori(a_star_graph_3d.grid_size.y / 2.0)
|
||||
# return (center_point_x + (int(x / 2.0) * a_star_graph_3d.grid_size.y)) + (center_point_y + int(y / 2.0))
|
||||
|
||||
|
||||
#func remove_world_tile(x: int, y: int) -> void:
|
||||
# if get_cell_item(Vector3i(x, 0, y)) != 1 or abs(x) >= a_star_graph_3d.grid_size.x or abs(y) >= a_star_graph_3d.grid_size.y:
|
||||
# return
|
||||
# set_cell_item(Vector3i(x, 0, y), INVALID_CELL_ITEM)
|
||||
# var point: int = cell_coord_to_astar_point(x, y)
|
||||
# var north_point: int = cell_coord_to_astar_point(x - 1, y)
|
||||
# var south_point: int = cell_coord_to_astar_point(x + 1, y)
|
||||
# var east_point: int = cell_coord_to_astar_point(x, y + 1)
|
||||
# var west_point: int = cell_coord_to_astar_point(x, y - 1)
|
||||
# if x % 2 == 0 and y % 2 == 0: #If the tile is on a point on the pathfinding grid
|
||||
# a_star_graph_3d.astar.set_point_disabled(point)
|
||||
# if x % 2 == 1 and y % 2 == 0: #If the cell breaks a north-south link
|
||||
# a_star_graph_3d.astar.disconnect_points(north_point, south_point)
|
||||
# if x % 2 == 0 and y % 2 == 1: #If the cell breaks a east-west link
|
||||
# a_star_graph_3d.astar.disconnect_points(east_point, west_point)
|
||||
|
||||
@@ -52,7 +52,8 @@ static func generate_wave(spawn_power: int, spawn_pool: Array[Enemy], spawners:
|
||||
var first_enemy_id: int = -1
|
||||
while !enemy_chosen:
|
||||
#Next, determine what is the most groups we can afford
|
||||
most_enemies_afforded = int(spawn_power / enemy.spawn_power)
|
||||
@warning_ignore("integer_division")
|
||||
most_enemies_afforded = spawn_power / enemy.spawn_power
|
||||
if most_enemies_afforded > 0:
|
||||
enemy_chosen = true
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user