From b5439da5a0fc41fc6db43ce3d53b942740dadd2f Mon Sep 17 00:00:00 2001 From: Ivan Kuzmenko <6745157+rndtrash@users.noreply.github.com> Date: Sat, 19 Aug 2023 17:09:11 +0300 Subject: [PATCH 01/10] now it's actually playable --- .gitignore | 2 ++ export_presets.cfg | 2 +- prefabs/furniture/door_closed.tscn | 2 ++ prefabs/player.tscn | 2 +- scenes/level.tscn | 23 +++++++++++++++++++---- scenes/main_scene.tscn | 21 ++++++++++++++++----- scripts/GameManager.cs | 25 ++++++++++++++++++------- scripts/PlayZone.cs | 3 +++ scripts/Player.cs | 3 ++- scripts/WinScreen.cs | 3 ++- scripts/entities/And.cs | 4 +++- scripts/entities/Door.cs | 18 ++++++++++++++---- sprites/key_space.tres | 2 +- 13 files changed, 84 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 4709183..c672ad3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ # Godot 4+ specific ignores .godot/ +# Binaries +bin/ \ No newline at end of file diff --git a/export_presets.cfg b/export_presets.cfg index 80a994c..43bfce7 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -48,7 +48,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="" +export_path="bin/quest-of-light.exe" encryption_include_filters="" encryption_exclude_filters="" encrypt_pck=false diff --git a/prefabs/furniture/door_closed.tscn b/prefabs/furniture/door_closed.tscn index ba5c537..ef75763 100644 --- a/prefabs/furniture/door_closed.tscn +++ b/prefabs/furniture/door_closed.tscn @@ -34,6 +34,8 @@ sprite_frames = SubResource("SpriteFrames_v2loo") animation = &"closed" [node name="StaticBody2D" type="StaticBody2D" parent="."] +collision_layer = 4 +collision_mask = 4 [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] position = Vector2(0, 6) diff --git a/prefabs/player.tscn b/prefabs/player.tscn index 6666d8f..eee135d 100644 --- a/prefabs/player.tscn +++ b/prefabs/player.tscn @@ -2,7 +2,7 @@ [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"] +[ext_resource type="SpriteFrames" uid="uid://dqtp1l5ecav4k" path="res://sprites/key_space.tres" id="3_h0r18"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_5hhj3"] size = Vector2(15, 15) diff --git a/scenes/level.tscn b/scenes/level.tscn index dc4f303..b9aada4 100644 --- a/scenes/level.tscn +++ b/scenes/level.tscn @@ -82,12 +82,15 @@ position = Vector2(624, -385) [node name="spikes" parent="." instance=ExtResource("10_yerk5")] position = Vector2(683, -352) +Enabled = true [node name="spikes2" parent="." instance=ExtResource("10_yerk5")] position = Vector2(683, -384) +Enabled = true [node name="spikes3" parent="." instance=ExtResource("10_yerk5")] position = Vector2(683, -415) +Enabled = true [node name="papers2" parent="." instance=ExtResource("5_th514")] position = Vector2(751, 92) @@ -106,33 +109,39 @@ position = Vector2(688, -850) [node name="spikes4" parent="." instance=ExtResource("10_yerk5")] position = Vector2(785, -847) +Enabled = true [node name="spikes5" parent="." instance=ExtResource("10_yerk5")] position = Vector2(847, -847) +Enabled = true [node name="spikes6" parent="." instance=ExtResource("10_yerk5")] position = Vector2(817, -847) +Enabled = true [node name="spikes7" parent="." instance=ExtResource("10_yerk5")] position = Vector2(848, -816) +Enabled = true [node name="spikes8" parent="." instance=ExtResource("10_yerk5")] position = Vector2(848, -783) +Enabled = true [node name="spikes9" parent="." instance=ExtResource("10_yerk5")] position = Vector2(848, -752) +Enabled = true [node name="pressure_plate_puzzle_4_bl" parent="." instance=ExtResource("9_6ydrq")] -position = Vector2(-113, -592) +position = Vector2(-83, -622) [node name="pressure_plate_puzzle_4_br" parent="." instance=ExtResource("9_6ydrq")] -position = Vector2(432, -592) +position = Vector2(404, -624) [node name="pressure_plate_puzzle_4_tl" parent="." instance=ExtResource("9_6ydrq")] -position = Vector2(-110, -1072) +position = Vector2(-87, -1046) [node name="pressure_plate_puzzle_4_tr" parent="." instance=ExtResource("9_6ydrq")] -position = Vector2(432, -1071) +position = Vector2(413, -1045) [node name="door_closed_puzzle_4" parent="." instance=ExtResource("7_kt8g1")] position = Vector2(177, -1112) @@ -256,21 +265,27 @@ position = Vector2(791, 783) [node name="spikes10" parent="." instance=ExtResource("10_yerk5")] position = Vector2(732, 980) +Enabled = true [node name="spikes11" parent="." instance=ExtResource("10_yerk5")] position = Vector2(764, 947) +Enabled = true [node name="spikes12" parent="." instance=ExtResource("10_yerk5")] position = Vector2(796, 915) +Enabled = true [node name="spikes13" parent="." instance=ExtResource("10_yerk5")] position = Vector2(576, 978) +Enabled = true [node name="spikes14" parent="." instance=ExtResource("10_yerk5")] position = Vector2(544, 946) +Enabled = true [node name="spikes15" parent="." instance=ExtResource("10_yerk5")] position = Vector2(512, 915) +Enabled = true [node name="Watcher" parent="." instance=ExtResource("13_nbkmp")] position = Vector2(1489, 566) diff --git a/scenes/main_scene.tscn b/scenes/main_scene.tscn index 0eb26f9..f6d4957 100644 --- a/scenes/main_scene.tscn +++ b/scenes/main_scene.tscn @@ -22,7 +22,7 @@ point_count = 2 [sub_resource type="ShaderMaterial" id="ShaderMaterial_m680d"] shader = ExtResource("5_64d71") -[sub_resource type="ViewportTexture" id="ViewportTexture_42ps6"] +[sub_resource type="ViewportTexture" id="ViewportTexture_57pph"] viewport_path = NodePath("FlashlightViewport") [sub_resource type="CircleShape2D" id="CircleShape2D_prnh4"] @@ -46,8 +46,9 @@ height = 192 [node name="Root" type="Node2D"] y_sort_enabled = true -[node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("Player")] +[node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("FirstZone", "Player")] script = ExtResource("1_ij566") +FirstZone = NodePath("../Zones/PlayZone1") Player = NodePath("../Player") [node name="Sounds" type="Node" parent="."] @@ -242,7 +243,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_42ps6") +texture = SubResource("ViewportTexture_57pph") script = ExtResource("6_slohe") LightViewport = NodePath("../../FlashlightViewport") @@ -302,7 +303,7 @@ layout_mode = 0 [node name="MonsterSprite" type="TextureRect" parent="CanvasLayer/DeathScreen"] layout_mode = 0 -[node name="WinScreen" type="TextureRect" parent="CanvasLayer" node_paths=PackedStringArray("Manager")] +[node name="WinScreen" type="TextureRect" parent="CanvasLayer" node_paths=PackedStringArray("Manager", "TextLabel")] visible = false z_index = 15 anchors_preset = 15 @@ -313,6 +314,7 @@ grow_vertical = 2 texture = SubResource("GradientTexture2D_2sbp3") script = ExtResource("13_prax6") Manager = NodePath("../../GameManager") +TextLabel = NodePath("Label2") [node name="Label" type="Label" parent="CanvasLayer/WinScreen"] layout_mode = 1 @@ -327,7 +329,6 @@ horizontal_alignment = 1 vertical_alignment = 1 [node name="Label2" type="Label" parent="CanvasLayer/WinScreen"] -visible = false layout_mode = 1 anchors_preset = 14 anchor_top = 0.5 @@ -360,5 +361,15 @@ horizontal_alignment = 1 vertical_alignment = 1 [connection signal="GameOver" from="GameManager" to="CanvasLayer/WinScreen" method="Open"] +[connection signal="ZoneEntered" from="Zones/PlayZone1" to="GameManager" method="SetCurrentZone"] +[connection signal="ZoneEntered" from="Zones/PlayZone2" to="GameManager" method="SetCurrentZone"] +[connection signal="ZoneEntered" from="Zones/PlayZone3" to="GameManager" method="SetCurrentZone"] +[connection signal="ZoneEntered" from="Zones/PlayZone4" to="GameManager" method="SetCurrentZone"] +[connection signal="ZoneEntered" from="Zones/PlayZone5" to="GameManager" method="SetCurrentZone"] +[connection signal="ZoneEntered" from="Zones/PlayZone6" to="GameManager" method="SetCurrentZone"] +[connection signal="ZoneEntered" from="Zones/PlayZone7" to="GameManager" method="SetCurrentZone"] +[connection signal="ZoneEntered" from="Zones/PlayZone8" to="GameManager" method="SetCurrentZone"] +[connection signal="ZoneEntered" from="Zones/PlayZone9" to="GameManager" method="SetCurrentZone"] +[connection signal="Killed" from="Player" to="GameManager" method="OnPlayerDied"] [connection signal="BossKilled" from="level" to="GameManager" method="EndGame"] [connection signal="timeout" from="CanvasLayer/DeathScreen/Timer" to="CanvasLayer/DeathScreen" method="Timeout"] diff --git a/scripts/GameManager.cs b/scripts/GameManager.cs index 35a3866..de5ab02 100644 --- a/scripts/GameManager.cs +++ b/scripts/GameManager.cs @@ -8,11 +8,17 @@ public partial class GameManager : Node public ulong GameStart = 0; public ulong GameEnd = 0; public int Attempts = 0; - public Node2D Checkpoint; + public NodePath Checkpoint = new NodePath(); - public GameInfo(Node2D checkpoint) + public GameInfo(NodePath path) { - Checkpoint = checkpoint; + SetCheckpoint(path); + } + + public void SetCheckpoint(NodePath path) + { + GD.Print($"{path}"); + Checkpoint = path; } } @@ -30,8 +36,9 @@ public partial class GameManager : Node { if (!IsPlaying) { + GD.Print("Restart stats"); IsPlaying = true; - _gameInfo = new GameInfo(FirstZone.PlayerSpawnPoint); + _gameInfo = new GameInfo(GetPathTo(FirstZone.PlayerSpawnPoint)); } StartGame(); @@ -40,18 +47,21 @@ public partial class GameManager : Node public void StartGame() { _gameInfo.GameStart = Time.GetTicksMsec(); - Player.Position = _gameInfo.Checkpoint.GlobalPosition; + Player.GlobalPosition = GetNode(_gameInfo.Checkpoint).GlobalPosition; } public void EndGame() { _gameInfo.GameEnd = Time.GetTicksMsec(); + Player.Invincible = true; + Player.SetProcess(false); + EmitSignal(SignalName.GameOver); } public string GetFormattedTimeElapsed() => - TimeSpan.FromMilliseconds(_gameInfo.GameEnd - _gameInfo.GameStart).ToString(@"hh\:mm\:ss.fff"); + TimeSpan.FromMilliseconds(_gameInfo.GameEnd - _gameInfo.GameStart).ToString(@"hh\:mm\:ss\.fff"); public void OnPlayerDied() => _gameInfo.Attempts++; @@ -60,6 +70,7 @@ public partial class GameManager : Node public void SetCurrentZone(PlayZone zone) { GD.Print($"New zone {zone}"); - _gameInfo.Checkpoint = zone.PlayerSpawnPoint; + var path = GetPathTo(zone.PlayerSpawnPoint); + _gameInfo.SetCheckpoint(path); } } diff --git a/scripts/PlayZone.cs b/scripts/PlayZone.cs index 9fb3cd7..aeab63d 100644 --- a/scripts/PlayZone.cs +++ b/scripts/PlayZone.cs @@ -16,9 +16,12 @@ public partial class PlayZone : Node2D private Area2D _area2D; private CollisionShape2D _collisionShape2D; + //private GameManager _gameManager; public override void _Ready() { + //_gameManager = (GameManager)GetTree().Root.FindChild("GameManager"); + _area2D = (Area2D)FindChild("Area2D"); _collisionShape2D = (CollisionShape2D)FindChild("CollisionShape2D"); diff --git a/scripts/Player.cs b/scripts/Player.cs index aaa51a5..1fa02b4 100644 --- a/scripts/Player.cs +++ b/scripts/Player.cs @@ -8,6 +8,7 @@ public partial class Player : CharacterBody2D public delegate void KilledEventHandler(); public bool Alive = true; + public bool Invincible = false; public static Player Instance { get; private set; } @@ -65,7 +66,7 @@ public partial class Player : CharacterBody2D public void Kill(Node2D killer) { - if (!Alive) + if (!Alive || Invincible) return; GD.Print($"Killed by {killer.Name}"); diff --git a/scripts/WinScreen.cs b/scripts/WinScreen.cs index 62c1790..76758c4 100644 --- a/scripts/WinScreen.cs +++ b/scripts/WinScreen.cs @@ -4,6 +4,7 @@ using System; public partial class WinScreen : TextureRect { [Export] public GameManager Manager; + [Export] public Label TextLabel; public override void _Ready() { @@ -14,7 +15,7 @@ public partial class WinScreen : TextureRect { Visible = true; - ((Label)FindChild("Label2")).Text = + TextLabel.Text = $"It took you\n{Manager.GetAttempts()} attempts\nand {Manager.GetFormattedTimeElapsed()}\nto finish the game."; } diff --git a/scripts/entities/And.cs b/scripts/entities/And.cs index e3a4ddc..83c05d9 100644 --- a/scripts/entities/And.cs +++ b/scripts/entities/And.cs @@ -15,13 +15,15 @@ public partial class And : Node public void Increment() { _buttons++; + GD.Print($"Increment {_buttons}/{CountOfButtons}"); if (_buttons == CountOfButtons) - EmitSignal(SignalName.ConditionNotMet); + EmitSignal(SignalName.ConditionMet); } public void Decrement() { _buttons--; + GD.Print($"Decrement {_buttons}/{CountOfButtons}"); if (_buttons != CountOfButtons) EmitSignal(SignalName.ConditionNotMet); } diff --git a/scripts/entities/Door.cs b/scripts/entities/Door.cs index 05868d3..122c0d3 100644 --- a/scripts/entities/Door.cs +++ b/scripts/entities/Door.cs @@ -3,12 +3,18 @@ using Godot; public partial class Door : Node2D { private AnimatedSprite2D _animatedSprite2D; - private CollisionShape2D _collisionShape2D; + private StaticBody2D _staticBody2D; + + private uint _collisionMask; + private uint _collisionLayer; public override void _Ready() { _animatedSprite2D = (AnimatedSprite2D)FindChild("AnimatedSprite2D"); - _collisionShape2D = (CollisionShape2D)FindChild("CollisionShape2D"); + _staticBody2D = (StaticBody2D)FindChild("StaticBody2D"); + + _collisionMask = _staticBody2D.CollisionMask; + _collisionLayer = _staticBody2D.CollisionLayer; Close(); } @@ -16,12 +22,16 @@ public partial class Door : Node2D public void Close() { _animatedSprite2D.Play("close"); - _collisionShape2D.Disabled = false; + + _staticBody2D.CollisionMask = _collisionMask; + _staticBody2D.CollisionLayer = _collisionLayer; } public void Open() { _animatedSprite2D.Play("open"); - _collisionShape2D.Disabled = true; + + _staticBody2D.CollisionMask = 0; + _staticBody2D.CollisionLayer = 0; } } diff --git a/sprites/key_space.tres b/sprites/key_space.tres index b517e13..a2f8c35 100644 --- a/sprites/key_space.tres +++ b/sprites/key_space.tres @@ -1,4 +1,4 @@ -[gd_resource type="SpriteFrames" load_steps=4 format=3 uid="uid://2621hqkv4w0x"] +[gd_resource type="SpriteFrames" load_steps=4 format=3 uid="uid://dqtp1l5ecav4k"] [ext_resource type="Texture2D" uid="uid://geiagnq38try" path="res://sprites/key_space.png" id="1_xhlet"] From 591dd263724f33cb6f845dbe79b65ec307c815b7 Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Sat, 19 Aug 2023 19:28:47 +0300 Subject: [PATCH 02/10] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=B4=D1=81=D1=87=D0=B5?= =?UTF-8?q?=D1=82=D0=B0=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/GameManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/GameManager.cs b/scripts/GameManager.cs index de5ab02..09e069c 100644 --- a/scripts/GameManager.cs +++ b/scripts/GameManager.cs @@ -39,6 +39,7 @@ public partial class GameManager : Node GD.Print("Restart stats"); IsPlaying = true; _gameInfo = new GameInfo(GetPathTo(FirstZone.PlayerSpawnPoint)); + _gameInfo.GameStart = Time.GetTicksMsec(); } StartGame(); @@ -46,7 +47,6 @@ public partial class GameManager : Node public void StartGame() { - _gameInfo.GameStart = Time.GetTicksMsec(); Player.GlobalPosition = GetNode(_gameInfo.Checkpoint).GlobalPosition; } From 6f68068d168c4b1e1a036cacc3d805f82a9ef762 Mon Sep 17 00:00:00 2001 From: Ivan Kuzmenko <6745157+rndtrash@users.noreply.github.com> Date: Mon, 21 Aug 2023 18:41:36 +0300 Subject: [PATCH 03/10] Add FlipH to the death screen --- scripts/DeathScreen.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/DeathScreen.cs b/scripts/DeathScreen.cs index e8854f8..9f2071c 100644 --- a/scripts/DeathScreen.cs +++ b/scripts/DeathScreen.cs @@ -41,6 +41,7 @@ public partial class DeathScreen : TextureRect _playerSprite.Texture = animatedSprite2D.SpriteFrames.GetFrameTexture(animatedSprite2D.Animation, animatedSprite2D.Frame); _playerSprite.Position -= _playerSprite.Texture.GetSize() / 2; + _playerSprite.FlipH = animatedSprite2D.FlipH; } if (killer.FindChild("AnimatedSprite2D") is AnimatedSprite2D killerAnimatedSprite2D) @@ -49,6 +50,7 @@ public partial class DeathScreen : TextureRect _monsterSprite.Texture = killerAnimatedSprite2D.SpriteFrames.GetFrameTexture(killerAnimatedSprite2D.Animation, killerAnimatedSprite2D.Frame); _monsterSprite.Position -= _monsterSprite.Texture.GetSize() / 2; + _monsterSprite.FlipH = killerAnimatedSprite2D.FlipH; } Visible = true; From f2675313f765a2790472bd0e8f245e0221875a50 Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Mon, 21 Aug 2023 16:56:48 +0300 Subject: [PATCH 04/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B0=D0=B9=D0=B4=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=82=D0=BE=D1=87=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BF=D0=BE=D0=BD=D0=B8=D0=BC=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D0=B3=D0=B4=D0=B0=20=D0=BE=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0=B0=20=D0=B1=D1=8B=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0.=20=D0=A2=D0=B0=D0=BA=D0=B6=D0=B5=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=20#2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prefabs/entities/pressure_plate.tscn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prefabs/entities/pressure_plate.tscn b/prefabs/entities/pressure_plate.tscn index 91933c3..c10c162 100644 --- a/prefabs/entities/pressure_plate.tscn +++ b/prefabs/entities/pressure_plate.tscn @@ -1,10 +1,10 @@ [gd_scene load_steps=4 format=3 uid="uid://bj1ixwjdpnooo"] -[ext_resource type="SpriteFrames" uid="uid://chfnxa71xs3ww" path="res://sprites/tiles/floor/pressure_plate.tres" id="1_1wdq4"] +[ext_resource type="SpriteFrames" uid="uid://8qygv4lq4pjf" path="res://sprites/tiles/floor/pressure_plate.tres" id="1_1wdq4"] [ext_resource type="Script" path="res://scripts/entities/PressurePlate.cs" id="1_httlb"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_1jim7"] -size = Vector2(32, 32) +size = Vector2(24, 24) [node name="pressure_plate" type="Area2D"] z_index = -1 From 3e60215e11231c19461e959f2cb73965cc037a26 Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Mon, 21 Aug 2023 17:28:40 +0300 Subject: [PATCH 05/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B0=D0=BD=D0=B8=D0=BC=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D1=88=D0=B8=D0=BF=D0=BE=D0=B2,=20=D0=B0?= =?UTF-8?q?=20=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D1=85=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BA=D0=B8=20(=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=BA=D1=80?= =?UTF-8?q?=D1=8B=D1=82=D0=B8=D0=B8,=20=D1=83=D0=B2=D0=B5=D0=BB=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=20=D0=B2=20=D1=83=D0=B1=D1=80=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F=D0=BD=D0=B8?= =?UTF-8?q?=D0=B8,=20=D1=83=D0=BC=D0=B5=D0=BD=D1=8C=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B0=D0=B9=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prefabs/entities/spikes.tscn | 4 +--- scripts/entities/Spikes.cs | 9 +++++---- sprites/tiles/floor/spikes/spikes.tres | 21 +++++++++++++-------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/prefabs/entities/spikes.tscn b/prefabs/entities/spikes.tscn index 6fbfe54..92c188f 100644 --- a/prefabs/entities/spikes.tscn +++ b/prefabs/entities/spikes.tscn @@ -4,7 +4,7 @@ [ext_resource type="SpriteFrames" uid="uid://uith5rxps4s" path="res://sprites/tiles/floor/spikes/spikes.tres" id="2_t76h0"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_guqiy"] -size = Vector2(32, 32) +size = Vector2(24, 24) [node name="spikes" type="Area2D"] z_index = -1 @@ -12,8 +12,6 @@ script = ExtResource("1_r27mb") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] sprite_frames = ExtResource("2_t76h0") -frame = 2 -frame_progress = 1.0 [node name="Sprite2D" type="Sprite2D" parent="AnimatedSprite2D"] diff --git a/scripts/entities/Spikes.cs b/scripts/entities/Spikes.cs index 8bb0e1b..08f9779 100644 --- a/scripts/entities/Spikes.cs +++ b/scripts/entities/Spikes.cs @@ -13,7 +13,7 @@ public partial class Spikes : Area2D } [Export] public bool Enabled = false; - [Export] public float SpikesTimeout = 1f; + [Export] public float SpikesTimeout = 2f; [Export] public float StartOffset = 0f; private AnimatedSprite2D _sprite; private State _state = State.Waiting; @@ -40,7 +40,7 @@ public partial class Spikes : Area2D switch (_state) { case State.Waiting: - _sprite.Stop(); + _sprite.Play("default"); _timeSinceState += (float)delta; if (_timeSinceState > SpikesTimeout) { @@ -49,11 +49,12 @@ public partial class Spikes : Area2D } break; case State.Opening: - _sprite.Play("default"); + _sprite.Play("activated"); KillBodiesOnButton(); break; case State.Closing: - _sprite.PlayBackwards("default"); + _sprite.PlayBackwards("activated"); + KillBodiesOnButton(); break; } } diff --git a/sprites/tiles/floor/spikes/spikes.tres b/sprites/tiles/floor/spikes/spikes.tres index c83293e..d417279 100644 --- a/sprites/tiles/floor/spikes/spikes.tres +++ b/sprites/tiles/floor/spikes/spikes.tres @@ -2,10 +2,6 @@ [ext_resource type="Texture2D" uid="uid://l3v1hs32uxfp" path="res://sprites/tiles/floor/spikes/spikes_0001-sheet.png" id="1_xhodh"] -[sub_resource type="AtlasTexture" id="AtlasTexture_ebjk6"] -atlas = ExtResource("1_xhodh") -region = Rect2(64, 0, 32, 32) - [sub_resource type="AtlasTexture" id="AtlasTexture_my1hb"] atlas = ExtResource("1_xhodh") region = Rect2(32, 0, 32, 32) @@ -14,19 +10,28 @@ region = Rect2(32, 0, 32, 32) atlas = ExtResource("1_xhodh") region = Rect2(0, 0, 32, 32) +[sub_resource type="AtlasTexture" id="AtlasTexture_qhlyu"] +atlas = ExtResource("1_xhodh") +region = Rect2(64, 0, 32, 32) + [resource] animations = [{ "frames": [{ "duration": 1.0, -"texture": SubResource("AtlasTexture_ebjk6") -}, { -"duration": 1.0, "texture": SubResource("AtlasTexture_my1hb") }, { "duration": 1.0, "texture": SubResource("AtlasTexture_nfdn1") }], "loop": false, +"name": &"activated", +"speed": 2.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_qhlyu") +}], +"loop": true, "name": &"default", -"speed": 3.0 +"speed": 5.0 }] From 26cc09241f3ef1ea39cbd880b4e24c30ac0d66b7 Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Mon, 21 Aug 2023 21:27:22 +0300 Subject: [PATCH 06/10] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BF=D1=83=D1=82?= =?UTF-8?q?=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prefabs/enemies/boss/claw.tscn | 5 ++++ prefabs/enemies/living_armor.tscn | 9 ++++-- prefabs/enemies/wretched.tscn | 14 +++++++-- scenes/level.tscn | 49 ++++++++++++++++++++++++++++--- scenes/main_scene.tscn | 4 +-- scripts/enemies/Claw.cs | 13 ++++++-- scripts/enemies/LivingArmor.cs | 18 ++++++++++-- scripts/enemies/Wretched.cs | 13 ++++++-- 8 files changed, 107 insertions(+), 18 deletions(-) diff --git a/prefabs/enemies/boss/claw.tscn b/prefabs/enemies/boss/claw.tscn index 2068990..c7782ea 100644 --- a/prefabs/enemies/boss/claw.tscn +++ b/prefabs/enemies/boss/claw.tscn @@ -27,5 +27,10 @@ shape = SubResource("CircleShape2D_v67co") position = Vector2(-2, 0) shape = SubResource("CircleShape2D_smr3g") +[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."] +avoidance_enabled = true +debug_use_custom = true +debug_path_custom_color = Color(0, 0, 1, 1) + [connection signal="body_entered" from="Area2D" to="." method="_OnEntered"] [connection signal="body_exited" from="Area2D" to="." method="_OnExited"] diff --git a/prefabs/enemies/living_armor.tscn b/prefabs/enemies/living_armor.tscn index 125417d..5d9cf09 100644 --- a/prefabs/enemies/living_armor.tscn +++ b/prefabs/enemies/living_armor.tscn @@ -4,7 +4,7 @@ [ext_resource type="Script" path="res://scripts/enemies/LivingArmor.cs" id="1_ofbsx"] [ext_resource type="PackedScene" uid="uid://cf0wpahgwygxx" path="res://prefabs/light_sense.tscn" id="2_xkyos"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_d1ojb"] +[sub_resource type="RectangleShape2D" id="RectangleShape2D_8sbby"] size = Vector2(15, 15) [sub_resource type="CircleShape2D" id="CircleShape2D_ex1co"] @@ -33,7 +33,7 @@ polygon = PackedVector2Array(-7, -4, -7, 15, 8, 15, 8, -4, 5, -11, -4, -11) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0.5, 7.5) -shape = SubResource("RectangleShape2D_d1ojb") +shape = SubResource("RectangleShape2D_8sbby") [node name="AreaOfSight" type="Area2D" parent="."] @@ -47,6 +47,11 @@ monitorable = false position = Vector2(1, 8) shape = SubResource("CircleShape2D_62y1x") +[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."] +path_desired_distance = 0.1 +target_desired_distance = 0.1 +avoidance_enabled = true + [connection signal="area_entered" from="LightSense" to="." method="_OnLightEntered"] [connection signal="area_exited" from="LightSense" to="." method="_OnLightExited"] [connection signal="body_entered" from="AreaOfSight" to="." method="_OnBodyEntered"] diff --git a/prefabs/enemies/wretched.tscn b/prefabs/enemies/wretched.tscn index 967a61b..6567d43 100644 --- a/prefabs/enemies/wretched.tscn +++ b/prefabs/enemies/wretched.tscn @@ -1,11 +1,11 @@ [gd_scene load_steps=6 format=3 uid="uid://bmyjqerhno5vi"] -[ext_resource type="SpriteFrames" uid="uid://blijqhtsnyq7n" path="res://sprites/enemies/wretched/wretched.tres" id="1_aqrsj"] +[ext_resource type="SpriteFrames" uid="uid://cisc0k30gpx1q" path="res://sprites/enemies/wretched/wretched.tres" id="1_aqrsj"] [ext_resource type="Script" path="res://scripts/enemies/Wretched.cs" id="1_ec388"] [ext_resource type="PackedScene" uid="uid://cf0wpahgwygxx" path="res://prefabs/light_sense.tscn" id="2_16fib"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_svj4b"] -size = Vector2(24, 16) +size = Vector2(15, 15) [sub_resource type="CircleShape2D" id="CircleShape2D_nortt"] radius = 15.0 @@ -28,7 +28,7 @@ frame_progress = 0.776966 polygon = PackedVector2Array(-5, -16, -7, -3, -7, 9, -11, 14, -11, 16, 8, 16, 8, 8, 7, 4, 7, -16) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] -position = Vector2(1, 8) +position = Vector2(0, 8) shape = SubResource("RectangleShape2D_svj4b") [node name="PlayerCollision" type="Area2D" parent="."] @@ -38,5 +38,13 @@ monitorable = false position = Vector2(1, 8) shape = SubResource("CircleShape2D_nortt") +[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."] +path_desired_distance = 0.1 +target_desired_distance = 0.1 +avoidance_enabled = true +avoidance_mask = 2 +debug_use_custom = true +debug_path_custom_color = Color(0, 1, 0, 1) + [connection signal="area_entered" from="LightSense" to="." method="_OnLightEntered"] [connection signal="body_entered" from="PlayerCollision" to="." method="_OnPlayerCollision"] diff --git a/scenes/level.tscn b/scenes/level.tscn index b9aada4..aa9f8bc 100644 --- a/scenes/level.tscn +++ b/scenes/level.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=3 uid="uid://cn0rwyjern2vx"] +[gd_scene load_steps=28 format=3 uid="uid://cn0rwyjern2vx"] [ext_resource type="Script" path="res://scripts/Level.cs" id="1_cxv3e"] [ext_resource type="TileSet" uid="uid://c7x8hryljgpha" path="res://sprites/tiles/QoL.tres" id="1_kp7y7"] @@ -14,8 +14,8 @@ [ext_resource type="PackedScene" uid="uid://bo5we64scaa1x" path="res://prefabs/furniture/table2.tscn" id="11_43o4k"] [ext_resource type="PackedScene" uid="uid://cvfk53tse4okx" path="res://prefabs/furniture/book.tscn" id="12_7tfnm"] [ext_resource type="PackedScene" uid="uid://ccg3n7sobsvdw" path="res://prefabs/enemies/watcher.tscn" id="13_nbkmp"] -[ext_resource type="PackedScene" path="res://prefabs/enemies/living_armor.tscn" id="14_4tmmq"] -[ext_resource type="PackedScene" path="res://prefabs/enemies/wretched.tscn" id="15_3rigu"] +[ext_resource type="PackedScene" uid="uid://bpusphyhhg074" path="res://prefabs/enemies/living_armor.tscn" id="14_4tmmq"] +[ext_resource type="PackedScene" uid="uid://bmyjqerhno5vi" path="res://prefabs/enemies/wretched.tscn" id="15_3rigu"] [ext_resource type="PackedScene" uid="uid://crulyoxqqw74r" path="res://prefabs/entities/Teleport.tscn" id="16_c6ifr"] [ext_resource type="PackedScene" uid="uid://dteeck6gict0d" path="res://prefabs/entities/teleport_dest.tscn" id="17_0di6y"] [ext_resource type="PackedScene" uid="uid://cpi5lgdlnvhlg" path="res://prefabs/enemies/boss/boss.tscn" id="18_8j1w1"] @@ -24,6 +24,31 @@ [sub_resource type="RectangleShape2D" id="RectangleShape2D_kwmx6"] +[sub_resource type="NavigationPolygon" id="NavigationPolygon_ngvpl"] +vertices = PackedVector2Array(312, -944, 192, -944, 40, -984, 96, -984, 320, -816, 200, -816, 48, -888, 56, -888, 40, -760, 56, -760, 440, -584, -120, -584, -120, -720, 312, -888, 440, -1080, 280, -984, 280, -1032, -72, -760, -120, -1080, 224, -1032, 224, -984, 144, -984, 144, -1032, 96, -1032, 192, -888, 176, -888, 176, -944, 56, -944, -8, -984, 200, -760, 176, -760, 176, -816, 56, -816, -72, -888, 440, -376, 440, -168, 168, -168, 168, -296, -232, -376, -408, -296, -408, -856, -232, -720, -120, -856, -80, -816, 320, -760, -72, -944, 40, -816, 48, -944, -8, -1032, 40, -1032) +polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(4, 5, 6, 7), PackedInt32Array(8, 9, 10, 11, 12), PackedInt32Array(13, 0, 14, 10, 4), PackedInt32Array(14, 0, 15, 16), PackedInt32Array(17, 8, 12), PackedInt32Array(18, 14, 16, 19), PackedInt32Array(19, 20, 21, 22), PackedInt32Array(18, 19, 22), PackedInt32Array(18, 22, 23), PackedInt32Array(1, 24, 25, 26), PackedInt32Array(2, 1, 26), PackedInt32Array(2, 26, 27, 28), PackedInt32Array(5, 29, 30, 31), PackedInt32Array(6, 5, 31), PackedInt32Array(6, 31, 32, 33), PackedInt32Array(34, 35, 36, 37), PackedInt32Array(38, 34, 37, 39), PackedInt32Array(38, 39, 40, 41), PackedInt32Array(17, 12, 41, 40, 42, 43), PackedInt32Array(29, 44, 10), PackedInt32Array(20, 15, 0), PackedInt32Array(33, 43, 42, 18, 45), PackedInt32Array(30, 29, 10), PackedInt32Array(10, 44, 4), PackedInt32Array(24, 13, 4), PackedInt32Array(9, 30, 10), PackedInt32Array(32, 9, 8, 46), PackedInt32Array(33, 32, 46), PackedInt32Array(33, 46, 43), PackedInt32Array(25, 24, 4), PackedInt32Array(7, 25, 4), PackedInt32Array(27, 7, 6, 47), PackedInt32Array(28, 27, 47), PackedInt32Array(28, 47, 45), PackedInt32Array(28, 45, 18, 48), PackedInt32Array(21, 20, 0), PackedInt32Array(49, 48, 18), PackedInt32Array(49, 18, 23), PackedInt32Array(49, 23, 3, 2), PackedInt32Array(0, 3, 21)]) +outlines = Array[PackedVector2Array]([PackedVector2Array(168, -168, 440, -168, 440, -376, -232, -376, -232, -720, -120, -720, -120, -584, 440, -584, 440, -1080, -120, -1080, -120, -856, -408, -856, -408, -296, 168, -296), PackedVector2Array(-72, -760, 40, -760, 40, -816, -80, -816), PackedVector2Array(56, -816, 56, -760, 176, -760, 176, -816), PackedVector2Array(200, -760, 320, -760, 320, -816, 200, -816), PackedVector2Array(-72, -888, 48, -888, 48, -944, -72, -944), PackedVector2Array(56, -944, 56, -888, 176, -888, 176, -944), PackedVector2Array(192, -888, 312, -888, 312, -944, 192, -944), PackedVector2Array(-8, -984, 40, -984, 40, -1032, -8, -1032), PackedVector2Array(96, -984, 144, -984, 144, -1032, 96, -1032), PackedVector2Array(224, -1032, 224, -984, 280, -984, 280, -1032)]) + +[sub_resource type="NavigationPolygon" id="NavigationPolygon_v2a1f"] +vertices = PackedVector2Array(897, -96, 897, 129, 607, 129, 607, -96) +polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) +outlines = Array[PackedVector2Array]([PackedVector2Array(607, -96, 607, 129, 897, 129, 897, -96)]) + +[sub_resource type="NavigationPolygon" id="NavigationPolygon_2d3fn"] +vertices = PackedVector2Array(897, -512, 897, -287, 607, -287, 607, -512) +polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) +outlines = Array[PackedVector2Array]([PackedVector2Array(607, -512, 607, -287, 897, -287, 897, -512)]) + +[sub_resource type="NavigationPolygon" id="NavigationPolygon_ackae"] +vertices = PackedVector2Array(447, 832, 865, 832, 865, 1153, 447, 1153) +polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) +outlines = Array[PackedVector2Array]([PackedVector2Array(447, 1153, 865, 1153, 865, 832, 447, 832)]) + +[sub_resource type="NavigationPolygon" id="NavigationPolygon_wwnnq"] +vertices = PackedVector2Array(-48, -1870, 242, -1870, 242, -1645, -48, -1645) +polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) +outlines = Array[PackedVector2Array]([PackedVector2Array(-48, -1645, 242, -1645, 242, -1870, -48, -1870)]) + [node name="level" type="Node2D"] script = ExtResource("1_cxv3e") @@ -312,7 +337,7 @@ position = Vector2(630, -730) position = Vector2(322, -381) [node name="Wretched" parent="." instance=ExtResource("15_3rigu")] -position = Vector2(181, -383) +position = Vector2(216, -381) [node name="Wretched2" parent="." instance=ExtResource("15_3rigu")] position = Vector2(-241, -457) @@ -445,6 +470,22 @@ Facing = 2 [node name="And_puzzle_4" parent="." instance=ExtResource("20_1ng7x")] CountOfButtons = 4 +[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."] +navigation_polygon = SubResource("NavigationPolygon_ngvpl") + +[node name="NavigationRegion2D2" type="NavigationRegion2D" parent="."] +navigation_polygon = SubResource("NavigationPolygon_v2a1f") + +[node name="NavigationRegion2D3" type="NavigationRegion2D" parent="."] +navigation_polygon = SubResource("NavigationPolygon_2d3fn") + +[node name="NavigationRegion2D4" type="NavigationRegion2D" parent="."] +navigation_polygon = SubResource("NavigationPolygon_ackae") + +[node name="NavigationRegion2D5" type="NavigationRegion2D" parent="."] +position = Vector2(655, 942) +navigation_polygon = SubResource("NavigationPolygon_wwnnq") + [connection signal="ButtonPressed" from="pressure_plate_puzzle_1" to="door_closed_puzzle_1" method="Open"] [connection signal="ButtonUnpressed" from="pressure_plate_puzzle_1" to="door_closed_puzzle_1" method="Close"] [connection signal="ButtonPressed" from="pressure_plate_puzzle_2" to="door_closed_puzzle_2" method="Open"] diff --git a/scenes/main_scene.tscn b/scenes/main_scene.tscn index f6d4957..6d3771f 100644 --- a/scenes/main_scene.tscn +++ b/scenes/main_scene.tscn @@ -22,7 +22,7 @@ point_count = 2 [sub_resource type="ShaderMaterial" id="ShaderMaterial_m680d"] shader = ExtResource("5_64d71") -[sub_resource type="ViewportTexture" id="ViewportTexture_57pph"] +[sub_resource type="ViewportTexture" id="ViewportTexture_kr1ga"] viewport_path = NodePath("FlashlightViewport") [sub_resource type="CircleShape2D" id="CircleShape2D_prnh4"] @@ -243,7 +243,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_57pph") +texture = SubResource("ViewportTexture_kr1ga") script = ExtResource("6_slohe") LightViewport = NodePath("../../FlashlightViewport") diff --git a/scripts/enemies/Claw.cs b/scripts/enemies/Claw.cs index bcb1525..bd6ba5b 100644 --- a/scripts/enemies/Claw.cs +++ b/scripts/enemies/Claw.cs @@ -17,11 +17,14 @@ public partial class Claw : CharacterBody2D private float _stateTimeout = 0; private bool _isPlayerNearBy = false; private AnimatedSprite2D _sprite; + private NavigationAgent2D _nav; // Called when the node enters the scene tree for the first time. public override void _Ready() { _sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D"); + _nav = (NavigationAgent2D)FindChild("NavigationAgent2D"); + _nav.VelocityComputed += OnNavVelocityCompute; } // Called every frame. 'delta' is the elapsed time since the previous frame. @@ -38,10 +41,11 @@ public partial class Claw : CharacterBody2D break; case State.Moving: - var direction = (Player.Instance.Position - Position).Normalized(); - Velocity = direction * MovingSpeed; + _nav.TargetPosition = Player.Instance.Position; + var direction = (_nav.GetNextPathPosition() - Position).Normalized(); _sprite.FlipH = Velocity.X < 0.001f; _sprite.Play("default"); + _nav.Velocity = direction * MovingSpeed; MoveAndSlide(); break; case State.Prepare: @@ -87,4 +91,9 @@ public partial class Claw : CharacterBody2D GD.Print("Boss enabled"); _state = State.Moving; } + + private void OnNavVelocityCompute(Vector2 safeVelocity) + { + Velocity = safeVelocity; + } } diff --git a/scripts/enemies/LivingArmor.cs b/scripts/enemies/LivingArmor.cs index 0f43f3d..c773dc8 100644 --- a/scripts/enemies/LivingArmor.cs +++ b/scripts/enemies/LivingArmor.cs @@ -48,6 +48,7 @@ public partial class LivingArmor : CharacterBody2D private State _state; private float _timeSinceState; private AnimatedSprite2D _sprite; + private NavigationAgent2D _nav; private bool _isLitUp; //private readonly List _bodiesInSight = new List(); private readonly List _bodiesInSight = new List(); @@ -58,6 +59,8 @@ public partial class LivingArmor : CharacterBody2D public override void _Ready() { _sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D"); + _nav = (NavigationAgent2D)FindChild("NavigationAgent2D"); + _nav.VelocityComputed += OnNavVelocityCompute; _respawnPosition = Position; CurrentState = State.Waiting; var animationName = "side_walk"; @@ -78,6 +81,7 @@ public partial class LivingArmor : CharacterBody2D _sprite.Play(animationName); _sprite.Stop(); + } public override void _Process(double delta) @@ -127,13 +131,15 @@ public partial class LivingArmor : CharacterBody2D } break; } + if (_target is null) { _state = State.Waiting; return; } - var direction = (_target.Position - Position).Normalized(); - Velocity = direction * MovingSpeed; + + _nav.TargetPosition = _target.Position; + var direction = (_nav.GetNextPathPosition() - GlobalPosition).Normalized(); var animationName = "side_walk"; @@ -147,8 +153,8 @@ public partial class LivingArmor : CharacterBody2D _sprite.FlipH = Velocity.X < 0.001f && animationName == "side_walk"; _sprite.Play(animationName); + _nav.Velocity = direction * MovingSpeed; MoveAndSlide(); - //MoveAndCollide(direction); break; } @@ -252,5 +258,11 @@ public partial class LivingArmor : CharacterBody2D Position = _respawnPosition; // QueueFree(); // TODO } + + private void OnNavVelocityCompute(Vector2 safeVelocity) + { + Velocity = safeVelocity; + } + } diff --git a/scripts/enemies/Wretched.cs b/scripts/enemies/Wretched.cs index 9e959ee..da29cc0 100644 --- a/scripts/enemies/Wretched.cs +++ b/scripts/enemies/Wretched.cs @@ -50,11 +50,14 @@ public partial class Wretched : CharacterBody2D private State _state; private float _timeSinceState; private AnimatedSprite2D _sprite; + private NavigationAgent2D _nav; private bool _isActivated; public override void _Ready() { _sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D"); + _nav = (NavigationAgent2D)FindChild("NavigationAgent2D"); + _nav.VelocityComputed += OnNavVelocityCompute; CurrentState = State.Waiting; var animationName = "NonActivatedSide"; switch (Facing) @@ -93,8 +96,8 @@ public partial class Wretched : CharacterBody2D break; case State.Moving: - var direction = (Player.Instance.Position - Position).Normalized(); - Velocity = direction * MovingSpeed; + _nav.TargetPosition = Player.Instance.Position; + var direction = (_nav.GetNextPathPosition() - Position).Normalized(); var animationName = "ActivatedSide"; @@ -108,6 +111,7 @@ public partial class Wretched : CharacterBody2D _sprite.FlipH = Velocity.X < 0.001f && animationName == "ActivatedSide"; _sprite.Play(animationName); + _nav.Velocity = direction * MovingSpeed; MoveAndSlide(); break; } @@ -158,4 +162,9 @@ public partial class Wretched : CharacterBody2D EmitSignal(SignalName.Killed); QueueFree(); // TODO } + + private void OnNavVelocityCompute(Vector2 safeVelocity) + { + Velocity = safeVelocity; + } } From d14bc6359ece8e6ec82d36de673d3fae7750b91e Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Mon, 29 Jan 2024 18:46:58 +0300 Subject: [PATCH 07/10] Godot 4.2 --- .gitignore | 1 + 1bit-game-jam.csproj | 2 +- project.godot | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c672ad3..103581b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Godot 4+ specific ignores .godot/ +*.csproj.old # Binaries bin/ \ No newline at end of file diff --git a/1bit-game-jam.csproj b/1bit-game-jam.csproj index b63e5d0..d31daf9 100644 --- a/1bit-game-jam.csproj +++ b/1bit-game-jam.csproj @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/project.godot b/project.godot index 8dd5ea9..55f86cd 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="1bit-game-jam" run/main_scene="res://scenes/menu.tscn" -config/features=PackedStringArray("4.1", "C#", "Mobile") +config/features=PackedStringArray("4.2", "C#", "Mobile") boot_splash/bg_color=Color(0.141176, 0.141176, 0.141176, 1) config/icon="res://icon.svg" From 5950f7f5bfc8a89a207f2d45762a8a598dc9970f Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Mon, 29 Jan 2024 21:02:33 +0300 Subject: [PATCH 08/10] Localization code + Russian localization --- locales/en.mo | Bin 0 -> 696 bytes locales/en.po | 36 ++++++++++++++++++++++++++++++++++++ locales/ru.mo | Bin 0 -> 858 bytes locales/ru.po | 37 +++++++++++++++++++++++++++++++++++++ locales/template.pot | 17 +++++++++++++++++ project.godot | 9 +++++++++ scenes/menu.tscn | 16 ++++++++++++++++ scripts/Menu.cs | 15 +++++++++++++++ scripts/WinScreen.cs | 4 +++- 9 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 locales/en.mo create mode 100644 locales/en.po create mode 100644 locales/ru.mo create mode 100644 locales/ru.po create mode 100644 locales/template.pot diff --git a/locales/en.mo b/locales/en.mo new file mode 100644 index 0000000000000000000000000000000000000000..6b296722847c7183e8b1734a689a1bf8ce686448 GIT binary patch literal 696 zcmd6k!D>@M6ozj#x|nXHh#-iZ>{{r=B&|?xxQkNL5=fiS+=|<2a*|w4X2Q&gcxk)t z6Zin`^c8#M3{yx?mgJf>__dGw=f(f}h|y z_zhly%2txRfWC(Qfxd-C|Nf)3KZ8cUherQBH2S|mVO>>aqfa&(cX_<|hHYIZy^FKU z6YrIen&=x=L-qS*b&_{?vywh7q$pfk}1=~%(<5IJ%>O8 zFF*9XhCsj)KlIxOkHZ(AHC`;qZeQMU52S{-rc__Lw((l=a z!r7Emzo#$xa}hiJ&In`FH9>UljSVv+&aWnRvNRLch@Jn_r^HsBch1`nfsI;Soj5FL zkx?#?C;Ua;V7$V-b5pI#v(RCrJKU;b;)2GhQLrQkB qYD3m+;kNN4+qG29sIk{lAM_bp_UnE7jz@*iLG7^CRLTGJ1b+dX@V7Dm literal 0 HcmV?d00001 diff --git a/locales/en.po b/locales/en.po new file mode 100644 index 0000000..c7e2ab2 --- /dev/null +++ b/locales/en.po @@ -0,0 +1,36 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.4.2\n" + +msgid "Press Start or Enter" +msgstr "Press Start or Enter" + +msgid "by Tea Sanctuary, 2023" +msgstr "by Tea Sanctuary, 2023" + +msgid "CONGRATULATIONS!" +msgstr "CONGRATULATIONS!" + +msgid "" +"It took you\n" +"{0} attempts\n" +"and {1}\n" +"to finish the game." +msgstr "" +"It took you\n" +"{0} attempts\n" +"and {1}\n" +"to finish the game." + +msgid "Thank you for playing! :)" +msgstr "Thank you for playing! :)" diff --git a/locales/ru.mo b/locales/ru.mo new file mode 100644 index 0000000000000000000000000000000000000000..cb1f6751499f9d4580ccd44b6964c7e386309552 GIT binary patch literal 858 zcmZuvO-~b16de^^j4?6BXiSW`T}UK4wNq+B3IibsqzNAl6ywIlqkWXo_DwVMYHWZ6 zaKQpijFGtTd#5Xl2B|>cFWmV9{s9;M11*beDaW^S&)tmZEYKxoEV)NEX<4z7IKpl(+MM|NqgP{YIt>XA+aG_17rjl#T8u@224R;!4HtI7$=b{Vq` zDo8=oLKSsg_>CKsPNln{;@y`;ZRJYV9q9+Ir?O<`C#@;@(2YFnw$KuxF%f91;0qO0 zg!cS6qRMqqmKJ2I|M*$*>*jcFeE3MvPNvKu4+AP_G-}Y(@{zuY@m$qQ#d+ZeQadw+ z5v%8@F1l+@`qr>2dL_IfOFgr$HuIIbFDllE=U0O)saos?PIoU}8)ckp>Z+Y`9Gf~j zDLSSSj&0Kbr3mHl`@au$ubCdUo4|qRZ4VQU~H+i4GAh?UjO86xH z(NUTY!u4~Dta=tu89e@CE2+~Tj{a`-rD@EZty<2`O6v30lvNbjPm my$JjP+RbnUL0n9{&CS34@jgJe$=mT41(=2 && " +"n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n" +"X-Generator: Poedit 3.4.2\n" + +msgid "Press Start or Enter" +msgstr "Нажмите Start или Enter" + +msgid "by Tea Sanctuary, 2023" +msgstr "разработчик: Tea Sanctuary, 2023" + +msgid "CONGRATULATIONS!" +msgstr "ПОЗДРАВЛЯЕМ!" + +msgid "" +"It took you\n" +"{0} attempts\n" +"and {1}\n" +"to finish the game." +msgstr "" +"Вам потребовалось\n" +"{0} попыток\n" +"и {1}\n" +"чтобы пройти игру." + +msgid "Thank you for playing! :)" +msgstr "Спасибо за игру! :)" diff --git a/locales/template.pot b/locales/template.pot new file mode 100644 index 0000000..1208104 --- /dev/null +++ b/locales/template.pot @@ -0,0 +1,17 @@ +msgid "" +msgstr "" + +msgid "Press Start or Enter" +msgstr "" + +msgid "by Tea Sanctuary, 2023" +msgstr "" + +msgid "CONGRATULATIONS!" +msgstr "" + +msgid "It took you\n{0} attempts\nand {1}\nto finish the game." +msgstr "" + +msgid "Thank you for playing! :)" +msgstr "" \ No newline at end of file diff --git a/project.godot b/project.godot index 55f86cd..6a3b84c 100644 --- a/project.godot +++ b/project.godot @@ -71,6 +71,15 @@ ui_confirm={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null) ] } +ui_change_language={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":76,"key_label":0,"unicode":108,"echo":false,"script":null) +] +} + +[internationalization] + +locale/translations=PackedStringArray("res://locales/en.po", "res://locales/ru.po") [layer_names] diff --git a/scenes/menu.tscn b/scenes/menu.tscn index 298b9f5..523feac 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -281,6 +281,22 @@ text = "Press Start or Enter" horizontal_alignment = 1 vertical_alignment = 1 +[node name="Label2" type="Label" parent="CanvasLayer"] +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -18.0 +offset_bottom = 8.00002 +grow_horizontal = 2 +grow_vertical = 0 +rotation = -0.001216 +auto_translate = false +theme = ExtResource("3_d3ur4") +text = "Press L to change language" +horizontal_alignment = 1 +vertical_alignment = 1 + [node name="Flash" type="TextureRect" parent="CanvasLayer"] clip_children = 2 material = SubResource("ShaderMaterial_eqq24") diff --git a/scripts/Menu.cs b/scripts/Menu.cs index ca2fb38..6b0a388 100644 --- a/scripts/Menu.cs +++ b/scripts/Menu.cs @@ -1,13 +1,21 @@ +using System.Collections.Generic; using Godot; +using Godot.Collections; public partial class Menu : Node2D { private Timer _timer; private AudioStreamPlayer2D _thunderclap; private AnimationPlayer _animationPlayer; + private Array _translations = new Array{"en", "ru"}; + private int _languagesCount; + private int _currentLanguage = 0; public override void _Ready() { + TranslationServer.SetLocale("en"); + _languagesCount = _translations.Count; + _timer = (Timer)FindChild("Timer"); _thunderclap = (AudioStreamPlayer2D)FindChild("Thunderclap"); _animationPlayer = (AnimationPlayer)FindChild("AnimationPlayer"); @@ -24,6 +32,13 @@ public partial class Menu : Node2D _thunderclap.Play(); _timer.Start(); } + else if (@event.IsActionPressed("ui_change_language")) + { + _currentLanguage++; + if (_currentLanguage >= _languagesCount) + _currentLanguage = 0; + TranslationServer.SetLocale(_translations[_currentLanguage]); + } } public void ChangeScene() diff --git a/scripts/WinScreen.cs b/scripts/WinScreen.cs index 76758c4..2e7723e 100644 --- a/scripts/WinScreen.cs +++ b/scripts/WinScreen.cs @@ -16,7 +16,9 @@ public partial class WinScreen : TextureRect Visible = true; TextLabel.Text = - $"It took you\n{Manager.GetAttempts()} attempts\nand {Manager.GetFormattedTimeElapsed()}\nto finish the game."; + string.Format(Tr("It took you\n{0} attempts\nand {1}\nto finish the game."), + Manager.GetAttempts(), + Manager.GetFormattedTimeElapsed()); } public override void _Input(InputEvent @event) From d42bd00c3d4e1805c069cd700c5dac10d922eaa9 Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Sun, 25 Feb 2024 12:32:07 +0300 Subject: [PATCH 09/10] Some gamepad improvements --- .gitignore | 3 ++- export_presets.cfg | 8 ++++++-- project.godot | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 103581b..257440c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .godot/ *.csproj.old # Binaries -bin/ \ No newline at end of file +bin/ +qol-builds/ diff --git a/export_presets.cfg b/export_presets.cfg index 43bfce7..dcdae99 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -37,6 +37,7 @@ progressive_web_app/icon_512x512="" progressive_web_app/background_color=Color(0, 0, 0, 1) dotnet/include_scripts_content=false dotnet/include_debug_symbols=true +dotnet/embed_build_outputs=false [preset.1] @@ -82,6 +83,7 @@ application/product_name="" application/file_description="" application/copyright="" application/trademarks="" +application/export_angle=0 ssh_remote_deploy/enabled=false ssh_remote_deploy/host="user@host_ip" ssh_remote_deploy/port="22" @@ -101,6 +103,7 @@ Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorActi Remove-Item -Recurse -Force '{temp_dir}'" dotnet/include_scripts_content=false dotnet/include_debug_symbols=true +dotnet/embed_build_outputs=false [preset.2] @@ -112,7 +115,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="" +export_path="qol-builds/qol.x86_64" encryption_include_filters="" encryption_exclude_filters="" encrypt_pck=false @@ -142,4 +145,5 @@ ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\") rm -rf \"{temp_dir}\"" dotnet/include_scripts_content=false -dotnet/include_debug_symbols=true +dotnet/include_debug_symbols=false +dotnet/embed_build_outputs=false diff --git a/project.godot b/project.godot index 6a3b84c..f7cb697 100644 --- a/project.godot +++ b/project.godot @@ -63,6 +63,7 @@ character_right={ flashlight_charge={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":false,"script":null) ] } ui_confirm={ @@ -74,6 +75,7 @@ ui_confirm={ ui_change_language={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":76,"key_label":0,"unicode":108,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null) ] } From bbb66a52734d079926d1edf411955c0c046cc036 Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Fri, 9 Aug 2024 19:07:35 +0300 Subject: [PATCH 10/10] =?UTF-8?q?=D0=92=D0=B8=D1=80=D1=82=D1=83=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BA=D1=83=D1=80=D1=81=D0=BE?= =?UTF-8?q?=D1=80=20(=D0=B4=D0=BB=D1=8F=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=20=D0=B3=D0=B5=D0=B9?= =?UTF-8?q?=D0=BC=D0=BF=D0=B0=D0=B4=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1bit-game-jam.csproj | 2 +- 1bit-game-jam.csproj.old.1 | 7 +++++++ prefabs/virtual_cursor.tscn | 10 ++++++++++ project.godot | 22 +++++++++++++++++++++- scenes/level.tscn | 5 +++++ scenes/main_scene.tscn | 13 +++++++++---- scripts/Flashlight.cs | 3 ++- scripts/GameCamera.cs | 15 ++++++++++++++- scripts/Menu.cs | 2 ++ scripts/VirtualCursor.cs | 30 ++++++++++++++++++++++++++++++ sprites/cursor.png | Bin 0 -> 4251 bytes sprites/cursor.png.import | 34 ++++++++++++++++++++++++++++++++++ 12 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 1bit-game-jam.csproj.old.1 create mode 100644 prefabs/virtual_cursor.tscn create mode 100644 scripts/VirtualCursor.cs create mode 100644 sprites/cursor.png create mode 100644 sprites/cursor.png.import diff --git a/1bit-game-jam.csproj b/1bit-game-jam.csproj index d31daf9..c627206 100644 --- a/1bit-game-jam.csproj +++ b/1bit-game-jam.csproj @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/1bit-game-jam.csproj.old.1 b/1bit-game-jam.csproj.old.1 new file mode 100644 index 0000000..d31daf9 --- /dev/null +++ b/1bit-game-jam.csproj.old.1 @@ -0,0 +1,7 @@ + + + net6.0 + true + bitgamejam + + \ No newline at end of file diff --git a/prefabs/virtual_cursor.tscn b/prefabs/virtual_cursor.tscn new file mode 100644 index 0000000..9881490 --- /dev/null +++ b/prefabs/virtual_cursor.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=3 uid="uid://4d6fhm87mn55"] + +[ext_resource type="Script" path="res://scripts/VirtualCursor.cs" id="1_va4ba"] +[ext_resource type="Texture2D" uid="uid://up1nl3dnhadr" path="res://sprites/cursor.png" id="2_k2bth"] + +[node name="VirtualCursor" type="Node2D"] +script = ExtResource("1_va4ba") + +[node name="CursorSprite" type="Sprite2D" parent="."] +texture = ExtResource("2_k2bth") diff --git a/project.godot b/project.godot index f7cb697..1bc57cd 100644 --- a/project.godot +++ b/project.godot @@ -30,7 +30,7 @@ project/assembly_name="1bit-game-jam" character_up={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":87,"physical_keycode":87,"key_label":87,"unicode":0,"echo":false,"script":null) , null, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null) @@ -78,6 +78,26 @@ ui_change_language={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null) ] } +cursor_up={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null) +] +} +cursor_down={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null) +] +} +cursor_left={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null) +] +} +cursor_right={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null) +] +} [internationalization] diff --git a/scenes/level.tscn b/scenes/level.tscn index aa9f8bc..6d09561 100644 --- a/scenes/level.tscn +++ b/scenes/level.tscn @@ -28,26 +28,31 @@ vertices = PackedVector2Array(312, -944, 192, -944, 40, -984, 96, -984, 320, -816, 200, -816, 48, -888, 56, -888, 40, -760, 56, -760, 440, -584, -120, -584, -120, -720, 312, -888, 440, -1080, 280, -984, 280, -1032, -72, -760, -120, -1080, 224, -1032, 224, -984, 144, -984, 144, -1032, 96, -1032, 192, -888, 176, -888, 176, -944, 56, -944, -8, -984, 200, -760, 176, -760, 176, -816, 56, -816, -72, -888, 440, -376, 440, -168, 168, -168, 168, -296, -232, -376, -408, -296, -408, -856, -232, -720, -120, -856, -80, -816, 320, -760, -72, -944, 40, -816, 48, -944, -8, -1032, 40, -1032) polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(4, 5, 6, 7), PackedInt32Array(8, 9, 10, 11, 12), PackedInt32Array(13, 0, 14, 10, 4), PackedInt32Array(14, 0, 15, 16), PackedInt32Array(17, 8, 12), PackedInt32Array(18, 14, 16, 19), PackedInt32Array(19, 20, 21, 22), PackedInt32Array(18, 19, 22), PackedInt32Array(18, 22, 23), PackedInt32Array(1, 24, 25, 26), PackedInt32Array(2, 1, 26), PackedInt32Array(2, 26, 27, 28), PackedInt32Array(5, 29, 30, 31), PackedInt32Array(6, 5, 31), PackedInt32Array(6, 31, 32, 33), PackedInt32Array(34, 35, 36, 37), PackedInt32Array(38, 34, 37, 39), PackedInt32Array(38, 39, 40, 41), PackedInt32Array(17, 12, 41, 40, 42, 43), PackedInt32Array(29, 44, 10), PackedInt32Array(20, 15, 0), PackedInt32Array(33, 43, 42, 18, 45), PackedInt32Array(30, 29, 10), PackedInt32Array(10, 44, 4), PackedInt32Array(24, 13, 4), PackedInt32Array(9, 30, 10), PackedInt32Array(32, 9, 8, 46), PackedInt32Array(33, 32, 46), PackedInt32Array(33, 46, 43), PackedInt32Array(25, 24, 4), PackedInt32Array(7, 25, 4), PackedInt32Array(27, 7, 6, 47), PackedInt32Array(28, 27, 47), PackedInt32Array(28, 47, 45), PackedInt32Array(28, 45, 18, 48), PackedInt32Array(21, 20, 0), PackedInt32Array(49, 48, 18), PackedInt32Array(49, 18, 23), PackedInt32Array(49, 23, 3, 2), PackedInt32Array(0, 3, 21)]) outlines = Array[PackedVector2Array]([PackedVector2Array(168, -168, 440, -168, 440, -376, -232, -376, -232, -720, -120, -720, -120, -584, 440, -584, 440, -1080, -120, -1080, -120, -856, -408, -856, -408, -296, 168, -296), PackedVector2Array(-72, -760, 40, -760, 40, -816, -80, -816), PackedVector2Array(56, -816, 56, -760, 176, -760, 176, -816), PackedVector2Array(200, -760, 320, -760, 320, -816, 200, -816), PackedVector2Array(-72, -888, 48, -888, 48, -944, -72, -944), PackedVector2Array(56, -944, 56, -888, 176, -888, 176, -944), PackedVector2Array(192, -888, 312, -888, 312, -944, 192, -944), PackedVector2Array(-8, -984, 40, -984, 40, -1032, -8, -1032), PackedVector2Array(96, -984, 144, -984, 144, -1032, 96, -1032), PackedVector2Array(224, -1032, 224, -984, 280, -984, 280, -1032)]) +source_geometry_group_name = &"navigation_polygon_source_group" [sub_resource type="NavigationPolygon" id="NavigationPolygon_v2a1f"] vertices = PackedVector2Array(897, -96, 897, 129, 607, 129, 607, -96) polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) outlines = Array[PackedVector2Array]([PackedVector2Array(607, -96, 607, 129, 897, 129, 897, -96)]) +source_geometry_group_name = &"navigation_polygon_source_group" [sub_resource type="NavigationPolygon" id="NavigationPolygon_2d3fn"] vertices = PackedVector2Array(897, -512, 897, -287, 607, -287, 607, -512) polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) outlines = Array[PackedVector2Array]([PackedVector2Array(607, -512, 607, -287, 897, -287, 897, -512)]) +source_geometry_group_name = &"navigation_polygon_source_group" [sub_resource type="NavigationPolygon" id="NavigationPolygon_ackae"] vertices = PackedVector2Array(447, 832, 865, 832, 865, 1153, 447, 1153) polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) outlines = Array[PackedVector2Array]([PackedVector2Array(447, 1153, 865, 1153, 865, 832, 447, 832)]) +source_geometry_group_name = &"navigation_polygon_source_group" [sub_resource type="NavigationPolygon" id="NavigationPolygon_wwnnq"] vertices = PackedVector2Array(-48, -1870, 242, -1870, 242, -1645, -48, -1645) polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) outlines = Array[PackedVector2Array]([PackedVector2Array(-48, -1645, 242, -1645, 242, -1870, -48, -1870)]) +source_geometry_group_name = &"navigation_polygon_source_group" [node name="level" type="Node2D"] script = ExtResource("1_cxv3e") diff --git a/scenes/main_scene.tscn b/scenes/main_scene.tscn index 6d3771f..1cb9bc6 100644 --- a/scenes/main_scene.tscn +++ b/scenes/main_scene.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=3 uid="uid://dhn7yt46fyac8"] +[gd_scene load_steps=24 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"] @@ -11,6 +11,7 @@ [ext_resource type="PackedScene" uid="uid://cn0rwyjern2vx" path="res://scenes/level.tscn" id="5_skctj"] [ext_resource type="Script" path="res://scripts/GameCamera.cs" id="6_quua3"] [ext_resource type="Script" path="res://scripts/PointLight2DWorkaround.cs" id="6_slohe"] +[ext_resource type="PackedScene" uid="uid://4d6fhm87mn55" path="res://prefabs/virtual_cursor.tscn" id="11_xqdcm"] [ext_resource type="Script" path="res://scripts/WinScreen.cs" id="13_prax6"] [ext_resource type="Theme" uid="uid://daxgxg7c8v0ih" path="res://themes/zx_theme.tres" id="14_g1c0r"] [ext_resource type="Script" path="res://scripts/DeathScreen.cs" id="15_12mhe"] @@ -22,7 +23,7 @@ point_count = 2 [sub_resource type="ShaderMaterial" id="ShaderMaterial_m680d"] shader = ExtResource("5_64d71") -[sub_resource type="ViewportTexture" id="ViewportTexture_kr1ga"] +[sub_resource type="ViewportTexture" id="ViewportTexture_meb87"] viewport_path = NodePath("FlashlightViewport") [sub_resource type="CircleShape2D" id="CircleShape2D_prnh4"] @@ -46,6 +47,9 @@ height = 192 [node name="Root" type="Node2D"] y_sort_enabled = true +[node name="VirtualCursor" parent="." instance=ExtResource("11_xqdcm")] +position = Vector2(169.203, 958.57) + [node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("FirstZone", "Player")] script = ExtResource("1_ij566") FirstZone = NodePath("../Zones/PlayZone1") @@ -235,15 +239,16 @@ texture = ExtResource("3_8o315") [node name="Triangle" type="Polygon2D" parent="FlashlightViewport/CanvasGroup"] polygon = PackedVector2Array(-21, -25, 31, 29, -42, 31) -[node name="PlayerCamera" type="Camera2D" parent="." node_paths=PackedStringArray("Player")] +[node name="PlayerCamera" type="Camera2D" parent="." node_paths=PackedStringArray("Player", "Cursor")] script = ExtResource("6_quua3") Player = NodePath("../Player") CameraBounds = Vector2(30, 20) +Cursor = NodePath("../VirtualCursor") [node name="PointLight2D" type="PointLight2D" parent="PlayerCamera" node_paths=PackedStringArray("LightViewport")] blend_mode = 2 range_item_cull_mask = 2 -texture = SubResource("ViewportTexture_kr1ga") +texture = SubResource("ViewportTexture_meb87") script = ExtResource("6_slohe") LightViewport = NodePath("../../FlashlightViewport") diff --git a/scripts/Flashlight.cs b/scripts/Flashlight.cs index c506ab2..6dd8fa8 100644 --- a/scripts/Flashlight.cs +++ b/scripts/Flashlight.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using Godot; public partial class Flashlight : Node @@ -23,7 +24,7 @@ public partial class Flashlight : Node [Export] public Curve BrightnessCurve; [Export] public AudioStreamPlayer CrankSoundPlayer; - + private float FlashlightRadius = Constants.MaxFlashlightRadius; private float FlashlightEnergy = 0; private float FlashlightChargeTimeout = 1; diff --git a/scripts/GameCamera.cs b/scripts/GameCamera.cs index 52f7e7b..8be510d 100644 --- a/scripts/GameCamera.cs +++ b/scripts/GameCamera.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using Godot; public partial class GameCamera : Camera2D @@ -6,7 +7,10 @@ public partial class GameCamera : Camera2D [Export] public Vector2 CameraBounds = new(40, 30); [Export] public Vector2 CameraFollowBounds = new(20, 10); [Export] public float Speed = 0.5f; - + + [Export] public VirtualCursor Cursor; + [Export] public const float CursorSpeed = 2.0f; + /// /// World position of the flashlight /// @@ -14,6 +18,12 @@ public partial class GameCamera : Camera2D public override void _PhysicsProcess(double delta) { + Vector2 direction = Input.GetVector("cursor_left", "cursor_right", "cursor_up", "cursor_down"); + if (direction != Vector2.Zero) + { + FlashlightPosition += direction * CursorSpeed; + } + var difference = Vector2.Zero; var relativePlayerPosition = Player.Position - Position; @@ -39,6 +49,8 @@ public partial class GameCamera : Camera2D Position = (Position + difference).Round(); FlashlightPosition = (FlashlightPosition + difference).Round(); + Cursor.Position = FlashlightPosition; + } public override void _Input(InputEvent @event) @@ -48,6 +60,7 @@ public partial class GameCamera : Camera2D if (@event is InputEventMouseMotion eventMouseMotion) { FlashlightPosition = eventMouseMotion.Position - Constants.HalfScreenSize + Position; + //Cursor.Position = eventMouseMotion.Position - Constants.HalfScreenSize + Position; } } } diff --git a/scripts/Menu.cs b/scripts/Menu.cs index 6b0a388..9fc4132 100644 --- a/scripts/Menu.cs +++ b/scripts/Menu.cs @@ -10,6 +10,7 @@ public partial class Menu : Node2D private Array _translations = new Array{"en", "ru"}; private int _languagesCount; private int _currentLanguage = 0; + private Resource _cursorTexture; public override void _Ready() { @@ -31,6 +32,7 @@ public partial class Menu : Node2D _animationPlayer.Play("thunder"); _thunderclap.Play(); _timer.Start(); + DisplayServer.MouseSetMode(DisplayServer.MouseMode.Hidden); } else if (@event.IsActionPressed("ui_change_language")) { diff --git a/scripts/VirtualCursor.cs b/scripts/VirtualCursor.cs new file mode 100644 index 0000000..386faeb --- /dev/null +++ b/scripts/VirtualCursor.cs @@ -0,0 +1,30 @@ +using Godot; +using System; + +public partial class VirtualCursor : Node2D +{ + //[Export] public Node2D Cursor; + + protected Sprite2D CursorSprite; + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + CursorSprite = (Sprite2D)FindChild("CursorSprite"); + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + + } + + public override void _Input(InputEvent @event) + { + // base._Input(@event); + // + // if (@event is InputEventMouseMotion eventMouseMotion) + // { + // CursorSprite.Position = eventMouseMotion.Position - Constants.HalfScreenSize + Position; + // } + } +} diff --git a/sprites/cursor.png b/sprites/cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..f7d1acad8856950aced166f55ea31718d0e12ddf GIT binary patch literal 4251 zcmeHLeQ*tyXd| zBodWHsTLq=A_5Q)mqddh{#mGELEZ@@_xp?a53J96)V_J?5yAH9)n|%#zk6kR>gm## zb1%1CA9HWv&dG;oS04IASOz*pPxC9!@0_s3zHaK`qI2KmpPnb!5;K|qZfPhQck{{j zKkD?pJT>`tYeDZn_Ov!$7uHZTJzB7I>xhu(uWB${&e^mGFpKo7$ciz_l)L<}fklgMH zpWEG64Xk0$>a8yCiH8b0pQ!rv!kLAak<<%&*#k=hCl3Y==1!cqWbeY9Z4V!9^|{Za zQZo)uEVx;nWDncFyY%(U-1SqCKjoD_XRb`$YA)V5>5k1eu3q`_!j(dVo>j&?wQt>P z=QahL_lwHw`?~I2b8TwV$};aC&rbNZbL?XuoOd}_wQua6eO+0***IOMj!pYT>8|kE zCRZ^0^x^K;2-o4y?&&7SGvOXR=dDmIz%BJes^#{M`ObQ21 zT268$=Vm09r0g-;#7wtZWEld&D&@h{T!@A}3?C*JDVg1ugs z6>n*r^~QzYS{r{q|I9sw*s9xZYir#2-RAqdj4wWL?DRJC}mfmZLQ|>2Nr3g2E{Zg9uDXgjFt% zg_UUr@wt!f~W8zfi>Q@23wd85N)&c$|yiq?y1&A$+ih zqL$P{l1xHB=%EDQD#a^-BG*NEP*M-V>a@WW0^jc+sf*U?6&RHq60+3i zuju#CB&d->5#0-lJp`#r;(%B~a??iiat0>?-TQfmp!;gq!4T#5vmTkR)6(;KT&NbG z6=Yr#Sp8NMIl)2Nc#Nkh3q~^>g#`(Q!~hR$BFS5A0&N>alNjh0ldj=5$ouQc=sP zB6NUjKne?TOc?+Nq!6f5IZaQ}Mp-D*ZlxR+yPdI71E579s=!{nfp;`)v=Gi~&hYL#JRL;Yx0Fn|E%@TH&a0Ey@%MdK( zm_=CF0oho;EJ$MF$I#mHL7eGH_eu(kpU_R|HB|*xrk~P}wUWM=5JX=VEXSuyP`LVx z#*iyL#4qQIYS`GNRVOaJ0jPJT*FdeSm2TF8j)*Q3JeQ8 z(p^89T&97SDG-LgfMW1f>6v`c4PUdegAbQ_47apzYy19f&@wvWU91=kVa(eToq zNzj<1`urt1f6Em%N`0O=f$9@~KSSoh{|wvl;aT6g9(tmb!=-`iH2?fW)?wRg0?(Q^CY>4nSK8s8_q