Initiation à Godot

Structuring the game

Structuring the game

Godot is structure to maximize your team's efficiency. Every member can focus on one part of the game (interactions, graphics, sounds...) without stepping on other members' toes. Particular effort is made to remove programmers bottleneck.

Our game story will be simple : a bat will be flying but always falling. We need to help it reach the goal by pressing the space bar which help it go up. The problem is that there are obstacles in the city : building are a danger to bat, and incredibly, even clouds. So when the bat hits one of them, it just looses (we could make it like hitting the ground wouldn’t kill but just make it fall a bit or loose points, but as a demo we keep it as simple as possible). When an obstacle is successfully passed, a point is added to the score. And it goes on until the bat looses (nobody is immortal but this bat can be, so if you play well you might die before).

From that description, we need some elements :

  • a bat drawing
  • a building drawing 
  • a cloud drawing
To make it nicer we can have several buildings, clouds, an animated bat when flying and when falling. At least, let’s add a background.
Our game is simple, there is for now one level. We might consider having a splash screen at the beginning containing a start button but it is not necessary.
Finally, we have
  • 4 drawing for the bat flying
  • 4 drawing for the bat falling
  • 1 building drawing (adding random to them is an unnecessary complexity for the demo)
  • 1 cloud drawing
  • 1 background drawing
  • 1 splash screen drawing
  • 1 start button drawing (and a second if we want the pressed state)
We could add to this a nice font for the score which will be displayed.
If we want to add sound, we will need :
  • a music (nice and cool and not ultrasonic but could be 3 : one for splash scree, one for play time, one when game finishes)
  • sound when we press the Space key for feedback
  • sound when the bat hits an obstacle
  • if we want, a sound when a point is won

Now that we have a project, we will need to populate it. In Godot, the main part of it can be sum up as creating scenes, putting them together, making element interact. So, the way we will work here is create a scene for each individual parts:

  • it will help clarify the project
  • it will make elements more reusable
  • it will make elements easier to modify
  • it will give the maximum of liberty in the game structure, particularly in Game design principles change…
  • as each scene is an independant file, there's is less risk of conflicts. SVN users may leverage the locking facility.

In that purpose, divide your game in little parts, as little as possible and define how they interact. For example, the game will need a world, which will be composed of several object included a background and non-players element, obstacles, enemies, … each of them may be created as a separate scene, which can themselves be subdivided depending on their complexity. The principles is : do more with less. Which drives to : reuse, reuse, combine. 

Our game will lead us to create a scene for each element that we need to manipulate :

  • the bat
  • the building and clouds (apart in different scenes) and a scene to mix them up
  • a scene for point
  • a scene for ui
  • one for the game level
  • and if chosen one for the splash screen and one for the end
Generally we will need some scripts for each scene :
bat scene
  • manage keys or joystick (here we’ll use keys) 
  • change bat position
  • die function
  • what it does when colliding
  • what it does when passing an obstacle
building and cloud
  • spawn them
  • position them 
  • display the points value
  • provide a pause game and quit game possibilities …
This is a basis we can begin with.

Organizing your files

Godot relies on the filesystem to organise your assets, and you are free to use any directory layout. Here are a few ideas to guide you:

  • Godot will detect any directory containing engine.cfg as a game project
  • You can group together files related to a game level (e.g. level1, level2, boss1...), rather than by type (gfx, sfx, scripts...)
  • Paths are relatives; if you need to move files, you can use the recent Refactoring feature

Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.

Vous devriez rafraîchir la page.