Full controle tactile et souris

This commit is contained in:
Thomas
2025-03-29 11:34:41 +01:00
parent be1ef5d71c
commit 2125236638
8 changed files with 81 additions and 84 deletions

View File

@@ -35,8 +35,8 @@ shader_parameter/line_thickness = 0.0
size = Vector2(40, 10)
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_i362a"]
radius = 52.0
height = 108.0
radius = 25.0
height = 74.0
[node name="Bob" type="CharacterBody2D"]
z_index = 100
@@ -95,7 +95,7 @@ visible = false
z_index = 1000
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="area_entered" from="detector" to="." method="_on_area_2d_area_entered"]

View File

@@ -71,17 +71,16 @@ func start_interaction(askingForInteraction: Human):
func stop_interaction():
humanInteractionTarget = null
enable_interaction_clue()
func get_feet_global_position():
return global_position + Vector2(0, 43)
func enable_interaction_clue():
func enable_interaction_clue(from: Human):
if interactionZone:
var mat = $Sprite2D.get("material") as ShaderMaterial
if mat:
mat.set_shader_parameter("line_thickness", 1)
interactionZone.enable_interaction_clue()
interactionZone.enable_interaction_clue(from)
func disable_interaction_clue():
if interactionZone:

View File

@@ -1,4 +1,5 @@
extends Node2D
class_name HumanPathFinder
var astar_grid: AStarGrid2D
var toFollow: Array[Vector2i]
@@ -14,9 +15,9 @@ func _ready() -> void:
astar_grid = AStarGrid2D.new()
astar_grid.region = world.get_used_rect()
astar_grid.cell_size = Vector2(48, 48)
astar_grid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
astar_grid.default_compute_heuristic = AStarGrid2D.HEURISTIC_EUCLIDEAN
astar_grid.default_estimate_heuristic = AStarGrid2D.HEURISTIC_EUCLIDEAN
astar_grid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_AT_LEAST_ONE_WALKABLE
astar_grid.default_compute_heuristic = AStarGrid2D.HEURISTIC_CHEBYSHEV
astar_grid.default_estimate_heuristic = AStarGrid2D.HEURISTIC_CHEBYSHEV
astar_grid.update()
# only take into account the tiles that are marked with a navigation layer for cars
@@ -33,10 +34,15 @@ func _ready() -> void:
astar_grid.set_point_solid(tile_position)
else:
astar_grid.set_point_solid(tile_position)
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)
#TODO find if the world cell is matching a semaphore pylon
func _process(delta: float) -> void:
if !controled:
return
@@ -50,7 +56,7 @@ func _process(delta: float) -> void:
var points = astar_grid.get_id_path(
world.local_to_map(world.to_local(my_global_position)),
world.local_to_map(world.to_local(target_global_position))
).slice(1, -1)
).slice(1)
if !points.is_empty():
toFollow = points

View File

@@ -3,10 +3,6 @@ extends Node
@onready var controled:Human = get_parent()
func _on_character_body_2d_start_intracting(interactingWith: Human) -> void:
controled.face(interactingWith.global_position)
# ouvre un dialogue

View File

@@ -4,6 +4,7 @@ extends Node2D
@export var ray : ShapeCast2D
var can_interact_with : Node2D
@onready var world: World = get_parent().get_parent();
@onready var pathFinder : HumanPathFinder = $"../PathFinder"
var possible_interactables : Array[Node2D]
@@ -19,11 +20,12 @@ func _unhandled_input(event: InputEvent) -> void:
human.wants_to_interact_with = can_interact_with
else:
human.wants_to_grab = true
# moving using either touch or mouse button
if event is InputEventMouseButton or event is InputEventScreenTouch:
var tile_pos = world.local_to_map(world.to_local(get_global_mouse_position()))
if event.pressed:
print(event.position, tile_pos)
$"../PathFinder".destination = get_global_mouse_position()
pathFinder.destination = get_global_mouse_position()
func _process(delta) -> void:
ray.target_position = human.last_facing_direction * 48
@@ -77,4 +79,4 @@ func _process(delta) -> void:
if can_interact_with != closest:
can_interact_with = closest
if can_interact_with:
can_interact_with.enable_interaction_clue()
can_interact_with.enable_interaction_clue(human)

View File

@@ -2,11 +2,22 @@ extends Area2D
class_name InteractionZone
@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:
clue.setVisible(true)
clue.setVisible(clueEnabled)
func disable_interaction_clue():
clueEnabled = false
if clue:
clue.setVisible(false)
clue.setVisible(clueEnabled)

File diff suppressed because one or more lines are too long

View File

@@ -1,12 +1,9 @@
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var hasManipulatedZIndex = false