Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

Pour terminer

Nous avons maintenant terminé toutes les fonctionnalités de notre jeu. Ci-dessous sont quelques étapes restantes pour ajouter un peu plus de "jus" pour améliorer l'expérience de jeu.

N'hésitez pas à développer le gameplay avec vos propres idées.

Arrière-plan

The default gray background is not very appealing, so let's change its color. One way to do this is to use a ColorRect node. Make it 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 select "Layout" -> "Anchors Preset" -> "Full Rect" either in the toolbar at the top of the viewport or in the inspector so that it covers the screen.

Vous pouvez également ajouter une image de fond, si vous en avez une, en utilisant un nœud TextureRect à la place.

Effets sonores

Sound and music can be the single most effective way to add appeal to the game experience. In your game's art folder, you have two sound files: "House In a Forest Loop.ogg" for background music, and "gameover.wav" for when the player loses.

Ajouter deux nœuds AudioStreamPlayer en tant qu'enfants de Main. Nommez l'un d'eux Music et l'autre DeathSound. Sur chacun d'eux, cliquez sur la propriété Stream, sélectionnez "Charger", et choisissez le fichier audio correspondant.

All audio is automatically imported with the Loop setting disabled. If you want the music to loop seamlessly, click on the Stream file arrow, select Make Unique, then click on the Stream file and check the Loop box.

Pour jouer de la musique, ajouter $Music.play() dans la fonction new_game() et $Music.stop() dans la fonction game_over().

Enfin, ajoutez $DeathSound.play() dans la fonction game_over().

func game_over():
    ...
    $Music.stop()
    $DeathSound.play()

func new_game():
    ...
    $Music.play()

Raccourci clavier

Puisque le jeu se joue avec les touches du clavier, il serait pratique si nous pouvions également commencer le jeu en appuyant sur une touche du clavier. Une façon d'y parvenir est d'utiliser la propriété "Raccourci" du nœud Button.

Dans une leçon précédente, nous avons créé quatre actions d'entrée pour déplacer le personnage. Nous allons créer une action d'entrée similaire pour l'associer au bouton de démarrage.

Sélectionnez "Projet" -> "Paramètres du projet..." puis cliquez sur l'onglet "Contrôles". De la même manière que vous avez créé les actions d'entrée de mouvement, créez une nouvelle action d'entrée appelée start_game et ajoutez un lien de touche pour la touche Enter.

Now would be a good time to add controller support if you have one available. Attach or pair your controller and then under each input action that you wish to add controller support for, click on the "+" button and press the corresponding button, d-pad, or stick direction that you want to map to the respective input action.

In the HUD scene, select the StartButton and find its Shortcut property in the Inspector. Create a new Shortcut resource by clicking within the box, open the Events array and add a new array element to it by clicking on Array[InputEvent] (size 0).

../../_images/start_button_shortcut.webp

Create a new InputEventAction and name it start_game.

../../_images/start_button_shortcut2.webp

Maintenant, lorsque le bouton de démarrage apparaît, vous pouvez soit cliquer dessus, soit appuyer sur Enter pour démarrer le jeu.

Et avec ça, vous avez terminé votre premier jeu en 2D dans Godot.

../../_images/dodge_preview.gif

Vous avez créer un personnage contrôlé par le joueur, des ennemis qui apparaissent de manière aléatoire sur le plateau de jeu, compté le score, mis en place une fonction de fin de partie et rejouer, une interface utilisateur, des sons, etc. Félicitations !

Il y a encore beaucoup à apprendre, mais vous pouvez prendre un moment pour apprécier ce que vous avez réalisé.

Et lorsque vous serez prêt, vous pourrez passer à Votre premier jeu 3D pour apprendre à créer un jeu 3D complet à partir de zéro, dans Godot.