Chests now spawn health pickups. Health pickups drop from the sky when spawned until they hit the ground.

This commit is contained in:
Nitsud Yarg 2024-07-22 17:38:06 -07:00
parent 2ff08298b7
commit 9ef4d1748b
4 changed files with 35 additions and 1 deletions

View File

@ -7,8 +7,16 @@ extends Interactable
onready var sprite: Sprite = $Sprite onready var sprite: Sprite = $Sprite
const pickup = preload("res://src/Interactables/HealthPickup.tscn")
var opened := false
func trigger_interaction(): func trigger_interaction():
# This is something that should maybe be extended for every differant interactible. # This is something that should maybe be extended for every differant interactible.
# They could inherit from this base class and implement this function. # They could inherit from this base class and implement this function.
sprite.frame = 1 sprite.frame = 1
if !opened:
var chest_item = pickup.instance()
chest_item.global_position = global_position + Vector2(0,-50)
owner.add_child(chest_item)
opened = true

View File

@ -4,6 +4,22 @@ extends Interactable
onready var health_icon: AnimatedSprite = $AnimatedSprite onready var health_icon: AnimatedSprite = $AnimatedSprite
onready var drop_raycast: RayCast2D = $RayCast2D
func _ready():
#gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
gravity = 90
# Doesn't get enabled until it drops
monitoring = false
func _physics_process(delta):
if drop_raycast.is_colliding() == false:
var velocity = Vector2(0,0)
position.y += delta * gravity
else:
monitoring = true
func trigger_interaction(): func trigger_interaction():
# This is something that should maybe be extended for every differant interactible. # This is something that should maybe be extended for every differant interactible.
# They could inherit from this base class and implement this function. # They could inherit from this base class and implement this function.

View File

@ -8,11 +8,18 @@
radius = 6.0 radius = 6.0
[node name="HealthPickup" instance=ExtResource( 2 )] [node name="HealthPickup" instance=ExtResource( 2 )]
monitoring = false
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="." index="0"] [node name="AnimatedSprite" type="AnimatedSprite" parent="." index="0"]
frames = ExtResource( 3 ) frames = ExtResource( 3 )
frame = 2
playing = true playing = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"] [node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"]
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="RayCast2D" type="RayCast2D" parent="." index="2"]
enabled = true
cast_to = Vector2( 0, 8 )
collision_mask = 3

View File

@ -36,7 +36,7 @@ extents = Vector2( 8, 53 )
script = ExtResource( 10 ) script = ExtResource( 10 )
[node name="PlayerStart" type="Position2D" parent="."] [node name="PlayerStart" type="Position2D" parent="."]
position = Vector2( 1047, 111 ) position = Vector2( 92, 87 )
[node name="CameraBoundaries" type="Area2D" parent="."] [node name="CameraBoundaries" type="Area2D" parent="."]
collision_layer = 256 collision_layer = 256
@ -122,6 +122,9 @@ position = Vector2( 494, 39 )
[node name="HealthPickup" parent="." instance=ExtResource( 5 )] [node name="HealthPickup" parent="." instance=ExtResource( 5 )]
position = Vector2( 226, 153 ) position = Vector2( 226, 153 )
[node name="HealthPickup" parent="HealthPickup" instance=ExtResource( 5 )]
position = Vector2( 754, -123 )
[node name="Chest2" parent="." instance=ExtResource( 4 )] [node name="Chest2" parent="." instance=ExtResource( 4 )]
position = Vector2( 319, 112 ) position = Vector2( 319, 112 )