XNA 2d Voxel Collision

DuffCola

Mitglied
Hallo.
Ich versuche gerade eine 2d Voxel Engine für XNA zu machen.
Bis jetzt habe ich einfach ein Enum und eine Block Klasse:

Code:
enum BlockType
    {
        EMPTY,
        DIRT,
        GRASS
    }
    class Block
    {
        public BlockType block_type;

        public Block()
        {
            this.block_type = BlockType.EMPTY;
        }
        public Block(BlockType block_type)
        {
            this.block_type = block_type;
        }
    }

Dann habe ich eine Level Klasse:

Code:
    public class Level
    {
        private Block[,] world;
        private Texture2D texture_grass;
        private Texture2D texture_dirt;

        public Level()
        {
            world = new Block[100, 100];
        }
        public void Initalize()
        {
            for (int x = 0; x < 100; x++)
            {
                for (int y = 0; y < 100; y++)
                {
                    world[x, y] = new Block(BlockType.DIRT);
                }
            }
        }
        public void LoadContent(ContentManager content_manager)
        {
            texture_grass = content_manager.Load<Texture2D>("Block_Grass");
            texture_dirt = content_manager.Load<Texture2D>("Block_Dirt");
        }
        public void Draw(SpriteBatch sprite_batch)
        {
            for (int x = 0; x < 100; x++)
            {
                for (int y = 0; y < 100; y++)
                {
                    switch (world[x, y].block_type)
                    {
                        case BlockType.EMPTY:

                            break;
                        case BlockType.GRASS:
                            sprite_batch.Draw(texture_grass, new Vector2(x * 40, y * 40), Color.White);
                            break;
                        case BlockType.DIRT:
                            sprite_batch.Draw(texture_dirt, new Vector2(x * 40, y * 40), Color.White);
                            break;
                        default:

                            break;
                    }
                }
            }
        }
    }

So.
Jetzt habe ich aber kein Ahnung, wie ich zum Beispiel die Collision prüfen soll usw...
Kla, ich könnte jetzt noch eine Funktion einbauen, die sämtliche Blöcke, nach einer Position durchsucht und dann zurück gibt, ob eine Collision stattgefunden hat.
(Habe beim suchen nur ein paar Ansätze gefunden, wo ich aber nicht weiß wie ich die anwenden soll z.B. erst eine Grobe Collisions Überprüfung und wenn die wahr ist eine genauere)
Aber bei unglaublich vielen Blöcken, würde der Pc das wohl nicht mehr schaffen.

Und das andere ist, wie gehe ich vor, wenn ich für jeden Block eine eigene Klasse haben will, die alle von einer abstracten Klasse Block erben.
Bis jetzt habe ich ja nur eine Klasse Block, der nur die Texture verändert.

Ich hoffe ihr könnt mich auch vielleicht korrigieren, wenn dieser Ansatz völlig falsch ist.

Vielen Dank allein fürs durchlesen :D
 
Zurück