From f26bdbbcd41f0e3cdf6bb542017f5ab528049e77 Mon Sep 17 00:00:00 2001 From: Pierre Ellul <7912093+pellul@users.noreply.github.com> Date: Fri, 19 Mar 2021 13:02:45 +0100 Subject: [PATCH] Update first_2d_game C# variables capitalization (#4723) --- .../first_2d_game/03.coding_the_player.rst | 14 +++++++------- .../first_2d_game/05.the_main_game_scene.rst | 12 ++++++------ .../first_2d_game/06.heads_up_display.rst | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/getting_started/first_2d_game/03.coding_the_player.rst b/getting_started/first_2d_game/03.coding_the_player.rst index ae807e47c..59e81d69d 100644 --- a/getting_started/first_2d_game/03.coding_the_player.rst +++ b/getting_started/first_2d_game/03.coding_the_player.rst @@ -37,13 +37,13 @@ Start by declaring the member variables this object will need: using Godot; using System; - + public class Player : Area2D { [Export] - public int speed = 400; // How fast the player will move (pixels/sec). + public int Speed = 400; // How fast the player will move (pixels/sec). - public Vector2 screenSize; // Size of the game window. + public Vector2 ScreenSize; // Size of the game window. } @@ -75,7 +75,7 @@ a good time to find the size of the game window: public override void _Ready() { - screenSize = GetViewportRect().Size; + ScreenSize = GetViewportRect().Size; } Now we can use the ``_process()`` function to define what the player will do. @@ -147,7 +147,7 @@ which returns ``true`` if it's pressed or ``false`` if it isn't. if (velocity.Length() > 0) { - velocity = velocity.Normalized() * speed; + velocity = velocity.Normalized() * Speed; animatedSprite.Play(); } else @@ -199,8 +199,8 @@ the ``_process`` function (make sure it's not indented under the `else`): Position += velocity * delta; Position = new Vector2( - x: Mathf.Clamp(Position.x, 0, screenSize.x), - y: Mathf.Clamp(Position.y, 0, screenSize.y) + x: Mathf.Clamp(Position.x, 0, ScreenSize.x), + y: Mathf.Clamp(Position.y, 0, ScreenSize.y) ); diff --git a/getting_started/first_2d_game/05.the_main_game_scene.rst b/getting_started/first_2d_game/05.the_main_game_scene.rst index dbfba687c..ebcac7a71 100644 --- a/getting_started/first_2d_game/05.the_main_game_scene.rst +++ b/getting_started/first_2d_game/05.the_main_game_scene.rst @@ -93,10 +93,10 @@ Add a script to ``Main``. At the top of the script, we use ``export #pragma warning disable 649 // We assign this in the editor, so we don't need the warning about not being assigned. [Export] - public PackedScene mobScene; + public PackedScene MobScene; #pragma warning restore 649 - public int score; + public int Score; public override void _Ready() { @@ -147,7 +147,7 @@ new game: public void NewGame() { - score = 0; + Score = 0; var player = GetNode("Player"); var startPosition = GetNode("StartPosition"); @@ -180,7 +180,7 @@ the other two timers. ``ScoreTimer`` will increment the score by 1. public void OnScoreTimerTimeout() { - score++; + Score++; } In ``_on_MobTimer_timeout()``, we will create a mob instance, pick a random @@ -229,7 +229,7 @@ Note that a new instance must be added to the scene using ``add_child()``. mobSpawnLocation.Offset = GD.Randi(); // Create a Mob instance and add it to the scene. - var mob = (Mob)mobScene.Instance(); + var mob = (Mob)MobScene.Instance(); AddChild(mob); // Set the mob's direction perpendicular to the path direction. @@ -243,7 +243,7 @@ Note that a new instance must be added to the scene using ``add_child()``. mob.Rotation = direction; // Choose the velocity. - var velocity = new Vector2((float)GD.RandRange(mob.minSpeed, mob.maxSpeed), 0); + var velocity = new Vector2((float)GD.RandRange(mob.MinSpeed, mob.MaxSpeed), 0); mob.LinearVelocity = velocity.Rotated(direction); } diff --git a/getting_started/first_2d_game/06.heads_up_display.rst b/getting_started/first_2d_game/06.heads_up_display.rst index 58d2d5b33..c3997a1d5 100644 --- a/getting_started/first_2d_game/06.heads_up_display.rst +++ b/getting_started/first_2d_game/06.heads_up_display.rst @@ -245,7 +245,7 @@ In ``new_game()``, update the score display and show the "Get Ready" message: .. code-tab:: csharp var hud = GetNode("HUD"); - hud.UpdateScore(score); + hud.UpdateScore(Score); hud.ShowMessage("Get Ready!"); In ``game_over()`` we need to call the corresponding ``HUD`` function: @@ -269,7 +269,7 @@ with the changing score: .. code-tab:: csharp - GetNode("HUD").UpdateScore(score); + GetNode("HUD").UpdateScore(Score); Now you're ready to play! Click the "Play the Project" button. You will be asked to select a main scene, so choose ``Main.tscn``.