mirror of
https://github.com/stan220/godot-docs.git
synced 2026-09-08 20:29:03 +00:00
Update first_2d_game C# variables capitalization (#4723)
This commit is contained in:
@@ -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)
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -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>("Player");
|
||||
var startPosition = GetNode<Position2D>("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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
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>("HUD").UpdateScore(score);
|
||||
GetNode<HUD>("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``.
|
||||
|
||||
Reference in New Issue
Block a user