Skip to content

Commit f2326e2

Browse files
committed
Close #148: Change the Pawns' animated character based on the party members
1 parent 5ac082a commit f2326e2

File tree

6 files changed

+59
-23
lines changed

6 files changed

+59
-23
lines changed

godot/animation/GodettePawnAnim.tscn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
[ext_resource path="res://animation/PawnAnim.tscn" type="PackedScene" id=1]
44
[ext_resource path="res://assets/sprites/local_map/characters/godette_pawn.png" type="Texture" id=2]
55

6-
[node name="GodettePawnAnim" index="0" instance=ExtResource( 1 )]
6+
[node name="GodettePawnAnim" instance=ExtResource( 1 )]
77

88
[node name="Body" parent="Root" index="0"]
9-
position = Vector2( 0, -188.656 )
9+
scale = Vector2( 1, 1 )
1010
texture = ExtResource( 2 )
11+
offset = Vector2( 0, -179.527 )
1112

godot/animation/RobiPawnAnim.tscn

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
[gd_scene load_steps=2 format=2]
1+
[gd_scene load_steps=3 format=2]
22

33
[ext_resource path="res://animation/PawnAnim.tscn" type="PackedScene" id=1]
4+
[ext_resource path="res://assets/sprites/local_map/characters/robi_pawn.png" type="Texture" id=2]
45

56
[node name="RobiPawnAnim" index="0" instance=ExtResource( 1 )]
67

8+
[node name="Body" parent="Root" index="0"]
9+
scale = Vector2( 1, 1 )
10+
texture = ExtResource( 2 )
11+
offset = Vector2( 0, -171.413 )
12+

godot/local_map/grid/PawnContainer.gd

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
extends Node2D
1+
"""
2+
Container for all pawns on the map.
3+
Sorts pawns by their Y position,
4+
Spawns and rebuilds the player's party
5+
"""
6+
extends YSort
27

38
export var party_scene : PackedScene
49

@@ -14,20 +19,21 @@ func spawn_party(game_board, party : Object) -> void:
1419
var party_size = min(get_child_count(), party.PARTY_SIZE) - 1
1520
for index in range(party_size):
1621
pawn_previous = spawn_pawn(
17-
game_board.spawning_point.position,
18-
pawn_previous,
19-
party.get_child(index).name,
22+
party.get_child(index),
23+
game_board,
24+
pawn_previous,
2025
index == 0)
21-
pawn_previous.initialize(game_board)
2226
party_members.append(pawn_previous)
2327

24-
func spawn_pawn(pos : Vector2, pawn_previous : Object, pawn_name : String, is_leader : bool = false) -> Object:
25-
var new_pawn = Leader.instance() if is_leader else Follower.instance()
26-
new_pawn.name = pawn_name
27-
new_pawn.position = pos
28+
func spawn_pawn(party_member : PartyMember, game_board : GameBoard, pawn_previous : Object, is_leader : bool = false) -> Object:
29+
var new_pawn : PawnActor = Leader.instance() if is_leader else Follower.instance()
30+
new_pawn.name = party_member.name
31+
new_pawn.position = game_board.spawning_point.position
32+
new_pawn.initialize(game_board)
2833
if pawn_previous:
2934
pawn_previous.connect("moved", new_pawn, "_on_target_Pawn_moved")
3035
add_child(new_pawn)
36+
new_pawn.change_skin(party_member.get_pawn_anim())
3137
return new_pawn
3238

3339
func rebuild_party() -> void:

godot/local_map/pawns/PawnActor.gd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var game_board
66
signal moved(last_position, current_position)
77

88
onready var pivot = $Pivot
9-
onready var anim : PawnAnim = $Pivot/PawnAnim
109
onready var tween = $Tween
10+
onready var anim : PawnAnim = pivot.get_node("PawnAnim")
1111

1212
func _ready():
1313
update_look_direction(Vector2(1, 0))
@@ -36,3 +36,12 @@ func bump():
3636
set_process(false)
3737
yield(anim.play_bump(), "completed")
3838
set_process(true)
39+
40+
func change_skin(pawn_anim : PawnAnim):
41+
"""
42+
Replaces the pawn's animated character with another
43+
"""
44+
if anim:
45+
anim.queue_free()
46+
anim = pawn_anim
47+
pivot.add_child(pawn_anim)

godot/party/Party.tscn

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=13 format=2]
1+
[gd_scene load_steps=15 format=2]
22

33
[ext_resource path="res://party/Party.gd" type="Script" id=1]
44
[ext_resource path="res://party/PartyMember.tscn" type="PackedScene" id=2]
@@ -8,18 +8,21 @@
88
[ext_resource path="res://combat/battlers/skills/LearnedSkill.tscn" type="PackedScene" id=6]
99
[ext_resource path="res://combat/battlers/skills/Lollislash.tres" type="Resource" id=7]
1010
[ext_resource path="res://combat/battlers/ai/PlayerInput.gd" type="Script" id=8]
11-
[ext_resource path="res://combat/battlers/jobs/RobiJob.tres" type="Resource" id=9]
12-
[ext_resource path="res://assets/sprites/battlers/robi_portrait_256.png" type="Texture" id=10]
13-
[ext_resource path="res://animation/RobiAnim.tscn" type="PackedScene" id=11]
14-
[ext_resource path="res://combat/battlers/skills/Slash.tres" type="Resource" id=12]
11+
[ext_resource path="res://animation/GodettePawnAnim.tscn" type="PackedScene" id=9]
12+
[ext_resource path="res://combat/battlers/jobs/RobiJob.tres" type="Resource" id=10]
13+
[ext_resource path="res://assets/sprites/battlers/robi_portrait_256.png" type="Texture" id=11]
14+
[ext_resource path="res://animation/RobiAnim.tscn" type="PackedScene" id=12]
15+
[ext_resource path="res://combat/battlers/skills/Slash.tres" type="Resource" id=13]
16+
[ext_resource path="res://animation/RobiPawnAnim.tscn" type="PackedScene" id=14]
1517

1618
[node name="Party" type="Node2D"]
1719
script = ExtResource( 1 )
18-
PARTY_SIZE = null
1920

2021
[node name="Godette" parent="." instance=ExtResource( 2 )]
22+
pawn_anim_path = NodePath("GodettePawnAnim")
2123

2224
[node name="Battler" parent="Godette" index="0"]
25+
editor/display_folded = true
2326
stats = ExtResource( 3 )
2427
party_member = true
2528
turn_order_icon = ExtResource( 4 )
@@ -32,22 +35,28 @@ skill = ExtResource( 7 )
3235
[node name="AI" parent="Godette/Battler" index="6"]
3336
script = ExtResource( 8 )
3437

38+
[node name="GodettePawnAnim" parent="Godette" instance=ExtResource( 9 )]
39+
3540
[node name="Robi" parent="." instance=ExtResource( 2 )]
41+
pawn_anim_path = NodePath("RobiPawnAnim")
3642

3743
[node name="Battler" parent="Robi" index="0"]
38-
stats = ExtResource( 9 )
44+
editor/display_folded = true
45+
stats = ExtResource( 10 )
3946
party_member = true
40-
turn_order_icon = ExtResource( 10 )
47+
turn_order_icon = ExtResource( 11 )
4148

42-
[node name="RobiAnim" parent="Robi/Battler/Skin" index="2" instance=ExtResource( 11 )]
49+
[node name="RobiAnim" parent="Robi/Battler/Skin" index="2" instance=ExtResource( 12 )]
4350

4451
[node name="Slash" parent="Robi/Battler/Skills" index="0" instance=ExtResource( 6 )]
45-
skill = ExtResource( 12 )
52+
skill = ExtResource( 13 )
4653
level = 0
4754

4855
[node name="AI" parent="Robi/Battler" index="6"]
4956
script = ExtResource( 8 )
5057

58+
[node name="RobiPawnAnim" parent="Robi" instance=ExtResource( 14 )]
59+
5160

5261
[editable path="Godette"]
5362

godot/party/PartyMember.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ extends Node2D
22

33
class_name PartyMember
44

5+
export var pawn_anim_path : NodePath
56
onready var battler = $Battler
67

78
func _ready():
9+
assert pawn_anim_path
810
battler.stats.reset()
911

1012
func update_stats(stats : CharacterStats):
@@ -20,3 +22,6 @@ func ready_for_combat():
2022
at the start of a battle
2123
"""
2224
return battler.duplicate()
25+
26+
func get_pawn_anim():
27+
return get_node(pawn_anim_path).duplicate()

0 commit comments

Comments
 (0)