Advertisement

Some questions

Started by July 11, 2001 11:41 AM
3 comments, last by Padalec 23 years, 7 months ago
So I have some questions: 1)Should I use a one big list of map object''s (TMapObj Temp; Temp.Type=Tile; Temp.X=1; Temp.Y=3; MapObj.Add(Temp)) or a 2d vector ( array ) of map objects (map[2][2].Add(Tile)) ? 2)I want to my walls become transparent when charecter is in a room , but how can I determine is he in a room and what walls should be transparent.
1.) A multiple subscript array is actually a single dimension array in memory, or x[4][4] = same as x[16], just that x[4][4] is alittle harder to deal with AND causes more problems than you want. IMHO I would choose the single dimension approach and use

x [j] = x [i*WIDTH + j]

2.) It totally depends on what type of view you have and how your rendering things. Like if it is some sort of isosemetric game (like DiabloII) you could say ''for every wall within the map, if the player is covered by it, render that way transparent'' Or if your in an FPS (like Oni) you could say ::gasp:: cast a ray to the player and every wall it intersects should be flagged as ''draw transparent''. Their are plenty of approaches with some better than others, just remember the key is to experiment! If something dosn''t work well for one game, it might be the best solution on a future project.


CodeSmith the Pixel Pusher
www.cs.trinity.edu/~csmith8
CodeSmith the Pixel PusherCodeSmith Webpage
Advertisement
1) as CodeSmith said in real memory things are just the same, I prefer using a 2d vector, it''s more intuitive... but is all up to you, the way you feel better

2) to see if the character is in a room you could use a rectangle representing the room area, and when the player gets into that area you would substitute de tiles of the walls with the inside of the room (or some special tiles having some kind of semitransparent walls with the inside of the room in the bg).

=)

have a nice day

jakovo
"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"
1) You should NOT use a 2d-vector if you want fast code, unless the size of the first entry is a power of two (2,4,8,16,...). At least not if the code has to be fast (usually the case in games)

This is because when using a 2d-map, you will have that multiplication (x+y*width) built into the code, if you have a 2d-vector "int yo[52][71]" and writes "yo[2][4]=7" It will compile to yo[2*52+7], and you will have a integer multiplication. So what, you think? "If I use a 1D-vector, I still need the multiplication, I just have to do it myself!" Well, not necessarily. Take a look at this 2d-loop:

for(y=0;y<27;y++)
for(x=0;x<13;x++)
yo[x+52*y]=map.crate(x,y);

In this case, using a yindex can remove this multiplication. You won''t notice a speed difference running this code, but in large structures that has to be fast (like drawing pixels to the screen) you can do without that multiplication like this:

yindex=0;
for(y=0;y<27;y++){
for(x=0;x<13;x++){
yo[x+yindex]=map.crate(x,y);
}
yindex+=52;
}

Same code, just faster...

2)Can''t be answered unless you tell us what is a "wall" and a "room" in your game... But you use the term "tile", so I guess it is tilebased. In games like "the Sims" you could determine wich tiles where inside a room before runtime. Before the game starts, mark each tile with a roomnumber. Then it it easy to check wich room a character is... You ofcourse would have to mark each wall with a roomnumber too, in games like the sims it would be the room on the far side of tha wall (recalculate if the viewpoint is changed)

Hope this will help...
Joke/dST
My game is very similiar to Fallout.

Maybe I should create a house class, I''ll hold in this class pointers to every wall ( if the wall is in the back of the house it won''t become transparent, so there won''t be any pointer to it). So if this building will be destroyed by player, i''ll just remove that object.

What do you think?

This topic is closed to new replies.

Advertisement