Full controle tactile et souris
This commit is contained in:
@@ -35,8 +35,8 @@ shader_parameter/line_thickness = 0.0
|
|||||||
size = Vector2(40, 10)
|
size = Vector2(40, 10)
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_i362a"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_i362a"]
|
||||||
radius = 52.0
|
radius = 25.0
|
||||||
height = 108.0
|
height = 74.0
|
||||||
|
|
||||||
[node name="Bob" type="CharacterBody2D"]
|
[node name="Bob" type="CharacterBody2D"]
|
||||||
z_index = 100
|
z_index = 100
|
||||||
@@ -95,7 +95,7 @@ visible = false
|
|||||||
z_index = 1000
|
z_index = 1000
|
||||||
position = Vector2(44, -38)
|
position = Vector2(44, -38)
|
||||||
|
|
||||||
[node name="Node2D" parent="." instance=ExtResource("11_ubech")]
|
[node name="pathFinder" parent="." instance=ExtResource("11_ubech")]
|
||||||
|
|
||||||
[connection signal="start_intracting" from="." to="npcControler" method="_on_character_body_2d_start_intracting"]
|
[connection signal="start_intracting" from="." to="npcControler" method="_on_character_body_2d_start_intracting"]
|
||||||
[connection signal="area_entered" from="detector" to="." method="_on_area_2d_area_entered"]
|
[connection signal="area_entered" from="detector" to="." method="_on_area_2d_area_entered"]
|
||||||
|
|||||||
@@ -71,17 +71,16 @@ func start_interaction(askingForInteraction: Human):
|
|||||||
|
|
||||||
func stop_interaction():
|
func stop_interaction():
|
||||||
humanInteractionTarget = null
|
humanInteractionTarget = null
|
||||||
enable_interaction_clue()
|
|
||||||
|
|
||||||
func get_feet_global_position():
|
func get_feet_global_position():
|
||||||
return global_position + Vector2(0, 43)
|
return global_position + Vector2(0, 43)
|
||||||
|
|
||||||
func enable_interaction_clue():
|
func enable_interaction_clue(from: Human):
|
||||||
if interactionZone:
|
if interactionZone:
|
||||||
var mat = $Sprite2D.get("material") as ShaderMaterial
|
var mat = $Sprite2D.get("material") as ShaderMaterial
|
||||||
if mat:
|
if mat:
|
||||||
mat.set_shader_parameter("line_thickness", 1)
|
mat.set_shader_parameter("line_thickness", 1)
|
||||||
interactionZone.enable_interaction_clue()
|
interactionZone.enable_interaction_clue(from)
|
||||||
|
|
||||||
func disable_interaction_clue():
|
func disable_interaction_clue():
|
||||||
if interactionZone:
|
if interactionZone:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
|
class_name HumanPathFinder
|
||||||
|
|
||||||
var astar_grid: AStarGrid2D
|
var astar_grid: AStarGrid2D
|
||||||
var toFollow: Array[Vector2i]
|
var toFollow: Array[Vector2i]
|
||||||
@@ -14,9 +15,9 @@ func _ready() -> void:
|
|||||||
astar_grid = AStarGrid2D.new()
|
astar_grid = AStarGrid2D.new()
|
||||||
astar_grid.region = world.get_used_rect()
|
astar_grid.region = world.get_used_rect()
|
||||||
astar_grid.cell_size = Vector2(48, 48)
|
astar_grid.cell_size = Vector2(48, 48)
|
||||||
astar_grid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
|
astar_grid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_AT_LEAST_ONE_WALKABLE
|
||||||
astar_grid.default_compute_heuristic = AStarGrid2D.HEURISTIC_EUCLIDEAN
|
astar_grid.default_compute_heuristic = AStarGrid2D.HEURISTIC_CHEBYSHEV
|
||||||
astar_grid.default_estimate_heuristic = AStarGrid2D.HEURISTIC_EUCLIDEAN
|
astar_grid.default_estimate_heuristic = AStarGrid2D.HEURISTIC_CHEBYSHEV
|
||||||
astar_grid.update()
|
astar_grid.update()
|
||||||
|
|
||||||
# only take into account the tiles that are marked with a navigation layer for cars
|
# only take into account the tiles that are marked with a navigation layer for cars
|
||||||
@@ -33,9 +34,14 @@ func _ready() -> void:
|
|||||||
astar_grid.set_point_solid(tile_position)
|
astar_grid.set_point_solid(tile_position)
|
||||||
else:
|
else:
|
||||||
astar_grid.set_point_solid(tile_position)
|
astar_grid.set_point_solid(tile_position)
|
||||||
|
|
||||||
for obstacles in world.obstacles:
|
for obstacles in world.obstacles:
|
||||||
if obstacles.get_cell_tile_data(tile_position) != null and obstacles.get_cell_tile_data(tile_position).get_collision_polygons_count(0):
|
if (obstacles.get_cell_tile_data(tile_position) != null and
|
||||||
|
obstacles.get_cell_tile_data(tile_position).get_collision_polygons_count(0)):
|
||||||
astar_grid.set_point_solid(tile_position)
|
astar_grid.set_point_solid(tile_position)
|
||||||
|
|
||||||
|
#TODO find if the world cell is matching a semaphore pylon
|
||||||
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
if !controled:
|
if !controled:
|
||||||
@@ -50,7 +56,7 @@ func _process(delta: float) -> void:
|
|||||||
var points = astar_grid.get_id_path(
|
var points = astar_grid.get_id_path(
|
||||||
world.local_to_map(world.to_local(my_global_position)),
|
world.local_to_map(world.to_local(my_global_position)),
|
||||||
world.local_to_map(world.to_local(target_global_position))
|
world.local_to_map(world.to_local(target_global_position))
|
||||||
).slice(1, -1)
|
).slice(1)
|
||||||
if !points.is_empty():
|
if !points.is_empty():
|
||||||
toFollow = points
|
toFollow = points
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ extends Node
|
|||||||
|
|
||||||
@onready var controled:Human = get_parent()
|
@onready var controled:Human = get_parent()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_character_body_2d_start_intracting(interactingWith: Human) -> void:
|
func _on_character_body_2d_start_intracting(interactingWith: Human) -> void:
|
||||||
controled.face(interactingWith.global_position)
|
controled.face(interactingWith.global_position)
|
||||||
# ouvre un dialogue
|
# ouvre un dialogue
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ extends Node2D
|
|||||||
@export var ray : ShapeCast2D
|
@export var ray : ShapeCast2D
|
||||||
var can_interact_with : Node2D
|
var can_interact_with : Node2D
|
||||||
@onready var world: World = get_parent().get_parent();
|
@onready var world: World = get_parent().get_parent();
|
||||||
|
@onready var pathFinder : HumanPathFinder = $"../PathFinder"
|
||||||
|
|
||||||
var possible_interactables : Array[Node2D]
|
var possible_interactables : Array[Node2D]
|
||||||
|
|
||||||
@@ -19,11 +20,12 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||||||
human.wants_to_interact_with = can_interact_with
|
human.wants_to_interact_with = can_interact_with
|
||||||
else:
|
else:
|
||||||
human.wants_to_grab = true
|
human.wants_to_grab = true
|
||||||
|
|
||||||
|
# moving using either touch or mouse button
|
||||||
if event is InputEventMouseButton or event is InputEventScreenTouch:
|
if event is InputEventMouseButton or event is InputEventScreenTouch:
|
||||||
var tile_pos = world.local_to_map(world.to_local(get_global_mouse_position()))
|
var tile_pos = world.local_to_map(world.to_local(get_global_mouse_position()))
|
||||||
if event.pressed:
|
if event.pressed:
|
||||||
print(event.position, tile_pos)
|
pathFinder.destination = get_global_mouse_position()
|
||||||
$"../PathFinder".destination = get_global_mouse_position()
|
|
||||||
|
|
||||||
func _process(delta) -> void:
|
func _process(delta) -> void:
|
||||||
ray.target_position = human.last_facing_direction * 48
|
ray.target_position = human.last_facing_direction * 48
|
||||||
@@ -77,4 +79,4 @@ func _process(delta) -> void:
|
|||||||
if can_interact_with != closest:
|
if can_interact_with != closest:
|
||||||
can_interact_with = closest
|
can_interact_with = closest
|
||||||
if can_interact_with:
|
if can_interact_with:
|
||||||
can_interact_with.enable_interaction_clue()
|
can_interact_with.enable_interaction_clue(human)
|
||||||
|
|||||||
@@ -2,11 +2,22 @@ extends Area2D
|
|||||||
class_name InteractionZone
|
class_name InteractionZone
|
||||||
|
|
||||||
@export var clue: BubbleClue
|
@export var clue: BubbleClue
|
||||||
|
var clueEnabled = false
|
||||||
|
var player: Human
|
||||||
|
|
||||||
func enable_interaction_clue():
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
|
if event is InputEventMouseButton or event is InputEventScreenTouch:
|
||||||
|
if event.pressed:
|
||||||
|
if clueEnabled:
|
||||||
|
player.wants_to_interact_with = get_parent()
|
||||||
|
|
||||||
|
func enable_interaction_clue(h: Human):
|
||||||
|
player = h
|
||||||
|
clueEnabled = true
|
||||||
if clue:
|
if clue:
|
||||||
clue.setVisible(true)
|
clue.setVisible(clueEnabled)
|
||||||
|
|
||||||
func disable_interaction_clue():
|
func disable_interaction_clue():
|
||||||
|
clueEnabled = false
|
||||||
if clue:
|
if clue:
|
||||||
clue.setVisible(false)
|
clue.setVisible(clueEnabled)
|
||||||
|
|||||||
106
maps/world.tscn
106
maps/world.tscn
File diff suppressed because one or more lines are too long
@@ -1,12 +1,9 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
var hasManipulatedZIndex = false
|
var hasManipulatedZIndex = false
|
||||||
|
|||||||
Reference in New Issue
Block a user