Skip to content

Commit

Permalink
Fix the updated JRPG demo for Godot 4.0 (#3)
Browse files Browse the repository at this point in the history
* Fix the updated JRPG demo for Godot 4.0

* Add theme to health bars

* Fix animation bugs and other issues in JRPG demo
  • Loading branch information
Nonparoxysmic authored Oct 8, 2023
1 parent 9f52b31 commit 942c872
Show file tree
Hide file tree
Showing 13 changed files with 732 additions and 674 deletions.
1,123 changes: 548 additions & 575 deletions 2d/role_playing_game/combat/combat.tscn

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions 2d/role_playing_game/combat/combatants/opponent.tscn
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=4 format=3 uid="uid://dp7gq0vfmf4nc"]

[ext_resource path="res://combat/combatants/combatant.tscn" type="PackedScene" id=1]
[ext_resource path="res://combat/combatants/opponent.gd" type="Script" id=2]
[ext_resource path="res://combat/combatants/sprites/opponent_battle.png" type="Texture2D" id=3]
[ext_resource type="PackedScene" uid="uid://blh4bx2nbvbn5" path="res://combat/combatants/combatant.tscn" id="1"]
[ext_resource type="Script" path="res://combat/combatants/opponent.gd" id="2"]
[ext_resource type="Texture2D" uid="uid://bebxw4udsw7i3" path="res://combat/combatants/sprites/opponent_battle.png" id="3"]

[node name="Opponent" instance=ExtResource( 1 )]
script = ExtResource( 2 )
[node name="Opponent" instance=ExtResource("1")]
script = ExtResource("2")
damage = 3

[node name="Health" parent="." index="0"]
life = 7
max_life = 7

[node name="Body" parent="Sprite2D/Pivot" index="1"]
texture = ExtResource( 3 )
texture = ExtResource("3")

[node name="Timer" type="Timer" parent="." index="2"]
wait_time = 0.25
Expand Down
8 changes: 0 additions & 8 deletions 2d/role_playing_game/combat/combatants/sprites/sprite.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ libraries = {
}
next/take_damage = &"idle"

[node name="Tween" type="Tween" parent="."]
_import_path = NodePath("")
unique_name_in_owner = false
process_mode = 0
process_priority = 0
editor_description = ""
script = null

[node name="Pivot" type="Marker2D" parent="."]

[node name="Shadow" type="Sprite2D" parent="Pivot"]
Expand Down
99 changes: 69 additions & 30 deletions 2d/role_playing_game/combat/interface/info.tscn
Original file line number Diff line number Diff line change
@@ -1,51 +1,90 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=6 format=3 uid="uid://bypumcqt7j0iv"]

[ext_resource path="res://theme/fonts/montserrat_extra_bold.otf" type="FontFile" id=1]
[ext_resource type="FontFile" uid="uid://b2r8e5d6rc4pg" path="res://theme/fonts/montserrat_extra_bold.otf" id="1"]

[sub_resource type="FontFile" id=1]
size = 42
font_data = ExtResource( 1 )
[sub_resource type="FontFile" id="1"]
fallbacks = Array[Font]([ExtResource("1")])
face_index = null
embolden = null
transform = null
cache/0/16/0/ascent = 0.0
cache/0/16/0/descent = 0.0
cache/0/16/0/underline_position = 0.0
cache/0/16/0/underline_thickness = 0.0
cache/0/16/0/scale = 1.0
cache/0/16/0/kerning_overrides/16/0 = Vector2(0, 0)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dsedd"]
bg_color = Color(0.541176, 0.72549, 0.819608, 1)
border_width_left = 5
border_width_top = 5
border_width_right = 5
border_width_bottom = 5
border_color = Color(0.4488, 0.602933, 0.68, 1)
border_blend = true
corner_radius_top_left = 16
corner_radius_top_right = 16
corner_radius_bottom_right = 16
corner_radius_bottom_left = 16

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_s3yjq"]
bg_color = Color(0.945098, 0.235294, 0.376471, 1)
border_width_left = 5
border_width_top = 5
border_width_right = 5
border_width_bottom = 5
border_color = Color(0.8, 0.8, 0.8, 0)
corner_radius_top_left = 16
corner_radius_top_right = 16
corner_radius_bottom_right = 16
corner_radius_bottom_left = 16

[sub_resource type="Theme" id="Theme_vywfd"]
ProgressBar/styles/background = SubResource("StyleBoxFlat_dsedd")
ProgressBar/styles/fill = SubResource("StyleBoxFlat_s3yjq")

[node name="Info" type="PanelContainer"]
offset_right = 400.0
offset_bottom = 239.0
scale = Vector2( 0.907481, 1 )
scale = Vector2(0.907481, 1)
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="VBoxContainer" type="VBoxContainer" parent="."]
offset_left = 7.0
offset_top = 7.0
offset_right = 393.0
offset_bottom = 232.0
custom_minimum_size = Vector2( 0, 150 )

[node name="Name" type="Label" parent="VBoxContainer"]
offset_right = 386.0
offset_bottom = 110.0
grow_horizontal = 2
grow_vertical = 2
custom_minimum_size = Vector2(0, 150)
layout_mode = 2
alignment = 1

[node name="NameContainer" type="CenterContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3

[node name="Name" type="Label" parent="VBoxContainer/NameContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 7
theme_override_colors/font_color = Color( 0.0745098, 0.27451, 0.368627, 1 )
theme_override_colors/font_shadow_color = Color( 0.184314, 0.419608, 0.533333, 0.356863 )
theme_override_colors/font_color = Color(0.0745098, 0.27451, 0.368627, 1)
theme_override_colors/font_shadow_color = Color(0.184314, 0.419608, 0.533333, 0.356863)
theme_override_constants/shadow_offset_x = 1
theme_override_constants/shadow_offset_y = 2
theme_override_fonts/font = SubResource( 1 )
theme_override_fonts/font = SubResource("1")
text = "{NAME}"
align = 1
valign = 2
autowrap = true
horizontal_alignment = 1
vertical_alignment = 1
uppercase = true
percent_visible = -0.166667

[node name="Health" type="ProgressBar" parent="VBoxContainer"]
offset_top = 168.0
offset_right = 386.0
offset_bottom = 170.0
size_flags_vertical = 6
[node name="HealthContainer" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3

[node name="Health" type="ProgressBar" parent="VBoxContainer/HealthContainer"]
custom_minimum_size = Vector2(300, 50)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 2
theme = SubResource("Theme_vywfd")
max_value = 10.0
step = 1.0
value = 5.0
rounded = true
percent_visible = false
show_percentage = false
4 changes: 2 additions & 2 deletions 2d/role_playing_game/combat/interface/ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ func initialize():
for combatant in combatants_node.get_children():
var health = combatant.get_node("Health")
var info = info_scene.instantiate()
var health_info = info.get_node("VBoxContainer/Health")
var health_info = info.get_node("VBoxContainer/HealthContainer/Health")
health_info.value = health.life
health_info.max_value = health.max_life
info.get_node("VBoxContainer/Name").text = combatant.name
info.get_node("VBoxContainer/NameContainer/Name").text = combatant.name
health.connect("health_changed", Callable(health_info, "set_value"))
$Combatants.add_child(info)
$Buttons/GridContainer/Attack.grab_focus()
Expand Down
7 changes: 4 additions & 3 deletions 2d/role_playing_game/dialogue/interface/interface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ func show_dialogue(player, dialogue):
show()
$Button.grab_focus()
dialogue_node = dialogue
for c in dialogue.get_signal_connection_list("dialogue_finished"):
if self == c.target:
for c in dialogue.get_signal_connection_list("dialogue_started"):
if player == c.callable.get_object():
dialogue_node.start_dialogue()
break
$Name.text = "[center]" + dialogue_node.dialogue_name + "[/center]"
$Text.text = dialogue_node.dialogue_text
return
dialogue_node.connect("dialogue_started", Callable(player, "set_active").bind(false))
dialogue_node.connect("dialogue_finished", Callable(player, "set_active").bind(true))
Expand Down
31 changes: 17 additions & 14 deletions 2d/role_playing_game/dialogue/interface/interface.tscn
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=3 format=3 uid="uid://nb2wowyl2vi0"]

[ext_resource path="res://theme/theme.tres" type="Theme" id=1]
[ext_resource path="res://dialogue/interface/interface.gd" type="Script" id=2]
[ext_resource type="Theme" uid="uid://dtao6d0ebglcf" path="res://theme/theme.tres" id="1"]
[ext_resource type="Script" path="res://dialogue/interface/interface.gd" id="2"]

[node name="Dialogue" type="Panel"]
offset_top = 544.0
offset_right = 1280.0
offset_bottom = 544.0
theme = ExtResource( 1 )
script = ExtResource( 2 )
theme = ExtResource("1")
script = ExtResource("2")

[node name="Panel" type="Panel" parent="."]
layout_mode = 0
offset_left = 20.0
offset_top = -60.0
offset_right = 312.698
offset_bottom = 82.95
theme = ExtResource( 1 )
theme_type_variation = "title_panel"
theme = ExtResource("1")
theme_type_variation = &"title_panel"

[node name="Panel2" type="Panel" parent="."]
layout_mode = 0
offset_left = 20.0
offset_right = 1260.0
offset_bottom = 176.0

[node name="Name" type="RichTextLabel" parent="."]
layout_mode = 0
offset_left = 51.0
offset_top = -47.0
offset_right = 275.0
offset_bottom = -7.0
theme_override_colors/default_color = Color( 0.0745098, 0.27451, 0.368627, 1 )
theme_override_colors/font_shadow_color = Color( 0.184314, 0.419608, 0.533333, 0.356863 )
theme_override_colors/default_color = Color(0.0745098, 0.27451, 0.368627, 1)
theme_override_colors/font_shadow_color = Color(0.184314, 0.419608, 0.533333, 0.356863)
theme_override_constants/shadow_offset_x = 1
theme_override_constants/shadow_offset_y = 2
bbcode_enabled = true
text = "[center]NAME[/center]"
text = "NAME"
scroll_active = false

[node name="Text" type="RichTextLabel" parent="."]
offset_left = 57.0
offset_top = 63.0
offset_right = 1361.0
layout_mode = 0
offset_left = 120.0
offset_top = 60.0
offset_right = 1020.0
offset_bottom = 120.0
scale = Vector2( 0.75, 0.75 )
text = "Dialogue Text"

[node name="Button" type="Button" parent="."]
layout_mode = 0
offset_left = 1080.0
offset_top = 17.0
offset_right = 1240.0
Expand Down
2 changes: 1 addition & 1 deletion 2d/role_playing_game/game.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://8ylj6j3vmxoy"]

[ext_resource type="Script" path="res://game.gd" id="1"]
[ext_resource type="PackedScene" path="res://combat/combat.tscn" id="2"]
[ext_resource type="PackedScene" uid="uid://b4aouv6fsdecc" path="res://combat/combat.tscn" id="2"]
[ext_resource type="PackedScene" uid="uid://ckgv4m67a5kfj" path="res://grid_movement/exploration.tscn" id="3"]

[sub_resource type="Animation" id="1"]
Expand Down
24 changes: 19 additions & 5 deletions 2d/role_playing_game/grid_movement/exploration.tscn

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions 2d/role_playing_game/grid_movement/grid/grid.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enum CellType { ACTOR, OBSTACLE, OBJECT }

func _ready():
for child in get_children():
set_cell(0, local_to_map(child.position), child.type)
set_cell(0, local_to_map(child.position), child.type, Vector2i.ZERO)


func get_cell_pawn(cell, type = CellType.ACTOR):
Expand All @@ -22,15 +22,15 @@ func request_move(pawn, direction: Vector2i):
var cell_start = local_to_map(pawn.position)
var cell_target = cell_start + direction

var cell_tile_id = get_cell_atlas_coords(0, cell_target)
var cell_tile_id = get_cell_source_id(0, cell_target)
match cell_tile_id:
-1:
set_cell(0, cell_target, CellType.ACTOR)
set_cell(0, cell_start, -1)
return map_to_local(cell_target) + Vector2(tile_set.tile_size) / 2
set_cell(0, cell_target, CellType.ACTOR, Vector2i.ZERO)
set_cell(0, cell_start, -1, Vector2i.ZERO)
return map_to_local(cell_target)
CellType.OBJECT, CellType.ACTOR:
var target_pawn = get_cell_pawn(cell_target, cell_tile_id)
print("Cell %s contains %s" % [cell_target, target_pawn.name])
#print("Cell %s contains %s" % [cell_target, target_pawn.name])

if not target_pawn.has_node("DialoguePlayer"):
return
Expand Down
Loading

0 comments on commit 942c872

Please sign in to comment.