diff --git a/scenes/main_scene.tscn b/scenes/main_scene.tscn index dfefed4..d0a7101 100644 --- a/scenes/main_scene.tscn +++ b/scenes/main_scene.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=17 format=3 uid="uid://dhn7yt46fyac8"] +[gd_scene load_steps=18 format=3 uid="uid://dhn7yt46fyac8"] [ext_resource type="PackedScene" uid="uid://bhulqhxesd5gc" path="res://prefabs/player.tscn" id="1_65a7v"] +[ext_resource type="AudioStream" uid="uid://bsy2d0bl3lgg0" path="res://sounds/crank.ogg" id="1_cweq4"] [ext_resource type="Texture2D" uid="uid://py6qiu3rm7cu" path="res://sprites/brickwall.png" id="2_edqdh"] [ext_resource type="Texture2D" uid="uid://dlbl6d4yghvht" path="res://sprites/mask.png" id="3_8o315"] [ext_resource type="Script" path="res://scripts/Flashlight.cs" id="3_cylxo"] @@ -19,7 +20,7 @@ light_mode = 2 [sub_resource type="ShaderMaterial" id="ShaderMaterial_m680d"] shader = ExtResource("5_64d71") -[sub_resource type="ViewportTexture" id="ViewportTexture_0u602"] +[sub_resource type="ViewportTexture" id="ViewportTexture_nebfb"] viewport_path = NodePath("FlashlightViewport") [sub_resource type="CircleShape2D" id="CircleShape2D_prnh4"] @@ -36,10 +37,12 @@ light_mode = 2 [node name="Root" type="Node2D"] y_sort_enabled = true -[node name="Player" parent="." instance=ExtResource("1_65a7v")] -position = Vector2(19, 4) +[node name="Sounds" type="Node" parent="."] -[node name="Controller" type="Node" parent="." node_paths=PackedStringArray("Player", "Camera", "Circle", "PlayerCircle", "Polygon", "CollisionCircle", "CollisionPlayerCircle", "CollisionPolygon", "FlashlightGroup")] +[node name="CrankSound" type="AudioStreamPlayer" parent="Sounds"] +stream = ExtResource("1_cweq4") + +[node name="FlashlightController" type="Node" parent="." node_paths=PackedStringArray("Player", "Camera", "Circle", "PlayerCircle", "Polygon", "CollisionCircle", "CollisionPlayerCircle", "CollisionPolygon", "FlashlightGroup", "CrankSoundPlayer")] script = ExtResource("3_cylxo") Player = NodePath("../Player") Camera = NodePath("../PlayerCamera") @@ -51,6 +54,10 @@ CollisionPlayerCircle = NodePath("../PlayerCamera/Area2D/PlayerCircle") CollisionPolygon = NodePath("../PlayerCamera/Area2D/CollisionPolygon2D") FlashlightGroup = NodePath("../FlashlightViewport/CanvasGroup") BrightnessCurve = SubResource("Curve_o5byr") +CrankSoundPlayer = NodePath("../Sounds/CrankSound") + +[node name="Player" parent="." instance=ExtResource("1_65a7v")] +position = Vector2(19, 4) [node name="TestWall" type="Sprite2D" parent="."] light_mask = 2 @@ -95,7 +102,7 @@ CameraBounds = Vector2(30, 20) [node name="PointLight2D" type="PointLight2D" parent="PlayerCamera" node_paths=PackedStringArray("LightViewport")] blend_mode = 2 range_item_cull_mask = 2 -texture = SubResource("ViewportTexture_0u602") +texture = SubResource("ViewportTexture_nebfb") script = ExtResource("6_slohe") LightViewport = NodePath("../../FlashlightViewport") diff --git a/scripts/Flashlight.cs b/scripts/Flashlight.cs index 9648f29..6efe809 100644 --- a/scripts/Flashlight.cs +++ b/scripts/Flashlight.cs @@ -14,13 +14,15 @@ public partial class Flashlight : Node [Export] public CollisionShape2D CollisionPlayerCircle; [Export] public CollisionPolygon2D CollisionPolygon; [Export] public CanvasGroup FlashlightGroup; - + [Export] public Curve BrightnessCurve; - + + [Export] public AudioStreamPlayer CrankSoundPlayer; + private float FlashlightRadius = Constants.MaxFlashlightRadius; private float FlashlightEnergy = Constants.MaxFlashlightEnergy; private float FlashlightChargeTimeout = 1; - + public override void _Ready() { base._Ready(); @@ -44,7 +46,7 @@ public partial class Flashlight : Node FlashlightRadius = Mathf.Lerp(Constants.MinFlashlightRadius, Constants.MaxFlashlightRadius, Mathf.Clamp(d - Constants.MinFlashlightDistance, 0, Constants.MaxFlashlightDistance - Constants.MinFlashlightDistance) / Constants.MaxFlashlightDistance); - + var flashlightScreenPosition = flashlightScreenCenterPosition + Constants.HalfScreenSize; var flashlightScale = FlashlightRadius / Constants.MaxFlashlightRadius; Circle.Position = flashlightScreenPosition; @@ -67,20 +69,26 @@ public partial class Flashlight : Node var xy3 = a * new Vector2(Mathf.Cos(dslkhjdsflkhjsdfhlkjdfsjlk), Mathf.Sin(dslkhjdsflkhjsdfhlkjdfsjlk)); var dslkhjdsflkhjsdfhlkjdfsjlk2 = angle - arcsinRd; var xy4 = a * new Vector2(Mathf.Cos(dslkhjdsflkhjsdfhlkjdfsjlk2), Mathf.Sin(dslkhjdsflkhjsdfhlkjdfsjlk2)); - + var polygon = new[] { playerScreenPosition, playerScreenPosition + xy3, playerScreenPosition + xy4 }; Polygon.Polygon = polygon; CollisionPolygon.Polygon = polygon; } - FlashlightChargeTimeout = Mathf.Clamp(FlashlightChargeTimeout-(float)delta,0,1); - if (Input.IsActionJustPressed("flashlight_charge") && FlashlightChargeTimeout <= 0){ + FlashlightChargeTimeout = Mathf.Clamp(FlashlightChargeTimeout - (float)delta, 0, 1); + if (Input.IsActionJustPressed("flashlight_charge") && FlashlightChargeTimeout <= 0) + { FlashlightChargeTimeout = 1; - FlashlightEnergy+=Constants.FlashlightEneregyPerCharge; + FlashlightEnergy += Constants.FlashlightEneregyPerCharge; + var rng = new RandomNumberGenerator(); + CrankSoundPlayer.PitchScale = rng.RandfRange(1f, 1.15f); + CrankSoundPlayer.Play(); } - FlashlightEnergy = Mathf.Clamp(FlashlightEnergy-(float)delta, 0, Constants.MaxFlashlightEnergy); - FlashlightGroup.Modulate = new Color(BrightnessCurve.Sample(FlashlightEnergy/Constants.MaxFlashlightEnergy), 1, 1, 1); - CollisionCircle.Enabled = CollisionPlayerCircle.Enabled = CollisionPolygon.Enabled = FlashlightEnergy >= 10; + + FlashlightEnergy = Mathf.Clamp(FlashlightEnergy - (float)delta, 0, Constants.MaxFlashlightEnergy); + FlashlightGroup.Modulate = + new Color(BrightnessCurve.Sample(FlashlightEnergy / Constants.MaxFlashlightEnergy), 1, 1, 1); + CollisionCircle.Disabled = CollisionPlayerCircle.Disabled = CollisionPolygon.Disabled = FlashlightEnergy < 10; } } diff --git a/scripts/GameCamera.cs b/scripts/GameCamera.cs index 556961f..289f4b3 100644 --- a/scripts/GameCamera.cs +++ b/scripts/GameCamera.cs @@ -21,7 +21,7 @@ public partial class GameCamera : Camera2D var halfCameraFollowBounds = CameraFollowBounds / 2; var hardLimit = relativePlayerPosition.Clamp(-halfCameraBounds, halfCameraBounds); difference = relativePlayerPosition - hardLimit; - GD.Print($"HardDiff {difference}"); + //GD.Print($"HardDiff {difference}"); if (difference.IsZeroApprox()) { float x = 0, y = 0; @@ -36,7 +36,7 @@ public partial class GameCamera : Camera2D } difference = new Vector2(x, y); - GD.Print($"SmoothDiff {difference}"); + //GD.Print($"SmoothDiff {difference}"); } Position = (Position + difference).Round(); diff --git a/sounds/crank.ogg b/sounds/crank.ogg new file mode 100644 index 0000000..23f6a81 Binary files /dev/null and b/sounds/crank.ogg differ diff --git a/sounds/crank.ogg.import b/sounds/crank.ogg.import new file mode 100644 index 0000000..90061ff --- /dev/null +++ b/sounds/crank.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://bsy2d0bl3lgg0" +path="res://.godot/imported/crank.ogg-de862830fd5b0b5f87e0226fbb2d93d0.oggvorbisstr" + +[deps] + +source_file="res://sounds/crank.ogg" +dest_files=["res://.godot/imported/crank.ogg-de862830fd5b0b5f87e0226fbb2d93d0.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4