Archived

This topic is now archived and is closed to further replies.

Coaster Kev

Setting boundries in Adventure Games...

Recommended Posts

Hi. I''m currently working on a 2D style adventure game, and I am a little curious about how I should set up the boundries in all of my rooms. I don''t want the player to walk on the walls or anything. I''ve heard of two good examples to take care of this problem... one being a bouncing box, or something like that... and another being to have a seperate background image that has boundry lines drawn on it. Fact is, I have no idea how to implement either. Could some one give me some tips and set me in the right direction? Thanks a lot.

Share this post


Link to post
Share on other sites
A bounding box is simple basically you don''t want the player''s on screen .x and .y value to ever be inside that of the bounding box (say the wall) for instance if you dont want thep layer to walk off the right side of the screen because there is a 10 pixel wide wall there you simply say:

if( player.x>=SCREENWIDTH - WALLWIDTH)
{
player.x=(SCREENWIDTH-WALLWIDTH);
}


this says dont let thep layers x value ever be greater than what the screens xvalue is (usually 640) minus whatever the width of your wall bitmap is (like 10 or something) so if the players.x value is ever greater than or equal to 630 pixels make sure he is locked at that 630 and dont let him go any further (since he would be in the wall if he did). There are more and better ways of doing this...im not a pro, just trying to get u started.


Shane

Share this post


Link to post
Share on other sites
You could have bounding polygons (better than boxes, since you can have oddly-shaped rooms) each having a type. For example one polygon could be "walkable" another could be an "exit-polygon" (ie whenever a character enters it she is transported to some other location) etc etc.

Share this post


Link to post
Share on other sites
The easer way (not involving any math) is the second way you asked about. Make a second image with two colors (perhaps black and white).

If the character''s feet are at (x,y) then you can check to make sure that it is a white spot on the boundaries image. If it is then it''s ok. If it''s black then you need to put him back to the last white spot he was at. Or you could do the reverse and check beforehand to see if where he would move would be black or white. If it''s not a good spot then don''t move him.

If you want more details on this post another message (as well as perhaps the language you are using so I could give more details).

And by the way, I suggest this method only because I suck with math. I don''t know how to check for polygon collisions. That may be even better. I know for sure that at least Quest for Glory 2 used them. I''m pretty sure most quest games did.

Share this post


Link to post
Share on other sites
I think it would be easier for me to use the second image option... I''m designing and writing this in C++ with DirectX. GameCreator, if u can share more information, I''d be more than thankful. The only reason I knew about this technique is because AGI was a hobby of mine... which used this technique.

Thanks to everyone else too.

Share this post


Link to post
Share on other sites
You might want to lookup some info on Sierra''s old AGI and SCI game systems. I''ll tell you right now your best bet is to use a seperate picture that defines your players allowed movements. But spec your system out on paper before you get started. Keep in mind you might need to define a series of various colored areas and line markers to determine not only walls but in game layers & objects like tables, trees, rocks, etc. (something you can walk in front of, as well as behind, but not through).

As I remember it, the AGI system used two pictures for each room, the actual background and a color coded representation of the room''s physical structure. Of which certain portions of the screen were drawn with priorities, so some trees in the foreground (which a player should disappear behind if he walked into them) should have had a lower priority map color and thus would be drawn in after the character sprite was. This might be a good way to approach your own engine design. Of course instead of having only a single background image, you could use multiple layers (background, midground, and foreground) and or sprites to make it a bit easier.

Hope that helps a little...

Share this post


Link to post
Share on other sites
Oh, by the way, just a quick note: using the priority map method you could for example set light-blue to represent a water mass, and if your player is within that area set his animation state to aniSwim (or whatever).

Share this post


Link to post
Share on other sites
Basically you''d be working with DirectDraw (or Direct3D using 2D simulation). For each area you''d load several layers. Here would be how I would do it.

First I''d put down a picture of just the ground and walls. Where the doors would go you''d have a picture of what''s behind them (or black if you don''t want the inside/outside to show).

Next comes the hard part. You have to order everything correctly. Put down the tables, pillars, and other things the player can walk behind as well as the player in the right order.

Now, to move him around, you have to check if he would actually bump into anything. That''s where another picture of the scene would come in handy. It would be two colors, like I mentioned before. If the character would move up 2 pixels then check that picture to see if that''s a color that allows the player to move there. Everything in that image that the player can''t step onto would be one color. Every other place that the player could walk onto would be the other color.

I wish I could give you functions and so on but I''m kind of learning DirectX myself but I''ve worked with similar ideas in DJGPP and Allegro.

Good luck!

Share this post


Link to post
Share on other sites