update c# class examples

This commit is contained in:
Hana
2023-01-11 21:03:35 +01:00
parent 33c61914b4
commit 9e90766a92
37 changed files with 144 additions and 121 deletions

View File

@@ -64,9 +64,8 @@ or lose precision if the frame rate is too high or too low.
.. code-tab:: csharp
using Godot;
using System;
public class PhysicsScript : CharacterBody2D
public partial class PhysicsScript : CharacterBody2D
{
public override void _PhysicsProcess(float delta)
{
@@ -128,9 +127,8 @@ So, let's move our sprite downwards until it hits the floor:
.. code-tab:: csharp
using Godot;
using System;
public class PhysicsScript : CharacterBody2D
public partial class PhysicsScript : CharacterBody2D
{
public override void _PhysicsProcess(float delta)
{
@@ -162,9 +160,8 @@ little more like a regular game character:
.. code-tab:: csharp
using Godot;
using System;
public class PhysicsScript : CharacterBody2D
public partial class PhysicsScript : CharacterBody2D
{
const float gravity = 200.0f;
Vector2 velocity;
@@ -213,9 +210,8 @@ This adds basic support for walking when pressing left and right:
.. code-tab:: csharp
using Godot;
using System;
public class PhysicsScript : CharacterBody2D
public partial class PhysicsScript : CharacterBody2D
{
const float gravity = 200.0f;
const int walkSpeed = 200;

View File

@@ -275,7 +275,9 @@ For example, here is the code for an "Asteroids" style spaceship:
.. code-tab:: csharp
class Spaceship : RigidBody2D
using Godot;
public partial class Spaceship : RigidBody2D
{
private Vector2 _thrust = new Vector2(0, -250);
private float _torque = 20000;
@@ -366,7 +368,9 @@ occurred:
.. code-tab:: csharp
class Body : PhysicsBody2D
using Godot;
public partial class Body : PhysicsBody2D
{
private Vector2 _velocity = new Vector2(250, 250);
@@ -396,7 +400,9 @@ Or to bounce off of the colliding object:
.. code-tab:: csharp
class Body : PhysicsBody2D
using Godot;
public partial class Body : PhysicsBody2D
{
private Vector2 _velocity = new Vector2(250, 250);
@@ -455,7 +461,9 @@ the ground (including slopes) and jump when standing on the ground:
.. code-tab:: csharp
class Body : CharacterBody2D
using Godot;
public partial class Body : CharacterBody2D
{
private float _runSpeed = 350;
private float _jumpSpeed = -1000;

View File

@@ -177,7 +177,9 @@ collision object node:
.. code-tab:: csharp
class Body : CharacterBody2D
using Godot;
public partial class Body : CharacterBody2D
{
public override void _PhysicsProcess(float delta)
{
@@ -211,7 +213,9 @@ member variable:
.. code-tab:: csharp
class Body : CharacterBody2D
using Godot;
public partial class Body : CharacterBody2D
{
public override void _PhysicsProcess(float delta)
{

View File

@@ -50,7 +50,9 @@ Here is a custom ``look_at()`` method that will work reliably with rigid bodies:
.. code-tab:: csharp
class Body : RigidBody
using Godot;
public partial class Body : RigidBody3D
{
private void LookFollow(PhysicsDirectBodyState state, Transform3D currentTransform, Vector3 targetPosition)
{

View File

@@ -78,7 +78,9 @@ use ``area_entered``. However, let's assume our player is a ``CharacterBody2D``
.. code-tab:: csharp
public class Coin : Area2D
using Godot;
public partial class Coin : Area2D
{
public void OnCoinBodyEntered(PhysicsBody2D body)

View File

@@ -254,9 +254,8 @@ Attach a script to the CharacterBody2D and add the following code:
.. code-tab:: csharp
using Godot;
using System;
public class KBExample : CharacterBody2D
public partial class KBExample : CharacterBody2D
{
public int Speed = 250;
private Vector2 _velocity = new Vector2();
@@ -358,9 +357,8 @@ uses the mouse pointer. Here is the code for the Player, using ``move_and_slide(
.. code-tab:: csharp
using Godot;
using System;
public class KBExample : CharacterBody2D
public partial class KBExample : CharacterBody2D
{
private PackedScene _bullet = (PackedScene)GD.Load("res://Bullet.tscn");
public int Speed = 200;
@@ -434,9 +432,8 @@ And the code for the Bullet:
.. code-tab:: csharp
using Godot;
using System;
public class Bullet : CharacterBody2D
public partial class Bullet : CharacterBody2D
{
public int Speed = 750;
private Vector2 _velocity = new Vector2();
@@ -531,9 +528,8 @@ Here's the code for the player body:
.. code-tab:: csharp
using Godot;
using System;
public class KBExample : CharacterBody2D
public partial class KBExample : CharacterBody2D
{
[Export] public int RunSpeed = 100;
[Export] public int JumpSpeed = -400;