Подсказка по управлению фонарем

This commit is contained in:
Евгений Титаренко 2023-08-19 15:41:46 +03:00
parent 4d3ac1e4fb
commit e8f5c3de80
6 changed files with 95 additions and 1 deletions

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=3 uid="uid://bhulqhxesd5gc"]
[gd_scene load_steps=5 format=3 uid="uid://bhulqhxesd5gc"]
[ext_resource type="Script" path="res://scripts/Player.cs" id="1_1vpun"]
[ext_resource type="SpriteFrames" uid="uid://cfdng3tdv65p6" path="res://sprites/player/player.tres" id="1_8jl58"]
[ext_resource type="SpriteFrames" uid="uid://2621hqkv4w0x" path="res://sprites/key_space.tres" id="3_h0r18"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5hhj3"]
size = Vector2(15, 15)
@ -19,3 +20,9 @@ shape = SubResource("RectangleShape2D_5hhj3")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = ExtResource("1_8jl58")
animation = &"down"
[node name="AnimatedSprite2D2" type="AnimatedSprite2D" parent="."]
position = Vector2(0, -19)
scale = Vector2(0.25, 0.25)
sprite_frames = ExtResource("3_h0r18")
frame_progress = 0.535545

View file

@ -3,6 +3,11 @@ using Godot;
public partial class Flashlight : Node
{
[Signal]
public delegate void EnergyOutEventHandler();
[Signal]
public delegate void ChargedEventHandler();
[Export] public Player Player;
[Export] public GameCamera Camera;
@ -22,6 +27,7 @@ public partial class Flashlight : Node
private float FlashlightRadius = Constants.MaxFlashlightRadius;
private float FlashlightEnergy = 0;
private float FlashlightChargeTimeout = 1;
private bool _isDischarged = true;
public override void _Ready()
{
@ -79,6 +85,8 @@ public partial class Flashlight : Node
FlashlightChargeTimeout = Mathf.Clamp(FlashlightChargeTimeout - (float)delta, 0, 1);
if (Input.IsActionJustPressed("flashlight_charge") && FlashlightChargeTimeout <= 0)
{
EmitSignal(SignalName.Charged);
_isDischarged = false;
FlashlightChargeTimeout = 1;
FlashlightEnergy += Constants.FlashlightEnergyPerCharge;
var rng = new RandomNumberGenerator();
@ -91,5 +99,11 @@ public partial class Flashlight : Node
FlashlightGroup.Modulate =
new Color(BrightnessCurve.Sample(FlashlightEnergy / Constants.MaxFlashlightEnergy), 1, 1, 1);
CollisionCircle.Disabled = CollisionPlayerCircle.Disabled = CollisionPolygon.Disabled = FlashlightEnergy < 10;
if (!_isDischarged && FlashlightEnergy < 5)
{
EmitSignal(SignalName.EnergyOut);
_isDischarged = true;
}
}
}

View file

@ -12,12 +12,17 @@ public partial class Player : CharacterBody2D
public static Player Instance { get; private set; }
protected AnimatedSprite2D Sprite;
protected AnimatedSprite2D SpriteSpaceBar;
public override void _Ready()
{
Instance = this;
Sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
SpriteSpaceBar = (AnimatedSprite2D)FindChild("AnimatedSprite2D2");
SpriteSpaceBar.Play("default");
SpriteSpaceBar.Visible = false;
}
public override void _PhysicsProcess(double delta)
@ -69,4 +74,13 @@ public partial class Player : CharacterBody2D
DeathScreen.Instance.Killed(killer);
}
public void FlashlightHelperOn()
{
SpriteSpaceBar.Visible = true;
}
public void FlashlightHelperOff()
{
SpriteSpaceBar.Visible = true;
}
}

BIN
sprites/key_space.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://geiagnq38try"
path="res://.godot/imported/key_space.png-edb1192899e0b0b0ccef977d3ce96b70.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/key_space.png"
dest_files=["res://.godot/imported/key_space.png-edb1192899e0b0b0ccef977d3ce96b70.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

25
sprites/key_space.tres Normal file
View file

@ -0,0 +1,25 @@
[gd_resource type="SpriteFrames" load_steps=4 format=3 uid="uid://2621hqkv4w0x"]
[ext_resource type="Texture2D" uid="uid://geiagnq38try" path="res://sprites/key_space.png" id="1_xhlet"]
[sub_resource type="AtlasTexture" id="AtlasTexture_ke1d0"]
atlas = ExtResource("1_xhlet")
region = Rect2(0, 0, 64, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_qc115"]
atlas = ExtResource("1_xhlet")
region = Rect2(64, 0, 64, 32)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ke1d0")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qc115")
}],
"loop": true,
"name": &"default",
"speed": 2.0
}]