-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a simple visual of generated names flying in an empty 2D space
- Loading branch information
Showing
7 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,48 @@ | ||
using Godot; | ||
using Syllabore; | ||
using System; | ||
|
||
public partial class MainVisualizer : Node2D | ||
{ | ||
private NameGenerator _nameGenerator; | ||
private PackedScene _nameFloaterScene; | ||
|
||
private int _speed = 100; | ||
private Random _random = new Random(); | ||
private int _xPadding = 100; | ||
|
||
public override void _Ready() | ||
{ | ||
_nameGenerator = new NameGenerator("ae","strl"); | ||
_nameFloaterScene = GD.Load<PackedScene>("res://NameFloater.tscn"); | ||
} | ||
|
||
public override void _Process(double delta) | ||
{ | ||
|
||
} | ||
|
||
public void GenerateName() | ||
{ | ||
|
||
var windowSize = GetViewportRect().Size; | ||
|
||
var xRoundTo = 50; | ||
var yRoundTo = 20; | ||
|
||
var xPosition = _xPadding + _random.Next((int)windowSize.X - (2 * _xPadding)); | ||
xPosition = (xPosition / xRoundTo) * xRoundTo; // Round to nearest 50 | ||
|
||
var yPosition = (int)windowSize.Y; | ||
yPosition = (yPosition / yRoundTo) * yRoundTo; | ||
|
||
var instance = (NameFloater)_nameFloaterScene.Instantiate(); | ||
|
||
instance.Text = _nameGenerator.Next(); | ||
instance.Speed = 100; | ||
instance.Position = new Vector2(xPosition, yPosition); | ||
|
||
this.GetTree().CurrentScene.AddChild(instance); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
[gd_scene format=3 uid="uid://dvet30uohxhwh"] | ||
[gd_scene load_steps=2 format=3 uid="uid://dvet30uohxhwh"] | ||
|
||
[ext_resource type="Script" path="res://MainVisualizer.cs" id="1_42c8l"] | ||
|
||
[node name="MainVisualizer" type="Node2D"] | ||
script = ExtResource("1_42c8l") | ||
|
||
[node name="ColorRect" type="ColorRect" parent="."] | ||
offset_right = 1159.0 | ||
offset_bottom = 651.0 | ||
color = Color(0, 0, 0, 1) | ||
|
||
[node name="GenerateNamesTimer" type="Timer" parent="."] | ||
wait_time = 0.5 | ||
autostart = true | ||
|
||
[connection signal="timeout" from="GenerateNamesTimer" to="." method="GenerateName"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Godot; | ||
using System; | ||
|
||
public partial class NameFloater : Node2D | ||
{ | ||
[Export] | ||
public int Speed = 10; | ||
|
||
public string Text { | ||
get | ||
{ | ||
return this.GetNode<Label>("NameLabel").Text; | ||
} | ||
set | ||
{ | ||
this.GetNode<Label>("NameLabel").Text = value; | ||
} | ||
} | ||
|
||
public override void _Process(double delta) | ||
{ | ||
if (this.Position.Y < -20) | ||
{ | ||
this.QueueFree(); | ||
} | ||
else | ||
{ | ||
this.Position += Vector2.Up * Speed * (float)delta; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://b8sdde54fk5v8"] | ||
|
||
[ext_resource type="Script" path="res://NameFloater.cs" id="1_qwpa5"] | ||
|
||
[sub_resource type="LabelSettings" id="LabelSettings_6ep6f"] | ||
font_size = 26 | ||
|
||
[node name="NameFloater" type="Node2D"] | ||
script = ExtResource("1_qwpa5") | ||
|
||
[node name="NameLabel" type="Label" parent="."] | ||
offset_right = 40.0 | ||
offset_bottom = 23.0 | ||
text = "Name" | ||
label_settings = SubResource("LabelSettings_6ep6f") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters