mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-18 13:23:48 +00:00
health station
This commit is contained in:
parent
cc1fa2cdc6
commit
f7cbd7d171
8 changed files with 268 additions and 11 deletions
81
Scenes/Actors/HealthStation.tscn
Normal file
81
Scenes/Actors/HealthStation.tscn
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
[gd_scene load_steps=10 format=3 uid="uid://c8lgk4wnyi1e6"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Activables/HealthStation.cs" id="1_bvrbs"]
|
||||||
|
[ext_resource type="SpriteFrames" uid="uid://w4jlaryen3we" path="res://Resources/Sprites/teleporter.tres" id="2_vd40s"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://doy352j5hb51l" path="res://Sprites/Actors/HealthStation.png" id="3_761ef"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_kwj8m"]
|
||||||
|
radius = 4.12311
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_dsfb4"]
|
||||||
|
atlas = ExtResource("3_761ef")
|
||||||
|
region = Rect2(16, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_mwkkm"]
|
||||||
|
atlas = ExtResource("3_761ef")
|
||||||
|
region = Rect2(32, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_bu57s"]
|
||||||
|
atlas = ExtResource("3_761ef")
|
||||||
|
region = Rect2(0, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_nmfjk"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_dsfb4")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_mwkkm")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Active",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_bu57s")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Default",
|
||||||
|
"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.819608, 0, 0, 1)
|
||||||
|
|
||||||
|
[node name="HealthStation" type="Area2D"]
|
||||||
|
collision_mask = 2
|
||||||
|
script = ExtResource("1_bvrbs")
|
||||||
|
IsEnabled = true
|
||||||
|
HealthPerSecond = 5.0
|
||||||
|
ShieldPerSecond = 5.0
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("CircleShape2D_kwj8m")
|
||||||
|
|
||||||
|
[node name="ParticleSprite" type="AnimatedSprite2D" parent="."]
|
||||||
|
visible = false
|
||||||
|
position = Vector2(0, -9)
|
||||||
|
sprite_frames = ExtResource("2_vd40s")
|
||||||
|
animation = &"Teleporting"
|
||||||
|
|
||||||
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
|
sprite_frames = SubResource("SpriteFrames_nmfjk")
|
||||||
|
animation = &"Default"
|
||||||
|
|
||||||
|
[node name="Particles" type="GPUParticles2D" parent="."]
|
||||||
|
z_index = 2
|
||||||
|
emitting = false
|
||||||
|
amount = 50
|
||||||
|
process_material = SubResource("ParticleProcessMaterial_we5sc")
|
||||||
|
lifetime = 0.8
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
|
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
|
||||||
|
|
@ -29,15 +29,16 @@ position = Vector2(0, -9)
|
||||||
sprite_frames = ExtResource("2_k58t7")
|
sprite_frames = ExtResource("2_k58t7")
|
||||||
animation = &"Teleporting"
|
animation = &"Teleporting"
|
||||||
|
|
||||||
[node name="Particles" type="GPUParticles2D" parent="."]
|
|
||||||
emitting = false
|
|
||||||
amount = 50
|
|
||||||
process_material = SubResource("ParticleProcessMaterial_we5sc")
|
|
||||||
lifetime = 0.8
|
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
sprite_frames = ExtResource("2_k58t7")
|
sprite_frames = ExtResource("2_k58t7")
|
||||||
animation = &"Default"
|
animation = &"Default"
|
||||||
frame_progress = 0.462812
|
frame_progress = 0.462812
|
||||||
|
|
||||||
|
[node name="Particles" type="GPUParticles2D" parent="."]
|
||||||
|
z_index = 2
|
||||||
|
emitting = false
|
||||||
|
amount = 50
|
||||||
|
process_material = SubResource("ParticleProcessMaterial_we5sc")
|
||||||
|
lifetime = 0.8
|
||||||
|
|
||||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
117
Scripts/Activables/HealthStation.cs
Normal file
117
Scripts/Activables/HealthStation.cs
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Activables;
|
||||||
|
|
||||||
|
public partial class HealthStation : Activable
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
public bool IsEnabled { get; set; }
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public float HealthPerSecond { get; private set; } = 10f;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public float ShieldPerSecond { get; private set; } = 10f;
|
||||||
|
|
||||||
|
private AnimatedSprite2D _animatedSprite;
|
||||||
|
|
||||||
|
private GpuParticles2D _particles;
|
||||||
|
|
||||||
|
private bool _isHealing = false;
|
||||||
|
|
||||||
|
private PlayerMovement _cachedPlayer;
|
||||||
|
|
||||||
|
private double _healingTimer = 0;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
_particles = GetNode<GpuParticles2D>("./Particles");
|
||||||
|
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||||
|
|
||||||
|
_particles.Emitting = false;
|
||||||
|
|
||||||
|
if (IsEnabled)
|
||||||
|
{
|
||||||
|
_animatedSprite.Play("Active");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_animatedSprite.Play("Default");
|
||||||
|
}
|
||||||
|
|
||||||
|
_healingTimer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
base._Process(delta);
|
||||||
|
|
||||||
|
if (_isHealing && _cachedPlayer != null)
|
||||||
|
{
|
||||||
|
_healingTimer += delta;
|
||||||
|
|
||||||
|
if (_healingTimer >= 1)
|
||||||
|
{
|
||||||
|
_cachedPlayer.CurrentHealth += HealthPerSecond;
|
||||||
|
_cachedPlayer.CurrentShield += ShieldPerSecond;
|
||||||
|
|
||||||
|
_healingTimer = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Activate(ActivationType activationType = ActivationType.Toggle)
|
||||||
|
{
|
||||||
|
switch (activationType)
|
||||||
|
{
|
||||||
|
case ActivationType.Toggle:
|
||||||
|
// Enables/Disables teleporter
|
||||||
|
break;
|
||||||
|
case ActivationType.Enable:
|
||||||
|
// Enables Teleporter
|
||||||
|
IsEnabled = true;
|
||||||
|
_animatedSprite.Play("Active");
|
||||||
|
break;
|
||||||
|
case ActivationType.Disable:
|
||||||
|
IsEnabled = false;
|
||||||
|
_animatedSprite.Play("Default");
|
||||||
|
// Disables Teleporter
|
||||||
|
break;
|
||||||
|
case ActivationType.Use:
|
||||||
|
// Teleports
|
||||||
|
break;
|
||||||
|
case ActivationType.Destroy:
|
||||||
|
// Destroys
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _on_body_entered(CharacterBody2D area)
|
||||||
|
{
|
||||||
|
// Heal player if active
|
||||||
|
if (!IsEnabled) return;
|
||||||
|
if (area is not PlayerMovement player) return;
|
||||||
|
|
||||||
|
_cachedPlayer = player;
|
||||||
|
|
||||||
|
_isHealing = true;
|
||||||
|
_particles.Emitting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _on_body_exited(CharacterBody2D area)
|
||||||
|
{
|
||||||
|
if (!_isHealing) return;
|
||||||
|
if (!IsEnabled) return;
|
||||||
|
if (area is not PlayerMovement player) return;
|
||||||
|
|
||||||
|
// Stop healing player if active
|
||||||
|
|
||||||
|
_isHealing = false;
|
||||||
|
_particles.Emitting = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -88,11 +88,16 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
if (_currentHealth != value)
|
if (_currentHealth != value)
|
||||||
{
|
{
|
||||||
_currentHealth = value;
|
_currentHealth = value;
|
||||||
|
|
||||||
|
if (_currentHealth > MaxHealth) {
|
||||||
|
_currentHealth = MaxHealth;
|
||||||
|
}
|
||||||
|
|
||||||
EmitSignal(nameof(HealthChanged), _currentHealth, MaxHealth);
|
EmitSignal(nameof(HealthChanged), _currentHealth, MaxHealth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float CurrentShield
|
public float CurrentShield
|
||||||
{
|
{
|
||||||
get => _currentShield;
|
get => _currentShield;
|
||||||
|
|
@ -101,11 +106,17 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
if (_currentShield != value)
|
if (_currentShield != value)
|
||||||
{
|
{
|
||||||
_currentShield = value;
|
_currentShield = value;
|
||||||
|
|
||||||
|
if (_currentShield > MaxShield)
|
||||||
|
{
|
||||||
|
_currentShield = MaxShield;
|
||||||
|
}
|
||||||
|
|
||||||
EmitSignal(nameof(ShieldChanged), _currentShield, MaxShield);
|
EmitSignal(nameof(ShieldChanged), _currentShield, MaxShield);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private InventoryManager _inventoryManager;
|
//private InventoryManager _inventoryManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
|
|
|
||||||
BIN
Sprites/Actors/HealthStation.aseprite
(Stored with Git LFS)
Normal file
BIN
Sprites/Actors/HealthStation.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Sprites/Actors/HealthStation.png
(Stored with Git LFS)
Normal file
BIN
Sprites/Actors/HealthStation.png
(Stored with Git LFS)
Normal file
Binary file not shown.
34
Sprites/Actors/HealthStation.png.import
Normal file
34
Sprites/Actors/HealthStation.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://doy352j5hb51l"
|
||||||
|
path="res://.godot/imported/HealthStation.png-063912324ed0e2bc652421f0f0e75865.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Sprites/Actors/HealthStation.png"
|
||||||
|
dest_files=["res://.godot/imported/HealthStation.png-063912324ed0e2bc652421f0f0e75865.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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue