سؤال

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.

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top