Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Construct 2

You're reading from   Learning Construct 2 Design and create your own engaging, extensible, and addictive game using Construct 2

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781784397678
Length 234 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Aryadi Subagio Aryadi Subagio
Author Profile Icon Aryadi Subagio
Aryadi Subagio
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Making enemies smarter


We created enemy objects in our example game earlier; these enemies are just falling down the screen and shooting, but now we will make cleverer enemies. The topic of AI is a complex one, and it is probably difficult to cover this topic in this chapter. So, instead of covering AI theories, I'll show you techniques that can make your enemies act smarter than usual.

Enabling enemy patrolling

The first thing we want to do to the enemies is to give them the ability to move around the screen, just like our own units. To do this, we'll first add a Timer behavior to the enemyBase object so that it can do something repeatedly. We also need to add an instance variable to it to record the state of the enemies; we don't want them to move around patrolling when they're shooting our units. Let's name this instance variable patrolling and make it a Boolean; don't forget to change the initial value to true.

We want the enemies to go on a patrol every few seconds, but to make it look...

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
Banner background image