Teleporters

This commit is contained in:
Marco 2025-02-06 17:57:06 +01:00
commit 7db0e8f5b6
12 changed files with 215 additions and 19 deletions

View file

@ -4,4 +4,5 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACastHelpers_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F3c92637ae2e83da0a63791071c41eae291d594156062866d8621b7ed7245c_003FCastHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnemy_005FScriptProperties_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fd6739058209280d46591ab296d6b49dfcf7ecd2_003FEnemy_005FScriptProperties_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fbb1b701f3c7411227a9d2e09f965d857ff3e771557650c4f513e427d77c_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerMovement_005FScriptMethods_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F4af4702ac4bbb9ab7299554c41beea2bf703b4a_003FPlayerMovement_005FScriptMethods_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVariantUtils_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F4fd22cd129a84c16b5d8004b467c426f518800_003F38_003Fb04c4423_003FVariantUtils_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>

View file

@ -5,7 +5,7 @@ using Cirno.Scripts;
public partial class Activable : Node2D, IActivable
{
public virtual void Activate()
public virtual void Activate(ActivationType activationType = ActivationType.Toggle)
{
//Debug.WriteLine("Activated");
}

View file

@ -1,10 +1,11 @@
[gd_scene load_steps=8 format=3 uid="uid://byms2dhliyux0"]
[gd_scene load_steps=10 format=3 uid="uid://byms2dhliyux0"]
[ext_resource type="Script" path="res://Scripts/Activables/Teleporter.cs" id="1_juavy"]
[ext_resource type="Texture2D" uid="uid://d3e762pxublbt" path="res://Sprites/teleporter.png" id="1_ppqan"]
[ext_resource type="Texture2D" uid="uid://dcrsv00yf6ylk" path="res://Sprites/Teleport_Particles.png" id="2_ggtec"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_uk8yj"]
size = Vector2(16, 16)
[sub_resource type="CircleShape2D" id="CircleShape2D_kwj8m"]
radius = 4.12311
[sub_resource type="AtlasTexture" id="AtlasTexture_ex07d"]
atlas = ExtResource("2_ggtec")
@ -40,13 +41,22 @@ animations = [{
"speed": 5.0
}]
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_we5sc"]
particle_flag_disable_z = true
emission_shape = 2
emission_sphere_radius = 8.85
orbit_velocity_min = -0.2
orbit_velocity_max = 0.2
gravity = Vector3(0, -98, 0)
color = Color(0.207843, 0.360784, 1, 1)
[node name="Teleporter" type="Area2D"]
collision_layer = 4
collision_mask = 2
script = ExtResource("1_juavy")
ParticleEmitTime = 0.8
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
shape = SubResource("RectangleShape2D_uk8yj")
shape = SubResource("CircleShape2D_kwj8m")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_ppqan")
@ -55,3 +65,11 @@ texture = ExtResource("1_ppqan")
position = Vector2(0, -9)
sprite_frames = SubResource("SpriteFrames_bt8wx")
animation = &"Idle"
[node name="Particles" type="GPUParticles2D" parent="."]
emitting = false
amount = 50
process_material = SubResource("ParticleProcessMaterial_we5sc")
lifetime = 0.8
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

File diff suppressed because one or more lines are too long

View file

@ -30,7 +30,7 @@ public partial class DialogueStarter : Activable
DialogueEndAction();
}
public override void Activate()
public override void Activate(ActivationType activationType = ActivationType.Toggle)
{
_gameManager.ChangeState(GameState.Dialogue);
_dialogic.Call("start", _trackName);

View file

@ -0,0 +1,135 @@
using System;
using System.Collections;
using System.Threading.Tasks;
using Godot;
namespace Cirno.Scripts.Activables;
public partial class Teleporter : Activable
{
[Export]
public bool IsEnabled { get; set; }
public bool IsPrimed { get; private set; }
[Export]
public Teleporter Target { get; set; }
[Export] public float ParticleEmitTime { get; private set; } = 2f;
[Export] public float TeleportAnimationLength { get; private set; } = 0.5f;
[Export] public Vector2 TeleportOffset { get; private set; } = new Vector2(0,-4f);
private double _particleTimer;
// [Export]
// public GpuParticles2D Particles { get; set; }
private GpuParticles2D _particles;
public override void _Ready()
{
_particles = GetNode<GpuParticles2D>("./Particles");
IsPrimed = true;
_particles.Emitting = false;
_particleTimer = 0;
}
public override void _Process(double delta)
{
if (!_particles.Emitting) return;
_particleTimer += delta;
if (_particleTimer >= ParticleEmitTime)
{
_particleTimer = 0;
_particles.Emitting = false;
}
}
public override void Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (activationType)
{
case ActivationType.Toggle:
// Enables/Disables teleporter
break;
case ActivationType.Enable:
// Enables Teleporter
IsEnabled = true;
break;
case ActivationType.Disable:
IsEnabled = false;
// Disables Teleporter
break;
case ActivationType.Use:
// Teleports
break;
case ActivationType.Destroy:
// Destroys
break;
}
}
public void PrepareForReceiving()
{
IsPrimed = false;
_particles.Emitting = true;
}
public void FireParticles()
{
_particles.Emitting = true;
_particleTimer = 0;
}
private void _on_body_entered(CharacterBody2D area)
{
if (area is not PlayerMovement player) return;
if (!IsPrimed)
{
IsPrimed = true;
//_particles.Emitting = false;
return;
}
// Teleport player to target if active
if (!IsEnabled) return;
if (Target is null) return;
// Call Teleport here
_ = Teleport(player);
}
private async Task Teleport(PlayerMovement player)
{
player.RequestMovementDisable(true);
await TweenPlayer(player);
Target.PrepareForReceiving();
_particles.Emitting = true;
await Task.Delay((int)(TeleportAnimationLength * 1000));
player.GlobalPosition = Target.GlobalPosition + TeleportOffset;
player.RequestMovementDisable(false);
}
private async Task TweenPlayer(PlayerMovement player)
{
// Create a Tween for the teleport animation
Tween tween = GetTree().CreateTween();
tween.SetEase(Tween.EaseType.InOut);
tween.SetTrans(Tween.TransitionType.Sine);
tween.TweenProperty(player, "global_position", GlobalPosition + new Vector2(0,-4f), TeleportAnimationLength);
// Wait for the tween to finish
await ToSignal(tween, "finished");
}
}

View file

@ -57,7 +57,7 @@ public partial class Boss : Enemy, IActivable
_currentHealth -= amount;
}
public void Activate()
public void Activate(ActivationType activationType = ActivationType.Toggle)
{
_started = true;
StartPhase(CurrentPhase);

View file

@ -44,7 +44,7 @@ public partial class Door : Activable
}
public override void Activate()
public override void Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (State)
{

View file

@ -2,5 +2,14 @@
public interface IActivable
{
void Activate();
void Activate(ActivationType activationType = ActivationType.Toggle);
}
public enum ActivationType
{
Toggle,
Enable,
Disable,
Use,
Destroy
}

View file

@ -5,6 +5,8 @@ namespace Cirno.Scripts.Interactables;
public partial class AreaTrigger : Area2D
{
[Export] public Node2D Target { get; set; }
[Export] public ActivationType ActivationType { get; set; } = Scripts.ActivationType.Toggle;
[Export] public bool OneTime { get; set; }
[Export] public bool DoNotActivateOnFirst { get; set; }

View file

@ -16,7 +16,7 @@ public partial class Pickupper : Activable
_inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
}
public override void Activate()
public override void Activate(ActivationType activationType = ActivationType.Toggle)
{
foreach (var item in LootTable)
{

View file

@ -122,6 +122,22 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
}
}
/// <summary>
/// Requests disable movement
/// </summary>
/// <param name="disable">true disables false enables</param>
public void RequestMovementDisable(bool disable)
{
if (disable)
{
_canMove = false;
}
else
{
_canMove = true;
}
}
/*public override _Process(float _delta)
{
if (Input.IsActionPressed("ui_right"))