diff --git a/Scenes/Animations/rockThrowAnim.tscn b/Scenes/Animations/rockThrowAnim.tscn index c503478..3f72603 100644 --- a/Scenes/Animations/rockThrowAnim.tscn +++ b/Scenes/Animations/rockThrowAnim.tscn @@ -1,14 +1,8 @@ -[gd_scene load_steps=6 format=3 uid="uid://c44hesqr12wxd"] +[gd_scene load_steps=11 format=3 uid="uid://c44hesqr12wxd"] [ext_resource type="Script" path="res://Scripts/Animations/rockThrowAnim.gd" id="1_owh0v"] [ext_resource type="Texture2D" uid="uid://dwsd0hggrxbdq" path="res://Sprites/Animations/Rock Pack/Rocks 64x64 by Captainskeleto.png" id="2_addwy"] -[sub_resource type="Curve2D" id="Curve2D_gdix6"] -_data = { -"points": PackedVector2Array(0, 0, 0, 0, 371, 664, 0, 0, 0, 0, 370, 481, 0, 0, 0, 0, 373, 311, 0, 0, 0, 0, 882, 362) -} -point_count = 4 - [sub_resource type="Curve2D" id="Curve2D_m36l3"] _data = { "points": PackedVector2Array(0, 0, 0, 0, 30, 39, 0, 0, 0, 0, 69, 45, 0, 0, 0, 0, 114, 61, 0, 0, 0, 0, 164, 98, 0, 0, 0, 0, 217, 179, 0, 0, 0, 0, 258, 318, 0, 0, 0, 0, 272, 436, 0, 0, 0, 0, 281, 600) @@ -19,9 +13,111 @@ point_count = 8 atlas = ExtResource("2_addwy") region = Rect2(128, 192, 64, 64) +[sub_resource type="Curve2D" id="Curve2D_gdix6"] +_data = { +"points": PackedVector2Array(0, 0, 0, 0, 371, 664, 0, 0, 0, 0, 370, 481, 0, 0, 0, 0, 373, 311, 0, 0, 0, 0, 882, 362) +} +point_count = 4 + +[sub_resource type="Animation" id="Animation_7dh1k"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("TextureRect:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector2(342, 645)] +} + +[sub_resource type="Animation" id="Animation_cfsn4"] +resource_name = "attackSegment1" +length = 0.5 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("TextureRect:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = false +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.49), +"transitions": PackedFloat32Array(1, 1), +"update": 2, +"values": [Vector2(342, 645), Vector2(342, 440)] +} + +[sub_resource type="Animation" id="Animation_uphdx"] +resource_name = "attackSegment2" +length = 0.5 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("TextureRect:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.5), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [Vector2(342, 440), Vector2(342, 280)] +} + +[sub_resource type="Animation" id="Animation_mlgwv"] +resource_name = "attackSegment3" +length = 0.23 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("TextureRect:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.23), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [Vector2(342, 280), Vector2(852, 331)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_cg24k"] +_data = { +"RESET": SubResource("Animation_7dh1k"), +"attackSegment1": SubResource("Animation_cfsn4"), +"attackSegment2": SubResource("Animation_uphdx"), +"attackSegment3": SubResource("Animation_mlgwv") +} + [node name="RockThrowAnim" type="Node2D"] script = ExtResource("1_owh0v") +[node name="Path2D2" type="Path2D" parent="."] +position = Vector2(339, 632) +curve = SubResource("Curve2D_m36l3") + +[node name="PathFollow2D" type="PathFollow2D" parent="Path2D2"] +position = Vector2(30, 39) +rotation = 0.152649 +rotates = false +loop = false + +[node name="TextureRect" type="TextureRect" parent="."] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = 342.0 +offset_top = 645.0 +offset_right = 406.0 +offset_bottom = 709.0 +grow_horizontal = 2 +grow_vertical = 2 +pivot_offset = Vector2(31.8413, 32.0651) +texture = SubResource("AtlasTexture_wqvpx") + [node name="Path2D" type="Path2D" parent="."] curve = SubResource("Curve2D_gdix6") @@ -30,27 +126,9 @@ position = Vector2(371, 664) rotates = false loop = false -[node name="Path2D" type="Path2D" parent="Path2D/PathFollow2D"] -position = Vector2(-32, -32) -curve = SubResource("Curve2D_m36l3") +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_cg24k") +} -[node name="PathFollow2D" type="PathFollow2D" parent="Path2D/PathFollow2D/Path2D"] -position = Vector2(30, 39) -rotation = 0.152649 -rotates = false -loop = false - -[node name="TextureRect" type="TextureRect" parent="Path2D/PathFollow2D"] -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -32.0 -offset_top = -32.0 -offset_right = 32.0 -offset_bottom = 32.0 -grow_horizontal = 2 -grow_vertical = 2 -pivot_offset = Vector2(31.8413, 32.0651) -texture = SubResource("AtlasTexture_wqvpx") +[connection signal="animation_finished" from="AnimationPlayer" to="." method="animFinished"] diff --git a/Scripts/Animations/rockThrowAnim.gd b/Scripts/Animations/rockThrowAnim.gd index 49268ae..d5ad0c5 100644 --- a/Scripts/Animations/rockThrowAnim.gd +++ b/Scripts/Animations/rockThrowAnim.gd @@ -1,39 +1,59 @@ extends "res://Scripts/animationBase.gd" -var path: PathFollow2D -var failPath: PathFollow2D -var casting: bool = true -var timer: float = 0 -@onready var texture: TextureRect = $Path2D/PathFollow2D/TextureRect +@onready var texture: TextureRect = $TextureRect +@onready var animationPlayer: AnimationPlayer = $AnimationPlayer + +var failIndex: int = 0 +var animQueue: Queue = Queue.new() # Called when the node enters the scene tree for the first time. func _ready(): - if !inverted: - path = $Path2D/PathFollow2D - failPath = $Path2D/PathFollow2D/Path2D/PathFollow2D - else: - path = $Path2D/PathFollow2D - failPath = $Path2D/PathFollow2D/Path2D/PathFollow2D + if inverted: + pass + #texture.position.x = (-(texture.position.x - 571)) + 571 + #for point: Vector2 in path: + #point.x = (-(point.x - 571)) + 571 + #for point: Vector2 in failPath: + #point.x = (-(point.x - 571)) + 571 + #if !inverted: + #pass + #path = $Path2D/PathFollow2D + #failPath = $Path2D/PathFollow2D/Path2D/PathFollow2D + #else: + #pass + #path = $Path2D/PathFollow2D + #failPath = $Path2D/PathFollow2D/Path2D/PathFollow2D # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): - if casting: - if targetProg / finalProg < 0.7: - timer = clampf(timer + delta, 0, clampf(targetProg / finalProg, 0, 0.35)) - path.progress_ratio = timer - else: - timer = clampf(timer + delta, 0, 1) - path.progress_ratio = timer - if path.progress_ratio == 1: - self.free() - else: - timer = clampf(timer + (1.25 * delta), 0, 1) - failPath.progress_ratio = timer - if failPath.progress_ratio == 1: - self.free() + pass + #if casting: + #if targetProg / finalProg < 0.7: + #timer = clampf(timer + delta, 0, clampf(targetProg / finalProg, 0, 0.35)) + #path.progress_ratio = timer + #else: + #timer = clampf(timer + delta, 0, 1) + #path.progress_ratio = timer + #if path.progress_ratio == 1: + #self.free() + #else: + #timer = clampf(timer + (1.25 * delta), 0, 1) + #failPath.progress_ratio = timer + #if failPath.progress_ratio == 1: + #self.free() func castFailed() -> void: - casting = false - texture.get_parent().remove_child(texture) - failPath.add_child(texture) - timer = 0 + queue_free() + #casting = false + #timer = 0 + #texture.get_parent().remove_child(texture) + #failPath.add_child(texture) + +func setProgress(target: float, final: float = finalProg) -> void: + targetProg = target + finalProg = final + animQueue.push("attackSegment" + str(target)) + +func animFinished(_animName): + if (animQueue.size() > 0): + animationPlayer.play(animQueue.pop()) diff --git a/Scripts/Queue.gd b/Scripts/Queue.gd new file mode 100644 index 0000000..84565c3 --- /dev/null +++ b/Scripts/Queue.gd @@ -0,0 +1,15 @@ +class_name Queue extends Object + +var items: Array + +func push(item): + items.append(item) + +func pop(): + return items.pop_front() + +func peek(): + return items[0] + +func size(): + return items.size() diff --git a/Scripts/data.gd b/Scripts/data.gd index 50891f1..2676309 100644 --- a/Scripts/data.gd +++ b/Scripts/data.gd @@ -1,6 +1,4 @@ -extends Node - -class_name Data +class_name Data extends Node enum Element{ NORMAL, diff --git a/project.godot b/project.godot index 2f4869a..b495151 100644 --- a/project.godot +++ b/project.godot @@ -17,7 +17,6 @@ config/icon="res://icon.svg" [display] -window/size/mode=3 window/stretch/mode="canvas_items" window/stretch/aspect="keep_width" mouse_cursor/custom_image_hotspot=Vector2(64, 128)