Finished with the bunny. As far as I know there are no bugs with it.
This commit is contained in:
@@ -4,18 +4,26 @@ extends Node2D
|
||||
@onready var wait_timer: Timer = $WaitTimer
|
||||
@onready var collision_shape_2d: CollisionShape2D = $Area2D/CollisionShape2D
|
||||
@onready var death_collision_box: CollisionShape2D = $DeathBox/DeathCollisionBox
|
||||
@onready var hit_box_wait: Timer = $HitBoxWait
|
||||
@onready var animation_timer: Timer = $AnimationTimer
|
||||
@onready var death_sound: AudioStreamPlayer2D = $DeathSound
|
||||
|
||||
var direction :float = 1.0
|
||||
const SPEED = 150
|
||||
|
||||
signal player_died
|
||||
var wait :bool = false
|
||||
var alive :bool = true
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if !alive:
|
||||
return
|
||||
if !wait:
|
||||
position.x += direction * SPEED * delta
|
||||
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
if !alive:
|
||||
return
|
||||
if body.name == "player":
|
||||
emit_signal("player_died", body)
|
||||
else:
|
||||
@@ -24,11 +32,14 @@ func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
animated_sprite_2d.animation = "idle"
|
||||
animated_sprite_2d.flip_h = !animated_sprite_2d.flip_h
|
||||
wait_timer.start()
|
||||
print(body)
|
||||
|
||||
|
||||
func _on_wait_timer_timeout() -> void:
|
||||
if !alive:
|
||||
return
|
||||
animated_sprite_2d.animation = "run"
|
||||
_death_box_disabled()
|
||||
hit_box_wait.start()
|
||||
wait = false
|
||||
direction *= -1
|
||||
|
||||
@@ -41,4 +52,15 @@ func _death_box_disabled() -> void:
|
||||
death_collision_box.set_deferred("disabled", true)
|
||||
|
||||
func _on_death_box_body_entered(body: Node2D) -> void:
|
||||
print("Dead")
|
||||
if body.name == "player":
|
||||
alive = false
|
||||
animated_sprite_2d.animation = "die"
|
||||
death_sound.play()
|
||||
animation_timer.start()
|
||||
|
||||
func _on_hit_box_wait_timeout() -> void:
|
||||
_death_box_disabled()
|
||||
|
||||
|
||||
func _on_animation_timer_timeout() -> void:
|
||||
queue_free()
|
||||
|
||||
+87
-5
@@ -3,6 +3,44 @@
|
||||
[ext_resource type="Script" uid="uid://br5jkh3x703qw" path="res://bunny.gd" id="1_dvrf6"]
|
||||
[ext_resource type="Texture2D" uid="uid://nr1dxc1p6fe8" path="res://assets/images/Bunny/BunnyRun-Sheet.png" id="1_u834r"]
|
||||
[ext_resource type="Texture2D" uid="uid://bl55ade1p47rf" path="res://assets/images/Bunny/BunnyIdle-Sheet.png" id="2_e4qck"]
|
||||
[ext_resource type="Texture2D" uid="uid://ckphhkwwkoel1" path="res://assets/images/Bunny/BunnyDead-Sheet.png" id="2_gs0sc"]
|
||||
[ext_resource type="AudioStream" uid="uid://7pkqsi6fv8hb" path="res://assets/sounds/squish.mp3" id="5_g7ptr"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_m81kn"]
|
||||
atlas = ExtResource("2_gs0sc")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_njyta"]
|
||||
atlas = ExtResource("2_gs0sc")
|
||||
region = Rect2(32, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wtqm1"]
|
||||
atlas = ExtResource("2_gs0sc")
|
||||
region = Rect2(64, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_yryj1"]
|
||||
atlas = ExtResource("2_gs0sc")
|
||||
region = Rect2(96, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_p8qhu"]
|
||||
atlas = ExtResource("2_gs0sc")
|
||||
region = Rect2(128, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_u1wgj"]
|
||||
atlas = ExtResource("2_gs0sc")
|
||||
region = Rect2(160, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_mtq28"]
|
||||
atlas = ExtResource("2_gs0sc")
|
||||
region = Rect2(192, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_82yh4"]
|
||||
atlas = ExtResource("2_gs0sc")
|
||||
region = Rect2(224, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ppqc4"]
|
||||
atlas = ExtResource("2_gs0sc")
|
||||
region = Rect2(256, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_5ecvt"]
|
||||
atlas = ExtResource("2_e4qck")
|
||||
@@ -60,6 +98,38 @@ region = Rect2(128, 0, 32, 32)
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_m81kn")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_njyta")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_wtqm1")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_yryj1")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_p8qhu")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_u1wgj")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_mtq28")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_82yh4")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ppqc4")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"die",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_5ecvt")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
@@ -85,7 +155,7 @@ animations = [{
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"idle",
|
||||
"speed": 5.0
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
@@ -112,7 +182,7 @@ animations = [{
|
||||
size = Vector2(19, 21)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_e4qck"]
|
||||
size = Vector2(14, 4)
|
||||
size = Vector2(19, 4)
|
||||
|
||||
[node name="Bunny" type="Node2D" unique_id=1276098802]
|
||||
script = ExtResource("1_dvrf6")
|
||||
@@ -120,13 +190,12 @@ script = ExtResource("1_dvrf6")
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=623860503]
|
||||
texture_filter = 1
|
||||
sprite_frames = SubResource("SpriteFrames_5ecvt")
|
||||
animation = &"idle"
|
||||
animation = &"die"
|
||||
autoplay = "run"
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="." unique_id=83756394]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=286806552]
|
||||
visible = false
|
||||
position = Vector2(-0.5, -0.5)
|
||||
shape = SubResource("RectangleShape2D_u834r")
|
||||
|
||||
@@ -136,9 +205,22 @@ one_shot = true
|
||||
[node name="DeathBox" type="Area2D" parent="." unique_id=78599148]
|
||||
|
||||
[node name="DeathCollisionBox" type="CollisionShape2D" parent="DeathBox" unique_id=993689400]
|
||||
position = Vector2(-3, -8)
|
||||
position = Vector2(-0.5, -8)
|
||||
shape = SubResource("RectangleShape2D_e4qck")
|
||||
|
||||
[node name="HitBoxWait" type="Timer" parent="." unique_id=2135714409]
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[node name="AnimationTimer" type="Timer" parent="." unique_id=1085040144]
|
||||
wait_time = 0.75
|
||||
one_shot = true
|
||||
|
||||
[node name="DeathSound" type="AudioStreamPlayer2D" parent="." unique_id=1645161094]
|
||||
stream = ExtResource("5_g7ptr")
|
||||
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
|
||||
[connection signal="timeout" from="WaitTimer" to="." method="_on_wait_timer_timeout"]
|
||||
[connection signal="body_entered" from="DeathBox" to="." method="_on_death_box_body_entered"]
|
||||
[connection signal="timeout" from="HitBoxWait" to="." method="_on_hit_box_wait_timeout"]
|
||||
[connection signal="timeout" from="AnimationTimer" to="." method="_on_animation_timer_timeout"]
|
||||
|
||||
+8
-6
@@ -235,12 +235,14 @@ horizontal_alignment = 1
|
||||
[node name="Label3" type="Label" parent="Instructions" unique_id=854653857]
|
||||
texture_filter = 1
|
||||
layout_mode = 0
|
||||
offset_left = 1258.0
|
||||
offset_top = -81.0
|
||||
offset_right = 1376.0
|
||||
offset_bottom = -58.0
|
||||
offset_left = 1222.6666
|
||||
offset_top = -107.66667
|
||||
offset_right = 1411.6666
|
||||
offset_bottom = -32.66667
|
||||
theme_override_font_sizes/font_size = 16
|
||||
text = "Some you can't"
|
||||
text = "Some you can only jump
|
||||
on when they are not
|
||||
moving"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Label4" type="Label" parent="Instructions" unique_id=2059209276]
|
||||
@@ -290,6 +292,6 @@ position = Vector2(971.3333, -150)
|
||||
position = Vector2(716, -150.33333)
|
||||
|
||||
[node name="Bunny" parent="Enemies" unique_id=1276098802 instance=ExtResource("4_v38iq")]
|
||||
position = Vector2(1300, 27)
|
||||
position = Vector2(1301, 27.666668)
|
||||
|
||||
[node name="Apples" type="Node2D" parent="." unique_id=1812140522]
|
||||
|
||||
Reference in New Issue
Block a user