File tree Expand file tree Collapse file tree 3 files changed +9
-22
lines changed Expand file tree Collapse file tree 3 files changed +9
-22
lines changed Original file line number Diff line number Diff line change @@ -5,19 +5,10 @@ public class Ball : Area2D
55{
66 private const int BallSpeed = 100 ;
77
8- private Vector2 direction = new Vector2 ( - 1 , 0 ) ;
98 private int speed = BallSpeed ;
10-
119 private Vector2 initialPos ;
1210
13- public void SetDirection ( Vector2 newDirection )
14- {
15- direction = newDirection ;
16- }
17- public Vector2 GetDirection ( )
18- {
19- return direction ;
20- }
11+ public Vector2 direction = new Vector2 ( - 1 , 0 ) ;
2112
2213 public void Reset ( )
2314 {
@@ -28,11 +19,11 @@ public void Reset()
2819
2920 public override void _Ready ( )
3021 {
31- initialPos = GetPosition ( ) ;
22+ initialPos = Position ;
3223 }
3324
3425 public override void _Process ( float delta )
3526 {
36- SetPosition ( GetPosition ( ) + direction * speed * delta ) ;
27+ Position += direction * speed * delta ;
3728 }
3829}
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ public void OnAreaEntered(Area2D area)
1010 {
1111 if ( area is Ball ball )
1212 {
13- ball . SetDirection ( ball . GetDirection ( ) + new Vector2 ( 0 , yDirection ) ) ;
13+ ball . direction += new Vector2 ( 0 , yDirection ) ;
1414 }
1515 }
1616}
Original file line number Diff line number Diff line change @@ -13,17 +13,13 @@ public override void _Process(float delta)
1313 String which = GetName ( ) ;
1414
1515 // Move up and down based on input
16- if ( Input . IsActionPressed ( which + "_move_up" ) && GetPosition ( ) . y > 0 )
16+ if ( Input . IsActionPressed ( which + "_move_up" ) && Position . y > 0 )
1717 {
18- Vector2 pos = GetPosition ( ) ;
19- pos . y -= MoveSpeed * delta ;
20- SetPosition ( pos ) ;
18+ Position -= new Vector2 ( 0 , MoveSpeed * delta ) ;
2119 }
22- if ( Input . IsActionPressed ( which + "_move_down" ) && GetPosition ( ) . y < GetViewportRect ( ) . Size . y )
20+ if ( Input . IsActionPressed ( which + "_move_down" ) && Position . y < GetViewportRect ( ) . Size . y )
2321 {
24- Vector2 pos = GetPosition ( ) ;
25- pos . y += MoveSpeed * delta ;
26- SetPosition ( pos ) ;
22+ Position += new Vector2 ( 0 , MoveSpeed * delta ) ;
2723 }
2824 }
2925
@@ -32,7 +28,7 @@ public void OnAreaEntered(Area2D area)
3228 if ( area is Ball ball )
3329 {
3430 // Assign new direction
35- ball . SetDirection ( new Vector2 ( ballDir , ( float ) new Random ( ) . NextDouble ( ) * 2 - 1 ) . normalized ( ) ) ;
31+ ball . direction = new Vector2 ( ballDir , ( float ) new Random ( ) . NextDouble ( ) * 2 - 1 ) . normalized ( ) ;
3632 }
3733 }
3834}
You can’t perform that action at this time.
0 commit comments