mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 22:15:53 +00:00
Area trigger
This commit is contained in:
parent
10ab6fce1a
commit
77765a581e
3 changed files with 58 additions and 1 deletions
15
Scenes/Interactable/AreaTrigger.tscn
Normal file
15
Scenes/Interactable/AreaTrigger.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://bdp710abe10s5"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Interactables/AreaTrigger.cs" id="1_oc40x"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1nht3"]
|
||||
|
||||
[node name="AreaTrigger" type="Area2D"]
|
||||
collision_layer = 4
|
||||
collision_mask = 2
|
||||
script = ExtResource("1_oc40x")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_1nht3")
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=28 format=4 uid="uid://bv451a8wgty4u"]
|
||||
[gd_scene load_steps=29 format=4 uid="uid://bv451a8wgty4u"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
|
||||
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"]
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
[ext_resource type="Script" path="res://Scenes/CameraTarget.gd" id="24_0c2yt"]
|
||||
[ext_resource type="PackedScene" uid="uid://djf0y08ix66fn" path="res://Scenes/Interactable/Chest.tscn" id="25_4b2ed"]
|
||||
[ext_resource type="Script" path="res://Scripts/AlarmManager.cs" id="25_rpwvt"]
|
||||
[ext_resource type="PackedScene" uid="uid://bdp710abe10s5" path="res://Scenes/Interactable/AreaTrigger.tscn" id="28_njwjr"]
|
||||
|
||||
[node name="GameScene" type="Node2D" node_paths=PackedStringArray("PlayerSpawnMarker")]
|
||||
position = Vector2(38, 39)
|
||||
|
|
@ -192,4 +193,8 @@ script = ExtResource("25_rpwvt")
|
|||
[node name="Camera" parent="." instance=ExtResource("16_clqjt")]
|
||||
position = Vector2(-1096, -23)
|
||||
|
||||
[node name="AreaTrigger" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("28_njwjr")]
|
||||
position = Vector2(-822, 200)
|
||||
Target = NodePath("../Factory Tilemaps/Door_vertical2")
|
||||
|
||||
[editable path="Factory Tilemaps/Camera"]
|
||||
|
|
|
|||
37
Scripts/Interactables/AreaTrigger.cs
Normal file
37
Scripts/Interactables/AreaTrigger.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Interactables;
|
||||
|
||||
public partial class AreaTrigger : Area2D
|
||||
{
|
||||
[Export] public Activable Target { get; set; }
|
||||
|
||||
[Export] public bool OneTime { get; set; }
|
||||
[Export] public bool DoNotActivateOnFirst { get; set; }
|
||||
|
||||
private int _activations = 0;
|
||||
|
||||
public bool Activate(InteractionController player)
|
||||
{
|
||||
if (_activations == 0 && DoNotActivateOnFirst)
|
||||
{
|
||||
_activations++;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OneTime && _activations > 0) return false;
|
||||
|
||||
Target?.Activate();
|
||||
|
||||
_activations++;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private void _on_area_entered(Area2D area)
|
||||
{
|
||||
if (area is not InteractionController player) return;
|
||||
Activate(player);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue