move the maxRandomAngle double to an exported var.

this means you can set the maxRandomAngle in the inspector, without having to modify the code.
This commit is contained in:
Fries 2023-05-17 10:52:55 -07:00
parent 4681c2e620
commit 133e0fb734
4 changed files with 6 additions and 4 deletions

View file

@ -15,5 +15,6 @@ position = Vector2(0, -2)
[node name="Ball" parent="." instance=ExtResource("2_u2ksv")]
_ballSpeed = 50.0
_maxRandomAngle = 0.42
[node name="Walls" parent="." instance=ExtResource("3_jfis7")]

View file

@ -5,6 +5,7 @@ namespace Pong.Scripts;
public partial class Ball : CharacterBody2D
{
[Export] private double _ballSpeed;
[Export] private double _maxRandomAngle;
private Vector2 _velocity;
@ -18,7 +19,7 @@ public partial class Ball : CharacterBody2D
// this should dispose when this method goes out of scope (this means after the velocity variable is assigned)
using var rng = new RandomNumberGenerator();
// set the velocity currently to the left of the screen with a random y angle.
_velocity = Vector2.Left * BallSpeed + new Vector2(0, rng.RandfRange(-0.5, 0.5) * BallSpeed);
_velocity = Vector2.Left * BallSpeed + new Vector2(0, rng.RandfRange(-_maxRandomAngle, _maxRandomAngle) * BallSpeed);
}
public override void _PhysicsProcess(double delta)

View file

@ -46,4 +46,4 @@ paddle_down={
[rendering]
renderer/rendering_method="mobile"
renderer/rendering_method="gl_compatibility"