diff --git a/project.godot b/project.godot index 6bb0f23..624573e 100644 --- a/project.godot +++ b/project.godot @@ -154,6 +154,11 @@ place_tnt_block={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777240,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } +ignite_tnt={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":73,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} [rendering] diff --git a/scenes/game/tnt_block.tscn b/scenes/game/tnt_block.tscn index c869dbc..9fddaa9 100644 --- a/scenes/game/tnt_block.tscn +++ b/scenes/game/tnt_block.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://assets/tnt.png" type="Texture" id=1] [ext_resource path="res://assets/explosion.png" type="Texture" id=2] @@ -26,6 +26,72 @@ albedo_texture = ExtResource( 2 ) [sub_resource type="QuadMesh" id=5] material = SubResource( 4 ) +[sub_resource type="Animation" id=6] +resource_name = "explode" +length = 3.0 +tracks/0/type = "value" +tracks/0/path = NodePath("MeshInstance:visible") +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": [ false ] +} +tracks/1/type = "value" +tracks/1/path = NodePath("CollisionShape:disabled") +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": [ true ] +} +tracks/2/type = "value" +tracks/2/path = NodePath("Explosion:emitting") +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": [ true ] +} +tracks/3/type = "value" +tracks/3/path = NodePath("ExplosionSound:playing") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 1, +"values": [ true ] +} +tracks/4/type = "method" +tracks/4/path = NodePath(".") +tracks/4/interp = 1 +tracks/4/loop_wrap = true +tracks/4/imported = false +tracks/4/enabled = true +tracks/4/keys = { +"times": PoolRealArray( 3 ), +"transitions": PoolRealArray( 1 ), +"values": [ { +"args": [ ], +"method": "queue_free" +} ] +} + [node name="TNTBlock" type="StaticBody"] script = ExtResource( 3 ) @@ -49,15 +115,5 @@ initial_velocity = 100.0 [node name="ExplosionSound" type="AudioStreamPlayer3D" parent="."] stream = ExtResource( 4 ) -[node name="Timer" type="Timer" parent="."] -wait_time = 10.0 -one_shot = true -autostart = true - -[node name="Timer2" type="Timer" parent="."] -wait_time = 12.0 -one_shot = true -autostart = true - -[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] -[connection signal="timeout" from="Timer2" to="." method="queue_free"] +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/explode = SubResource( 6 ) diff --git a/scripts/game/TNTBlock.gd b/scripts/game/TNTBlock.gd index 0633306..6c78e6d 100644 --- a/scripts/game/TNTBlock.gd +++ b/scripts/game/TNTBlock.gd @@ -4,15 +4,13 @@ extends StaticBody const remove_radius = 5 var pw var chunk_size -onready var mesh_instance: MeshInstance = $MeshInstance -onready var explosion: CPUParticles = $Explosion -onready var explosion_sound: AudioStreamPlayer3D = $ExplosionSound +onready var animation_player: AnimationPlayer = $AnimationPlayer -func _on_timer_timeout(): - explosion.emitting = true - explosion_sound.play() - mesh_instance.hide() +func _physics_process(_delta): + if not Input.is_action_just_released("ignite_tnt"): + return + animation_player.play("explode") var changed_chunks: Array = [] for x in range(translation.x - 5, translation.x + 5): for y in range(translation.y - 5, translation.y + 5):