Step 5

Setting up enemyAI


Next we need to create the enemy function.

Create a new function and call it ‘enemyAI’.

Set up the sprite variable, position and type.

We want ghost to be a type of ‘enemy’ and be positioned randomly near the top of the screen.

Enemy following


Let’s set up the ghost’s ability to chase the princess on the screen.

Enemy following


Now lastly set up the ghost’s animation.

Don’t forget to set up to 4 ghost picture frames from the gallery.