From e8f5c3de80964739fbb41830f0fb973eff18f492 Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Sat, 19 Aug 2023 15:41:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D1=81=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BF=D0=BE=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8E=20=D1=84=D0=BE=D0=BD=D0=B0=D1=80?= =?UTF-8?q?=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prefabs/player.tscn | 9 ++++++++- scripts/Flashlight.cs | 14 ++++++++++++++ scripts/Player.cs | 14 ++++++++++++++ sprites/key_space.png | Bin 0 -> 457 bytes sprites/key_space.png.import | 34 ++++++++++++++++++++++++++++++++++ sprites/key_space.tres | 25 +++++++++++++++++++++++++ 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 sprites/key_space.png create mode 100644 sprites/key_space.png.import create mode 100644 sprites/key_space.tres diff --git a/prefabs/player.tscn b/prefabs/player.tscn index a852cf2..6666d8f 100644 --- a/prefabs/player.tscn +++ b/prefabs/player.tscn @@ -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 diff --git a/scripts/Flashlight.cs b/scripts/Flashlight.cs index 8558d70..c506ab2 100644 --- a/scripts/Flashlight.cs +++ b/scripts/Flashlight.cs @@ -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; + } } } diff --git a/scripts/Player.cs b/scripts/Player.cs index c559408..aaa51a5 100644 --- a/scripts/Player.cs +++ b/scripts/Player.cs @@ -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; + } } diff --git a/sprites/key_space.png b/sprites/key_space.png new file mode 100644 index 0000000000000000000000000000000000000000..e3c60b687a2677076fa2d05b6d00cca2a41ece17 GIT binary patch literal 457 zcmV;)0XF`LP)Px$X-PyuRCt{2n%kDcAP7ZqR{#H(>BB^aq)0A0RpIQ%NE5*Wm{=kZnxtIgug~JU zXg-JK7z`#NV)m(ll#06$!NzO!1SZ6%`uCIskOE+4mRVxop<*|C_1Ju5GTPtlKD4l{ zTk-!<1xP8m4pJnt065ZuR;s|Q3Yb~35=#HE2WY@UCHxsZfk_Be0f|b5VhA8Ok6M7$ zE038Z?W{3*-)yHnLmP{hy*+un2dD-8xPa2m8q3!-Tk9ETw!j9Pzy>^2!es?8OAA=N z5-uwMl>9y{D**7zkQQKlExX$LwEiit)%q(lSAQFkR=*#=2KKPk#*QNCF$YiwEuaAp zl@J1Gz(XZG{SbI zVkdwIr)qb6^d1W$yauXx&w5D_K!ofkvX5}1#6bFqzl3c>S$v{>6692f;rS=g{RaSq z<_)*v9V>no4WIx301jnXNoGw=04e|g00;m8000000Mb*F00000NkvXXu0mjfP@ueq literal 0 HcmV?d00001 diff --git a/sprites/key_space.png.import b/sprites/key_space.png.import new file mode 100644 index 0000000..8a8eebf --- /dev/null +++ b/sprites/key_space.png.import @@ -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 diff --git a/sprites/key_space.tres b/sprites/key_space.tres new file mode 100644 index 0000000..b517e13 --- /dev/null +++ b/sprites/key_space.tres @@ -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 +}]