Lots of stuff I forgot to commit because Holidays

- D&D dice engine (see README)
- Markdown support
- Phantom camera
This commit is contained in:
Tony Bark 2023-12-24 20:39:57 -05:00
parent 9589acd877
commit 2b41f84b05
125 changed files with 13170 additions and 23 deletions

View file

@ -0,0 +1,26 @@
extends Area3D
@export var area_pcam: PhantomCamera3D
var initial_camera_position: Vector3
var initial_camera_rotation: Vector3
var tween: Tween
var tween_duration: float = 0.9
func _ready() -> void:
connect("area_entered", _entered_area)
connect("area_exited", _exited_area)
func _entered_area(area_3D: Area3D) -> void:
if area_3D.get_parent() is CharacterBody3D:
area_pcam.set_priority(20)
func _exited_area(area_3D: Area3D) -> void:
if area_3D.get_parent() is CharacterBody3D:
area_pcam.set_priority(0)

View file

@ -0,0 +1,66 @@
extends Node3D
@onready var npc_pcam: PhantomCamera3D = %NPCPhantomCamera3D
@onready var dialogueArea: Area3D = %NPCInteractionArea3D
@onready var dialogueLabel3D: Label3D = %NPCDialogueExampleLabel
@onready var player: CharacterBody3D = %PlayerCharacterBody3D
@onready var move_to_location: Vector3 = %MoveToLocation.get_global_position()
var dialogue_label_initial_position: Vector3
var dialogue_label_initial_rotation: Vector3
var tween: Tween
var tween_duration: float = 0.9
var tween_transition: Tween.TransitionType = Tween.TRANS_QUAD
var interactable: bool
var is_interacting: bool
func _ready() -> void:
dialogueArea.connect("area_entered", _interactable)
dialogueArea.connect("area_exited", _not_interactable)
dialogueLabel3D.set_visible(false)
dialogue_label_initial_position = dialogueLabel3D.get_global_position()
dialogue_label_initial_rotation = dialogueLabel3D.get_global_rotation()
func _interactable(area_3D: Area3D) -> void:
if area_3D.get_parent() is CharacterBody3D:
dialogueLabel3D.set_visible(true)
interactable = true
var tween: Tween = get_tree().create_tween().set_trans(tween_transition).set_ease(Tween.EASE_IN_OUT).set_loops()
tween.tween_property(dialogueLabel3D, "position", dialogue_label_initial_position - Vector3(0, -0.2, 0), tween_duration)
tween.tween_property(dialogueLabel3D, "position", dialogue_label_initial_position, tween_duration)
func _not_interactable(area_3D: Area3D) -> void:
if area_3D.get_parent() is CharacterBody3D:
dialogueLabel3D.set_visible(false)
interactable = false
func _input(event) -> void:
if not interactable: return
if event is InputEventKey and event.pressed:
if event.keycode == KEY_F:
var tween: Tween = get_tree().create_tween() \
.set_parallel(true) \
.set_trans(Tween.TRANS_QUART) \
.set_ease(Tween.EASE_IN_OUT)
if not is_interacting:
npc_pcam.set_priority(20)
player.set_physics_process(false)
tween.tween_property(player, "position", move_to_location, 0.6).set_trans(tween_transition)
tween.tween_property(dialogueLabel3D, "rotation", Vector3(deg_to_rad(-20), deg_to_rad(53), 0), 0.6).set_trans(tween_transition)
else:
npc_pcam.set_priority(0)
player.set_physics_process(true)
tween.tween_property(dialogueLabel3D, "rotation", dialogue_label_initial_rotation, 0.9)
is_interacting = !is_interacting

View file

@ -0,0 +1,18 @@
extends Node
@export var path_pcam: PhantomCamera3D
func _ready() -> void:
connect("area_entered", _entered_area)
connect("area_exited", _exited_area)
func _entered_area(area_3D: Area3D) -> void:
if area_3D.get_parent() is CharacterBody3D:
path_pcam.set_priority(20)
func _exited_area(area_3D: Area3D) -> void:
if area_3D.get_parent() is CharacterBody3D:
path_pcam.set_priority(0)

View file

@ -0,0 +1,81 @@
extends CharacterBody3D
@export var SPEED: float = 5.0
@export var JUMP_VELOCITY: float = 4.5
@export var enable_gravity = true
@onready var _camera: Camera3D = %MainCamera3D
@onready var _player_pcam: PhantomCamera3D = %PlayerPhantomCamera3D
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity: float = 9.8
const KEY_STRINGNAME: StringName = "Key"
const ACTION_STRINGNAME: StringName = "Action"
const INPUT_MOVE_UP_STRINGNAME: StringName = "move_up"
const INPUT_MOVE_DOWM_STRINGNAME: StringName = "move_down"
const INPUT_MOVE_LEFT_STRINGNAME: StringName = "move_left"
const INPUT_MOVE_RIGHT_STRINGNAME: StringName = "move_right"
var InputMovementDic: Dictionary = {
INPUT_MOVE_UP_STRINGNAME: {
KEY_STRINGNAME: KEY_W,
ACTION_STRINGNAME: INPUT_MOVE_UP_STRINGNAME
},
INPUT_MOVE_DOWM_STRINGNAME: {
KEY_STRINGNAME: KEY_S,
ACTION_STRINGNAME: INPUT_MOVE_DOWM_STRINGNAME
},
INPUT_MOVE_LEFT_STRINGNAME: {
KEY_STRINGNAME: KEY_A,
ACTION_STRINGNAME: INPUT_MOVE_LEFT_STRINGNAME
},
INPUT_MOVE_RIGHT_STRINGNAME: {
KEY_STRINGNAME: KEY_D,
ACTION_STRINGNAME: INPUT_MOVE_RIGHT_STRINGNAME
},
}
func _ready() -> void:
for input in InputMovementDic:
var key_val = InputMovementDic[input].get(KEY_STRINGNAME)
var action_val = InputMovementDic[input].get(ACTION_STRINGNAME)
var movement_input = InputEventKey.new()
movement_input.physical_keycode = key_val
InputMap.add_action(action_val)
InputMap.action_add_event(action_val, movement_input)
func _physics_process(delta: float) -> void:
# Add the gravity.
if enable_gravity and not is_on_floor():
velocity.y -= gravity * delta
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir: Vector2 = Input.get_vector(
INPUT_MOVE_LEFT_STRINGNAME,
INPUT_MOVE_RIGHT_STRINGNAME,
INPUT_MOVE_UP_STRINGNAME,
INPUT_MOVE_DOWM_STRINGNAME
)
var cam_dir: Vector3 = -_camera.global_transform.basis.z
var direction: Vector3 = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
var move_dir: Vector3 = Vector3.ZERO
move_dir.x = direction.x
move_dir.z = direction.z
move_dir = move_dir.rotated(Vector3.UP, _camera.rotation.y).normalized()
velocity.x = move_dir.x * SPEED
velocity.z = move_dir.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()

View file

@ -0,0 +1,83 @@
extends "player_controller.gd"
@onready var _aim_pcam: PhantomCamera3D = %PlayerAimPhantomCamera3D
@onready var _model: Node3D = $PlayerModel
@onready var _ceiling_pcam: PhantomCamera3D = %CeilingPhantomCamera3D
@export var mouse_sensitivity: float = 0.05
@export var min_yaw: float = -89.9
@export var max_yaw: float = 50
@export var min_pitch: float = 0
@export var max_pitch: float = 360
func _ready() -> void:
super()
if _player_pcam.get_follow_mode() == _player_pcam.Constants.FollowMode.THIRD_PERSON:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta: float) -> void:
super(delta)
if velocity.length() > 0.2:
var look_direction: Vector2 = Vector2(velocity.z, velocity.x)
_model.rotation.y = look_direction.angle()
func _unhandled_input(event: InputEvent) -> void:
if _player_pcam.get_follow_mode() == _player_pcam.Constants.FollowMode.THIRD_PERSON:
var active_pcam: PhantomCamera3D
if is_instance_valid(_aim_pcam):
_set_pcam_rotation(_player_pcam, event)
_set_pcam_rotation(_aim_pcam, event)
if _player_pcam.get_priority() > _aim_pcam.get_priority():
_toggle_aim_pcam(event)
else:
_toggle_aim_pcam(event)
if event is InputEventKey and event.pressed:
if event.keycode == KEY_SPACE:
if _ceiling_pcam.get_priority() < 30 and _player_pcam.is_active():
_ceiling_pcam.set_priority(30)
else:
_ceiling_pcam.set_priority(1)
func _set_pcam_rotation(pcam: PhantomCamera3D, event: InputEvent) -> void:
if event is InputEventMouseMotion:
var pcam_rotation_degrees: Vector3
# Assigns the current 3D rotation of the SpringArm3D node - so it starts off where it is in the editor
pcam_rotation_degrees = pcam.get_third_person_rotation_degrees()
# Change the X rotation
pcam_rotation_degrees.x -= event.relative.y * mouse_sensitivity
# Clamp the rotation in the X axis so it go over or under the target
pcam_rotation_degrees.x = clampf(pcam_rotation_degrees.x, min_yaw, max_yaw)
# Change the Y rotation value
pcam_rotation_degrees.y -= event.relative.x * mouse_sensitivity
# Sets the rotation to fully loop around its target, but witout going below or exceeding 0 and 360 degrees respectively
pcam_rotation_degrees.y = wrapf(pcam_rotation_degrees.y, min_pitch, max_pitch)
# Change the SpringArm3D node's rotation and rotate around its target
pcam.set_third_person_rotation_degrees(pcam_rotation_degrees)
func _toggle_aim_pcam(event: InputEvent) -> void:
if event is InputEventMouseButton \
and event.is_pressed() \
and event.button_index == 2 \
and (_player_pcam.is_active() or _aim_pcam.is_active()):
if _player_pcam.get_priority() > _aim_pcam.get_priority():
_aim_pcam.set_priority(30)
else:
_aim_pcam.set_priority(0)