File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -56,13 +56,31 @@ public void setVelocity(Vector2 velocity)
5656
5757 public void setPosition ( )
5858 {
59- _ball . Position += new Vector2 ( _ball . Velocity . X * _ball . Speed , _ball . Velocity . Y * _ball . Speed ) ;
60- if ( _ball . Position . X < 0 || _ball . Position . X > _table . Width - _ball . Radius )
61- _ball . Velocity *= - Vector2 . UnitX ;
59+ Vector2 newPosition = _ball . Position + new Vector2 ( _ball . Velocity . X * _ball . Speed , _ball . Velocity . Y * _ball . Speed ) ;
6260
63- if ( _ball . Position . Y < 0 || _ball . Position . Y > _table . Height - _ball . Radius )
64- _ball . Velocity *= - Vector2 . UnitY ;
61+ if ( newPosition . X < 0 )
62+ {
63+ _ball . Velocity = new Vector2 ( - _ball . Velocity . X , _ball . Velocity . Y ) ;
64+ newPosition . X = 0 ;
65+ }
66+ else if ( newPosition . X > _table . Width - _ball . Radius )
67+ {
68+ _ball . Velocity = new Vector2 ( - _ball . Velocity . X , _ball . Velocity . Y ) ;
69+ newPosition . X = _table . Width - _ball . Radius ;
70+ }
71+
72+ if ( newPosition . Y < 0 )
73+ {
74+ _ball . Velocity = new Vector2 ( _ball . Velocity . X , - _ball . Velocity . Y ) ;
75+ newPosition . Y = 0 ;
76+ }
77+ else if ( newPosition . Y > _table . Height - _ball . Radius )
78+ {
79+ _ball . Velocity = new Vector2 ( _ball . Velocity . X , - _ball . Velocity . Y ) ;
80+ newPosition . Y = _table . Height - _ball . Radius ;
81+ }
6582
83+ _ball . Position = newPosition ;
6684 RaisePropertyChanged ( nameof ( X ) ) ;
6785 RaisePropertyChanged ( nameof ( Y ) ) ;
6886 }
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public override void RunSimulation()
3232 {
3333 while ( true )
3434 {
35- Thread . Sleep ( TimeSpan . FromSeconds ( timeTravel ) ) ;
35+ // Thread.Sleep(TimeSpan.FromSeconds(timeTravel));
3636 try
3737 {
3838 _cancellationToken . ThrowIfCancellationRequested ( ) ;
You can’t perform that action at this time.
0 commit comments