Kończenie¶
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.
Tło¶
Domyślne szare tło nie jest zbyt atrakcyjne, więc zmieńmy jego kolor. Jednym ze sposobów na to jest użycie węzła ColorRect. Stwórz pierwszy węzeł pod Main
tak, aby był rysowany za innymi węzłami. ColorRect
ma tylko jedną właściwość: Kolor
. Wybierz kolor, który chcesz i przeciągnij ColorRect
tak, aby zakrył ekran.
Obraz tła można również dodać, jeśli taki istnieje, za pomocą węzła TextureRect
.
Efekty dźwiękowe¶
Dźwięk i muzyka mogą być najskuteczniejszym sposobem na uatrakcyjnienie wrażeń z gry. W folderze zasobów do gry znajdują się dwa pliki dźwiękowe: "House In a Forest Loop.ogg" na muzykę w tle i "gameover.wav" odtwarzaną w razie przegranej.
Dodaj dwa węzły AudioStreamPlayer jako dzieci Main
. Nazwij jedną z nich muzykę
, a drugą DeathSound
. Na każdym z nich kliknij na właściwość Stream
, wybierz opcję "Wczytaj" i wybierz odpowiedni plik audio.
Aby odtwarzać muzykę, dodaj $Music.play()
w funkcji new_game()
i $Music.stop( )
w funkcji game_over()
.
Na koniec dodaj $DeathSound.play()
do funkcji game_over()
.
Skrót klawiszowy¶
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
the "Shortcut" property of the Button
node.
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
input action called start_game
and add a key mapping for the Enter
key.
In the HUD
scene, select the StartButton
and find its Shortcut
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
the name start_game
.

Now when the start button appears, you can either click it or press Enter to start the game.
And with that, you completed your first 2D game in Godot.

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.
And when you're ready, you can move on to Your first 3D game to learn to create a complete 3D game from scratch, in Godot.