예제 #1
0
        public Tile(Point tilesetPos, int tilesetLengthX, int tilesetLengthY, TileType type)
        {
            TilesetHelper.setInitialTileOffset(this, tilesetPos, tilesetLengthX, tilesetLengthY);

            this.tilesetPos = tilesetPos;
            this.type       = type;
        }
예제 #2
0
        /**
         * Gets the index data for this tile.
         * @param startVert The starting index for this tile.
         * @return An int array containing the tile's indices.
         */
        public ushort[] getIndexData(ushort startVert)
        {
            ushort[] order;

            switch (type)
            {
            case TileType.Floor:
                order = new ushort[] { 0, 1, 2, 0, 2, 3 };
                break;

            case TileType.Wall:
                order = TilesetHelper.getTileIndices(this.borders);
                break;

            case TileType.Pit:
                order = TilesetHelper.getTileIndices(this.borders);
                break;

            default:
                order = new ushort[] { 0, 1, 2, 0, 2, 3 };
                break;
            }

            for (int i = 0; i < order.Length; i++)
            {
                order[i] += startVert;
            }

            return(order);
        }
예제 #3
0
        /**
         * Gets the vertex data for this tile.
         * @return The tile's vertices.
         */
        public float[] getVertexData()
        {
            //calculate vertices
            float s = SIZE_F / 2;

            float[] vertices  = null;
            float[] texCoords = null;
            float[] normals   = null;

            switch (type)
            {
            case TileType.Floor:
                vertices = new float[]
                {
                    -s, s, 0,
                    -s, -s, 0,
                    s, -s, 0,
                    s, s, 0
                };
                texCoords = new float[]
                {
                    0, 0,
                    0, 64f / 256f - 1f / 512f,
                    64f / 512f - 1f / 1024f, 64.0f / 256.0f - 1f / 512f,
                    64f / 512f - 1f / 1024f, 0
                };
                normals = new float[]
                {
                    0, 0, 1,
                    0, 0, 1,
                    0, 0, 1,
                    0, 0, 1
                };
                break;

            case TileType.Wall:
                vertices  = TilesetHelper.getTileVertices(this.borders, s, SIZE_F);
                texCoords = TilesetHelper.getWallTexCoords(this.borders);
                normals   = TilesetHelper.getTileNormals(this.borders);
                break;

            case TileType.Pit:
                vertices  = TilesetHelper.getTileVertices(this.borders, s, -SIZE_F);
                texCoords = TilesetHelper.getPitTexCoords(this.borders);
                normals   = TilesetHelper.getTileNormals(this.borders);
                break;

            default:
                //by default use the same vertices as the floor.
                vertices = new float[]
                {
                    -s, s, 0,
                    -s, -s, 0,
                    s, -s, 0,
                    s, s, 0
                };
                texCoords = new float[]
                {
                    0, 0,
                    0, 64f / 256f - 1f / 512f,
                    64f / 512f - 1f / 1024f, 64.0f / 256.0f - 1f / 512f,
                    64f / 512f - 1f / 1024f, 0
                };
                normals = new float[]
                {
                    0, 0, 1,
                    0, 0, 1,
                    0, 0, 1,
                    0, 0, 1
                };
                break;
            }

            //shift vertices to position
            for (int i = 0; i < vertices.Length; i += 3)
            {
                vertices[i]     += pos.X;
                vertices[i + 1] += pos.Y;
            }

            float[] vertexData = new float[(vertices.Length / 3) * 8];

            //interleave arrays
            for (int i = 0; i < vertices.Length / 3; i++)
            {
                vertexData[i * 8]     = vertices[i * 3];
                vertexData[i * 8 + 1] = vertices[i * 3 + 1];
                vertexData[i * 8 + 2] = vertices[i * 3 + 2];
                vertexData[i * 8 + 3] = texCoords[i * 2];
                vertexData[i * 8 + 4] = texCoords[i * 2 + 1];
                vertexData[i * 8 + 5] = normals[i * 3];
                vertexData[i * 8 + 6] = normals[i * 3 + 1];
                vertexData[i * 8 + 7] = normals[i * 3 + 2];
            }

            return(vertexData);
        }