Taking on a Zelda Clone, Part 13

I finished work early today so I got a couple hours today to work on this some more.

Height
For a second there, I was close to implementing a “height” thing where objects’ and enemies’ shadows would remain as-is while the enemy would rise up, thereby giving the feel of jumping, etc. This is done in Zelda 3 and other things, but it was started to get messy so I decided that this sort of feature creep isn’t what I need right now. It’d be a nice thing to have, though.

Enemy behavior
Now that I basically got enemies reimplemented, I decided it’s time to implement the movement and behavior stuff in a more streamlined, logical way. Before, I was using lots of ugly timers and variables declared on the spot, in different ways for different classes. It was clear it wasn’t going to work very well.

I couldn’t think of a good system until a random thought popped into my head during work – just use a queue, and dequeue action info once per clock tick, and if it gets emptied, just refill it up with a new action.

I tried this out and it worked pretty well once I smoothed out some tough stuff. So basically each enemy has an action queue now. The idea behind is is that I fill it up like so:

  • Show appearance smoke
  • Show appearance smoke
  • Show appearance smoke
  • Show appearance smoke
  • Show appearance smoke
  • Show appearance smoke
  • Show appearance smoke
  • Show appearance smoke
  • Walk
  • walk
  • Walk
  • Walk
  • Walk
  • walk
  • Walk
  • Walk
  • Stop
  • Stop
  • Stop
  • Stop
  • Stop
  • Stop

And then after it’s done processing that one activity per clock tick, the queue would get refilled and it’d start over again, minus the appearance stuff.

I realized I could take it a step further so I made an Action class/struct with an internal timer of its own that simplifies this a lot, So now the above is more like:

  • Show appearance smoke x8
  • Walk x8
  • Stop x6

And I did lots of various things to make it easy for me to make good, complicated behavior patterns. Even with just Stop, Move, and Random Walk, you can do a whole lot, as you can maybe sort of see in the video above.

I plan on using this all as a base to make good, sophisticated enemy behaviors. I’ll probably add in some more things like line-of-sight, so enemies can react if they see you, stuff like that. It’s pretty cool and exciting stuff, and best of all, a lot of this code can be reused for future action games I might make.

Download

Both comments and pings are currently closed.

Comments are closed.

Subscribe to RSS Feed Follow me on Twitter!