Boxswitch with state

This commit is contained in:
MaddoScientisto 2025-03-13 21:11:53 +01:00
commit 87645f2617
14 changed files with 278 additions and 37 deletions

View file

@ -0,0 +1,53 @@
[gd_scene load_steps=9 format=3 uid="uid://cl4r3t4c1klv7"]
[ext_resource type="Script" uid="uid://booisvod4sc6s" path="res://Scripts/Interactables/StateSwitch.cs" id="1_75bmt"]
[ext_resource type="Texture2D" uid="uid://cx4xcuxlnwqvj" path="res://Sprites/Interactables/BoxSwitch.png" id="2_ffjgg"]
[ext_resource type="AudioStream" uid="uid://bjvklk7qmlivd" path="res://SFX/288963__littlerobotsoundfactory__click_electronic_14.wav" id="3_ffjgg"]
[ext_resource type="Script" uid="uid://b5sanpv5j7wyd" path="res://Scripts/Interactables/Modules/SwitchSpriteChanger.cs" id="3_sqpe7"]
[sub_resource type="CircleShape2D" id="CircleShape2D_vvpve"]
[sub_resource type="AtlasTexture" id="AtlasTexture_01nkk"]
atlas = ExtResource("2_ffjgg")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_422n6"]
atlas = ExtResource("2_ffjgg")
region = Rect2(16, 0, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_l6x2t"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_01nkk")
}],
"loop": true,
"name": &"Off",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_422n6")
}],
"loop": true,
"name": &"On",
"speed": 5.0
}]
[node name="SwitchBox" type="Area2D" groups=["Interactable"]]
collision_layer = 4
collision_mask = 2
script = ExtResource("1_75bmt")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_vvpve")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." node_paths=PackedStringArray("Switch")]
sprite_frames = SubResource("SpriteFrames_l6x2t")
animation = &"On"
autoplay = "Off"
script = ExtResource("3_sqpe7")
Switch = NodePath("..")
[node name="ActivationSound" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("3_ffjgg")

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=14 format=4 uid="uid://ifiw6j7xcagf"]
[gd_scene load_steps=15 format=4 uid="uid://ifiw6j7xcagf"]
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_0k2rf"]
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_46boo"]
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="3_0k2rf"]
[ext_resource type="Resource" uid="uid://cs3ihltcn2166" path="res://Resources/Items/IcicleGun.tres" id="3_bjfex"]
[ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="3_qa6ev"]
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="4_uj7dw"]
@ -25,7 +26,7 @@ PlayerTemplate = ExtResource("2_46boo")
SpawnMarkers = Dictionary[int, NodePath]({
0: NodePath("PlayerStartPosition")
})
StartingEquipment = [ExtResource("3_bjfex")]
StartingEquipment = Array[ExtResource("3_0k2rf")]([ExtResource("3_bjfex")])
MapStartData = SubResource("Resource_6wo78")
PlayerParentNode = NodePath("Parallax2D/Tilemaps/PlayerParent")

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=39 format=4 uid="uid://6a6tjohypmmb"]
[gd_scene load_steps=43 format=4 uid="uid://6a6tjohypmmb"]
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_t2k72"]
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_2jsgm"]
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="3_hw1so"]
[ext_resource type="Resource" uid="uid://cs3ihltcn2166" path="res://Resources/Items/IcicleGun.tres" id="3_mqt4u"]
[ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="4_s1vkf"]
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_06rc0"]
@ -15,6 +16,7 @@
[ext_resource type="PackedScene" uid="uid://dkwi1hu1bixoe" path="res://Scenes/HUD/HUD.tscn" id="9_mnq21"]
[ext_resource type="Script" uid="uid://bdshph801ac2i" path="res://Scenes/CameraTarget.gd" id="10_4nd4a"]
[ext_resource type="Script" uid="uid://cnkipcolyj61w" path="res://Scripts/AlarmManager.cs" id="11_7an4p"]
[ext_resource type="Script" uid="uid://b5fesrd4lv8t1" path="res://Scripts/Resources/Events/EventResource.cs" id="14_lji43"]
[ext_resource type="Script" uid="uid://bwox5lmgiijcs" path="res://Scripts/Resources/Events/ActivateEvent.cs" id="14_s23f3"]
[ext_resource type="PackedScene" uid="uid://oi8svqsspcsj" path="res://Scenes/Interactable/ScriptableMovementSensor.tscn" id="16_ehuec"]
[ext_resource type="PackedScene" uid="uid://crph24e6e0v0q" path="res://Scenes/Interactable/Control_Pad.tscn" id="16_s23f3"]
@ -32,12 +34,14 @@
[ext_resource type="PackedScene" uid="uid://bjskkeb3ppcs8" path="res://Scenes/Actors/Turret360.tscn" id="26_g2ms1"]
[ext_resource type="PackedScene" uid="uid://cvctgw8eo2f7e" path="res://Scenes/Items/SpiderBomb_Pickup.tscn" id="27_577wb"]
[ext_resource type="PackedScene" uid="uid://bjb1xv0ny1qim" path="res://Scenes/Props/Chair.tscn" id="27_mq37i"]
[ext_resource type="PackedScene" uid="uid://dcbcyp1qogcl0" path="res://Scenes/Props/BigTankHorizontal.tscn" id="30_i668q"]
[ext_resource type="AudioStream" uid="uid://blohh20jktoyo" path="res://SFX/270641__phantastonia__alarm2.wav" id="31_nb1db"]
[ext_resource type="PackedScene" uid="uid://b0k2grrc8xp1l" path="res://Scenes/Props/BigTank.tscn" id="37_47klv"]
[sub_resource type="Resource" id="Resource_6wo78"]
script = ExtResource("4_s1vkf")
EggIndex = 0
StartingEquipment = [ExtResource("3_mqt4u")]
StartingEquipment = Array[ExtResource("3_hw1so")]([ExtResource("3_mqt4u")])
[sub_resource type="Resource" id="Resource_s23f3"]
script = ExtResource("14_s23f3")
@ -69,7 +73,7 @@ PlayerTemplate = ExtResource("2_2jsgm")
SpawnMarkers = Dictionary[int, NodePath]({
0: NodePath("PlayerStartPosition")
})
StartingEquipment = [ExtResource("3_mqt4u")]
StartingEquipment = Array[ExtResource("3_hw1so")]([ExtResource("3_mqt4u")])
MapStartData = SubResource("Resource_6wo78")
[node name="Tilemaps" type="Node2D" parent="."]
@ -118,7 +122,7 @@ position = Vector2(196, 296)
[node name="MotionSensor" parent="Tilemaps/Actors" instance=ExtResource("16_ehuec")]
position = Vector2(254, 296)
Events = [SubResource("Resource_s23f3")]
Events = Array[ExtResource("14_lji43")]([SubResource("Resource_s23f3")])
[node name="ControlPad" parent="Tilemaps/Actors" node_paths=PackedStringArray("Targets") instance=ExtResource("16_s23f3")]
position = Vector2(205, 292)
@ -139,11 +143,11 @@ position = Vector2(504, 468)
[node name="MovementSensorLonger" parent="Tilemaps/Actors" instance=ExtResource("20_fdi4d")]
position = Vector2(226, 486)
Events = [SubResource("Resource_qi6uc")]
Events = Array[ExtResource("14_lji43")]([SubResource("Resource_qi6uc")])
[node name="MovementSensorLonger2" parent="Tilemaps/Actors" instance=ExtResource("20_fdi4d")]
position = Vector2(391, 455)
Events = [SubResource("Resource_mq37i")]
Events = Array[ExtResource("14_lji43")]([SubResource("Resource_mq37i")])
[node name="WallEmitter" parent="Tilemaps/Actors" instance=ExtResource("21_qi6uc")]
position = Vector2(264, 482)
@ -209,6 +213,12 @@ collision_mask = 0
position = Vector2(27.5, -2.5)
shape = SubResource("RectangleShape2D_mq37i")
[node name="BigTankHorizontal" parent="Tilemaps/Actors" instance=ExtResource("30_i668q")]
position = Vector2(-306, 530)
[node name="BigTankHorizontal2" parent="Tilemaps/Actors" instance=ExtResource("30_i668q")]
position = Vector2(-274, 530)
[node name="CameraController" type="Camera2D" parent="."]
script = ExtResource("7_lxkiw")
pixel_snap = false
@ -236,3 +246,6 @@ position = Vector2(312, 303)
[node name="AlarmManager" type="Node2D" parent="."]
script = ExtResource("11_7an4p")
AlarmSound = ExtResource("31_nb1db")
[node name="BigTank" parent="." instance=ExtResource("37_47klv")]
position = Vector2(-243, 526)

View file

@ -56,8 +56,8 @@
[ext_resource type="PackedScene" uid="uid://dnbtou2fklyvp" path="res://Scenes/Actors/alarm_sign.tscn" id="36_rd6f6"]
[ext_resource type="PackedScene" uid="uid://dsbk2l40er2da" path="res://Scenes/Props/Box_Blue.tscn" id="37_gtga7"]
[ext_resource type="PackedScene" uid="uid://c8lgk4wnyi1e6" path="res://Scenes/Actors/HealthStation.tscn" id="38_kuhg5"]
[ext_resource type="PackedScene" uid="uid://cl4r3t4c1klv7" path="res://Scenes/Interactable/Switch_Box.tscn" id="38_qnbhd"]
[ext_resource type="Script" uid="uid://d0a0o50j82eo6" path="res://Scripts/Activables/ScriptableBase.cs" id="42_wigyb"]
[ext_resource type="Script" uid="uid://b5fesrd4lv8t1" path="res://Scripts/Resources/Events/EventResource.cs" id="42_yqnr2"]
[ext_resource type="PackedScene" uid="uid://fxvlaidieiv7" path="res://Scenes/Interactable/ScriptableAreaTrigger.tscn" id="43_kf3qc"]
[ext_resource type="Script" uid="uid://dkihoo85jfec5" path="res://Scripts/Resources/Events/MovePlayerEvent.cs" id="44_klwgh"]
[ext_resource type="PackedScene" uid="uid://dx1urm7nttkqk" path="res://Scenes/Actors/level_teleporter.tscn" id="44_q5xi2"]
@ -201,7 +201,7 @@ ActivationType = 0
Targets = Array[NodePath]([NodePath("../Rumia")])
WaitForCompletion = true
[sub_resource type="Resource" id="Resource_qnbhd"]
[sub_resource type="Resource" id="Resource_mah4x"]
resource_local_to_scene = true
script = ExtResource("49_0si7g")
Target = NodePath(".")
@ -448,6 +448,10 @@ position = Vector2(-843, -345)
[node name="Blue Box" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("37_gtga7")]
position = Vector2(-832, -396)
[node name="SwitchBox" parent="Parallax2D/Factory Tilemaps/Debug Room" node_paths=PackedStringArray("Targets") instance=ExtResource("38_qnbhd")]
position = Vector2(-686, -484)
Targets = [NodePath("../HorizontalForceField")]
[node name="Part2" type="Node2D" parent="Parallax2D/Factory Tilemaps"]
[node name="Mainframe" parent="Parallax2D/Factory Tilemaps/Part2" instance=ExtResource("13_acrmt")]
@ -543,7 +547,7 @@ Invisible = true
metadata/_edit_group_ = true
[node name="ScriptableAreaTrigger" parent="Parallax2D/Factory Tilemaps/LevelProps/DebugTeleporter" instance=ExtResource("43_kf3qc")]
Events = Array[ExtResource("42_yqnr2")]([SubResource("Resource_usuub")])
Events = [SubResource("Resource_usuub")]
[node name="BlueKeycard2" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("35_rblsn")]
position = Vector2(-1032, -317)
@ -719,7 +723,7 @@ position = Vector2(-1506, -188)
[node name="LevelStartTrigger" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
position = Vector2(-781, -160)
scale = Vector2(1.455, 1.455)
Events = Array[ExtResource("42_yqnr2")]([SubResource("Resource_5er5x"), SubResource("Resource_b25hy")])
Events = [SubResource("Resource_5er5x"), SubResource("Resource_b25hy")]
[node name="AreaTrigger2" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Target") instance=ExtResource("28_6au4t")]
position = Vector2(-435, -162)
@ -761,7 +765,7 @@ Targets = [NodePath("Script2")]
[node name="Script2" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer2"]
position = Vector2(120, 25)
script = ExtResource("42_wigyb")
Events = Array[ExtResource("42_yqnr2")]([SubResource("Resource_ji7au")])
Events = [SubResource("Resource_ji7au")]
[node name="Computer5" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("31_243ec")]
position = Vector2(-1344, -251)
@ -769,7 +773,7 @@ Targets = [NodePath("Computer5Script")]
[node name="Computer5Script" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer5"]
script = ExtResource("42_wigyb")
Events = Array[ExtResource("42_yqnr2")]([SubResource("Resource_fasrq"), SubResource("Resource_yot54")])
Events = [SubResource("Resource_fasrq"), SubResource("Resource_yot54")]
[node name="Computer3" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Target") instance=ExtResource("31_243ec")]
position = Vector2(-612.57, -358.528)
@ -777,7 +781,7 @@ Target = NodePath("Script")
[node name="Script" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer3"]
script = ExtResource("42_wigyb")
Events = Array[ExtResource("42_yqnr2")]([SubResource("Resource_o2kpk")])
Events = [SubResource("Resource_o2kpk")]
[node name="Computer4" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Target") instance=ExtResource("31_243ec")]
position = Vector2(-791, -505)
@ -785,7 +789,7 @@ Target = NodePath("Node2D")
[node name="Node2D" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer4"]
script = ExtResource("42_wigyb")
Events = Array[ExtResource("42_yqnr2")]([SubResource("Resource_s3g2w")])
Events = [SubResource("Resource_s3g2w")]
[node name="Label" type="Label" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer4"]
offset_left = -5.0
@ -813,11 +817,11 @@ position = Vector2(-792, -407)
[node name="BossBattleEndScript" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps"]
position = Vector2(-1628.53, -477.628)
script = ExtResource("42_wigyb")
Events = Array[ExtResource("42_yqnr2")]([SubResource("Resource_068l7"), SubResource("Resource_l3nop")])
Events = [SubResource("Resource_068l7"), SubResource("Resource_l3nop")]
[node name="BossBattleStartScript" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
position = Vector2(-1487, -396)
Events = Array[ExtResource("42_yqnr2")]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_qnbhd")])
Events = [SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_mah4x")]
[node name="Enemy13" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("47_u1ve6")]
position = Vector2(-1657, -788)

View file

@ -0,0 +1,9 @@
namespace Cirno.Scripts.Enums;
public enum SwitchState
{
On,
Off,
Destroyed,
Disabled
}

View file

@ -0,0 +1,46 @@
using System;
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Interactables.Modules;
public partial class SwitchSpriteChanger : AnimatedSprite2D
{
[Export]
public StateSwitch Switch { get; private set; }
[Export] public StringName OnAnimationName { get; private set; } = "On";
[Export] public StringName OffAnimationName { get; private set; } = "Off";
[Export] public StringName DestroyedAnimationName { get; private set; } = "Destroyed";
[Export] public StringName DisabledAnimationName { get; private set; } = "Disabled";
public override void _Ready()
{
Switch.OnActivated += SwitchOnActivated;
UpdateSprite();
}
private void SwitchOnActivated(ActivationType activationType)
{
UpdateSprite();
}
private void UpdateSprite()
{
switch (Switch.CurrentState)
{
case SwitchState.On:
this.Play(OnAnimationName);
break;
case SwitchState.Off:
this.Play(OffAnimationName);
break;
case SwitchState.Destroyed:
this.Play(DestroyedAnimationName);
break;
case SwitchState.Disabled:
this.Play(DisabledAnimationName);
break;
}
}
}

View file

@ -0,0 +1 @@
uid://b5sanpv5j7wyd

View file

@ -0,0 +1,62 @@
using System;
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Interactables;
public partial class StateSwitch : Switch
{
[Export]
public SwitchState StartingState { get; private set; } = SwitchState.Off;
public SwitchState CurrentState { get; private set; }
public override void _Ready()
{
base._Ready();
CurrentState = StartingState;
}
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (activationType)
{
case ActivationType.Use:
case ActivationType.Toggle:
switch (CurrentState)
{
case SwitchState.On:
return TriggerDisable();
case SwitchState.Off:
return TriggerEnable();
}
break;
case ActivationType.Close:
case ActivationType.Enable:
return TriggerEnable();
case ActivationType.Open:
case ActivationType.Disable:
return TriggerDisable();
case ActivationType.Destroy:
this.CurrentState = SwitchState.Destroyed;
break;
}
return false;
}
protected bool TriggerDisable()
{
CurrentState = SwitchState.Off;
//EmitSignal(Switch.SignalName.OnActivated, (int)ActivationType.Disable);
return base.Activate(ActivationType.Disable);
}
protected bool TriggerEnable()
{
CurrentState = SwitchState.On;
//EmitSignal(Switch.SignalName.OnActivated, (int)ActivationType.Enable);
return base.Activate(ActivationType.Enable);
}
}

View file

@ -0,0 +1 @@
uid://booisvod4sc6s

View file

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using Godot;
using Godot.Collections;
@ -9,6 +10,9 @@ public partial class Switch : Interactable
[Export] public Node2D Target { get; set; }
[Export] public Array<Node2D> Targets { get; private set; } = [];
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
[Signal]
public delegate void OnActivatedEventHandler(ActivationType activationType);
private AudioStreamPlayer2D _activationSound;
@ -23,17 +27,19 @@ public partial class Switch : Interactable
{
if (!MeetsRequirements()) return false;
_activationSound?.Play();
EmitSignal(SignalName.OnActivated, (int)activationType);
// Compatibility for old single system
bool success = ActivateTarget(Target);
bool success = ActivateTarget(Target, activationType);
return Targets.Aggregate(success, (current, target) => ActivateTarget(target) | success);
return Targets.Aggregate(success, (current, target) => ActivateTarget(target, activationType) | success);
}
private bool ActivateTarget(Node2D target)
private bool ActivateTarget(Node2D target, ActivationType activationType = ActivationType.Toggle)
{
if (target is not IActivable activable) return false;
activable?.Activate(ActivationType);
activable?.Activate(activationType);
return true;
}
}

BIN
Sprites/Interactables/BoxSwitch.aseprite (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Sprites/Interactables/BoxSwitch.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cx4xcuxlnwqvj"
path="res://.godot/imported/BoxSwitch.png-d2fa0b9c477032b2350f3a91c3a43137.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/Interactables/BoxSwitch.png"
dest_files=["res://.godot/imported/BoxSwitch.png-d2fa0b9c477032b2350f3a91c3a43137.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -2,46 +2,46 @@
"column_properties": {
"res://Resources/": {
"metadata/_custom_type_script": {
"visibility": 0
"visibility": 0.0
},
"resource_local_to_scene": {
"visibility": 0
"visibility": 0.0
},
"resource_name": {
"visibility": 0
"visibility": 0.0
}
},
"res://Resources/Bullets/": {
"metadata/_custom_type_script": {
"visibility": 0
"visibility": 0.0
},
"resource_local_to_scene": {
"visibility": 0
"visibility": 0.0
},
"resource_name": {
"visibility": 0
"visibility": 0.0
}
},
"res://Resources/Items/": {
"metadata/_custom_type_script": {
"visibility": 0
"visibility": 0.0
},
"resource_local_to_scene": {
"visibility": 0
"visibility": 0.0
},
"resource_name": {
"visibility": 0
"visibility": 0.0
}
},
"res://Resources/Weapons/": {
"metadata/_custom_type_script": {
"visibility": 0
"visibility": 0.0
},
"resource_local_to_scene": {
"visibility": 0
"visibility": 0.0
},
"resource_name": {
"visibility": 0
"visibility": 0.0
}
}
},
@ -52,6 +52,11 @@
"res://Resources/Bullets/"
],
"table_functions": {
"filter": [
"return true"
],
"process": [
"return value"
]
}
}