07.finishing-up.rst 3.0 KB

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