0

I generate 2D terrain objects such as trees at runtime. A game unit can be placed anywhere, the trees in the surrounding array of placement must then not be drawn to create an opening.

There is no map data, the world is generated the same each time. Trees are generated rectangular regions at a time. The region sizes can vary depending on the screen resolution. Memory for the game is pre-allocated, static memory allocation is preferred.

I stupidly tried to create an array based on screens height and width which I would then use to replace the trees in an element of the array with the game object. I could not create a static array based on non literals since a static array needs to know its size at compile time.

How can I store my rectangular tree region data such that I can quickly eliminate trees based on their positions.

1 Answers1

1

You could use one of the techniques to generate a dynamic 2D array described here.

Community
  • 1
  • 1
Phillip Ngan
  • 15,482
  • 8
  • 63
  • 79
  • This is a valid answer with a link to a great post, i will mark as the answer. However i realized that if i want to make a program that is the same on all devices then i might as well allocate a large static array for iPad 3 which is the highest resolution and then use part of it for the lower resolutions since the memory used by the app is pre-allocated at the same amount for every device. – user3345413 Apr 18 '14 at 11:03
  • To those who are interested I also considered implementing a recursive dimensional clustering and doing collision detection, or a quad tree etc which I think would have been valid solutions with multiple uses with more flexible object position layouts. i.e. Spatial Data Structures – user3345413 Apr 18 '14 at 11:08