Added Apple Drop on dying Slimes
parent
fa4a9582d7
commit
e65e98754d
|
|
@ -9,6 +9,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://cgu7w2jd42f3a" path="res://scenes/tile_map_layer(background).tscn" id="8_vtaks"]
|
||||
[ext_resource type="PackedScene" uid="uid://bgpsc6dvsn7ak" path="res://scenes/tile_map_layer(objects).tscn" id="9_kvpfn"]
|
||||
[ext_resource type="PackedScene" uid="uid://co8t1fr3b3kub" path="res://scenes/tile_map_layer(overlay).tscn" id="10_dinhu"]
|
||||
[ext_resource type="Script" uid="uid://ckv6prbe1o7s1" path="res://scripts/drop_manager.gd" id="10_vtaks"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_vtaks"]
|
||||
texture = ExtResource("7_gee14")
|
||||
|
|
@ -2375,5 +2376,6 @@ tile_map_data = PackedByteArray("AAACABEAAQAmACIAAAAXAAMAAAAEAAoAAAALABEAAAATAAo
|
|||
tile_set = SubResource("TileSet_dinhu")
|
||||
|
||||
[node name="DropManager" type="Node2D" parent="." unique_id=1629996711]
|
||||
script = ExtResource("10_vtaks")
|
||||
|
||||
[connection signal="timeout" from="SpawnTimer" to="SpawnControl" method="_on_spawn_timer_timeout"]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
[gd_scene format=3 uid="uid://ccotbw7gepsge"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://1drpgylrgrjj" path="res://scripts/slime.gd" id="1_1a61f"]
|
||||
[ext_resource type="Script" uid="uid://cjkaw7wqw4e30" path="res://scripts/drop_table.gd" id="2_2npkn"]
|
||||
[ext_resource type="Texture2D" uid="uid://e3ihc570p1n0" path="res://assets/Slime1/Without_shadow/Slime1_Death_without_shadow.png" id="2_kjhlw"]
|
||||
[ext_resource type="PackedScene" uid="uid://dm6d2jg52vi41" path="res://scenes/apple.tscn" id="3_fd6lc"]
|
||||
[ext_resource type="Texture2D" uid="uid://cxddvfs2wfwcl" path="res://assets/Slime1/Without_shadow/Slime1_Idle_without_shadow.png" id="3_rrqju"]
|
||||
[ext_resource type="Texture2D" uid="uid://b2bmw70co6noy" path="res://assets/Slime1/Without_shadow/Slime1_Walk_without_shadow.png" id="4_wyhst"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_gstla"]
|
||||
script = ExtResource("2_2npkn")
|
||||
drop = ExtResource("3_fd6lc")
|
||||
chance = 0.3
|
||||
metadata/_custom_type_script = "uid://cjkaw7wqw4e30"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_v5wyi"]
|
||||
atlas = ExtResource("2_kjhlw")
|
||||
region = Rect2(0, 0, 64, 64)
|
||||
|
|
@ -382,6 +390,7 @@ radius = 8.062258
|
|||
|
||||
[node name="Slime" type="CharacterBody2D" unique_id=1684858295]
|
||||
script = ExtResource("1_1a61f")
|
||||
drop_table = Array[ExtResource("2_2npkn")]([SubResource("Resource_gstla")])
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=752118449]
|
||||
texture_filter = 1
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
extends Node2D
|
||||
|
||||
|
||||
|
||||
# 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_enemy_died(enemy):
|
||||
drop_item(enemy)
|
||||
|
||||
func drop_item(enemy):
|
||||
for entry in enemy.drop_table:
|
||||
if randf() < entry.chance:
|
||||
var drop = entry.drop.instantiate()
|
||||
drop.global_position = enemy.global_position
|
||||
add_child(drop)
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://ckv6prbe1o7s1
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
extends Resource
|
||||
class_name DropTable
|
||||
|
||||
@export var drop: PackedScene
|
||||
@export var chance: float
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://cjkaw7wqw4e30
|
||||
|
|
@ -2,6 +2,7 @@ class_name EnemyBase
|
|||
extends CharacterBody2D
|
||||
|
||||
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
||||
@export var drop_table: Array[DropTable]
|
||||
|
||||
var is_dying = false
|
||||
var speed
|
||||
|
|
@ -11,6 +12,7 @@ var death_sound = preload("res://assets/music&sfx/sfx/hit2.wav")
|
|||
signal died
|
||||
|
||||
func _ready() -> void:
|
||||
died.connect(get_node("/root/Game/DropManager").on_enemy_died)
|
||||
witch = get_node("/root/Game/Witch")
|
||||
player = get_node("/root/Game/Player")
|
||||
pass # Replace with function body
|
||||
|
|
@ -25,9 +27,11 @@ func _die():
|
|||
player.bus = "SFX"
|
||||
player.play()
|
||||
await animated_sprite_2d.animation_finished
|
||||
died.emit(self)
|
||||
queue_free()
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in New Issue