فهرست منبع

:truck: Creat base vehicle class

DricomDragon 1 سال پیش
والد
کامیت
10b16140a2

+ 1 - 16
godot/component/entity/vehicles/jeep/jeep.gd

@@ -1,29 +1,14 @@
 class_name Jeep
-extends VehicleBody3D
+extends SeatedVehicle
 
 @export var max_engine_force: float = 500
 @export var max_steering: float = PI / 6.0 # degrees
 
-var _current_commander: LocalInput = null
-
 
 func steer(ratio: float) -> void:
 	set_steering(ratio * max_steering)
 
 
-## Make the vehicle responds to driver commands
-func drive_with(commander: LocalInput) -> void:
-	commander.dir_changed.connect(_on_dir_changed)
-	commander.main_action.connect(_on_main_action)
-	_current_commander = commander
-
-
-func get_out() -> void:
-	_current_commander.dir_changed.disconnect(_on_dir_changed)
-	_current_commander.main_action.disconnect(_on_main_action)
-	_current_commander = null
-
-
 func get_free_seat() -> Node3D:
 	return %RearSeat
 

+ 1 - 16
godot/component/entity/vehicles/plane/tiny_plane.gd

@@ -1,5 +1,5 @@
 class_name TinyPlane
-extends VehicleBody3D
+extends SeatedVehicle
 
 @export var thrust_power: float = 10000.0
 @export var turn_to_torque: float = 2000.0
@@ -12,8 +12,6 @@ var target_pitch: float = 0.0
 var target_rotation := Vector3.ZERO
 var target_thrust := Vector3.ZERO
 
-var _current_commander: LocalInput = null
-
 
 func trigger_thrust(activate: bool) -> void:
 	if activate:
@@ -27,19 +25,6 @@ func trigger_direction(dir: Vector2) -> void:
 	target_pitch = -dir.y * move_to_pitch
 
 
-## Make the vehicle responds to driver commands
-func drive_with(commander: LocalInput) -> void:
-	commander.dir_changed.connect(_on_dir_changed)
-	commander.main_action.connect(_on_main_action)
-	_current_commander = commander
-
-
-func get_out() -> void:
-	_current_commander.dir_changed.disconnect(_on_dir_changed)
-	_current_commander.main_action.disconnect(_on_main_action)
-	_current_commander = null
-
-
 func get_free_seat() -> Node3D:
 	return $DrivingSeat
 

+ 32 - 0
godot/component/entity/vehicles/seated_vehicle.gd

@@ -0,0 +1,32 @@
+class_name SeatedVehicle
+extends VehicleBody3D
+
+var _current_commander: LocalInput = null
+
+
+## Make the vehicle responds to driver commands
+func drive_with(commander: LocalInput) -> void:
+	commander.dir_changed.connect(_on_dir_changed)
+	commander.main_action.connect(_on_main_action)
+	_current_commander = commander
+
+
+func get_out() -> void:
+	_current_commander.dir_changed.disconnect(_on_dir_changed)
+	_current_commander.main_action.disconnect(_on_main_action)
+	_current_commander = null
+
+
+## Need to be overriden to return an available seat
+func get_free_seat() -> Node3D:
+	return null
+
+
+## Need to be overriden to react to direction changed
+func _on_dir_changed(dir: Vector2) -> void:
+	pass
+
+
+## Need to be overriden to react to main action
+func _on_main_action(pressed: bool) -> void:
+	pass