Advertisement

How to create a dynamic sized map?

Started by February 21, 2000 08:49 AM
11 comments, last by ZomeonE 24 years, 7 months ago
thanks, i didn''t know about this method spellbound mentioned, but i am sure i will use it next time i need a dynamical map...
but, can you also add elements to the array once it has already been initialized? i mean like doing

int *Map = new int[Width * Height];
int *End = Map[Width*Height];
memset(End, sizeof(int)*Width);

and you have a new row allocated. or does that only generate a protection fault?
No you can''t. It would generate a protection fault.

If you want to resize the map you need to allocate more memory and copy the whole existing map into it and then set your new rooms.

But you can always make a really large map at the beginning with walls that don''t let you use the whole map, then when you need to expand you just knock down a wall an build a new room.
Advertisement
If you use C-style memory allocation, you can try realloc.

This topic is closed to new replies.

Advertisement