Skip to content

Commit

Permalink
Update getting started 2D to 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Piralein committed Aug 25, 2024
1 parent 1508be4 commit b4b9d0f
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 21 deletions.
6 changes: 3 additions & 3 deletions getting_started/first_2d_game/03.coding_the_player.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ a good time to find the size of the game window:
.. tabs::
.. code-tab:: gdscript GDScript

func _ready():
func _ready() -> void:
screen_size = get_viewport_rect().size

.. code-tab:: csharp
Expand Down Expand Up @@ -140,7 +140,7 @@ which returns ``true`` if it's pressed or ``false`` if it isn't.
.. tabs::
.. code-tab:: gdscript GDScript

func _process(delta):
func _process(delta: float) -> void:
var velocity = Vector2.ZERO # The player's movement vector.
if Input.is_action_pressed("move_right"):
velocity.x += 1
Expand Down Expand Up @@ -399,7 +399,7 @@ Next, add this code to the function:
.. tabs::
.. code-tab:: gdscript GDScript

func _on_body_entered(body):
func _on_body_entered(body: Node2D) -> void:
hide() # Player disappears after being hit.
hit.emit()
# Must be deferred as we can't change physics properties on a physics callback.
Expand Down
4 changes: 2 additions & 2 deletions getting_started/first_2d_game/04.creating_the_enemy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ and randomly choose one of the three animation types:
.. tabs::
.. code-tab:: gdscript GDScript

func _ready():
func _ready() -> void:
var mob_types = $AnimatedSprite2D.sprite_frames.get_animation_names()
$AnimatedSprite2D.play(mob_types[randi() % mob_types.size()])

Expand Down Expand Up @@ -112,7 +112,7 @@ to the ``Mob`` and add this code:
.. tabs::
.. code-tab:: gdscript GDScript

func _on_visible_on_screen_notifier_2d_screen_exited():
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
queue_free()

.. code-tab:: csharp
Expand Down
12 changes: 6 additions & 6 deletions getting_started/first_2d_game/05.the_main_game_scene.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ everything up for a new game:
.. tabs::
.. code-tab:: gdscript GDScript

func game_over():
func game_over() -> void:
$ScoreTimer.stop()
$MobTimer.stop()

func new_game():
func new_game() -> void:
score = 0
$Player.start($StartPosition.position)
$StartTimer.start()
Expand Down Expand Up @@ -159,10 +159,10 @@ the other two timers. ``ScoreTimer`` will increment the score by 1.
.. tabs::
.. code-tab:: gdscript GDScript

func _on_score_timer_timeout():
func _on_score_timer_timeout() -> void:
score += 1

func _on_start_timer_timeout():
func _on_start_timer_timeout() -> void:
$MobTimer.start()
$ScoreTimer.start()

Expand Down Expand Up @@ -194,7 +194,7 @@ Note that a new instance must be added to the scene using ``add_child()``.
.. tabs::
.. code-tab:: gdscript GDScript

func _on_mob_timer_timeout():
func _on_mob_timer_timeout() -> void:
# Create a new instance of the Mob scene.
var mob = mob_scene.instantiate()

Expand Down Expand Up @@ -269,7 +269,7 @@ call to ``_ready()``:
.. tabs::
.. code-tab:: gdscript GDScript

func _ready():
func _ready() -> void:
new_game()

.. code-tab:: csharp
Expand Down
24 changes: 16 additions & 8 deletions getting_started/first_2d_game/06.heads_up_display.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ such as "Get Ready", so we add the following code
.. tabs::
.. code-tab:: gdscript GDScript

func show_message(text):
func show_message(text) -> void:
$Message.text = text
$Message.show()
$MessageTimer.start()
Expand All @@ -132,7 +132,7 @@ We also need to process what happens when the player loses. The code below will
.. tabs::
.. code-tab:: gdscript GDScript

func show_game_over():
func show_game_over() -> void:
show_message("Game Over")
# Wait until the MessageTimer has counted down.
await $MessageTimer.timeout
Expand Down Expand Up @@ -174,7 +174,7 @@ Add the code below to ``HUD`` to update the score
.. tabs::
.. code-tab:: gdscript GDScript

func update_score(score):
func update_score(score) -> void:
$ScoreLabel.text = str(score)

.. code-tab:: csharp
Expand All @@ -190,11 +190,11 @@ signal of ``MessageTimer`` to the ``HUD`` node, and add the following code to th
.. tabs::
.. code-tab:: gdscript GDScript

func _on_start_button_pressed():
func _on_start_button_pressed() -> void:
$StartButton.hide()
start_game.emit()

func _on_message_timer_timeout():
func _on_message_timer_timeout() -> void:
$Message.hide()

.. code-tab:: csharp
Expand Down Expand Up @@ -285,12 +285,20 @@ mobs to remove themselves. We can do this with the "group" feature.

In the ``Mob`` scene, select the root node and click the "Node" tab next to the
Inspector (the same place where you find the node's signals). Next to "Signals",
click "Groups" and you can type a new group name and click "Add".
click "Groups" to open the group overview
and the "+" button to open the "Create New Group" dialog.

.. image:: img/group_tab.webp

Now all mobs will be in the "mobs" group. We can then add the following line to
the ``new_game()`` function in ``Main``:
Name the group ``mobs`` and click "ok" to add a new scene group.

.. image:: img/add_group_dialog.webp

Now all mobs will be in the "mobs" group.

.. image:: img/scene_group_mobs.webp

We can then add the following line to the ``new_game()`` function in ``Main``:

.. tabs::
.. code-tab:: gdscript GDScript
Expand Down
4 changes: 2 additions & 2 deletions getting_started/first_2d_game/07.finishing-up.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ Finally, add ``$DeathSound.play()`` in the ``game_over()`` function.
.. tabs::
.. code-tab:: gdscript GDScript

func game_over():
func game_over() -> void:
...
$Music.stop()
$DeathSound.play()

func new_game():
func new_game() -> void:
...
$Music.play()

Expand Down
Binary file not shown.
Binary file modified getting_started/first_2d_game/img/attach_node_window.webp
Binary file not shown.
Binary file modified getting_started/first_2d_game/img/group_tab.webp
Binary file not shown.
Binary file modified getting_started/first_2d_game/img/input-mapping-add-action.webp
Binary file not shown.
Binary file modified getting_started/first_2d_game/img/input-mapping-add-key.webp
Binary file not shown.
Binary file modified getting_started/first_2d_game/img/input-mapping-completed.webp
Binary file not shown.
Binary file not shown.
Binary file modified getting_started/first_2d_game/img/player_signal_connection.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified getting_started/first_2d_game/img/setting-stretch-mode.webp
Binary file not shown.

0 comments on commit b4b9d0f

Please sign in to comment.