Adding ships to map

Started by
8 comments, last by Zombie 24 years, 3 months ago
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

Advertisement
Could you give a code example, or do you know any article about this?
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!

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.x > SCREEN_LEFT_POS && Ship.x < SCREEN_RIGHT_POS && Ship.y > SCREEN_TOP_POS && Ship.y < SCREEN_BOTTOM_POS)<BR> {<BR> Draw_Sprite(Ship);<BR> }<BR> }<BR></code><P>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. . .<P> <BR>

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.

Get off my lawn!

I'm using DX7 and VB. jtecin, can you translate that code to Basic or to VB?
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).]

Yeah, STG has basically got it.
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?
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.
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous

This topic is closed to new replies.

Advertisement