@@ -14,11 +14,13 @@ public class Asteroid
1414 private readonly int m_arenaWidth ;
1515 private readonly int m_arenaHeight ;
1616 private readonly float m_direction ;
17+ private readonly Vector2 [ ] m_offsets ;
1718 private static readonly int [ ] Radii = [ 2 , 4 , MaxRadius ] ;
1819 private static readonly int [ ] HitScores = [ 20 , 10 , 5 ] ;
1920 private static readonly int [ ] SizeMetrics = [ 1 , 2 , 4 ] ;
21+ private static readonly float [ ] Speeds = [ 1.5f , 1.0f , 0.6f ] ;
2022 private int m_size = 2 ;
21- private int m_invulnerable = 30 ;
23+ private int m_invulnerable = 10 ;
2224 private const int MaxRadius = 7 ;
2325
2426 public int SizeMetric => SizeMetrics [ m_size ] ;
@@ -52,11 +54,23 @@ public Asteroid(Vector2 position, float speed, Random rand, int arenaWidth, int
5254 Position = position ;
5355 m_direction = float . IsNaN ( direction ) ? rand . NextFloat ( ) * MathF . Tau : direction ;
5456 Shade = 0.3 + 0.6 * rand . NextDouble ( ) ;
57+
58+ m_offsets =
59+ [
60+ new Vector2 ( m_arenaWidth , 0 ) ,
61+ new Vector2 ( - m_arenaWidth , 0 ) ,
62+ new Vector2 ( 0 , m_arenaHeight ) ,
63+ new Vector2 ( 0 , - m_arenaHeight ) ,
64+ new Vector2 ( m_arenaWidth , m_arenaHeight ) ,
65+ new Vector2 ( - m_arenaWidth , - m_arenaHeight ) ,
66+ new Vector2 ( m_arenaWidth , - m_arenaHeight ) ,
67+ new Vector2 ( - m_arenaWidth , m_arenaHeight )
68+ ] ;
5569 }
5670
5771 public void Move ( )
5872 {
59- var v = Velocity ;
73+ var v = Velocity * Speeds [ m_size ] ;
6074
6175 var maxX = m_arenaWidth + Radius ;
6276 var maxY = m_arenaHeight + Radius ;
@@ -110,20 +124,8 @@ public void Explode(List<Asteroid> asteroids)
110124
111125 public float DistanceTo ( Vector2 shipPosition )
112126 {
113- var offsets = new [ ]
114- {
115- new Vector2 ( m_arenaWidth , 0 ) ,
116- new Vector2 ( - m_arenaWidth , 0 ) ,
117- new Vector2 ( 0 , m_arenaHeight ) ,
118- new Vector2 ( 0 , - m_arenaHeight ) ,
119- new Vector2 ( m_arenaWidth , m_arenaHeight ) ,
120- new Vector2 ( - m_arenaWidth , - m_arenaHeight ) ,
121- new Vector2 ( m_arenaWidth , - m_arenaHeight ) ,
122- new Vector2 ( - m_arenaWidth , m_arenaHeight ) ,
123- } ;
124-
125127 var minDist = Vector2 . Distance ( shipPosition , Position ) ;
126- foreach ( var offset in offsets )
128+ foreach ( var offset in m_offsets )
127129 minDist = MathF . Min ( minDist , Vector2 . Distance ( shipPosition , Position + offset ) ) ;
128130
129131 return minDist ;
0 commit comments