Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's interesting. The algorithm the author is trying is of a kind I have tried and, I believe, a mistake.

If you are building a roguelike, just have a sentinel list of entities. That is, do not try to break the level up into a 2d array of containers. Just have a ring, each entity having coordinates, and iterate through it as you need.

If you want to have an ai occupy multiple spaces, have that. Have an 'avatar' ai object own one-to-many (plotable) entities.

The mighty Jeff Lait gave me this insight in a code review. I believe he added, "premature optimisation is the root of all evil." I.e. be happy to iterate through linked lists until you are sure it is a problem.

Check out his game Smart Kobald.



Thanks for taking the time to respond to the way it's currently done.

The diagrams can give a slightly wrong impression and it looks like I've communicated the actual behaviour poorly because it works very much like you've described; there are not several objects occupying separate tiles that move in a synchronised way (so the troubles described by zenojevski are not applicable here). The constituents have no self-awareness and store nothing but their own appearance. They come in and out of existence as the object moves and are mere "markers"; they can't be interacted with but instead refer interaction to the object itself.

In that sense, it very much does consist of an 'avatar' ai object with several plotable entities except that the avatar object itself acts as one of the entities while the rest are kinda 'hollow'.

The objects are stored in their locations so this method of spreading them across tiles makes the most sense and you're probably right to be critical of this approach however it reflects reality and part of my objective is to make a program that my friends can contribute to as they learn code themselves and the easiest concepts to grasp are those that reflect reality rather than more abstract ones.

Also it hasn't presented any problems so far so I'd rather work with it than around it.

I hope I've understood and addressed what you're saying. Thanks for checking it out.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: