Search This Blog

Thursday, April 21, 2016

Monster handling

Code design (or game design) is sometimes more subtle than you may at first thing. In this case I'm talking about where to place some piece of code such that it is both logic and can handle the situation in a smart way.

My current problem is to make the monsters walk around the map, and under certain condition toward the player such to attack him later on. The first idea you would get is that a monster is an object by itself and therefore there is a class "monster" which will have all the logic. But is the logic of the monster not somewhat shared by the player as well? Will the monster and the player not somehow walk around on the same world? You see already that maybe both monsters and the player will have a parent class let's say "actor" which may contains the x,y position and some other information. Yet the monster will have a different logic as the player, as the player will be handled all by the guy/girl behind the screen while the monsters should walk alone. So some part will be specific for sure.

Also, how many monsters will we deal with? The whole infinite world? Or shall we keep the monsters only for the areas we have currently in memory? Quite certainly this second case, so monsters should be kept with their area, and when we destroy an area we will stop handling them as well. Freshly loaded or generated area should bring new monsters and therefore we will handle only a limited set of monsters at a given time. Infinite number of object handling is simply not possible so that seems a good option... yet what if a monster shall cross an area border? Then it need to be placed on the new area or.... killed if it goes out of the currently handled areas.

Remains also to think about the rendering, ideally the render part of the game engine should deal with players, monsters and NPC basically in the same way.

All that makes the whole idea a bit fuzzy / complex and therefore maybe need some further refinement.

What if we introduce "pets" or "friendly monsters"? What if we want to have monsters acting as a group? And so on... so I clearly don't have yet all the answers, and will try to clarify my mind while working on it.

No comments:

Post a Comment