Esempio n. 1
0
        public static bool CheckForPlacementCollision(BoundingBox collisionBox, Vector2 position, SurfaceContainer surface, Base.CollisionLayer collisionMask)
        {
            int[]   chunkList = BoundingBox.GetChunkBounds(collisionBox, position, surface);
            int[][] tileList  = BoundingBox.GetTileBounds(collisionBox, position);
            for (int i = 0; i < chunkList.Length; i++)
            {
                Chunk chunk = surface.GetChunk(chunkList[i], false);
                if (chunk == null)
                {
                    continue;
                }
                //entity collision checks
                List <Entity> collisionList = chunk.entityCollisionList;
                for (int j = 0; j < collisionList.Count; j++)
                {
                    if ((collisionList[j].collisionMask & collisionMask) != 0)
                    {
                        if (BoundingBox.CheckCollision(collisionBox, collisionList[j].collisionBox, position, collisionList[j].position))
                        {
                            return(true);
                        }
                    }
                }

                //tile collision checks
                //Perhaps switch to continually checking whether the player is colliding with a tile at his position until he isnt colliding with a tile?
                //Would fix the situation where getting stuck in water still allows movement within
                //TODO: try solution outline above
                for (int j = 0; j < tileList[i].Length; j++)
                {
                    Tile tile = surface.tileCollection.GetTerrainTile(chunk.GetTile(tileList[i][j]));
                    if ((collisionMask & tile.collisionMask) != 0)
                    {
                        Vector2 tilePos = surface.WorldToTileVector(chunkList[i], tileList[i][j]);
                        if (BoundingBox.CheckCollision(collisionBox, surface.tileBox, position, tilePos))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Generates the bounding box vertex array for a terrain using the map colors of the tile.
        /// </summary>
        /// <param name="chunk"></param>
        /// <param name="chunkIndex"></param>
        /// <param name="pointsTile"></param>
        /// <returns></returns>
        public VertexArray GenerateTerrainBoundingBoxArray(SurfaceContainer surface, Chunk chunk, int chunkIndex, float[] pointsTile)
        {
            VertexArray vertexArray = new VertexArray(PrimitiveType.Lines);

            for (int k = 0; k < Props.chunkSize; k++)
            {
                for (int l = 0; l < Props.chunkSize; l++)
                {
                    Tile tile = GetTerrainTile(chunk.GetTile(k, l));
                    if ((tile.collisionMask & Base.CollisionLayer.TerrainSolid) != 0)
                    {
                        Vector2 position = surface.WorldToTileVector(chunkIndex, k * Props.chunkSize + l);
                        for (int x = 0; x < pointsTile.Length; x += 2)
                        {
                            vertexArray.Append(new Vertex(new Vector2f(pointsTile[x] + position.x, pointsTile[x + 1] + position.y), tile.mapColor));
                            vertexArray.Append(new Vertex(new Vector2f(pointsTile[(x + 2) % 8] + position.x, pointsTile[(x + 3) % 8] + position.y), tile.mapColor));
                        }
                    }
                }
            }
            return(vertexArray);
        }