spring
This commit is contained in:
parent
d581ccde06
commit
58807ec142
6 changed files with 142 additions and 1 deletions
18
objects/spring/spring.gd
Normal file
18
objects/spring/spring.gd
Normal file
|
@ -0,0 +1,18 @@
|
|||
extends Node2D
|
||||
|
||||
@export var bounce_power = 240.0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
body.velocity.y = -bounce_power
|
||||
%AnimationPlayer.play("bounce")
|
67
objects/spring/spring.tscn
Normal file
67
objects/spring/spring.tscn
Normal file
|
@ -0,0 +1,67 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://68lav5rke5ag"]
|
||||
|
||||
[ext_resource type="Script" path="res://objects/spring/spring.gd" id="1_05bif"]
|
||||
[ext_resource type="Texture2D" uid="uid://bobpl8pwm216q" path="res://assets/textures/spring/spring.png" id="1_s1olr"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_8kq4q"]
|
||||
resource_name = "bounce"
|
||||
length = 0.3
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 0
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.0666667, 0.1, 0.133333, 0.166667),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [1, 2, 3, 2, 0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_pa4d8"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_2p5yk"]
|
||||
_data = {
|
||||
"RESET": SubResource("Animation_pa4d8"),
|
||||
"bounce": SubResource("Animation_8kq4q")
|
||||
}
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_c7407"]
|
||||
size = Vector2(16, 11)
|
||||
|
||||
[node name="Spring" type="Node2D"]
|
||||
script = ExtResource("1_05bif")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
position = Vector2(0, -8)
|
||||
texture = ExtResource("1_s1olr")
|
||||
hframes = 4
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_2p5yk")
|
||||
}
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2(0, -5.5)
|
||||
shape = SubResource("RectangleShape2D_c7407")
|
||||
|
||||
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
|
Loading…
Add table
Add a link
Reference in a new issue