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:
parent
4681c2e620
commit
133e0fb734
4 changed files with 6 additions and 4 deletions
|
@ -15,5 +15,6 @@ position = Vector2(0, -2)
|
||||||
|
|
||||||
[node name="Ball" parent="." instance=ExtResource("2_u2ksv")]
|
[node name="Ball" parent="." instance=ExtResource("2_u2ksv")]
|
||||||
_ballSpeed = 50.0
|
_ballSpeed = 50.0
|
||||||
|
_maxRandomAngle = 0.42
|
||||||
|
|
||||||
[node name="Walls" parent="." instance=ExtResource("3_jfis7")]
|
[node name="Walls" parent="." instance=ExtResource("3_jfis7")]
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Pong.Scripts;
|
||||||
public partial class Ball : CharacterBody2D
|
public partial class Ball : CharacterBody2D
|
||||||
{
|
{
|
||||||
[Export] private double _ballSpeed;
|
[Export] private double _ballSpeed;
|
||||||
|
[Export] private double _maxRandomAngle;
|
||||||
|
|
||||||
private Vector2 _velocity;
|
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)
|
// this should dispose when this method goes out of scope (this means after the velocity variable is assigned)
|
||||||
using var rng = new RandomNumberGenerator();
|
using var rng = new RandomNumberGenerator();
|
||||||
// set the velocity currently to the left of the screen with a random y angle.
|
// 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)
|
public override void _PhysicsProcess(double delta)
|
||||||
|
|
BIN
addons/godot-git-plugin/linux/libgit_plugin.linux.editor.double.arm64.so
(Stored with Git LFS)
BIN
addons/godot-git-plugin/linux/libgit_plugin.linux.editor.double.arm64.so
(Stored with Git LFS)
Binary file not shown.
|
@ -46,4 +46,4 @@ paddle_down={
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
renderer/rendering_method="mobile"
|
renderer/rendering_method="gl_compatibility"
|
||||||
|
|
Loading…
Reference in a new issue