Numbers on boxes

master
Sascha 2023-09-14 20:08:37 +07:00
parent e4f9b25f1b
commit e0bd43bfe5
8 changed files with 70 additions and 6 deletions

@ -25,3 +25,10 @@ shape = SubResource("BoxShape3D_6js7j")
[node name="BoxCSGBox" type="CSGBox3D" parent="BoxRigidBody3D/BoxCollisionShapeBox"]
material_override = SubResource("StandardMaterial3D_dsxvl")
material = SubResource("StandardMaterial3D_6qu7a")
[node name="NumberLabel" type="Label3D" parent="BoxRigidBody3D/BoxCollisionShapeBox/BoxCSGBox"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.501989)
modulate = Color(0, 0, 0, 1)
outline_modulate = Color(1, 1, 1, 1)
text = "1"
font_size = 64

@ -20,3 +20,10 @@ shape = SubResource("BoxShape3D_ii5xl")
[node name="CSGBox" type="CSGBox3D" parent="GreenBox/CollisionShapeBox"]
material = SubResource("StandardMaterial3D_ad5i3")
[node name="NumberLabel" type="Label3D" parent="GreenBox/CollisionShapeBox/CSGBox"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.501989)
modulate = Color(0, 0, 0, 1)
outline_modulate = Color(1, 1, 1, 1)
text = "1"
font_size = 64

@ -26,3 +26,10 @@ shape = SubResource("BoxShape3D_6js7j")
[node name="OrangeBoxCSGBox" type="CSGBox3D" parent="OrangeBoxRigidBody3D/OrangeBoxCollisionShapeBox"]
material_override = SubResource("StandardMaterial3D_dsxvl")
material = SubResource("StandardMaterial3D_6qu7a")
[node name="NumberLabel" type="Label3D" parent="OrangeBoxRigidBody3D/OrangeBoxCollisionShapeBox/OrangeBoxCSGBox"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.501989)
modulate = Color(0, 0, 0, 1)
outline_modulate = Color(1, 1, 1, 1)
text = "1"
font_size = 64

@ -20,3 +20,10 @@ shape = SubResource("BoxShape3D_ii62c")
[node name="CSGBox" type="CSGBox3D" parent="PurpleBox/CollisionShapeBox"]
material_override = SubResource("StandardMaterial3D_ge8g8")
[node name="NumberLabel" type="Label3D" parent="PurpleBox/CollisionShapeBox/CSGBox"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.501989)
modulate = Color(0, 0, 0, 1)
outline_modulate = Color(1, 1, 1, 1)
text = "1"
font_size = 64

@ -19,3 +19,10 @@ shape = SubResource("BoxShape3D_maiwq")
[node name="CSGBox" type="CSGBox3D" parent="RedBox/CollisionShapeBox"]
material_override = SubResource("StandardMaterial3D_lit0u")
[node name="NumberLabel" type="Label3D" parent="RedBox/CollisionShapeBox/CSGBox"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.501989)
modulate = Color(0, 0, 0, 1)
outline_modulate = Color(1, 1, 1, 1)
text = "1"
font_size = 64

@ -66,3 +66,10 @@ offset_top = 24.0
offset_right = 71.0
offset_bottom = 47.0
text = "FPS: 0"
[node name="Boxes" type="Label" parent="CanvasGroup"]
offset_left = 31.0
offset_top = 50.0
offset_right = 76.0
offset_bottom = 76.0
text = "Boxes: 0"

@ -7,20 +7,29 @@ public partial class Box : Node3D {
private RigidBody3D rb;
private Vector3 rotation;
private const double randomRange = 1;
public override void _Ready() {
rb = GetChild<RigidBody3D>(0);
rb.Position = new(GD.RandRange(-50, 50), GD.RandRange(50, 100), GD.RandRange(-50, 50));
rb.Rotation = new(GD.RandRange(-30, 30), GD.RandRange(-30, 30), GD.RandRange(-30, 30));
float mass =(float)GD.RandRange(0.1, 3);
rb.Mass = mass;
CollisionShape3D cs = rb.GetChild<CollisionShape3D>(0);
cs.Scale = new(mass, mass, mass);
rotation = new((float)GD.RandRange(-randomRange, randomRange), (float)GD.RandRange(-randomRange, randomRange), (float)GD.RandRange(-randomRange, randomRange));
rb.AddConstantTorque(rotation);
Label3D numberLabel = cs.GetChild<CsgBox3D>(0).GetChild<Label3D>(0);
numberLabel.Text = $"{World.Instance.BoxCount}";
}
public override void _Process(double delta) {
// rb.AngularVelocity = rotation * (float)delta;
if (rb.Position.Y < -50) QueueFree(); //Clear all boxes outside
if (rb.Position.Y < -50) {
World.Instance.DestroyBox();
QueueFree();
}
}
}

@ -5,16 +5,21 @@ using Godot;
namespace Evolution.scripts;
public partial class World : Node3D {
public static World Instance { get; private set; }
public int BoxCount { get; private set; }
private readonly List<PackedScene> boxScenes = new();
private double maxTimer = 0.1;
private double maxTimer = 0.01;
private double timer;
private double fpsTimer;
private Label fpsLabel;
private Label boxesLabel;
private int frameCount;
private readonly List<int> frameCounts = new();
public override void _Ready()
{
// boxScenes.AddRange(GD.Load<List<PackedScene>>("res://*Box.tscn"));
public override void _Ready() {
Instance = this;
boxScenes.Add(GD.Load<PackedScene>("res://scenes/GreenBox.tscn"));
boxScenes.Add(GD.Load<PackedScene>("res://scenes/OrangeBox.tscn"));
boxScenes.Add(GD.Load<PackedScene>("res://scenes/PurpleBox.tscn"));
@ -22,6 +27,7 @@ public partial class World : Node3D {
boxScenes.Add(GD.Load<PackedScene>("res://scenes/Box.tscn"));
fpsLabel = GetNode<Label>("CanvasGroup/FPS");
boxesLabel = GetNode<Label>("CanvasGroup/Boxes");
}
public override void _Process(double delta) {
@ -42,7 +48,14 @@ public partial class World : Node3D {
}
private void CreateNewBox() {
BoxCount++;
Node newBox = boxScenes[GD.RandRange(0, boxScenes.Count - 1)].Instantiate();
AddChild(newBox);
boxesLabel.Text = $"Boxes: {BoxCount}";
}
public void DestroyBox() {
BoxCount--;
boxesLabel.Text = $"Boxes: {BoxCount}";
}
}