Repository navigation
Expand file tree
/
Copy pathWorld.cs
More file actions
75 lines (64 loc) · 1.64 KB
/
Copy pathWorld.cs
File metadata and controls
75 lines (64 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using Tensorflow;
using Tensorflow.NumPy;
using static Ship;
using static Tensorflow.Binding;
using static Tensorflow.KerasApi;
using Sequential = Tensorflow.Keras.Engine.Sequential;
public partial class World : Node
{
[Export]
public int MaxStartVelocity;
[Export]
public float MaxStartAngularVelocity;
private Ship _ship;
private Marker2D _startPosition;
private RandomNumberGenerator _rng;
private Hud _hud;
private float _score = 0;
private float Score
{
get
{
return _score;
}
set
{
_score = value;
_hud.UpdateScore(_score);
}
}
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_rng = new RandomNumberGenerator();
_ship = GetNode<Ship>("Ship");
_startPosition = GetNode<Marker2D>("StartPosition");
_hud = GetNode<Hud>("HUD");
ResetShip();
}
private void ResetShip()
{
Score = 0;
Vector2 position = _startPosition.Position;
Vector2 velocity = new(_rng.RandfRange(-1f, 1f), _rng.RandfRange(-1f, 1f));
velocity = velocity.Normalized();
velocity *= _rng.RandiRange(0, MaxStartVelocity);
float angle = _rng.RandfRange(-Mathf.Pi, Mathf.Pi);
float angularVelocity = _rng.RandfRange(-MaxStartAngularVelocity, MaxStartAngularVelocity);
_ship.Reset(position, velocity, angle, angularVelocity);
}
private void OnScoreChange(float score)
{
Score += score;
}
private void OnSimulationEnd()
{
GD.Print("SimulationEnd signal received");
GD.Print($"End score was: {Score}");
ResetShip();
}
}