Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added the death animations #178

Merged
merged 3 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added poofarmer/Images/goblin-death.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions poofarmer/Images/goblin-death.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/goblin-death.png-bfd456b3a93dc0535a07850cecf32610.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Images/goblin-death.png"
dest_files=[ "res://.import/goblin-death.png-bfd456b3a93dc0535a07850cecf32610.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0
Binary file modified poofarmer/Images/troll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions poofarmer/Scenes/Enemies/Enemy.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://Scenes/MobAudioController.tscn" type="PackedScene" id=1]
[ext_resource path="res://Audio/Poo Farmer Goblin Laugh 1.wav" type="AudioStream" id=2]
[ext_resource path="res://Audio/Poo Farmer Goblin Attack.wav" type="AudioStream" id=3]
[ext_resource path="res://Audio/Poo Farmer Goblin Laugh 2.wav" type="AudioStream" id=4]
[ext_resource path="res://Scripts/Enemy.gd" type="Script" id=5]

[node name="Enemy" type="KinematicBody2D"]
script = ExtResource( 5 )

[node name="MobAudioController" parent="." instance=ExtResource( 1 )]
next_behavior_min = 30.0
next_behavior_max = 90.0
actions = [ ExtResource( 3 ) ]
behaviors = [ ExtResource( 2 ), ExtResource( 4 ) ]
34 changes: 33 additions & 1 deletion poofarmer/Scenes/Goblin.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
[gd_scene load_steps=27 format=2]
[gd_scene load_steps=34 format=2]

[ext_resource path="res://Scripts/Goblin.gd" type="Script" id=1]
[ext_resource path="res://Images/Goblin.png" type="Texture" id=2]
[ext_resource path="res://Scenes/MobAudioController.tscn" type="PackedScene" id=3]
[ext_resource path="res://Audio/Poo Farmer Goblin Laugh 1.wav" type="AudioStream" id=4]
[ext_resource path="res://Audio/Poo Farmer Goblin Attack.wav" type="AudioStream" id=5]
[ext_resource path="res://Audio/Poo Farmer Goblin Laugh 2.wav" type="AudioStream" id=6]
[ext_resource path="res://Images/goblin-death.png" type="Texture" id=7]

[sub_resource type="AtlasTexture" id=21]
atlas = ExtResource( 7 )
region = Rect2( 0, 0, 32, 16 )

[sub_resource type="AtlasTexture" id=22]
atlas = ExtResource( 7 )
region = Rect2( 32, 0, 32, 16 )

[sub_resource type="AtlasTexture" id=23]
atlas = ExtResource( 7 )
region = Rect2( 64, 0, 32, 16 )

[sub_resource type="AtlasTexture" id=24]
atlas = ExtResource( 7 )
region = Rect2( 96, 0, 32, 16 )

[sub_resource type="AtlasTexture" id=25]
atlas = ExtResource( 7 )
region = Rect2( 128, 0, 32, 16 )

[sub_resource type="AtlasTexture" id=26]
atlas = ExtResource( 7 )
region = Rect2( 160, 0, 32, 16 )

[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 2 )
Expand Down Expand Up @@ -73,6 +98,11 @@ region = Rect2( 48, 64, 16, 32 )

[sub_resource type="SpriteFrames" id=17]
animations = [ {
"frames": [ SubResource( 21 ), SubResource( 22 ), SubResource( 23 ), SubResource( 24 ), SubResource( 25 ), SubResource( 26 ) ],
"loop": false,
"name": "death",
"speed": 4.0
}, {
"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ) ],
"loop": true,
"name": "down",
Expand Down Expand Up @@ -112,6 +142,7 @@ script = ExtResource( 1 )
scale = Vector2( 1.5, 1.5 )
frames = SubResource( 17 )
animation = "down"
frame = 1
playing = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
Expand Down Expand Up @@ -143,6 +174,7 @@ next_behavior_max = 90.0
actions = [ ExtResource( 5 ) ]
behaviors = [ ExtResource( 4 ), ExtResource( 6 ) ]

[connection signal="animation_finished" from="AnimatedSprite" to="." method="_on_AnimatedSprite_animation_finished"]
[connection signal="area_entered" from="Visibility" to="." method="_on_Visibility_area_entered"]
[connection signal="area_exited" from="Visibility" to="." method="_on_Visibility_area_exited"]
[connection signal="area_entered" from="PooPickupDetection" to="." method="_on_PooPickupDetection_area_entered"]
Expand Down
36 changes: 34 additions & 2 deletions poofarmer/Scenes/Troll.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=26 format=2]
[gd_scene load_steps=31 format=2]

[ext_resource path="res://Scripts/Troll.gd" type="Script" id=1]
[ext_resource path="res://Audio/Poo Farmer Goblin Laugh 1.wav" type="AudioStream" id=2]
Expand All @@ -7,6 +7,26 @@
[ext_resource path="res://Images/troll.png" type="Texture" id=5]
[ext_resource path="res://Scenes/MobAudioController.tscn" type="PackedScene" id=6]

[sub_resource type="AtlasTexture" id=21]
atlas = ExtResource( 5 )
region = Rect2( 0, 128, 32, 32 )

[sub_resource type="AtlasTexture" id=22]
atlas = ExtResource( 5 )
region = Rect2( 32, 128, 32, 32 )

[sub_resource type="AtlasTexture" id=23]
atlas = ExtResource( 5 )
region = Rect2( 64, 128, 32, 32 )

[sub_resource type="AtlasTexture" id=24]
atlas = ExtResource( 5 )
region = Rect2( 96, 128, 32, 32 )

[sub_resource type="AtlasTexture" id=25]
atlas = ExtResource( 5 )
region = Rect2( 0, 160, 32, 32 )

[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 5 )
region = Rect2( 0, 0, 32, 32 )
Expand Down Expand Up @@ -73,6 +93,11 @@ region = Rect2( 96, 64, 32, 32 )

[sub_resource type="SpriteFrames" id=17]
animations = [ {
"frames": [ SubResource( 21 ), SubResource( 22 ), SubResource( 23 ), SubResource( 24 ), SubResource( 25 ) ],
"loop": false,
"name": "death",
"speed": 3.0
}, {
"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ) ],
"loop": true,
"name": "down",
Expand Down Expand Up @@ -104,11 +129,17 @@ extents = Vector2( 37, 37.5 )
collision_layer = 8
collision_mask = 52
script = ExtResource( 1 )
speed = 2000
fleeSpeedMultiplier = 1
health = 32
stealAmount = 5
siloStealAmount = 10

[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
scale = Vector2( 2.5, 2.5 )
frames = SubResource( 17 )
animation = "down"
animation = "death"
frame = 4
playing = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
Expand All @@ -129,4 +160,5 @@ next_behavior_max = 90.0
actions = [ ExtResource( 3 ) ]
behaviors = [ ExtResource( 2 ), ExtResource( 4 ) ]

[connection signal="animation_finished" from="AnimatedSprite" to="." method="_on_AnimatedSprite_animation_finished"]
[connection signal="area_entered" from="PooPickupDetection" to="." method="_on_PooPickupDetection_area_entered"]
70 changes: 70 additions & 0 deletions poofarmer/Scripts/Enemy.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
extends KinematicBody2D
class_name Enemy

signal global_poo_stolen(stealAmount)
signal enemy_killed

export var speed = 4000
export var fleeSpeedMultiplier = 4
export var health = 4
export var stealAmount = 3
export var siloStealAmount = 5
onready var silo = get_tree().get_nodes_in_group("silo")[0]
onready var player = get_tree().get_nodes_in_group("player")[0]
onready var audio_ctrl = $MobAudioController
var sprite
var isFleeing = false
var fleeingVector = Vector2(0,0)
var is_dying = false


func detected_something(area, player_steal):
if !is_dying:
if (area.is_in_group("poo")):
destroy_poo(area)

if (area.is_in_group("silo")):
emit_signal("global_poo_stolen", siloStealAmount)
isFleeing = true

if area.is_in_group("player") && player.currentHoldAmount > 0 && player_steal:
isFleeing = true
player.steal_poo(stealAmount)
audio_ctrl.act(0)

func destroy_poo(poo):
if (poo.is_in_group("poo")):
var pooInstance = poo as Poo
pooInstance.destroy()

func steal_from_player():
player.steal_poo(stealAmount)
audio_ctrl.act(0)

func move_at_body(body, delta):
var velocity = (body.position - position).normalized() * speed * delta * (fleeSpeedMultiplier if isFleeing else 1)
return move_and_slide(velocity)

func enemy_handle_hit(damage, sprite_offset):
health -= damage
if health <= 0 && !is_dying:
if sprite.animation == "right":
sprite.flip_h = true
sprite.offset.y = sprite_offset
sprite.play("death")
is_dying = true

func calculate_sprite_direction(velocity):
if velocity.x > 0:
sprite.animation = "right"
elif velocity.x < 0:
sprite.animation = "left"
elif velocity.y > 0:
sprite.animation = "down"
elif velocity.y < 0:
sprite.animation = "up"

func end_death():
if sprite.animation == "death":
queue_free()
emit_signal("enemy_killed")
Loading