add randomness to the ball and make the paddle smaller.
This commit is contained in:
parent
02c5b90415
commit
4681c2e620
2 changed files with 16 additions and 9 deletions
|
@ -1,12 +1,17 @@
|
||||||
[gd_scene load_steps=4 format=3 uid="uid://bklo6torhapa0"]
|
[gd_scene load_steps=5 format=3 uid="uid://bklo6torhapa0"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Scripts/Paddle.cs" id="1_uv7s3"]
|
[ext_resource type="Script" path="res://Scripts/Paddle.cs" id="1_uv7s3"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b186qihsjblv7" path="res://icon.svg" id="2_62eyv"]
|
|
||||||
|
|
||||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_r5a55"]
|
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_r5a55"]
|
||||||
friction = 0.0
|
friction = 0.0
|
||||||
bounce = 1.0
|
bounce = 1.0
|
||||||
|
|
||||||
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_iw3nx"]
|
||||||
|
size = Vector2(50, 75)
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dbik4"]
|
||||||
|
size = Vector2(12, 150)
|
||||||
|
|
||||||
[node name="Paddle" type="RigidBody2D"]
|
[node name="Paddle" type="RigidBody2D"]
|
||||||
physics_material_override = SubResource("PhysicsMaterial_r5a55")
|
physics_material_override = SubResource("PhysicsMaterial_r5a55")
|
||||||
gravity_scale = 0.0
|
gravity_scale = 0.0
|
||||||
|
@ -15,8 +20,7 @@ script = ExtResource("1_uv7s3")
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite2D" parent="."]
|
[node name="Sprite" type="Sprite2D" parent="."]
|
||||||
scale = Vector2(0.25, 2)
|
scale = Vector2(0.25, 2)
|
||||||
texture = ExtResource("2_62eyv")
|
texture = SubResource("PlaceholderTexture2D_iw3nx")
|
||||||
|
|
||||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
scale = Vector2(0.25, 2)
|
shape = SubResource("RectangleShape2D_dbik4")
|
||||||
polygon = PackedVector2Array(64, -60.8, 64, 59, 59.6, 64, -60.1, 64, -64, 60.7, -64, -59, -59, -63.8, 59.1, -64)
|
|
||||||
|
|
|
@ -7,15 +7,18 @@ public partial class Ball : CharacterBody2D
|
||||||
[Export] private double _ballSpeed;
|
[Export] private double _ballSpeed;
|
||||||
|
|
||||||
private Vector2 _velocity;
|
private Vector2 _velocity;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// this property multiples the ballSpeed by the Meter constant.
|
/// this property multiples the ballSpeed by the Meter constant.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private double BallSpeed => _ballSpeed * Constants.Meter;
|
private double BallSpeed => _ballSpeed * Constants.Meter;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_velocity = Vector2.Left * BallSpeed;
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
|
|
Loading…
Reference in a new issue