Wavefront, beginning estimations


Where we last left off, our enemy had a pathway to find the player, however, it took 38 passes for the furthest enemy to find you. The enemy will catch up to you, but you can move 38 pixels in total before the furthest enemy would be able to target you. There is an awkward time that the furthest enemy will just stand there not knowing where to move. What we need is an estimator.

Welcome back Taxicab.

During an earlier article, we explored Taxicab as a way for the enemy to find the player. It was a simple and fast way to guess a path to the player. Now there was an issue using taxicab as an exclusive way to find the player, so we dumped it. However, it is perfect to use as an estimator before the Grassfire kicks in all the way. We will, however, need to make a small modification. We don’t want the Taxicab to interfere with the Grassfire algorithm.

The way we can do that is with an offset. Here’s our code.

void TaxicabDifference()
    center = 0;    
    screenScanX = screenScanY = 0;
    //array is 150 slots big
    for (screenCounter = 0; screenCounter  0)
            grassfire[screenCounter] = 255;
        screenCounterStart ++;
        screenScanX ++;//last line

This is pretty much a duplicate of an earlier code we used (back a few articles). The only exception is a modification found in the line.

grassfire[screenScanX + scrw * screenScanY] = differenceX + differenceY + 128;//high offset so when grassfire kicks in, will round down

We are just adding 128 to the natural Taxicab difference. This is sufficiently high to provide an estimated pathway until the real Grassfire kicks in. In this matter, especially when run during the level setup, even the furthest enemy will be able to start moving in quick order.

In fact, we can use this as a replacement for the prepGrassFire() routine we used in the last article. That makes the code shorter, just like this article.


Author: andydansby

I'm a hobbyist coder working with the ZX Spectrum. Living in New York state near the Syracuse area. I grew up in Virgina. The first computer my parents bought for me was a Timex Sinclair 2068.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s