Archived

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

Zombie

Adding ships to map

Recommended Posts

You could have a map, but depending on how many you have, and if they can move easily, why not just have a list of all the objects in space and then keep their coords.

Then when you draw them you just draw the map, then check all the objects to see if they are on screen.

Thats what I do at least for RTS games, but the checks arent unreasonable.

-Geoff

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
First of all are you using DirectX 7 or the win32 api. if you are just using the Win32 api then all you have to do is to keep track of their coords on the screen in pixels and have bitblt SRCAND their masks to the screen and then have bitblt SRCPAINT their pictures over the masks which will leave you with the ships and the background of the map showing through that annoying whit back ground that MS Paint gives you! If you have anymore questions please feel free to send them to KonaRacer_69@hotmail.com

P.S Hope to be of help!

Share this post


Link to post
Share on other sites
Here is an example of storing the ships if you already have a ship struct.


For (i = 0; i < MAX_NUMBER_SHIPS; i++)
{
if (Ship[i].x > SCREEN_LEFT_POS && Ship[i].x < SCREEN_RIGHT_POS && Ship[i].y > SCREEN_TOP_POS && Ship[i].y < SCREEN_BOTTOM_POS)
{
Draw_Sprite(Ship);
}
}

I just did that from my head and didn't really check it over, but you get the point. An array of ships and you check if their on the screen using a for loop. . .


Share this post


Link to post
Share on other sites
if you are using C++, i would recommend using STL vector or STL list. use a vector if ships are not added or removed at a great frequency, and a list if they are added or removed at great frequency.

Share this post


Link to post
Share on other sites
I think you should be able to guess what the code means quite easily. Basicly the first line is a for loop and the && is AND.

anyway it should look something like this. (not checked)


for i = 0 to MAX_NUMBER_SHIPS-1

   if (Ship(i).x > SCREEN_LEFT_POS and Ship(i).x < SCREEN_RIGHT_POS and Ship(i).y > SCREEN_TOP_POS and Ship(i).y < SCREEN_BOTTOM_POS then
      Draw_Sprite(Ship(i))
   end if
next

[This message has been edited by STG (edited December 21, 1999).]

[This message has been edited by STG (edited December 21, 1999).]

[This message has been edited by STG (edited December 21, 1999).]

Share this post


Link to post
Share on other sites
I know you are using VB so this post does not apply to you... This is to TANSTAAFL, I would stay away from the STL in game programming. I would suggest codin your own LIST code.
Two reasons:
1: SPEED, a dedicated list class will perform faster.
2: SIZE, again a dedicated list class _can_ be smaller than STL's generic templates.
Of course this is all a matter of preference -but as game coders go, I would think that most would agree with me.

Share this post


Link to post
Share on other sites
I have a question for you (again!). I'm doing a 4-way scrolling space shooter, and
I should add the ships, stations and planets etc. to the map. How can I do that?
Do I have to do another map layer, and if, how do I do that?

Share this post


Link to post
Share on other sites