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:
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:
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.
spr_
obj_
scr_
scr_Player_Create
.scr_OffScreenRemoval
.variableWithManyWords
.canShoot
, isPlaying
.LEFT
, MAX_GRAVITY
.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)
.3.137.164.24