2023-01-12 20:49:14 +01:00
|
|
|
|
2022-09-10 12:15:58 +02:00
|
|
|
|
|
|
|
Finishing up
|
|
|
|
============
|
|
|
|
|
|
|
|
We have now completed all the functionality for our game. Below are some
|
|
|
|
remaining steps to add a bit more "juice" to improve the game experience.
|
|
|
|
|
|
|
|
Feel free to expand the gameplay with your own ideas.
|
|
|
|
|
|
|
|
Background
|
|
|
|
~~~~~~~~~~
|
|
|
|
|
|
|
|
The default gray background is not very appealing, so let's change its color.
|
2023-01-12 19:30:47 +01:00
|
|
|
One way to do this is to use a `ColorRect` node. Make it
|
2023-01-12 19:43:03 +01:00
|
|
|
the first node under `Main` so that it will be drawn behind the other nodes.
|
|
|
|
`ColorRect` only has one property: `Color`. Choose a color you like and
|
2022-09-10 12:15:58 +02:00
|
|
|
select "Layout" -> "Full Rect" so that it covers the screen.
|
|
|
|
|
|
|
|
You could also add a background image, if you have one, by using a
|
2023-01-12 19:43:03 +01:00
|
|
|
`TextureRect` node instead.
|
2022-09-10 12:15:58 +02:00
|
|
|
|
|
|
|
Sound effects
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Sound and music can be the single most effective way to add appeal to the game
|
|
|
|
experience. In your game assets folder, you have two sound files: "House In a
|
|
|
|
Forest Loop.ogg" for background music, and "gameover.wav" for when the player
|
|
|
|
loses.
|
|
|
|
|
2023-01-12 19:30:47 +01:00
|
|
|
Add two `AudioStreamPlayer` nodes as children of
|
2023-01-12 19:43:03 +01:00
|
|
|
`Main`. Name one of them `Music` and the other `DeathSound`. On each one,
|
|
|
|
click on the `Stream` property, select "Load", and choose the corresponding
|
2022-09-10 12:15:58 +02:00
|
|
|
audio file.
|
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
To play the music, add `$Music.play()` in the `new_game()` function and
|
|
|
|
`$Music.stop()` in the `game_over()` function.
|
2022-09-10 12:15:58 +02:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
Finally, add `$DeathSound.play()` in the `game_over()` function.
|
2022-09-10 12:15:58 +02:00
|
|
|
|
|
|
|
Keyboard shortcut
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Since the game is played with keyboard controls, it would be convenient if we
|
|
|
|
could also start the game by pressing a key on the keyboard. We can do this with
|
2023-01-12 19:43:03 +01:00
|
|
|
the "Shortcut" property of the `Button` node.
|
2022-09-10 12:15:58 +02:00
|
|
|
|
|
|
|
In a previous lesson, we created four input actions to move the character. We
|
|
|
|
will create a similar input action to map to the start button.
|
|
|
|
|
|
|
|
Select "Project" -> "Project Settings" and then click on the "Input Map"
|
|
|
|
tab. In the same way you created the movement input actions, create a new
|
2023-01-12 19:43:03 +01:00
|
|
|
input action called `start_game` and add a key mapping for the :kbd:`Enter`
|
2022-09-10 12:15:58 +02:00
|
|
|
key.
|
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
In the `HUD` scene, select the `StartButton` and find its *Shortcut*
|
2022-09-10 12:15:58 +02:00
|
|
|
property in the Inspector. Select "New Shortcut" and click on the "Shortcut"
|
|
|
|
item. A second *Shortcut* property will appear. Select "New InputEventAction"
|
|
|
|
and click the new "InputEventAction". Finally, in the *Action* property, type
|
2023-01-12 19:43:03 +01:00
|
|
|
the name `start_game`.
|
2022-09-10 12:15:58 +02:00
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
![](img/start_button_shortcut.png)
|
2022-09-10 12:15:58 +02:00
|
|
|
|
|
|
|
Now when the start button appears, you can either click it or press :kbd:`Enter`
|
|
|
|
to start the game.
|
|
|
|
|
|
|
|
And with that, you completed your first 2D game in Godot.
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
![](img/dodge_preview.gif)
|
2022-09-10 12:15:58 +02:00
|
|
|
|
|
|
|
You got to make a player-controlled character, enemies that spawn randomly
|
|
|
|
around the game board, count the score, implement a game over and replay, user
|
|
|
|
interface, sounds, and more. Congratulations!
|
|
|
|
|
|
|
|
There's still much to learn, but you can take a moment to appreciate what you
|
|
|
|
achieved.
|
|
|
|
|
2023-01-12 19:29:11 +01:00
|
|
|
And when you're ready, you can move on to `doc_your_first_3d_game` to learn
|
2022-09-10 12:15:58 +02:00
|
|
|
to create a complete 3D game from scratch, in Godot.
|