Separate animations, add some helper functions to draw cards

This commit is contained in:
Hamcha 2019-05-17 00:55:46 +02:00
parent a66f6258d5
commit c2ace7f531
Signed by: hamcha
GPG key ID: A40413D21021EAEE
4 changed files with 150 additions and 60 deletions

View file

@ -22,6 +22,7 @@ var cardMat = preload("res://MLPAssets/Placeholders/CardMat.tres")
var ready = false
onready var animation := $CardModel/Border/AnimationPlayer
onready var handanim := $CardModel/Border/HandAnimPlayer # Hack to get hand animations off the main queue
onready var cardImage := $CardModel/Border/CardImage
onready var texture: Texture = cardImage.get_surface_material(0)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=2]
[gd_scene load_steps=18 format=2]
[ext_resource path="res://Scenes/Components/Card.gd" type="Script" id=1]
[ext_resource path="res://MLPAssets/Models/cardborder.obj" type="ArrayMesh" id=2]
@ -9,22 +9,7 @@
margin = 0.001
extents = Vector3( 0.353, 0.001, 0.481 )
[sub_resource type="Animation" id=2]
resource_name = "blur"
length = 0.1
step = 0.01
tracks/0/type = "bezier"
tracks/0/path = NodePath("..:translation:z")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"points": PoolRealArray( -0.2, -0.0265325, 0.00965191, 0.0265325, -0.00965191, 0, -0.0730773, 0.0262065, 0.0730773, -0.0262065 ),
"times": PoolRealArray( 0, 0.1 )
}
[sub_resource type="Animation" id=11]
[sub_resource type="Animation" id=3]
resource_name = "drop-board"
length = 0.3
step = 0.05
@ -51,8 +36,7 @@ tracks/1/keys = {
"times": PoolRealArray( 0, 0.2, 0.3 )
}
[sub_resource type="Animation" id=3]
resource_name = "drop-hand"
[sub_resource type="Animation" id=4]
length = 0.1
step = 0.05
tracks/0/type = "value"
@ -68,8 +52,7 @@ tracks/0/keys = {
"values": [ Vector3( 0, 0.15, 0 ), Vector3( 0, 0, 0 ) ]
}
[sub_resource type="Animation" id=4]
resource_name = "flip"
[sub_resource type="Animation" id=5]
length = 0.5
step = 0.05
tracks/0/type = "value"
@ -97,7 +80,7 @@ tracks/1/keys = {
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 180 ) ]
}
[sub_resource type="Animation" id=9]
[sub_resource type="Animation" id=6]
resource_name = "flip-back"
length = 0.5
step = 0.05
@ -126,21 +109,65 @@ tracks/1/keys = {
"values": [ Vector3( 0, 0, 180 ), Vector3( 0, 0, 0 ) ]
}
[sub_resource type="Animation" id=5]
length = 0.1
step = 0.01
tracks/0/type = "bezier"
tracks/0/path = NodePath("..:translation:z")
tracks/0/interp = 1
[sub_resource type="Animation" id=20]
resource_name = "flip-back-fast"
length = 0.25
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath(".:translation")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"points": PoolRealArray( 0, -0.0120957, 0.235858, 0.0120957, -0.235858, -0.2, -0.0266453, -0.000916421, 0.0266453, 0.000916421 ),
"times": PoolRealArray( 0, 0.1 )
"times": PoolRealArray( 0, 0.25 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0.5, 0 ), Vector3( 0, 0, 0 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath(".:rotation_degrees")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.25 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0, 90 ), Vector3( 0, 0, 0 ) ]
}
[sub_resource type="Animation" id=6]
[sub_resource type="Animation" id=7]
resource_name = "flip-fast"
length = 0.2
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath(".:translation")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0.5, 0 ), Vector3( 0, 0.01, 0 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath(".:rotation_degrees")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0, -150 ), Vector3( 0, 0, -180 ) ]
}
[sub_resource type="Animation" id=9]
length = 0.3
step = 0.05
tracks/0/type = "value"
@ -166,7 +193,7 @@ tracks/1/keys = {
"times": PoolRealArray( 0, 0.112663, 0.3 )
}
[sub_resource type="Animation" id=7]
[sub_resource type="Animation" id=10]
length = 0.3
tracks/0/type = "value"
tracks/0/path = NodePath("..:rotation_degrees")
@ -181,8 +208,7 @@ tracks/0/keys = {
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, -90, 0 ) ]
}
[sub_resource type="Animation" id=10]
resource_name = "tap-back"
[sub_resource type="Animation" id=11]
length = 0.3
tracks/0/type = "value"
tracks/0/path = NodePath("..:rotation_degrees")
@ -197,7 +223,36 @@ tracks/0/keys = {
"values": [ Vector3( 0, -90, 0 ), Vector3( 0, 0, 0 ) ]
}
[sub_resource type="PlaneMesh" id=8]
[sub_resource type="Animation" id=13]
resource_name = "blur"
length = 0.1
step = 0.01
tracks/0/type = "bezier"
tracks/0/path = NodePath("..:translation:z")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"points": PoolRealArray( -0.2, -0.0265325, 0.00965191, 0.0265325, -0.00965191, 0, -0.0730773, 0.0262065, 0.0730773, -0.0262065 ),
"times": PoolRealArray( 0, 0.1 )
}
[sub_resource type="Animation" id=19]
length = 0.1
step = 0.01
tracks/0/type = "bezier"
tracks/0/path = NodePath("..:translation:z")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"points": PoolRealArray( 0, -0.0120957, 0.235858, 0.0120957, -0.235858, -0.2, -0.0266453, -0.000916421, 0.0266453, 0.000916421 ),
"times": PoolRealArray( 0, 0.1 )
}
[sub_resource type="PlaneMesh" id=12]
[node name="Card" type="Area"]
input_capture_on_drag = true
@ -208,25 +263,30 @@ transform = Transform( 1, 0, 0, 0, 1.17955, 0, 0, 0, 1, 0, 0.000197917, 0 )
shape = SubResource( 1 )
[node name="CardModel" type="Spatial" parent="."]
transform = Transform( 0.999409, 0.0343663, 0, -0.0343663, 0.999409, 0, 0, 0, 1, 0, 0.0986242, 0 )
[node name="Border" type="MeshInstance" parent="CardModel"]
mesh = ExtResource( 2 )
material/0 = ExtResource( 3 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="CardModel/Border"]
anims/blur = SubResource( 2 )
anims/drop-board = SubResource( 11 )
anims/drop-hand = SubResource( 3 )
anims/flip = SubResource( 4 )
anims/flip-back = SubResource( 9 )
anims/focus = SubResource( 5 )
anims/lift = SubResource( 6 )
anims/tap = SubResource( 7 )
anims/tap-back = SubResource( 10 )
anims/drop-board = SubResource( 3 )
anims/drop-hand = SubResource( 4 )
anims/flip = SubResource( 5 )
anims/flip-back = SubResource( 6 )
anims/flip-back-fast = SubResource( 20 )
anims/flip-fast = SubResource( 7 )
anims/lift = SubResource( 9 )
anims/tap = SubResource( 10 )
anims/tap-back = SubResource( 11 )
[node name="HandAnimPlayer" type="AnimationPlayer" parent="CardModel/Border"]
anims/blur = SubResource( 13 )
anims/focus = SubResource( 19 )
[node name="CardImage" type="MeshInstance" parent="CardModel/Border"]
transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.009, 0 )
mesh = SubResource( 8 )
mesh = SubResource( 12 )
material/0 = ExtResource( 4 )
[node name="Tween" type="Tween" parent="."]
@ -234,3 +294,4 @@ material/0 = ExtResource( 4 )
[connection signal="mouse_entered" from="." to="." method="_mouse_hover"]
[connection signal="mouse_exited" from="." to="." method="_mouse_blur"]
[connection signal="animation_finished" from="CardModel/Border/AnimationPlayer" to="." method="_check_drop_anim"]
[connection signal="animation_finished" from="CardModel/Border/HandAnimPlayer" to="." method="_check_drop_anim"]

View file

@ -28,6 +28,10 @@ func _mouse_exited():
emit_signal("blur")
func push_card(card):
# Flip card is stack has face-down cards
if faceDown:
card.flipped = true
card.animation.queue("flip-fast")
# Disable collider for top card
if cards.size() > 0:
cards[0].disableInput()
@ -37,13 +41,15 @@ func push_card(card):
func pop_card() -> Card:
if cards.size() < 1:
return null
var card: Card = cards.pop_front()
var card := cards.pop_front() as Card
reorder_cards()
if cards.size() > 0:
cards[0].enableInput()
if faceDown:
card.flipped = false
return card
const CARD_DISTANCE = 0.01
const CARD_DISTANCE = 0.005
func reorder_cards():
var i := 0

View file

@ -31,9 +31,21 @@ onready var zones: Dictionary = {
}
func _ready():
add_card("pr12", 0, false)
reorder_hand(0)
reorder_hand(1)
# Sample deck
var deck = [
"pr10","pr11","pr12","pr13","pr14","pr15","pr16","pr12","pr13","pr14",
"pr10","pr11","pr12","pr13","pr14","pr15","pr16","pr12","pr13","pr14",
"pr10","pr11","pr12","pr13","pr14","pr15","pr16","pr12","pr13","pr14",
"pr10","pr11","pr12","pr13","pr14","pr15","pr16","pr12","pr13","pr14",
"pr10","pr11","pr12","pr13","pr14","pr15","pr16","pr12","pr13","pr14"
]
# Fill deck with cards
for card in deck:
add_card(card, 0, "player1.deck")
#TODO Shuffle deck
#TODO Draw cards from deck
for i in range(0,6):
draw_card(0, "player1.deck")
func _input(event: InputEvent):
# Camera zoom
@ -75,11 +87,9 @@ func _process(delta: float):
# Move from old zone to new
call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], currentZone)
holdingCard.zoneName = currentZone.zoneName
holdingCard.flipped = currentZone.faceDown
else:
holdingCard.inZone = true
holdingCard.zoneName = currentZone.zoneName
holdingCard.flipped = currentZone.faceDown
if holdingCard.inHand:
call_deferred("reparent", holdingCard, hand, currentZone)
else:
@ -118,22 +128,21 @@ func _card_dropped(card: Card):
if card.inHand:
card.animation.queue("drop-hand")
reorder_hand(0)
else:
card.animation.queue("drop-board")
if currentZone != null:
elif currentZone != null:
card.inZone = true
currentZone.push_card(card)
card.animation.queue("drop-board")
holdingCard = null
func _card_selected(card: Card):
if card.inHand and focusedCard == null:
focusedCard = card
card.animation.queue("focus")
card.handanim.play("focus")
func _card_unselected(card: Card):
if focusedCard == card:
focusedCard = null
card.animation.queue("blur")
card.handanim.play("blur")
func reparent(object: Node, from: Node, to: Node):
from.remove_child(object)
@ -141,11 +150,11 @@ func reparent(object: Node, from: Node, to: Node):
object.set_owner(to)
reorder_hand(0)
func add_card(cardID: String, playerID: int, inHand: bool):
func add_card(cardID: String, playerID: int, zone: String):
var card := CardTemplate.instance()
card.cardID = cardID
card.playerID = playerID
card.inHand = inHand
card.inHand = zone == "hand"
card.connect("card_dropped", self, "_card_dropped", [card])
card.connect("card_picked", self, "_card_picked", [card])
card.connect("card_selected", ui, "_card_selected", [card])
@ -154,15 +163,28 @@ func add_card(cardID: String, playerID: int, inHand: bool):
card.connect("card_unselected", self, "_card_unselected", [card])
card.connect("card_dropped_anim", self, "check_hand_drop", [card])
card.connect("card_menu", ui, "show_card_menu", [card])
if inHand:
if card.inHand:
# TODO support for >2 players
if playerID == 0:
hand.add_child(card)
else:
oppHand.add_child(card)
elif zones.has(zone):
card.inZone = true
card.zoneName = zone
zones[zone].add_child(card)
zones[zone].push_card(card)
else:
cards.add_child(card)
func draw_card(playerID: int, from: String):
var card := (zones[from] as Stack).pop_card()
card.inHand = true
card.inZone = false
card.flipped = false
card.animation.queue("flip-back-fast")
reparent(card, zones[from], hand)
func check_hand_drop(card: Card):
# Re-order hand as soon as the animation is over
if card.inHand: