Create a dialog system using the Godot Add-On Dialogic. This lab goes along with the NPC art lab.
1. Setup
- Use your game project or download the Default Project Template
- Download the Assets folder if you need any assets
- Get a font from BitFontMaker2 or make one
- Download Dialogic in Godot’s Asset Library
- Duplicate the
DefaultScene
and add in aSceneManager
andUI
node - Use the
PlayerSimple
script for the player controller
2. Create the NPC scene
- Make a new scene called
NPC
and add it to the default scene - The default node is an
Area2D
- Add an
AnimatedSprite
with theIdle
andTalk
animations - Add a
CollisionShape2D
to create the activation area - Create a new
NPC
layer in the and add thePlayer
layer to the NPC mask on theArea2D
- Create the
NPC
script - Connect signals for the player enter and exit
3. Create a Dialogic dialog
- Start by adding the characters using the character portraits created in the NPCs art lab
- Adjust the theme
- Add a timeline for a test dialog
- Create events in the timeline
- Add definitions to update the item count
4. Connect the Dialogic dialog to the NPC
- Use the
NPC
export variabledialog_name
to launch the NPCs dialog - Update the
PlayerSimple
script to play theTalk
animation - Update the
SceneManager
to show changes to theMetrics
5. Add at least one more dialog
- Your scene should have at least two NPCs with two different dialogs
6. Documentation
- Take screen shots or video of the dialog and NPC
Full NPC Script
extends Area2D
# global variables
export var dialog_name = "Dialog Name"
var player = null
var dialog = null
var player_entered = false
var dialog_started = false
signal update_metrics
func _ready():
$Label.visible = false
func _process(_delta):
if player_entered and not dialog_started:
if Input.is_action_just_pressed("ui_accept"):
$Label.visible = false
dialog_started = true
dialog = Dialogic.start(dialog_name)
Dialogic.set_variable("apple_count", Global.item_count)
add_child(dialog)
$AnimatedSprite.play('Talk')
player.talk()
dialog.connect('timeline_end', self, 'end_dialog')
dialog.connect('dialogic_signal', self, 'update_resources')
func end_dialog(_param):
$AnimatedSprite.play('Idle')
player.move()
func update_resources(param):
if param == 'add_fireball':
print('Added a fireball!')
if param == 'remove_apple':
Global.item_count -= 1
emit_signal('update_metrics')
func _on_NPC_body_entered(body):
# when player enters NPC area
$Label.visible = true
player_entered = true
player = body
func _on_NPC_body_exited(body):
# when player leaves
remove_child(dialog)
player_entered = false
dialog_started = false
$Label.visible = false
end_dialog(_null)
Update PlayerSimple.gd
# variables
var is_moving = true
func talk():
$AnimatedSprite.play('Talk')
is_moving = false
func move():
is_moving = true
Update SceneManager.gd
func _on_NPC_update_metrics():
metrics.update_display()