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 0000000..e3c60b6 Binary files /dev/null and b/sprites/key_space.png differ 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 +}]