@@ -5,10 +5,10 @@ public class Main : Node
55#pragma warning disable 649
66 // We assign this in the editor, so we don't need the warning about not being assigned.
77 [ Export ]
8- private PackedScene _mobScene ;
8+ public PackedScene mobScene ;
99#pragma warning restore 649
1010
11- private int _score ;
11+ public int score ;
1212
1313 public override void _Ready ( )
1414 {
@@ -31,7 +31,7 @@ public void NewGame()
3131 // Note that for calling Godot-provided methods with strings,
3232 // we have to use the original Godot snake_case name.
3333 GetTree ( ) . CallGroup ( "mobs" , "queue_free" ) ;
34- _score = 0 ;
34+ score = 0 ;
3535
3636 var player = GetNode < Player > ( "Player" ) ;
3737 var startPosition = GetNode < Position2D > ( "StartPosition" ) ;
@@ -40,7 +40,7 @@ public void NewGame()
4040 GetNode < Timer > ( "StartTimer" ) . Start ( ) ;
4141
4242 var hud = GetNode < HUD > ( "HUD" ) ;
43- hud . UpdateScore ( _score ) ;
43+ hud . UpdateScore ( score ) ;
4444 hud . ShowMessage ( "Get Ready!" ) ;
4545
4646 GetNode < AudioStreamPlayer > ( "Music" ) . Play ( ) ;
@@ -54,9 +54,9 @@ public void OnStartTimerTimeout()
5454
5555 public void OnScoreTimerTimeout ( )
5656 {
57- _score ++ ;
57+ score ++ ;
5858
59- GetNode < HUD > ( "HUD" ) . UpdateScore ( _score ) ;
59+ GetNode < HUD > ( "HUD" ) . UpdateScore ( score ) ;
6060 }
6161
6262 public void OnMobTimerTimeout ( )
@@ -70,20 +70,21 @@ public void OnMobTimerTimeout()
7070 mobSpawnLocation . Offset = GD . Randi ( ) ;
7171
7272 // Create a Mob instance and add it to the scene.
73- var mobInstance = ( Mob ) _mobScene . Instance ( ) ;
74- AddChild ( mobInstance ) ;
73+ var mob = ( Mob ) mobScene . Instance ( ) ;
74+ AddChild ( mob ) ;
7575
7676 // Set the mob's direction perpendicular to the path direction.
77- float direction = mobSpawnLocation . Rotation + Mathf . Tau / 4 ;
77+ float direction = mobSpawnLocation . Rotation + Mathf . Pi / 2 ;
7878
7979 // Set the mob's position to a random location.
80- mobInstance . Position = mobSpawnLocation . Position ;
80+ mob . Position = mobSpawnLocation . Position ;
8181
8282 // Add some randomness to the direction.
83- direction += ( float ) GD . RandRange ( - Mathf . Tau / 8 , Mathf . Tau / 8 ) ;
84- mobInstance . Rotation = direction ;
83+ direction += ( float ) GD . RandRange ( - Mathf . Pi / 4 , Mathf . Pi / 4 ) ;
84+ mob . Rotation = direction ;
8585
8686 // Choose the velocity.
87- mobInstance . LinearVelocity = new Vector2 ( ( float ) GD . RandRange ( mobInstance . minSpeed , mobInstance . maxSpeed ) , 0 ) . Rotated ( direction ) ;
87+ var velocity = new Vector2 ( ( float ) GD . RandRange ( mob . minSpeed , mob . maxSpeed ) , 0 ) ;
88+ mob . LinearVelocity = velocity . Rotated ( direction ) ;
8889 }
8990}
0 commit comments