mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-20 20:33:11 +01:00
Add tweening to the card arrangement
This commit is contained in:
parent
306e852e73
commit
e2679fcec9
5 changed files with 57 additions and 12 deletions
8
card.gd
8
card.gd
|
@ -11,7 +11,7 @@ var _home_position = null
|
|||
|
||||
func _ready():
|
||||
set_process_unhandled_input(true)
|
||||
_home_position = position
|
||||
position = get_viewport_rect().size
|
||||
|
||||
func _process(delta):
|
||||
if dragged:
|
||||
|
@ -39,7 +39,7 @@ func _unhandled_input(event):
|
|||
else:
|
||||
move_back()
|
||||
else:
|
||||
_home_position = get_viewport().get_mouse_position() + drag_offset
|
||||
move_back()
|
||||
|
||||
func _mouse_entered():
|
||||
hovered = true
|
||||
|
@ -56,10 +56,10 @@ func move_back():
|
|||
|
||||
func buuurn():
|
||||
queue_free()
|
||||
$"..".draw_rand_card()
|
||||
#$"..".draw_rand_card()
|
||||
$"..".arrange_cards()
|
||||
|
||||
func dropped_on(other):
|
||||
#print("I have been dropped on "+str(other.id))
|
||||
var full_command = ""
|
||||
match arg_number:
|
||||
1:
|
||||
|
|
25
card.tscn
25
card.tscn
|
@ -1,8 +1,19 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://card.gd" type="Script" id=1]
|
||||
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=2]
|
||||
bg_color = Color( 0.145098, 0.529412, 0.682353, 1 )
|
||||
border_color = Color( 0.0627451, 0.141176, 0.176471, 1 )
|
||||
corner_radius_top_left = 10
|
||||
corner_radius_top_right = 10
|
||||
corner_radius_bottom_right = 10
|
||||
corner_radius_bottom_left = 10
|
||||
shadow_color = Color( 0, 0, 0, 0.392157 )
|
||||
shadow_size = 4
|
||||
shadow_offset = Vector2( -2, 2 )
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 105.74, 143.46 )
|
||||
|
||||
|
@ -11,7 +22,19 @@ extents = Vector2( 105.74, 143.46 )
|
|||
]]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
margin_left = -105.0
|
||||
margin_top = -291.0
|
||||
margin_right = 104.0
|
||||
margin_bottom = -2.0
|
||||
mouse_filter = 2
|
||||
custom_styles/panel = SubResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
visible = false
|
||||
margin_left = -103.0
|
||||
margin_top = -290.336
|
||||
margin_right = 103.0
|
||||
|
|
23
cardgame.gd
23
cardgame.gd
|
@ -12,7 +12,6 @@ var cards = [
|
|||
{"command": 'git reflog expire --expire=now --all; git prune', "arg_number": 0},
|
||||
{"command": 'git rebase', "arg_number": 1}
|
||||
]
|
||||
var total_angle = 45
|
||||
|
||||
func _ready():
|
||||
|
||||
|
@ -45,18 +44,32 @@ func draw_rand_card():
|
|||
arrange_cards()
|
||||
|
||||
func arrange_cards():
|
||||
var t = Timer.new()
|
||||
t.wait_time = 0.05
|
||||
add_child(t)
|
||||
t.start()
|
||||
yield(t, "timeout")
|
||||
|
||||
var amount_cards = get_tree().get_nodes_in_group("cards").size()
|
||||
var total_angle = 45.0/7*amount_cards
|
||||
var angle_between_cards = 0
|
||||
if amount_cards > 1:
|
||||
angle_between_cards = total_angle / (amount_cards-1)
|
||||
|
||||
var current_angle = -total_angle/2
|
||||
for card in get_tree().get_nodes_in_group("cards"):
|
||||
card.position = Vector2(get_viewport_rect().size.x/2, get_viewport_rect().size.y + 1500)
|
||||
card.rotation_degrees = current_angle
|
||||
var target_position = Vector2(get_viewport_rect().size.x/2, get_viewport_rect().size.y + 1500)
|
||||
var target_rotation = current_angle
|
||||
var translation_vec = Vector2(0,-1500).rotated(current_angle/180.0*PI)
|
||||
card.position += translation_vec
|
||||
print(current_angle)
|
||||
target_position += translation_vec
|
||||
current_angle += angle_between_cards
|
||||
card._home_position = target_position
|
||||
|
||||
var tween = Tween.new()
|
||||
tween.interpolate_property(card, "position", card.position, target_position, 0.5, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
||||
tween.interpolate_property(card, "rotation_degrees", card.rotation_degrees, target_rotation, 0.5, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
||||
add_child(tween)
|
||||
tween.start()
|
||||
|
||||
func redraw_all_cards():
|
||||
for card in get_tree().get_nodes_in_group("cards"):
|
||||
|
|
|
@ -8,10 +8,18 @@
|
|||
[node name="Cardgame" type="Node2D"]
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
margin_right = 1922.0
|
||||
margin_bottom = 1083.0
|
||||
mouse_filter = 2
|
||||
color = Color( 0.0823529, 0.0823529, 0.0823529, 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Repository" parent="." instance=ExtResource( 3 )]
|
||||
margin_right = 1481.0
|
||||
margin_bottom = 592.0
|
||||
file_browser_active = false
|
||||
simplified_view = true
|
||||
|
||||
[node name="DropArea" parent="." instance=ExtResource( 2 )]
|
||||
|
|
|
@ -37,7 +37,7 @@ __meta__ = {
|
|||
|
||||
[node name="TopHalf" type="Control" parent="Rows"]
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 980.0
|
||||
margin_bottom = 1052.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Output" type="RichTextLabel" parent="Rows/TopHalf"]
|
||||
|
@ -65,6 +65,7 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Rows"]
|
||||
visible = false
|
||||
margin_top = 984.0
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 1052.0
|
||||
|
|
Loading…
Reference in a new issue