Skip to content

Commit

Permalink
Close #148: Change the Pawns' animated character based on the party m…
Browse files Browse the repository at this point in the history
…embers
  • Loading branch information
NathanLovato committed Dec 27, 2018
1 parent 5ac082a commit f2326e2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 23 deletions.
5 changes: 3 additions & 2 deletions godot/animation/GodettePawnAnim.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
[ext_resource path="res://animation/PawnAnim.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/sprites/local_map/characters/godette_pawn.png" type="Texture" id=2]

[node name="GodettePawnAnim" index="0" instance=ExtResource( 1 )]
[node name="GodettePawnAnim" instance=ExtResource( 1 )]

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

8 changes: 7 additions & 1 deletion godot/animation/RobiPawnAnim.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]

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

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

[node name="Body" parent="Root" index="0"]
scale = Vector2( 1, 1 )
texture = ExtResource( 2 )
offset = Vector2( 0, -171.413 )

24 changes: 15 additions & 9 deletions godot/local_map/grid/PawnContainer.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
extends Node2D
"""
Container for all pawns on the map.
Sorts pawns by their Y position,
Spawns and rebuilds the player's party
"""
extends YSort

export var party_scene : PackedScene

Expand All @@ -14,20 +19,21 @@ func spawn_party(game_board, party : Object) -> void:
var party_size = min(get_child_count(), party.PARTY_SIZE) - 1
for index in range(party_size):
pawn_previous = spawn_pawn(
game_board.spawning_point.position,
pawn_previous,
party.get_child(index).name,
party.get_child(index),
game_board,
pawn_previous,
index == 0)
pawn_previous.initialize(game_board)
party_members.append(pawn_previous)

func spawn_pawn(pos : Vector2, pawn_previous : Object, pawn_name : String, is_leader : bool = false) -> Object:
var new_pawn = Leader.instance() if is_leader else Follower.instance()
new_pawn.name = pawn_name
new_pawn.position = pos
func spawn_pawn(party_member : PartyMember, game_board : GameBoard, pawn_previous : Object, is_leader : bool = false) -> Object:
var new_pawn : PawnActor = Leader.instance() if is_leader else Follower.instance()
new_pawn.name = party_member.name
new_pawn.position = game_board.spawning_point.position
new_pawn.initialize(game_board)
if pawn_previous:
pawn_previous.connect("moved", new_pawn, "_on_target_Pawn_moved")
add_child(new_pawn)
new_pawn.change_skin(party_member.get_pawn_anim())
return new_pawn

func rebuild_party() -> void:
Expand Down
11 changes: 10 additions & 1 deletion godot/local_map/pawns/PawnActor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ var game_board
signal moved(last_position, current_position)

onready var pivot = $Pivot
onready var anim : PawnAnim = $Pivot/PawnAnim
onready var tween = $Tween
onready var anim : PawnAnim = pivot.get_node("PawnAnim")

func _ready():
update_look_direction(Vector2(1, 0))
Expand Down Expand Up @@ -36,3 +36,12 @@ func bump():
set_process(false)
yield(anim.play_bump(), "completed")
set_process(true)

func change_skin(pawn_anim : PawnAnim):
"""
Replaces the pawn's animated character with another
"""
if anim:
anim.queue_free()
anim = pawn_anim
pivot.add_child(pawn_anim)
29 changes: 19 additions & 10 deletions godot/party/Party.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=15 format=2]

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

[node name="Party" type="Node2D"]
script = ExtResource( 1 )
PARTY_SIZE = null

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

[node name="Battler" parent="Godette" index="0"]
editor/display_folded = true
stats = ExtResource( 3 )
party_member = true
turn_order_icon = ExtResource( 4 )
Expand All @@ -32,22 +35,28 @@ skill = ExtResource( 7 )
[node name="AI" parent="Godette/Battler" index="6"]
script = ExtResource( 8 )

[node name="GodettePawnAnim" parent="Godette" instance=ExtResource( 9 )]

[node name="Robi" parent="." instance=ExtResource( 2 )]
pawn_anim_path = NodePath("RobiPawnAnim")

[node name="Battler" parent="Robi" index="0"]
stats = ExtResource( 9 )
editor/display_folded = true
stats = ExtResource( 10 )
party_member = true
turn_order_icon = ExtResource( 10 )
turn_order_icon = ExtResource( 11 )

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

[node name="Slash" parent="Robi/Battler/Skills" index="0" instance=ExtResource( 6 )]
skill = ExtResource( 12 )
skill = ExtResource( 13 )
level = 0

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

[node name="RobiPawnAnim" parent="Robi" instance=ExtResource( 14 )]


[editable path="Godette"]

Expand Down
5 changes: 5 additions & 0 deletions godot/party/PartyMember.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ extends Node2D

class_name PartyMember

export var pawn_anim_path : NodePath
onready var battler = $Battler

func _ready():
assert pawn_anim_path
battler.stats.reset()

func update_stats(stats : CharacterStats):
Expand All @@ -20,3 +22,6 @@ func ready_for_combat():
at the start of a battle
"""
return battler.duplicate()

func get_pawn_anim():
return get_node(pawn_anim_path).duplicate()

0 comments on commit f2326e2

Please sign in to comment.