From 3832a05c1bad3e52f8059d3efc8acd33b651d867 Mon Sep 17 00:00:00 2001
From: Ivan Kuzmenko <6745157+rndtrash@users.noreply.github.com>
Date: Mon, 14 Aug 2023 23:46:21 +0300
Subject: [PATCH] Flashlight and basic character controls
---
.idea/.idea.1bit-game-jam/.idea/.gitignore | 13 +++++
.idea/.idea.1bit-game-jam/.idea/encodings.xml | 4 ++
.../.idea.1bit-game-jam/.idea/indexLayout.xml | 8 +++
.idea/.idea.1bit-game-jam/.idea/vcs.xml | 6 ++
1bit-game-jam.csproj | 7 +++
1bit-game-jam.sln | 19 +++++++
prefabs/player.tscn | 4 +-
project.godot | 20 ++++++-
scenes/main_scene.tscn | 48 +++++++++++++++-
scripts/Player.cs | 52 ++++++++++++++++++
shaders/light_shader.gdshader | 7 +++
shaders/light_shader_material.tres | 6 ++
sprites/mask.png | Bin 0 -> 807 bytes
sprites/mask.png.import | 34 ++++++++++++
sprites/mask_inv.png | Bin 0 -> 5072 bytes
sprites/mask_inv.png.import | 34 ++++++++++++
16 files changed, 258 insertions(+), 4 deletions(-)
create mode 100644 .idea/.idea.1bit-game-jam/.idea/.gitignore
create mode 100644 .idea/.idea.1bit-game-jam/.idea/encodings.xml
create mode 100644 .idea/.idea.1bit-game-jam/.idea/indexLayout.xml
create mode 100644 .idea/.idea.1bit-game-jam/.idea/vcs.xml
create mode 100644 1bit-game-jam.csproj
create mode 100644 1bit-game-jam.sln
create mode 100644 scripts/Player.cs
create mode 100644 shaders/light_shader.gdshader
create mode 100644 shaders/light_shader_material.tres
create mode 100644 sprites/mask.png
create mode 100644 sprites/mask.png.import
create mode 100644 sprites/mask_inv.png
create mode 100644 sprites/mask_inv.png.import
diff --git a/.idea/.idea.1bit-game-jam/.idea/.gitignore b/.idea/.idea.1bit-game-jam/.idea/.gitignore
new file mode 100644
index 0000000..f16178a
--- /dev/null
+++ b/.idea/.idea.1bit-game-jam/.idea/.gitignore
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/projectSettingsUpdater.xml
+/contentModel.xml
+/.idea.1bit-game-jam.iml
+/modules.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/.idea.1bit-game-jam/.idea/encodings.xml b/.idea/.idea.1bit-game-jam/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/.idea.1bit-game-jam/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.1bit-game-jam/.idea/indexLayout.xml b/.idea/.idea.1bit-game-jam/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/.idea/.idea.1bit-game-jam/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.1bit-game-jam/.idea/vcs.xml b/.idea/.idea.1bit-game-jam/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/.idea.1bit-game-jam/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/1bit-game-jam.csproj b/1bit-game-jam.csproj
new file mode 100644
index 0000000..b63e5d0
--- /dev/null
+++ b/1bit-game-jam.csproj
@@ -0,0 +1,7 @@
+
+
+ net6.0
+ true
+ bitgamejam
+
+
\ No newline at end of file
diff --git a/1bit-game-jam.sln b/1bit-game-jam.sln
new file mode 100644
index 0000000..8fb9902
--- /dev/null
+++ b/1bit-game-jam.sln
@@ -0,0 +1,19 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "1bit-game-jam", "1bit-game-jam.csproj", "{C33BED68-271C-4720-9764-1F965577E38A}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ ExportDebug|Any CPU = ExportDebug|Any CPU
+ ExportRelease|Any CPU = ExportRelease|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C33BED68-271C-4720-9764-1F965577E38A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C33BED68-271C-4720-9764-1F965577E38A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C33BED68-271C-4720-9764-1F965577E38A}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
+ {C33BED68-271C-4720-9764-1F965577E38A}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
+ {C33BED68-271C-4720-9764-1F965577E38A}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
+ {C33BED68-271C-4720-9764-1F965577E38A}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
+ EndGlobalSection
+EndGlobal
diff --git a/prefabs/player.tscn b/prefabs/player.tscn
index 1ca25fc..23fe052 100644
--- a/prefabs/player.tscn
+++ b/prefabs/player.tscn
@@ -1,11 +1,13 @@
-[gd_scene load_steps=3 format=3 uid="uid://bhulqhxesd5gc"]
+[gd_scene load_steps=4 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"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5hhj3"]
size = Vector2(15, 15)
[node name="Player" type="CharacterBody2D"]
+script = ExtResource("1_1vpun")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0.5, 7.5)
diff --git a/project.godot b/project.godot
index cd18e09..a6dc99f 100644
--- a/project.godot
+++ b/project.godot
@@ -12,10 +12,26 @@ config_version=5
config/name="1bit-game-jam"
run/main_scene="res://scenes/main_scene.tscn"
-config/features=PackedStringArray("4.1", "Mobile")
+config/features=PackedStringArray("4.1", "C#", "Mobile")
boot_splash/bg_color=Color(0.141176, 0.141176, 0.141176, 1)
config/icon="res://icon.svg"
+[display]
+
+window/size/viewport_width=256
+window/size/viewport_height=192
+window/stretch/mode="viewport"
+
+[dotnet]
+
+project/assembly_name="1bit-game-jam"
+
+[layer_names]
+
+2d_render/layer_1="Dark World"
+2d_render/layer_2="Light World"
+2d_render/layer_3="UI"
+
[rendering]
textures/canvas_textures/default_texture_filter=0
@@ -23,5 +39,7 @@ renderer/rendering_method="mobile"
textures/lossless_compression/force_png=true
textures/default_filters/anisotropic_filtering_level=0
anti_aliasing/screen_space_roughness_limiter/enabled=false
+environment/glow/upscale_mode=0
+environment/defaults/default_clear_color=Color(0, 0, 0, 1)
2d/snap/snap_2d_transforms_to_pixel=true
2d/snap/snap_2d_vertices_to_pixel=true
diff --git a/scenes/main_scene.tscn b/scenes/main_scene.tscn
index 4840581..b2d7764 100644
--- a/scenes/main_scene.tscn
+++ b/scenes/main_scene.tscn
@@ -1,5 +1,49 @@
-[gd_scene format=3 uid="uid://dhn7yt46fyac8"]
+[gd_scene load_steps=6 format=3 uid="uid://dhn7yt46fyac8"]
+
+[ext_resource type="PackedScene" uid="uid://bhulqhxesd5gc" path="res://prefabs/player.tscn" id="1_65a7v"]
+[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="Material" uid="uid://xuvxq5hy1dt" path="res://shaders/light_shader_material.tres" id="4_ro05e"]
+
+[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_wg1ao"]
+light_mode = 2
[node name="Root" type="Node2D"]
-[node name="DarkCamera2D" type="Camera2D" parent="."]
+[node name="Player" parent="." node_paths=PackedStringArray("FlashlightUI", "FlashlightWorld") instance=ExtResource("1_65a7v")]
+position = Vector2(19, 4)
+FlashlightUI = NodePath("../CanvasLayer/FlashlightUI")
+FlashlightWorld = NodePath("../Camera2D/PointLight2D")
+
+[node name="TestWall" type="Sprite2D" parent="."]
+light_mask = 2
+material = SubResource("CanvasItemMaterial_wg1ao")
+position = Vector2(-108, -74)
+texture = ExtResource("2_edqdh")
+
+[node name="CanvasLayer" type="CanvasLayer" parent="."]
+
+[node name="FlashlightUI" type="Sprite2D" parent="CanvasLayer"]
+clip_children = 1
+texture = ExtResource("3_8o315")
+
+[node name="InvertRect" type="ColorRect" parent="CanvasLayer/FlashlightUI"]
+material = ExtResource("4_ro05e")
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+offset_left = -32.0
+offset_top = -32.0
+offset_right = -32.0
+offset_bottom = -32.0
+grow_horizontal = 2
+grow_vertical = 2
+metadata/_edit_use_anchors_ = true
+
+[node name="Camera2D" type="Camera2D" parent="."]
+
+[node name="PointLight2D" type="PointLight2D" parent="Camera2D"]
+energy = 16.0
+blend_mode = 2
+range_item_cull_mask = 2
+texture = ExtResource("3_8o315")
diff --git a/scripts/Player.cs b/scripts/Player.cs
new file mode 100644
index 0000000..0182dcd
--- /dev/null
+++ b/scripts/Player.cs
@@ -0,0 +1,52 @@
+using Godot;
+using System;
+
+public partial class Player : CharacterBody2D
+{
+ [Export] public Node2D FlashlightUI;
+ [Export] public Node2D FlashlightWorld;
+
+ [Export] public const float Speed = 50.0f;
+
+ protected AnimatedSprite2D Sprite;
+
+ public override void _Ready()
+ {
+ base._Ready();
+
+ Sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
+ }
+
+ public override void _PhysicsProcess(double delta)
+ {
+ Vector2 velocity = Velocity;
+
+ // Get the input direction and handle the movement/deceleration.
+ // As good practice, you should replace UI actions with custom gameplay actions.
+ Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
+ if (direction != Vector2.Zero)
+ {
+ velocity.X = direction.X * Speed;
+ velocity.Y = direction.Y * Speed;
+ }
+ else
+ {
+ velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
+ velocity.Y = Mathf.MoveToward(Velocity.Y, 0, Speed);
+ }
+
+ Velocity = velocity;
+ MoveAndSlide();
+ }
+
+ public override void _Input(InputEvent @event)
+ {
+ base._Input(@event);
+
+ if (@event is InputEventMouseMotion eventMouseMotion)
+ {
+ FlashlightUI.Position = eventMouseMotion.Position;
+ FlashlightWorld.Position = eventMouseMotion.Position - new Vector2(128F, 96F);
+ }
+ }
+}
\ No newline at end of file
diff --git a/shaders/light_shader.gdshader b/shaders/light_shader.gdshader
new file mode 100644
index 0000000..de69663
--- /dev/null
+++ b/shaders/light_shader.gdshader
@@ -0,0 +1,7 @@
+shader_type canvas_item;
+
+uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
+
+void fragment() {
+ COLOR = vec4(vec3(1,1,1) - texture(screen_texture, SCREEN_UV).rgb, 1);
+}
\ No newline at end of file
diff --git a/shaders/light_shader_material.tres b/shaders/light_shader_material.tres
new file mode 100644
index 0000000..3cd56e3
--- /dev/null
+++ b/shaders/light_shader_material.tres
@@ -0,0 +1,6 @@
+[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://xuvxq5hy1dt"]
+
+[ext_resource type="Shader" path="res://shaders/light_shader.gdshader" id="1_o757w"]
+
+[resource]
+shader = ExtResource("1_o757w")
diff --git a/sprites/mask.png b/sprites/mask.png
new file mode 100644
index 0000000000000000000000000000000000000000..816214406c397705476619535e1c8d739de03a6c
GIT binary patch
literal 807
zcmV+?1K9kDP)EX>4Tx04R}tkv&MmKpe$iQ?*5^f_4yb$WWc^q9Tr^ibb$c+6t{Ym|XfHG-*gu
zTpR`0f`cE6RR4rtTPCT<|
z>74h8!>lYR#OK5l23?T&k?XR{Z=6dG3p_JyWYcrRVPdh=!Ey()vY`@B6Gs$PqkJLf
zvch?bvs$UK);;+PLj`R)!*!aYNMI33q#!~@4I8MyLX=jG6ccIMk9+t>9Dj;jGPyRu
z$T5#9R7j2={11M2YZj*_-K0<)=zg*7k1-&y3pDGt{e5iP%@e@?3|wh#f3*S3ev)2q
zYmp;hU>mr&Zfo)$aJd5vKk1SoIg+2IP%HxPXY@^ZVCWX;U3GhF?c?+T$Wm8JH^9Lm
zFkYhUHIH`(JA3>0Osl^iKmc-*A{t_*00009a7bBm001r{001r{0eGc9b^rhX2XskI
zMF-~y4iX419G6Y80000PbVXQnLvL+uWo~o;Lvm$dbY)~9cWHEJAV*0}P*;Ht7XSbO
z5lKWrRCwC$n?VwTFbo4x|NrOo+F=SMB?-2*oH?M4=A7TJc?qBKRpF
ziY|OM2xSmG6Na*i9|b{Kg^vQE3gYiTPzB+4K&YDdUI?lvz6XM;ioXg$mBn9y@Y>8D
zRX_b-E|7!xGYCY$<@AqSASdzPAlOHM8Q^CBeGG7b;`g^=O1U5vjM4+k*x|XD>
zL10htp9oZO!L3!<>=1@5OJ{{JbX`6hgeirI3?QagW+FpaTAGRk;<4IX1PCFDldEBb
ltj?|gk)}L73dpMZ{2M;~lvtq?n4kav002ovPDHLkV1l`4N@xH8
literal 0
HcmV?d00001
diff --git a/sprites/mask.png.import b/sprites/mask.png.import
new file mode 100644
index 0000000..f7f0c9e
--- /dev/null
+++ b/sprites/mask.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://dlbl6d4yghvht"
+path="res://.godot/imported/mask.png-5403fce0f0c69d7184a2784f953221c8.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://sprites/mask.png"
+dest_files=["res://.godot/imported/mask.png-5403fce0f0c69d7184a2784f953221c8.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/mask_inv.png b/sprites/mask_inv.png
new file mode 100644
index 0000000000000000000000000000000000000000..a28539dd15e0b46f6a6d72848f6543b3b2c15365
GIT binary patch
literal 5072
zcmeHLc~lcu7Y~~(f?5?tks1TlR?NPUNLYjb0fK-L!Gb!OnS?1M6O(~NYAOiIridt_
z)lZ~S1q7Aq(N=J);PO!qvJ^zy0#<9S3sh^xO3U{W5b=CH=R2PB^*=LbCU5S$_xJAm
z-FI)^OKxODu#>|~2NH?oBnb(O2H$?B+io0qR$;4uAd##nX|h-%8q$+BT3mr8qhw-@
z1|_2gOhFAA75iQ#a=AB
zHm{4@JNV?1-MW3N+ou+Ndbday81|m?;aEfcjoP3*Z1bVdjpIA%k2T$^a;%TVmuxsW
zm^CZuMknf8cImI|&n~T>AM;0j)cqZ^k35Dwk)i6ukI6(_fzkJA2}Q6
zbYq$&PwMf@o*g^;o|kA_fp<<{J?sx|`a#`9*KWJnP|#xg9Zbx=f6YrQol$%FMdX(K
z)y}`WvGeX%Zc;OCks6r!vH!DJI3VKb^+?RNW5Z6538C$kt^0IWH_wa@U;725P-md_
zZiNo~a*|e_Iy3q5-U4q3yF4djJH9e;7quzgeT%3e;`+a>(X8N4>azRPv*3=&QNJyW
z>CacDe4QV1&Uaq2)jKm6R-CdN{JHez?fK*i&uIt*E1jb*=u)8h8oxH>;s`V=vG
z`sJ)z-s@;@*AV{M_TH^b*LN)Mkz~EXuv=EvA;k;#-1aE4u>IEJrr~0u3cVAy>E!&p
z7}*yt*QZvd7Z*|1Ef8ocsuH8Wtv+yAoV3H+ldf!f@-$w$VApaUdtyxWDTDUugP$HX
zCPDSw=$7?D>Wa`x=O9ncGVg@ivX0D&g4VKNp9lT>v-b1K7l%ndRCm-D$1K#}d%u5g
zT}t2Qo!cVHTX#i>o?r({?^Ih=@{sZ}_le^#1kZSS;6&|T?L!va8|{XzpSnIgFs`yI
zz~*XaZiIq-F_-k6pHoBO^=)xPXzskPt~hqP%Qmp~wA&wS^B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0000000..cd93111
--- /dev/null
+++ b/sprites/mask_inv.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://cxnd43vcss7rm"
+path="res://.godot/imported/mask_inv.png-8ac95d87dd1b42a71c6dd5d5cfce4783.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://sprites/mask_inv.png"
+dest_files=["res://.godot/imported/mask_inv.png-8ac95d87dd1b42a71c6dd5d5cfce4783.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