Book Image

Creative Greenfoot: RAW

By : Michael Haungs
Book Image

Creative Greenfoot: RAW

By: Michael Haungs

Overview of this book

Table of Contents (17 chapters)
Creative Greenfoot
About the Author
About the Reviewers

Intelligently behaving actors

We are now going to add enemies to our MazeWorld scenario that implement different methods of simulating intelligent behavior. The first method we will discuss uses probabilistic movement, the second method uses simple heuristics, and the last method uses the A* pathfinding algorithm to guide actor movement. Before discussing each method, we present the ScrollingEnemy class that implements a common structure for intelligently behaving actors.

The ScrollingEnemy class

The class ScrollingEnemy inherits from ScrollingActor, so it will be placed properly within a scrolling world. Then, it sets up a pattern of behavior that is conducive to intelligently moving actors. Modeling actual sentient animals, ScrollingEnemy provides a three-phase action-taking process in its act() method. First, it calls a method that requires the actor to sense its environment, then it calls a method to choose a course of action based on what it has sensed, and then it calls a method to move...