implement block logic
This commit is contained in:
parent
51ee11b6ce
commit
6fc89f832c
50
scenes/block/Block.cs
Normal file
50
scenes/block/Block.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public class Block : StaticBody2D
|
||||||
|
{
|
||||||
|
private AnimatedSprite _sprite;
|
||||||
|
private AnimationPlayer _animation;
|
||||||
|
private Area2D _bolt;
|
||||||
|
private AnimationPlayer _boltAnimation;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
_sprite = GetNode<AnimatedSprite>("AnimatedSprite");
|
||||||
|
_animation = GetNode<AnimationPlayer>("AnimationPlayer");
|
||||||
|
_bolt = GetNode<Area2D>("Bolt");
|
||||||
|
_boltAnimation = GetNode<AnimationPlayer>("Bolt/AnimationPlayer");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Hit()
|
||||||
|
{
|
||||||
|
if (_animation.HasAnimation("hit"))
|
||||||
|
{
|
||||||
|
_animation.Play("hit");
|
||||||
|
_boltAnimation.Play("bounce");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnAnimationPlayerAnimationFinished(string AnimName)
|
||||||
|
{
|
||||||
|
GD.Print(AnimName);
|
||||||
|
if (AnimName.Equals("hit"))
|
||||||
|
{
|
||||||
|
_sprite.Play("opened");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AnimName.Equals("bounce"))
|
||||||
|
{
|
||||||
|
if (_bolt.HasMethod("Collected"))
|
||||||
|
{
|
||||||
|
_bolt.CallDeferred("Collected");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_bolt.QueueFree();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
[gd_scene load_steps=6 format=2]
|
[gd_scene load_steps=10 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://assets/block/block.png" type="Texture" id=1]
|
[ext_resource path="res://assets/block/block.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://scenes/collectables/Bolt.tscn" type="PackedScene" id=2]
|
||||||
|
[ext_resource path="res://scenes/block/Block.cs" type="Script" id=3]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id=1]
|
[sub_resource type="AtlasTexture" id=1]
|
||||||
atlas = ExtResource( 1 )
|
atlas = ExtResource( 1 )
|
||||||
@ -26,7 +28,40 @@ animations = [ {
|
|||||||
[sub_resource type="RectangleShape2D" id=4]
|
[sub_resource type="RectangleShape2D" id=4]
|
||||||
extents = Vector2( 8, 8 )
|
extents = Vector2( 8, 8 )
|
||||||
|
|
||||||
[node name="MysteryBlock" type="StaticBody2D"]
|
[sub_resource type="Animation" id=5]
|
||||||
|
resource_name = "hit"
|
||||||
|
length = 0.2
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("AnimatedSprite:position")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.1, 0.2 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1 ),
|
||||||
|
"update": 0,
|
||||||
|
"values": [ Vector2( 0, 0 ), Vector2( 0, -4 ), Vector2( 0, 0 ) ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=6]
|
||||||
|
resource_name = "bounce"
|
||||||
|
length = 0.4
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath(".:position")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.2, 0.4 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1 ),
|
||||||
|
"update": 0,
|
||||||
|
"values": [ Vector2( 0, 0 ), Vector2( 0, -16 ), Vector2( 0, 0 ) ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="MysteryBlock" type="StaticBody2D" groups=["Block"]]
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
frames = SubResource( 3 )
|
frames = SubResource( 3 )
|
||||||
@ -37,3 +72,19 @@ centered = false
|
|||||||
visible = false
|
visible = false
|
||||||
position = Vector2( 8, 8 )
|
position = Vector2( 8, 8 )
|
||||||
shape = SubResource( 4 )
|
shape = SubResource( 4 )
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||||
|
anims/hit = SubResource( 5 )
|
||||||
|
|
||||||
|
[node name="Bolt" parent="." instance=ExtResource( 2 )]
|
||||||
|
z_index = -1
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 0
|
||||||
|
monitoring = false
|
||||||
|
monitorable = false
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="Bolt"]
|
||||||
|
anims/bounce = SubResource( 6 )
|
||||||
|
|
||||||
|
[connection signal="animation_finished" from="AnimationPlayer" to="." method="OnAnimationPlayerAnimationFinished"]
|
||||||
|
[connection signal="animation_finished" from="Bolt/AnimationPlayer" to="." method="OnAnimationPlayerAnimationFinished"]
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
[gd_scene load_steps=6 format=2]
|
[gd_scene load_steps=10 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://assets/block/cave_block.png" type="Texture" id=1]
|
[ext_resource path="res://assets/block/cave_block.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://scenes/block/Block.cs" type="Script" id=2]
|
||||||
|
[ext_resource path="res://scenes/collectables/Bolt.tscn" type="PackedScene" id=3]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id=5]
|
[sub_resource type="AtlasTexture" id=5]
|
||||||
atlas = ExtResource( 1 )
|
atlas = ExtResource( 1 )
|
||||||
@ -26,7 +28,40 @@ animations = [ {
|
|||||||
[sub_resource type="RectangleShape2D" id=4]
|
[sub_resource type="RectangleShape2D" id=4]
|
||||||
extents = Vector2( 8, 8 )
|
extents = Vector2( 8, 8 )
|
||||||
|
|
||||||
[node name="MysteryBlockCave" type="StaticBody2D"]
|
[sub_resource type="Animation" id=7]
|
||||||
|
resource_name = "hit"
|
||||||
|
length = 0.2
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("AnimatedSprite:position")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.1, 0.2 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1 ),
|
||||||
|
"update": 0,
|
||||||
|
"values": [ Vector2( 0, 0 ), Vector2( 0, -4 ), Vector2( 0, 0 ) ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=8]
|
||||||
|
resource_name = "bounce"
|
||||||
|
length = 0.4
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath(".:position")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.2, 0.4 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1 ),
|
||||||
|
"update": 0,
|
||||||
|
"values": [ Vector2( 0, 0 ), Vector2( 0, -16 ), Vector2( 0, 0 ) ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="MysteryBlockCave" type="StaticBody2D" groups=["Block"]]
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
frames = SubResource( 3 )
|
frames = SubResource( 3 )
|
||||||
@ -37,3 +72,19 @@ centered = false
|
|||||||
visible = false
|
visible = false
|
||||||
position = Vector2( 8, 8 )
|
position = Vector2( 8, 8 )
|
||||||
shape = SubResource( 4 )
|
shape = SubResource( 4 )
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||||
|
anims/hit = SubResource( 7 )
|
||||||
|
|
||||||
|
[node name="Bolt" parent="." instance=ExtResource( 3 )]
|
||||||
|
z_index = -1
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 0
|
||||||
|
monitoring = false
|
||||||
|
monitorable = false
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="Bolt"]
|
||||||
|
anims/bounce = SubResource( 8 )
|
||||||
|
|
||||||
|
[connection signal="animation_finished" from="AnimationPlayer" to="." method="OnAnimationPlayerAnimationFinished"]
|
||||||
|
[connection signal="animation_finished" from="Bolt/AnimationPlayer" to="." method="OnAnimationPlayerAnimationFinished"]
|
||||||
|
Loading…
Reference in New Issue
Block a user