فهرست منبع

:tada: Allow chocolate to be picked up by driven vehicle

DricomDragon 1 ماه پیش
والد
کامیت
1af169a832

+ 11 - 1
godot/component/entity/collectibles/chocolate/chocolate.gd

@@ -17,7 +17,8 @@ func _on_chocolate_tablet_body_entered(body: Node3D) -> void:
 
 	if body is Walker:
 		_give_chocolate_to(body)
-		_collected = true
+	if body is SeatedVehicle:
+		_give_chocolate_to_driver_of(body)
 
 
 func _give_chocolate_to(walker: Walker) -> void:
@@ -25,6 +26,15 @@ func _give_chocolate_to(walker: Walker) -> void:
 	_go_to_pocket.call_deferred(walker)
 	chocolateAnimation.play(COLLECT_ANIM)
 	pickupSound.play()
+	_collected = true
+
+
+func _give_chocolate_to_driver_of(vehicle: SeatedVehicle) -> void:
+	var driver = vehicle.get_current_driver()
+	if driver == null:
+		return
+
+	_give_chocolate_to(driver)
 
 
 func _go_to_pocket(walker: Walker) -> void:

+ 14 - 1
godot/component/entity/vehicles/seated_vehicle.gd

@@ -5,12 +5,14 @@ const CRASH_EFFECT: Resource = preload("res://effect/crash/crash.tscn")
 const MINIMAL_CRASH_SPEED: float = 1.0 # m2/s2
 
 var _current_commander: LocalInput = null
+var _current_driver: Walker
 var _has_collided: bool = false
 
 @onready var _seat: Node3D = find_child("*Seat")
 @onready var _doors: Array = find_children("*Door", "Node3D") # Array[Node3D]
 
 
+
 func _init() -> void:
 	body_shape_entered.connect(_on_body_shape_entered)
 
@@ -19,6 +21,11 @@ func _ready() -> void:
 	assert(_doors.all(func(door): return door is Node3D))
 
 
+## Signal a new driver
+func become_driven_by(driver: Walker) -> void:
+	_current_driver = driver
+
+
 ## Make the vehicle responds to driver commands
 func drive_with(commander: LocalInput) -> void:
 	commander.dir_changed.connect(_on_dir_changed)
@@ -34,6 +41,7 @@ func get_out() -> void:
 	_current_commander.stop_action.disconnect(_on_stop_action)
 	_current_commander.analog_action.disconnect(_on_analog_action)
 	_current_commander = null
+	_current_driver = null
 
 
 func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
@@ -80,6 +88,11 @@ func get_closest_door(from: Vector3) -> Node3D:
 	return _doors.reduce(closest)
 
 
+## Return current walker who is driving the vehicle, null if none
+func get_current_driver() -> Walker:
+	return _current_driver
+
+
 ## Need to be overridden to react to direction changed
 func _on_dir_changed(_dir: Vector2) -> void:
 	pass
@@ -90,7 +103,7 @@ func _on_main_action(_pressed: bool) -> void:
 	pass
 
 
-## Need to be overridden to react to main action
+## Need to be overridden to react to stop action
 func _on_stop_action(_pressed: bool) -> void:
 	pass
 

+ 1 - 0
godot/component/entity/walker/walker.gd

@@ -139,6 +139,7 @@ func _get_in_vehicle(commander: LocalInput) -> void:
 	_vehicle = closest_vehicle
 	reparent(_vehicle)
 	add_collision_exception_with(_vehicle)
+	_vehicle.become_driven_by(self)
 	_vehicle.drive_with(commander)
 	_move_to_seat(_vehicle)
 	got_in.emit(_vehicle)