Jump to content
  • Advertisement

Archived

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

-Fruz-

Directdraw - top-down game, limited vision?

This topic is 5532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hmmm.. how would i go about adding limited "vision" in my top-down shooter. like, everything is black, exept a triangle wich is your "sight field"? hmm.. do i create a triangle, and just blit a hole with it? hmm.. but then, how would i rotate it? as far as i know, only d3d suports rotating/has it built in, and i figured any rotation done by pixel manipulation is too slow? JFK

Share this post


Link to post
Share on other sites
Advertisement
Firstly, you were right about pixel stuff being way too slow, and that triangle thing was a good thought but completely out of the question.
You''d better hope you are doing a tile-based game, or you only want your los to apply to objects and not the enviorment. Basicly, it is very simple... every time you want to blit something (perhaps a tile or an enemy or whatever) you first check to see if the pleyer can ''see'' it. If he can, then go ahead and blit. How do we know if the player can see something? Like this...
Two ways, I sugest you use a combination of both for what you want.
For that triangle thing, for each object or tile you blit you check the difference between the dirrection the player is facing and the direction from the player to the thing we are blitting. If the angle difference is bellow, say, 45 degrees, then we go ahead and blit. This is how I would do the triangle thing.
The other way is to check if a straight line between the player and the object/tile is blocked. If it is, then the player cannot ''see'' the thing so we do not blit it. However, I suggest checking if the lines are blocked on a tilemap based level for the sake of speed, and if your not using a tilemap I''m sure you''ll think of something.
For what you want, I suggest using a combination of both methods - first check the angle difference, the go on to check the straight line thing.
Of course, your line of sight will be totally ''blocky'' ie you see something one moment then the next it is completely gone, but that is about the best you can do in DDraw.
Note that this is how I do it, and there is quite possibly a better way, considering that this method comes straight from my own creation.
If you need help, post back. I have all the code you would need. And for God''s sake, checking the difference between two angles does NOT mean simply subtracting one from the other.

Share this post


Link to post
Share on other sites
thanx jack, that was really helpfull. i would be lying if i said i havent thought of similar ways, but i never thaught they were good enough, ie, fast enough and looked nice enough. but now i''m convinced. thanx for taking the time to post such a big and informative post.
JFK

Share this post


Link to post
Share on other sites
Well it certainly doesnt look great... but it works well speed-wise. I use the strait-line-blocked thing in my tile based game and it works perfectly with no drop in the framerate whatsoever. I blit about 300 tiles to my screen at once and, as I said, no speed cost - suiprising when I have a 450 mhz PC with less than 64 megs of ram.
To disguise the blockyness of los on tiles, you could hold the los thing in an array, run a check, and blit edges for the los onto the back buffer.

Share this post


Link to post
Share on other sites
mkey, hmm.. you said you had some code, if i needed more help. hmm, i dont need help with the code, but, it would be great to see an example of it in action, i can only imagine, and.. imagination is often wrong :\ hmm.. so, willing to share?

JFK

Share this post


Link to post
Share on other sites
Geee... my game that I am working on (with my los) is getting fairly large... uses DDraw. I suppose I could give you some screenshots demonstrating los. E-Mail adress? I use hotmail, and maximum sending thing is 1 meg, see why I cant send the whole thing?

Share this post


Link to post
Share on other sites
heh, i guiess i was just dumb not thinking of ascreenshot. that would be just as goood, thanx. if you would mail me one, you could either click my little mail icon, or use this address: jfk-post@online.no
i will be very thankfull. thanx

JFK

Share this post


Link to post
Share on other sites
Just sent the screenshots. The only thing I ask is that you dont take any of my graphics... not that you would, but I should cover myself. Let me know if you need any more help.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!