File tree Expand file tree Collapse file tree 4 files changed +9
-12
lines changed Expand file tree Collapse file tree 4 files changed +9
-12
lines changed Original file line number Diff line number Diff line change 33
44public class Ball : Area2D
55{
6- private const int BALL_SPEED = 100 ;
6+ private const int BallSpeed = 100 ;
77
88 private Vector2 direction = new Vector2 ( - 1 , 0 ) ;
9- private int speed = BALL_SPEED ;
9+ private int speed = BallSpeed ;
1010
1111 private Vector2 initialPos ;
1212
@@ -22,7 +22,7 @@ public Vector2 GetDirection()
2222 public void Reset ( )
2323 {
2424 SetPosition ( initialPos ) ;
25- speed = BALL_SPEED ;
25+ speed = BallSpeed ;
2626 direction = new Vector2 ( - 1 , 0 ) ;
2727 }
2828
Original file line number Diff line number Diff line change @@ -8,9 +8,8 @@ public class CeilingFloor : Area2D
88
99 public void OnAreaEntered ( Area2D area )
1010 {
11- if ( area is Ball )
11+ if ( area is Ball ball )
1212 {
13- Ball ball = ( Ball ) area ;
1413 ball . SetDirection ( ball . GetDirection ( ) + new Vector2 ( 0 , yDirection ) ) ;
1514 }
1615 }
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ public class Paddle : Area2D
66 [ Export ]
77 private int ballDir = 1 ;
88
9- private const int MOVE_SPEED = 100 ;
9+ private const int MoveSpeed = 100 ;
1010
1111 public override void _Process ( float delta )
1212 {
@@ -16,23 +16,22 @@ public override void _Process(float delta)
1616 if ( Input . IsActionPressed ( which + "_move_up" ) && GetPosition ( ) . y > 0 )
1717 {
1818 Vector2 pos = GetPosition ( ) ;
19- pos . y -= MOVE_SPEED * delta ;
19+ pos . y -= MoveSpeed * delta ;
2020 SetPosition ( pos ) ;
2121 }
2222 if ( Input . IsActionPressed ( which + "_move_down" ) && GetPosition ( ) . y < GetViewportRect ( ) . Size . y )
2323 {
2424 Vector2 pos = GetPosition ( ) ;
25- pos . y += MOVE_SPEED * delta ;
25+ pos . y += MoveSpeed * delta ;
2626 SetPosition ( pos ) ;
2727 }
2828 }
2929
3030 public void OnAreaEntered ( Area2D area )
3131 {
32- if ( area is Ball )
32+ if ( area is Ball ball )
3333 {
3434 // Assign new direction
35- Ball ball = ( Ball ) area ;
3635 ball . SetDirection ( new Vector2 ( ballDir , ( float ) new Random ( ) . NextDouble ( ) * 2 - 1 ) . normalized ( ) ) ;
3736 }
3837 }
Original file line number Diff line number Diff line change @@ -5,10 +5,9 @@ public class Wall : Area2D
55{
66 public void OnWallAreaEntered ( Area2D area )
77 {
8- if ( area is Ball )
8+ if ( area is Ball ball )
99 {
1010 // Oops, ball went out of game place, reset
11- Ball ball = ( Ball ) area ;
1211 ball . Reset ( ) ;
1312 }
1413 }
You can’t perform that action at this time.
0 commit comments