Skip to main content
GameDev.net gamedev.net
🔒 Locked

Adding ships to map

Started by Zombie Dec 24, 1999 at 2:32 PM 8 replies 900+ views
Original Post
Zombie
Zombie
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?
ghowland
ghowland
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

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


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

Dak Lozar
Dak Lozar
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.