Easy AI For Your Next Prototype

AIGame Maker Studio 2Gameplay Tutorials

The big problem everyone runs into when trying to make their game is always the scope, or the polish (a.k.a the stuff that makes it more marketable) of the game they are trying to make. Then everyone says “prototype it first” and more often than not prototypes are never published.

Prototyping is one of my favorite things to do, if not the thing I feel most comfortable with because it is meant to be rough around the edges yet resemble a proof of concept. It is meant to be expanded on later!

This week, I want to tell you about my experience prototyping simple enemy AI with a few students of mine and how it all clicked.

I hope this weeks post inspires you to just open an editor and make something simple.


Every now and then I tutor kids (ages 12-16) in Computer Science and Game Development. It’s always interesting to see what they grasp immediately and what takes more time, but one thing is for the sure — kids have an endless amount of imagination.

For an assignment, we looked at programming some simple AI in Game Maker Studio 2 for a top-down game. I knew that the code itself would take some time to digest but the outcome opened up so many doors…

We programmed something like this:

if instance_exists(ob_player){

if point_distance(ob_player.x, ob_player.y, x, y,) > 25 {

if (random(5) < 1 {

//create bullet

} else {

//walk towards player

}

}

}

The above code…

  1. Checks to make sure the player “exists” in the game.
  2. Finds the distance between the player and the enemy. If greater than 25 pixels (mostly always will be) then…
  3. Decide if the enemy should shoot at the player or walk closer to it by randomizing on the spot to see if the decimal number is less than 1.

All of this runs in an alarm so it is constantly resetting and running (though it very well could run in a step event).

Once the kids had just these if statements, their imaginations kicked in and the next steps formed their own prototypes.

For example:

  1. They made the enemies wrap around the room
  2. They made the bullets wrap around the room
  3. They made the player have to hit the enemy to kill it (without getting hit by the bullet)
  4. They made the player increase in size yet slow down the speed when the player kills an enemy (bigger target for bullets) making it much harder

No polish, no artwork. Just placeholder squares moving around the screen and they loved it. They created a challenge and a goal so naturally! Then the following week they came back and added…

  1. High scores
  2. Dodging
  3. Shooting
  4. Spawning enemies in waves

And the ideas kept growing from there.

The takeaway — it doesn’t matter if you are currently learning to program, or know everything there is to know about it; just make one thing function and add to it and see where that idea takes you first.

Focus on the game more than the code and watch your prototype take shape!

See you next week,

Jerementor