Monster Spawning and AI Code

I’ve added the first  monster to the game, the Slime. They hop around at random, until the player or an NPC gets within their 16-block aggro range, and then they start chasing it. The monsters will tend to head towards the town center block like the NPCs do, if they don’t have a target. Monsters will need to be taken care of as you build your town.

I fixed the spawning system so that things appear anywhere within the active portion of the game world, except for within the town limit and too close to the player. Right now things spawn every half-second, to the set limit of 64 monsters and 8 NPCs, so the town would be swarmed pretty quickly. Obviously I won’t be leaving it that way.

I had a problem with massive slowdowns if anything fell off the edge of the map, so I’m now killing anything that gets under the map by 100 units. If the player hops off the side, I’m just respawning him.

I took the time to fix the sprite lighting a bit, so now they’ll be colored to match the time of day. It isn’t as smooth as I’d like, but I’m moving forward:

The monsters will chase now, but there’s no entity collision testing yet. That will be the next step.


Tags: , , , , ,

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: