Skip to content

Commit

Permalink
Separate pawn animation from the PawnActor into a PawnAnim scene
Browse files Browse the repository at this point in the history
Just like BattlerAnim before it, we have pawns that are reusable character
controllers, that apply to NPCs and to the playable character. And these pawns
could be any character in the game, so we need to be able to change the skin on
them.

Having separate scenes for animation is also essential for animators to be able
to do their job properly, while the devs can keep working on the Pawn scenes
  • Loading branch information
NathanLovato committed Dec 27, 2018
1 parent 3d8f3b5 commit 9e0bb7b
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 176 deletions.
16 changes: 16 additions & 0 deletions godot/animation/PawnAnim.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends Position2D

class_name PawnAnim

onready var anim = $AnimationPlayer

func play_walk():
anim.play("walk")
yield(anim, "animation_finished")

func play_bump():
anim.play("bump")
yield(anim, "animation_finished")

func get_current_animation_length():
return anim.current_animation_length
68 changes: 68 additions & 0 deletions godot/animation/PawnAnim.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[gd_scene load_steps=5 format=2]

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

[sub_resource type="Animation" id=1]

resource_name = "bump"
length = 0.1
step = 0.01
tracks/0/type = "value"
tracks/0/path = NodePath("Root:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.02, 0.04, 0.06, 0.08, 0.1 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1 ),
"update": 0,
"values": [ Vector2( 0, 0 ), Vector2( -1.5, -9 ), Vector2( 6.5, 2.5 ), Vector2( -11.5, 8.5 ), Vector2( 4, -5 ), Vector2( 0, 0 ) ]
}

[sub_resource type="Animation" id=2]

resource_name = "walk"
length = 0.25
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("Root:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.15, 0.25 ),
"transitions": PoolRealArray( 1, 0.303143, 2.61003, 1 ),
"update": 0,
"values": [ Vector2( 1.43051e-06, -1.90735e-06 ), Vector2( 1.43051e-06, -1.90735e-06 ), Vector2( 0, -20 ), Vector2( 1.43051e-06, -1.90735e-06 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Root:scale")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.05, 0.15, 0.25 ),
"transitions": PoolRealArray( 1, 0.354553, 1, 1 ),
"update": 0,
"values": [ Vector2( 1, 1 ), Vector2( 1.20007, 0.917384 ), Vector2( 0.916712, 1.13495 ), Vector2( 1, 1 ) ]
}

[node name="PawnAnim" type="Position2D"]
scale = Vector2( 0.328641, 0.328641 )
script = ExtResource( 1 )

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/bump = SubResource( 1 )
anims/walk = SubResource( 2 )

[node name="Root" type="Position2D" parent="."]
position = Vector2( 1.43051e-06, -1.90735e-06 )

[node name="Body" type="Sprite" parent="Root"]
position = Vector2( 0, -170.399 )
texture = ExtResource( 2 )

11 changes: 4 additions & 7 deletions godot/local_map/pawns/PawnActor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var game_board
signal moved(last_position, current_position)

onready var pivot = $Pivot
onready var anim_player = $AnimationPlayer
onready var anim : PawnAnim = $Pivot/PawnAnim
onready var tween = $Tween

func _ready():
Expand All @@ -27,15 +27,12 @@ func move_to(target_position):
var move_direction = (target_position - position).normalized()
position = target_position
pivot.position = - move_direction * 40.0
tween.interpolate_property($Pivot, "position", pivot.position, Vector2(), anim_player.current_animation_length, Tween.TRANS_LINEAR, Tween.EASE_IN)
anim_player.play("walk")

tween.interpolate_property($Pivot, "position", pivot.position, Vector2(), anim.get_current_animation_length(), Tween.TRANS_LINEAR, Tween.EASE_IN)
tween.start()
yield($AnimationPlayer, "animation_finished")
yield(anim.play_walk(), "completed")
set_process(true)

func bump():
set_process(false)
anim_player.play("bump")
yield(anim_player, "animation_finished")
yield(anim.play_bump(), "completed")
set_process(true)
99 changes: 5 additions & 94 deletions godot/local_map/pawns/PawnFollower.tscn
Original file line number Diff line number Diff line change
@@ -1,111 +1,22 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://local_map/pawns/PawnFollower.gd" type="Script" id=1]
[ext_resource path="res://local_map/pawns/sprites/character.png" type="Texture" id=2]
[ext_resource path="res://animation/PawnAnim.tscn" type="PackedScene" id=2]

[sub_resource type="Animation" id=1]
[sub_resource type="RectangleShape2D" id=1]

resource_name = "bump"
length = 0.1
loop = false
step = 0.01
tracks/0/type = "value"
tracks/0/path = NodePath("Pivot/Sprite:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.02, 0.04, 0.06, 0.08, 0.1 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1 ),
"update": 0,
"values": [ Vector2( 0, 0 ), Vector2( -1.5, -9 ), Vector2( 6.5, 2.5 ), Vector2( -11.5, 8.5 ), Vector2( 4, -5 ), Vector2( 0, 0 ) ]
}

[sub_resource type="Animation" id=2]

resource_name = "walk"
length = 0.25
loop = false
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("Pivot/Sprite:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = false
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.25 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 0.9375, 0, 1 ), Color( 1, 1, 1, 1 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Pivot/Sprite:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.1, 0.15, 0.25 ),
"transitions": PoolRealArray( 1, 0.303143, 2.61003, 1 ),
"update": 0,
"values": [ Vector2( 1.43051e-006, -1.90735e-006 ), Vector2( 1.43051e-006, -1.90735e-006 ), Vector2( 0, -20 ), Vector2( 1.43051e-006, -1.90735e-006 ) ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("Pivot/Sprite:scale")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 0.05, 0.15, 0.25 ),
"transitions": PoolRealArray( 1, 0.354553, 1, 1 ),
"update": 0,
"values": [ Vector2( 1, 1 ), Vector2( 1.20007, 0.917384 ), Vector2( 0.916712, 1.13495 ), Vector2( 1, 1 ) ]
}

[sub_resource type="RectangleShape2D" id=3]

custom_solver_bias = 0.0
extents = Vector2( 30, 30 )

[node name="Follower" type="KinematicBody2D"]
position = Vector2( 32, 32 )
z_index = 1
input_pickable = false
collision_layer = 1
collision_mask = 1
collision/safe_margin = 0.08
motion/sync_to_physics = false
script = ExtResource( 1 )

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
root_node = NodePath("..")
autoplay = ""
playback_process_mode = 1
playback_default_blend_time = 0.0
playback_speed = 1.0
anims/bump = SubResource( 1 )
anims/walk = SubResource( 2 )
blend_times = [ ]

[node name="Tween" type="Tween" parent="."]
repeat = false
playback_process_mode = 1
playback_speed = 1.0
playback/active = false
playback/repeat = false
playback/speed = 1.0

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

[node name="Sprite" type="Sprite" parent="Pivot"]
position = Vector2( 1.43051e-006, -1.90735e-006 )
texture = ExtResource( 2 )
centered = false
offset = Vector2( -32, -32 )
[node name="PawnAnim" parent="Pivot" instance=ExtResource( 2 )]

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 3 )
shape = SubResource( 1 )

7 changes: 4 additions & 3 deletions godot/local_map/pawns/PawnInteractive.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://local_map/pawns/PawnInteractive.gd" type="Script" id=1]
[ext_resource path="res://local_map/pawns/sprites/star.png" type="Texture" id=2]
[ext_resource path="res://animation/PawnAnim.tscn" type="PackedScene" id=2]
[ext_resource path="res://assets/sprites/dialogue_balloon.png" type="Texture" id=3]

[sub_resource type="RectangleShape2D" id=1]
Expand All @@ -23,8 +23,9 @@ facing = {
"up": true
}

[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 2 )
[node name="Pivot" type="Position2D" parent="."]

[node name="PawnAnim" parent="Pivot" instance=ExtResource( 2 )]

[node name="DialogueBalloon" type="Sprite" parent="."]
visible = false
Expand Down
75 changes: 3 additions & 72 deletions godot/local_map/pawns/PawnLeader.tscn
Original file line number Diff line number Diff line change
@@ -1,69 +1,9 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=5 format=2]

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

[sub_resource type="Animation" id=1]

resource_name = "bump"
length = 0.1
step = 0.01
tracks/0/type = "value"
tracks/0/path = NodePath("Pivot/Sprite:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.02, 0.04, 0.06, 0.08, 0.1 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1 ),
"update": 0,
"values": [ Vector2( 0, 0 ), Vector2( -1.5, -9 ), Vector2( 6.5, 2.5 ), Vector2( -11.5, 8.5 ), Vector2( 4, -5 ), Vector2( 0, 0 ) ]
}

[sub_resource type="Animation" id=2]

resource_name = "walk"
length = 0.25
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("Pivot/Sprite:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = false
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.25 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 0.9375, 0, 1 ), Color( 1, 1, 1, 1 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Pivot/Sprite:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = false
tracks/1/keys = {
"times": PoolRealArray( 0, 0.1, 0.15, 0.25 ),
"transitions": PoolRealArray( 1, 0.303143, 2.61003, 1 ),
"update": 0,
"values": [ Vector2( 1.43051e-006, -1.90735e-006 ), Vector2( 1.43051e-006, -1.90735e-006 ), Vector2( 0, -20 ), Vector2( 1.43051e-006, -1.90735e-006 ) ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("Pivot/Sprite:scale")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = false
tracks/2/keys = {
"times": PoolRealArray( 0, 0.05, 0.15, 0.25 ),
"transitions": PoolRealArray( 1, 0.354553, 1, 1 ),
"update": 0,
"values": [ Vector2( 1, 1 ), Vector2( 1.20007, 0.917384 ), Vector2( 0.916712, 1.13495 ), Vector2( 1, 1 ) ]
}

[sub_resource type="RectangleShape2D" id=3]

extents = Vector2( 30, 30 )
Expand All @@ -74,20 +14,11 @@ collision_layer = 2
collision_mask = 4
script = ExtResource( 1 )

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/bump = SubResource( 1 )
anims/walk = SubResource( 2 )

[node name="Tween" type="Tween" parent="."]

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

[node name="Sprite" type="Sprite" parent="Pivot"]
position = Vector2( -3.8147e-006, 20 )
scale = Vector2( 0.33389, 0.33389 )
texture = ExtResource( 2 )
centered = false
offset = Vector2( -175, -388 )
[node name="PawnAnim" parent="Pivot" instance=ExtResource( 2 )]

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 3 )
Expand Down
6 changes: 6 additions & 0 deletions godot/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://local_map/pawns/PawnActor.gd"
}, {
"base": "Position2D",
"class": "PawnAnim",
"language": "GDScript",
"path": "res://animation/PawnAnim.gd"
}, {
"base": "Node2D",
"class": "PawnFollower",
"language": "GDScript",
Expand Down Expand Up @@ -236,6 +241,7 @@ _global_script_class_icons={
"Pathfinder": "",
"Pawn": "",
"PawnActor": "",
"PawnAnim": "",
"PawnFollower": "",
"PawnLeader": "",
"RectExtents": "",
Expand Down

0 comments on commit 9e0bb7b

Please sign in to comment.