-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupplyCrate.gd
More file actions
49 lines (36 loc) · 1.29 KB
/
SupplyCrate.gd
File metadata and controls
49 lines (36 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
extends Area2D
var health_drop_scene = preload("res://HealthDrop.tscn")
var power_up_scene = preload("res://PowerUp.tscn")
# New: Track if the crate is within the player FOV
var is_active = false
func _ready():
# Keep your group logic
add_to_group("enemies")
add_to_group("crate")
z_index = 0
func take_damage(_amount = 1, _pos = Vector2.ZERO):
# If the crate is off-screen (inactive), it ignores damage
if not is_active:
return
handle_destruction()
func handle_destruction():
determine_loot()
queue_free()
func determine_loot():
var roll = randi() % 4
# 25% chance to drop the "Good" HealthDrop
if roll == 0:
var drop = health_drop_scene.instance()
get_tree().current_scene.call_deferred("add_child", drop)
drop.global_position = global_position
# 25% chance to drop a PowerUp (Magnet, Overdrive, or Speed ONLY)
elif roll == 1:
var p_up = power_up_scene.instance()
# randi() % 3 + 1 forces the result to be 1, 2, or 3.
# This skips 0 (HEALTH) so you never see the green logo placeholder again.
p_up.powerup_type = (randi() % 3) + 1
get_tree().current_scene.call_deferred("add_child", p_up)
p_up.global_position = global_position
func _on_VisibilityNotifier2D_screen_entered():
# Enable damage once the Neo Bushi's sensors detect the crate on screen
is_active = true