Hey guys –
I’m curious about all your opinions on the best way to organize a level in a game, and I’m thinking specifically a 2D top-down look akin to SNES RPGs, but this discussion could branch anywhere from there and I’d still be interested. What’s the most efficient way to do this? How should collision be factored? What about “fog” for not being able to look past walls and things? How would you do it, or how did you do it? What do you think is the most widely adopted way of doing this?
I have to this point used a 3D array to handle all static unmoved objects, like walls and buildings. Maybe one or two of them will be moved or deleted at a time, but on the whole the objects in my array do not act, they merely draw and represent the environment and things the player cannot walk through. Every other layer represents a layer the player can “walk” in, that is a layer where walls can block the player and doors can be opened. When a player walks up stairs, the active layer is changed to two layers up. These layers than can be active do not have anything drawn to the screen – they merely have things to decide possible walking locations and whatnot, therefore allowing for invisible walls, or walls that can be walked through, etc. The layers that sandwich them form foreground and background (depending on if they are above or below the active layer), and are drawn, but the player can never interact with them (in terms of collision). So a “passwall” would have a drawn wall, but in the center layer there would be no matching Wall, and therefore it could be walked through even though it may not appear like that should be true.
Agents are all saved in a single ArrayList, which is one thing I think may be poorly designed. This means all characters, monsters, etc., have to be checked for collision with the player at every timestep. I never have too many Agents in the list at once so there is never too much overhead, but I feel there is probably a better way to design this. Because players do not move along a grid and because you can walk through them, I felt it would be inappropriate to save them in the array. Perhaps 5 agents could be overlapping the same position, or be halfway in between what would be two array locations. But is an ArrayList too slow? This means every timestep I’ve already got O(n) going, before animation, having all Agents act(), etc. Slow?
Everything in the ArrayList is told to act every timestep, but the only items in the array drawn are ones on the screen, saving quite a bit of processor. This is obviously a fine idea, but I’m wondering if anyone maybe has a reason not to do this.
As for “fog,” I have straight lines factored in every direction along 36 different slopes (this means one every 10 degrees), then if these lined intersect a wall a black triangle is drawn at that angle along the wall. What results is a very realistic fog in terms of human visibility, but it looks sort of ugly. If I do partially transparent triangles it looks a little better as overlapping areas are darker, but it’s still sort of kinky. How do other people do this?
And that’s my take on it all. How about yours?