Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
GameMaker Programming By Example

You're reading from   GameMaker Programming By Example Master the development of 2D games by learning to use the powerful GameMaker Language and tools provided by the GameMaker: Studio workspace and engine!

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781785887963
Length 212 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Brian Christian Brian Christian
Author Profile Icon Brian Christian
Brian Christian
Steven Isaacs Steven Isaacs
Author Profile Icon Steven Isaacs
Steven Isaacs
Arrow right icon
View More author details
Toc

Programming a Boss AI


In this section, we'll be programming in a Boss AI for the player to fight after a certain time (a minute specifically). Create a missile sprite where its head points downwards (to make launching it from the boss easier to code), and of course, center its origin. Then, create a boss object and a missile object. We'll work on the boss later, but we'll have to reference it in the missile object.

Make the missile object a child of class_enemy, give it a depth of -10, and of course assign it its sprite. In the Create event for the object, give it two variables: hp, which should be set to 5, and dir, which should be set to 270. dir. This will be the default direction of the missile to face.

Now, add a Step event to the object. First call event_inherited(). Next, check if an instance of the boss object collides with the bottom of the missile (using place_meeting). If so, increment y by 5. What this does is have the missile move down out of the boss' launchers until it's outside...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime