2d platformer, patrolling enemy implementation question design

Started by
0 comments, last by nielsvermeiren 2 years, 11 months ago

Hi, I am working on a platformer where I want an enemy to ‘patrol’, walk back and forth between edges of a platform.

Below a screenshot:

Here I would simply like the enemy skeleton to walk back and forth between the whole platform,
turning at the edge on the left and turning again at the wall on the right.


There are a million bad ways to do this which I don't like due to tight coupling of the enemy and the platform entities.

I was thinking (never done this before) of creating some sort of mediator pattern to let the relevant platform talk to the enemy in a separate class. Is this a bad idea, overkill? How would you guys go about designing this?

I would also like, in the future, to do a similar things, for example, letting the saw blades I created follow the edges of the outer bounds of the tiles, like so:

Some tips would be greatly appreciated!

Full codebase of project so far: https://github.com/niels-vermeiren/2d-sidescroller-game

This topic is closed to new replies.

Advertisement