add falling block

This commit is contained in:
pennyrigate 2023-01-13 14:52:47 -05:00
parent d6547b61d4
commit 54f0880864
20 changed files with 153 additions and 26 deletions

View file

@ -0,0 +1,23 @@
extends Node2D
onready var anims = $AnimationPlayer
onready var timer = $Timer
export var time:float = 60
export(int, "Wood", "Yellow") var color
onready var time_frames = time * 0.0166666666666667 # Time is converted from ms to frames @ 60fps
func _ready():
#Autostart animationplayer
anims.play("idle")
timer.set_wait_time(time_frames)
timer.start()
func _on_AnimationPlayer_animation_finished(anim_name):
#Return to idle after turn animation
if anim_name == "turn":
anims.play("idle")
timer.set_wait_time(time_frames)
func _on_Timer_timeout():
anims.play("turn")

View file

@ -0,0 +1,113 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://objects/environment/turniwood/turniwood.gd" type="Script" id=1]
[ext_resource path="res://graphics/turniwood/turniwood_yellow.png" type="Texture" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 4, 1 )
[sub_resource type="Animation" id=2]
resource_name = "idle"
loop = true
step = 0.125
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:region_rect")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ Rect2( 0, 0, 8, 8 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Sprite:rotation_degrees")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ 0.0 ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("StaticBody2D/CollisionShape2D:disabled")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ false ]
}
[sub_resource type="Animation" id=3]
resource_name = "turn"
length = 0.5
step = 0.125
tracks/0/type = "value"
tracks/0/path = NodePath("StaticBody2D/CollisionShape2D:disabled")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.125, 0.5 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 1,
"values": [ false, true, false ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Sprite:region_rect")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.125, 0.25, 0.375, 0.5 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ Rect2( 0, 0, 8, 8 ), Rect2( 8, 0, 8, 8 ), Rect2( 0, 0, 8, 8 ), Rect2( 8, 0, 8, 8 ), Rect2( 0, 0, 8, 8 ) ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("Sprite:rotation_degrees")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 0.125, 0.25, 0.375, 0.5 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ 0.0, 90.0, 90.0, 0.0, 0.0 ]
}
[node name="Turniwood" type="Node2D"]
script = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 4, 4 )
texture = ExtResource( 2 )
region_enabled = true
region_rect = Rect2( 0, 0, 8, 8 )
[node name="StaticBody2D" type="StaticBody2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
position = Vector2( 4, 4 )
shape = SubResource( 1 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/idle = SubResource( 2 )
anims/turn = SubResource( 3 )
[node name="Timer" type="Timer" parent="."]
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_AnimationPlayer_animation_finished"]
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]