mirror of
https://github.com/RYGhub/the-cold-night.git
synced 2024-11-22 04:34:19 +00:00
✨ Create pickup system
This commit is contained in:
parent
7c14f73cc4
commit
2b59dceada
3 changed files with 91 additions and 1 deletions
58
src/entities/Pickup.gd
Normal file
58
src/entities/Pickup.gd
Normal file
|
@ -0,0 +1,58 @@
|
|||
extends Area2D
|
||||
|
||||
|
||||
export var sprite: Texture = preload("res://src/mechanics/White.png") setget set_sprite, get_sprite
|
||||
export var duration_seconds: float = 1.0 setget set_duration, get_duration
|
||||
export var despawn_seconds: float = INF setget set_despawn, get_despawn
|
||||
|
||||
signal picked_up
|
||||
signal expired
|
||||
signal despawned
|
||||
|
||||
|
||||
func _ready():
|
||||
set_sprite(sprite)
|
||||
set_duration(duration_seconds)
|
||||
set_despawn(despawn_seconds)
|
||||
|
||||
|
||||
func set_sprite(value):
|
||||
$Shape/Sprite.texture = value
|
||||
|
||||
func get_sprite():
|
||||
return $Shape/Sprite.texture
|
||||
|
||||
|
||||
func set_duration(value):
|
||||
$Duration.wait_time = value
|
||||
|
||||
func get_duration():
|
||||
return $Duration.wait_time
|
||||
|
||||
func _on_Duration_timeout():
|
||||
emit_signal("expired")
|
||||
queue_free()
|
||||
|
||||
|
||||
func set_despawn(value):
|
||||
$Despawn.wait_time = value
|
||||
$Despawn.start()
|
||||
|
||||
func get_despawn():
|
||||
return $Despawn.wait_time
|
||||
|
||||
func _on_Despawn_timeout():
|
||||
if $Shape.visible:
|
||||
emit_signal("despawned")
|
||||
queue_free()
|
||||
|
||||
|
||||
func pick_up():
|
||||
$Shape.visible = false
|
||||
$Duration.start()
|
||||
emit_signal("picked_up")
|
||||
|
||||
func _on_body_entered(_other: RigidBody2D):
|
||||
# TODO: check that it was the player who entered
|
||||
if $Shape.visible:
|
||||
pick_up()
|
27
src/entities/Pickup.tscn
Normal file
27
src/entities/Pickup.tscn
Normal file
|
@ -0,0 +1,27 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://src/mechanics/White.png" type="Texture" id=1]
|
||||
[ext_resource path="res://src/entities/Pickup.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 16, 16 )
|
||||
|
||||
[node name="Pickup" type="Area2D"]
|
||||
input_pickable = false
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Shape" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Shape"]
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="Duration" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="Despawn" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
[connection signal="timeout" from="Duration" to="." method="_on_Duration_timeout"]
|
||||
[connection signal="timeout" from="Despawn" to="." method="_on_Despawn_timeout"]
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=9 format=2]
|
||||
[gd_scene load_steps=10 format=2]
|
||||
|
||||
[ext_resource path="res://src/mechanics/Background.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://src/mechanics/Darkness.tscn" type="PackedScene" id=2]
|
||||
|
@ -7,6 +7,7 @@
|
|||
[ext_resource path="res://src/entities/Enemy.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://src/levels/Game.gd" type="Script" id=6]
|
||||
[ext_resource path="res://src/ui/TimeSurvived.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://src/entities/Pickup.tscn" type="PackedScene" id=8]
|
||||
[ext_resource path="res://src/levels/PhaseOneMusic.gd" type="Script" id=11]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
|
@ -49,6 +50,10 @@ position = Vector2( 755, 508 )
|
|||
position = Vector2( 493, 305 )
|
||||
intensity = 0.3
|
||||
|
||||
[node name="Pickup" parent="PhaseOne/PhaseOneContainer" instance=ExtResource( 8 )]
|
||||
position = Vector2( 618, 360 )
|
||||
duration_seconds = nan
|
||||
|
||||
[node name="UserInterface" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="UserIntefaceContainer" type="Panel" parent="UserInterface"]
|
||||
|
|
Loading…
Reference in a new issue