Chapter 3. Shoot 'em Up: Creating a Side-scrolling Shooter

In this chapter, we will create a very simple side-scrolling shooter that will introduce us to the basics of making a complete game utilizing GML code. We will have a player character that can move around the play area and fire weapons. If they collide into an enemy or enemy bullet, they will be destroyed and can respawn if they have any remaining lives.

We will create three different types of enemies that fly across the screen:

  • FloatBot: It has no weapons but is hard to hit, because it floats up and down as it moves.
  • SpaceMine: It is the slowest enemy and will fire a ring of bullets if the player gets too close.
  • Strafer: It is the fastest enemy that flies in a straight line and fires bullets directly at the player's location.

We will polish the game by displaying the score and player lives, scroll the background to create the illusion of movement, play music, and add explosions. Finally, we will restart the game by implementing a win/lose condition. The game will look as shown in the following screenshot:

Shoot 'em Up: Creating a Side-scrolling Shooter

Coding conventions

In order to write effective code, regardless of programming language, it is important to follow the recommended coding conventions. This will help ensure that other people can read and understand what the code is attempting to do and debug it. There is no universal standard for programming practices, though many languages follow similar guidelines. The GameMaker Language (GML) does not have an official recommended set of conventions, partially due to the fact that it was developed to be a learning tool and is very forgiving as a result.

For this book, we will define our own conventions based on common practices and ease of learning.

  • All assets, except Rooms, will start with a simple type signifier and an underscore. For example:
    • Sprites: spr_
    • Objects: obj_
    • Scripts: scr_
  • Even though it is possible to use the Execute Code DnD to write code directly on an event, all code will be placed into Scripts and the naming convention will indicate the Object it is attached to and the Event it is applied to. This will make it easier to find later for debugging purposes. For example, code placed onto the player object's Create event would have a Script named scr_Player_Create.
  • If a Script is intended to be used by multiple objects, the name should use a clear description of what it is doing. For example: for removing an object after it goes offscreen, the Script would be named scr_OffScreenRemoval.
  • Variables will be written using CamelCase wherever multiple words are used; the first word starts with a lowercase letter, and each following word starts with an uppercase letter, for example: variableWithManyWords.
  • Boolean variables should be posed as a question, for example: canShoot, isPlaying.
  • Constants are written using all uppercase letters and underscores to separate words, for example: LEFT, MAX_GRAVITY.
  • Expressions in if statements are always enclosed in parentheses. GameMaker does not require this, but it does make it easier to read the code; for example: if (x > 320).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.37.10