Game Maker: How to Make Enemies in Game Maker

Knoji reviews products and up-and-coming brands we think you'll love. In certain cases, we may receive a commission from brands mentioned in our guides. Learn more.
Game Maker has very easy coding in it, however, it can be hard to learn at some points. Now you can finish making a TDS. This is guide shows the easiest way on how to make one. Get better at GML and find out how to get better at it fast now!

Before you start with this guide, read this article first to catch up on this. After you have done that, it is time to add enemies. Start out by creating a sprite. Name it spr_enemy, click edit sprite create a new sprite and leave the width and height at 32 and click OK. Zoom in eight times. Click Draw an ellipse or press the hotkey I. Make sure you make the right color different from the color of middle of spr_main. Make a circle. Click the check, click it on the next screen, click center, on the next screen, click OK.

Open obj_main, go to the step event and change all the place_empty's to place_free. It should look like this 

if keyboard_check(vk_left) and place_free(solid.x-5,solid.y) x -= 5

if keyboard_check(vk_right) and place_free(solid.x+5,solid.y) x += 5

if keyboard_check(vk_up) and place_free(solid.x,solid.y-5) y -= 5

if keyboard_check(vk_down) and place_free(solid.x,solid.y+5) y += 5

Create an object and name it obj_enemy. Make its sprite spr_enemy. Click OK, open obj_bullet, click add event, choose collision-obj_enemy. Drag and Drop an execute code button, Make sure it is open and type in 

with self


with other


This means when the bullet collides with obj_enemy, the bullet and the enemy will be destroyed.

Click the check mark, click OK. Save the game. Open room0, put in as many enemies as you want. Open obj_main. Click add event, choose collision with obj_enemy. Drag and Drop an execute code button, with it open, type in

HitPoints = 100

This will set the variable HitPoints to 100. Open the execute code button in obj_main in the collision with obj_enemy eventyy type in 

HitPoints -= 1

if HitPoints < 1{

with self




This will make the variable HitPoints go down by 1 every step that it is touching obj_enemy, it will also destroy obj_main and end the game when it runs out of HitPoints. Click the check mark, Click OK. Create an object and name it draw_score. Add an event and choose Draw. Drag and drop the execute code button inside it, type in


Then add the event step. Type in 

if obj_main.objMain = false{

with self



This will make the number 100 be at the top left corner of the screen. Make its depth 10 (under "visible" and "solid"). Open room0 and place draw_text anywhere in the room, other than on an enemy or on obj_main. Click the check mark, click OK, click save. Now you're done, just run the game and have fun with it.

1 comment

Bruce Bostwick
Posted on Sep 16, 2012