diff --git a/Main.cs b/Main.cs index ee4dfd3..82c81ce 100644 --- a/Main.cs +++ b/Main.cs @@ -1,18 +1,37 @@ using Godot; -using System; public class Main : Node2D { public override void _Ready() { - + GD.Randomize(); + InitializeParticles(); } public override void _Process(float delta) { - if (Input.IsActionJustPressed("quit")) + if (Input.IsActionJustPressed("quit")) GetTree().Quit(); + if (Input.IsActionJustPressed("reset")) GetTree().ReloadCurrentScene(); + } + + private void InitializeParticles() + { + var particleScene = GD.Load("res://Particle.tscn"); + for (var i = 0; i < 50; i++) { - GetTree().Quit(); + var particle = particleScene.Instance(); + GetNode("Particles").AddChild(particle); + particle.Position = GetRandomParticlePosition(); + particle.Hue = (float) GD.RandRange(0, 1); } } -} + + private Vector2 GetRandomParticlePosition() + { + const int padding = 32; + var viewportRect = GetViewportRect(); + var position = new Vector2((float) GD.RandRange(padding, viewportRect.Size.x - padding), + (float) GD.RandRange(padding, viewportRect.Size.y - padding)); + return position; + } +} \ No newline at end of file diff --git a/Main.tscn b/Main.tscn index fcdf428..1a5b5ef 100644 --- a/Main.tscn +++ b/Main.tscn @@ -4,3 +4,5 @@ [node name="Main" type="Node2D"] script = ExtResource( 1 ) + +[node name="Particles" type="Node2D" parent="."] diff --git a/Particle.cs b/Particle.cs new file mode 100644 index 0000000..df553fe --- /dev/null +++ b/Particle.cs @@ -0,0 +1,22 @@ +using Godot; + +public class Particle : Node2D +{ + private float _spriteHue; + private Sprite _spriteNode; + + public float Hue + { + get => _spriteHue; + set + { + _spriteHue = Mathf.Clamp(value, 0, 1); + _spriteNode.Modulate = Color.FromHsv(_spriteHue, 1, 1); + } + } + + public override void _Ready() + { + _spriteNode = GetNode("Sprite"); + } +} \ No newline at end of file diff --git a/Particle.tscn b/Particle.tscn new file mode 100644 index 0000000..36effd2 --- /dev/null +++ b/Particle.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://textures/particle.png" type="Texture" id=1] +[ext_resource path="res://Particle.cs" type="Script" id=2] + +[node name="Particle" type="Node2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) diff --git a/default_env.tres b/default_env.tres deleted file mode 100644 index 20207a4..0000000 --- a/default_env.tres +++ /dev/null @@ -1,7 +0,0 @@ -[gd_resource type="Environment" load_steps=2 format=2] - -[sub_resource type="ProceduralSky" id=1] - -[resource] -background_mode = 2 -background_sky = SubResource( 1 ) diff --git a/icon.png b/icon.png index c98fbb6..73190c3 100644 Binary files a/icon.png and b/icon.png differ diff --git a/project.godot b/project.godot index f59c266..34ab24b 100644 --- a/project.godot +++ b/project.godot @@ -28,6 +28,11 @@ quit={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777217,"unicode":0,"echo":false,"script":null) ] } +reset={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":82,"unicode":0,"echo":false,"script":null) + ] +} [physics] @@ -38,4 +43,4 @@ common/enable_pause_aware_picking=true quality/driver/driver_name="GLES2" vram_compression/import_etc=true vram_compression/import_etc2=false -environment/default_environment="res://default_env.tres" +environment/default_clear_color=Color( 0, 0, 0, 1 ) diff --git a/textures/particle.png b/textures/particle.png new file mode 100644 index 0000000..73190c3 Binary files /dev/null and b/textures/particle.png differ diff --git a/textures/particle.png.import b/textures/particle.png.import new file mode 100644 index 0000000..d0780ba --- /dev/null +++ b/textures/particle.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/particle.png-6bc2982443cc9a0ea7820fc4c0d2daf7.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://textures/particle.png" +dest_files=[ "res://.import/particle.png-6bc2982443cc9a0ea7820fc4c0d2daf7.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0