Skip to content

Commit

Permalink
Working on frog death animation
Browse files Browse the repository at this point in the history
  • Loading branch information
willow-carroll-polzin committed Jan 29, 2024
1 parent b4d57e7 commit 890ce22
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
20 changes: 15 additions & 5 deletions Enemies/Frog.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=20 format=3 uid="uid://ddujm122dl7if"]
[gd_scene load_steps=21 format=3 uid="uid://ddujm122dl7if"]

[ext_resource type="Script" path="res://Enemies/frog.gd" id="1_6tbey"]
[ext_resource type="Texture2D" uid="uid://cnkk3bmgalp3y" path="res://GraphicAssets/Enemies/Frog/idle/frog-idle.png" id="1_6yb3i"]
Expand Down Expand Up @@ -61,7 +61,7 @@ animations = [{
"duration": 1.0,
"texture": ExtResource("6_6e50t")
}],
"loop": true,
"loop": false,
"name": &"Death",
"speed": 5.0
}, {
Expand Down Expand Up @@ -107,7 +107,10 @@ animations = [{
}]

[sub_resource type="CircleShape2D" id="CircleShape2D_ifxyw"]
radius = 61.0328
radius = 98.1275

[sub_resource type="RectangleShape2D" id="RectangleShape2D_ar6r3"]
size = Vector2(17, 21.5)

[node name="Frog" type="CharacterBody2D"]
script = ExtResource("1_6tbey")
Expand All @@ -119,8 +122,7 @@ shape = SubResource("RectangleShape2D_q187l")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(0, -10)
sprite_frames = SubResource("SpriteFrames_xdlj5")
animation = &"Idle"
frame_progress = 0.223236
animation = &"Death"

[node name="PlayerDetectionArea" type="Area2D" parent="."]
position = Vector2(-57.1189, -28.4062)
Expand All @@ -129,5 +131,13 @@ position = Vector2(-57.1189, -28.4062)
position = Vector2(57.1189, 18.4062)
shape = SubResource("CircleShape2D_ifxyw")

[node name="FrogDeathArea" type="Area2D" parent="."]
position = Vector2(-57.1189, -28.4062)

[node name="CollisionShape2D" type="CollisionShape2D" parent="FrogDeathArea"]
position = Vector2(57.1189, 18.1562)
shape = SubResource("RectangleShape2D_ar6r3")

[connection signal="body_entered" from="PlayerDetectionArea" to="." method="_on_player_detection_area_body_entered"]
[connection signal="body_exited" from="PlayerDetectionArea" to="." method="_on_player_detection_area_body_exited"]
[connection signal="body_entered" from="FrogDeathArea" to="." method="_on_player_death_area_body_entered"]
37 changes: 27 additions & 10 deletions Enemies/frog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,33 @@ var chase_flag = false # Not chasing the player if false

@onready var frog_animation = get_node("AnimatedSprite2D")

# Setup the frog
func _ready():
get_node("AnimatedSprite2D").play("Idle")

# Detect the player entering area
func _on_player_detection_area_body_entered(body):
if body.name == "Player": # If player is detected
if body.name == "Player": # where does godot install linuxIf player is detected
chase_flag = true

# Detect the player exiting area
func _on_player_detection_area_body_exited(body):
if body.name == "Player": # If player is detected
chase_flag = false

#Check ea
func _on_player_detection_area_for player collision/kill
func _on_player_death_area_body_entered(body):
if body.name == "Player": #Player is colliding with hitbox
get_node("AnimatedSprite2D").play("Death")
await get_node("AnimatedSprite2D").animation_finished
self.queue_free() #Delete the frog

func _physics_process(delta):
# Add GRAVITY
self.velocity.y += GRAVITY * delta
self.velocity.x = 0
chase_flag = false

# Check if we need to chase the player
if chase_flag == true:
Expand All @@ -34,15 +48,18 @@ func _physics_process(delta):

direction = (player_global_position - self_global_position).normalized()

if direction.x > 0: # On the right of the player
get_node("AnimatedSprite2D").flip_h = true
#self.velocity.x = direction.x * SPEED
elif direction.x < 0: # On the left of the player
get_node("AnimatedSprite2D").flip_h = false
#self.velocity.x = direction.x * SPEED
get_node("AnimatedSprite2D").play("Jump")
self.velocity.x = direction.x * SPEED
if get_node("AnimatedSprite2D").animation != "Death":
if direction.x > 0: # On the right of the player (sprite faces left by default)
get_node("AnimatedSprite2D").flip_h = true
#self.velocity.x = direction.x * SPEED
elif direction.x < 0: # On the left of the player
get_node("AnimatedSprite2D").flip_h = false
#self.velocity.x = direction.x * SPEED
get_node("AnimatedSprite2D").play("Jump")
self.velocity.x = direction.x * SPEED
else:
get_node("AnimatedSprite2D").play("Idle")
if get_node("AnimatedSprite2D").animation != "Death":
get_node("AnimatedSprite2D").play("Idle")
self.velocity.x = 0

move_and_slide()

0 comments on commit 890ce22

Please sign in to comment.