Example #1
0
        private static void drawOutside(SpriteBatch spriteBatch, GameTime gameTime)
        {
            Point topLeft     = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Left, SimulationGame.VisibleArea.Top, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);
            Point bottomRight = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Right, SimulationGame.VisibleArea.Bottom, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

            for (int blockX = topLeft.X; blockX < bottomRight.X; blockX++)
            {
                for (int blockY = topLeft.Y; blockY < bottomRight.Y; blockY++)
                {
                    Point          worldGridChunkPosition = GeometryUtils.GetChunkPosition(blockX, blockY, WorldGrid.WorldChunkBlockSize.X, WorldGrid.WorldChunkBlockSize.Y);
                    WorldGridChunk worldGridChunk         = SimulationGame.World.GetFromChunkPoint(worldGridChunkPosition.X, worldGridChunkPosition.Y);

                    BlockRenderer.Draw(spriteBatch, blockX * WorldGrid.BlockSize.X, blockY * WorldGrid.BlockSize.Y, worldGridChunk.GetBlockType(blockX, blockY));
                }
            }

            Point chunkTopLeft     = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Left, SimulationGame.VisibleArea.Top, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);
            Point chunkBottomRight = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Right, SimulationGame.VisibleArea.Bottom, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

            for (int chunkX = chunkTopLeft.X; chunkX <= chunkBottomRight.X; chunkX++)
            {
                for (int chunkY = chunkTopLeft.Y; chunkY <= chunkBottomRight.Y; chunkY++)
                {
                    WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkX, chunkY);

                    if (SimulationGame.IsDebug)
                    {
                        SimulationGame.PrimitiveDrawer.Rectangle(new Rectangle(chunkX * WorldGrid.WorldChunkPixelSize.X, chunkY * WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y), worldGridChunk.IsPersistent ? Color.Blue : Color.Red);
                    }

                    if (worldGridChunk.AmbientObjects != null)
                    {
                        foreach (AmbientObject ambientObject in worldGridChunk.AmbientObjects)
                        {
                            if (SimulationGame.VisibleArea.Contains(ambientObject.Position) && ambientObject.InteriorID == SimulationGame.Player.InteriorID)
                            {
                                if (ambientObject.CustomRenderer != null)
                                {
                                    ambientObject.CustomRenderer.Draw(spriteBatch, gameTime);
                                }
                                else
                                {
                                    AmbientObjectRenderer.Draw(spriteBatch, gameTime, ambientObject);
                                }
                            }
                        }
                    }

                    if (worldGridChunk.ContainedObjects != null)
                    {
                        foreach (var containedObject in worldGridChunk.ContainedObjects)
                        {
                            if (SimulationGame.VisibleArea.Contains(containedObject.Position) && containedObject.InteriorID == SimulationGame.Player.InteriorID)
                            {
                                if (containedObject.CustomRenderer != null)
                                {
                                    containedObject.CustomRenderer.Draw(spriteBatch, gameTime);
                                }
                                else
                                {
                                    if (containedObject is LivingEntity)
                                    {
                                        LivingEntityRenderer.Draw(spriteBatch, gameTime, (LivingEntity)containedObject);
                                    }
                                    else if (containedObject is AmbientHitableObject)
                                    {
                                        AmbientHitableObjectRenderer.Draw(spriteBatch, gameTime, (AmbientHitableObject)containedObject);
                                    }
                                }
                            }
                        }
                    }

                    if (worldGridChunk.ContainedEffects != null)
                    {
                        foreach (var effectItem in worldGridChunk.ContainedEffects)
                        {
                            EffectRenderer.Draw(spriteBatch, gameTime, effectItem.Value);
                        }
                    }

                    if (SimulationGame.IsDebug && worldGridChunk.WorldLinks != null)
                    {
                        foreach (var worldLinkItem in worldGridChunk.WorldLinks)
                        {
                            if (SimulationGame.VisibleArea.Contains(new Point(worldLinkItem.Value.FromBlock.X * WorldGrid.BlockSize.X, worldLinkItem.Value.FromBlock.Y * WorldGrid.BlockSize.Y)))
                            {
                                SimulationGame.PrimitiveDrawer.Rectangle(new Rectangle(worldLinkItem.Value.FromBlock.X * WorldGrid.BlockSize.X, worldLinkItem.Value.FromBlock.Y * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y), Color.DarkBlue);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private static void drawInterior(SpriteBatch spriteBatch, GameTime gameTime, Interior interior)
        {
            Point topLeft     = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Left, SimulationGame.VisibleArea.Top, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);
            Point bottomRight = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Right, SimulationGame.VisibleArea.Bottom, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

            topLeft.X = Math.Max(0, topLeft.X);
            topLeft.Y = Math.Max(0, topLeft.Y);

            bottomRight.X = Math.Min(interior.Dimensions.X, bottomRight.X);
            bottomRight.Y = Math.Min(interior.Dimensions.Y, bottomRight.Y);

            for (int blockX = topLeft.X; blockX < bottomRight.X; blockX++)
            {
                for (int blockY = topLeft.Y; blockY < bottomRight.Y; blockY++)
                {
                    BlockRenderer.Draw(spriteBatch, blockX * WorldGrid.BlockSize.X, blockY * WorldGrid.BlockSize.Y, interior.GetBlockType(blockX, blockY));
                }
            }

            if (interior.AmbientObjects != null)
            {
                foreach (AmbientObject ambientObject in interior.AmbientObjects)
                {
                    if (SimulationGame.VisibleArea.Contains(ambientObject.Position) && ambientObject.InteriorID == SimulationGame.Player.InteriorID)
                    {
                        if (ambientObject.CustomRenderer != null)
                        {
                            ambientObject.CustomRenderer.Draw(spriteBatch, gameTime);
                        }
                        else
                        {
                            AmbientObjectRenderer.Draw(spriteBatch, gameTime, ambientObject);
                        }
                    }
                }
            }

            if (interior.ContainedObjects != null)
            {
                foreach (var containedObject in interior.ContainedObjects)
                {
                    if (SimulationGame.VisibleArea.Contains(containedObject.Position) && containedObject.InteriorID == SimulationGame.Player.InteriorID)
                    {
                        if (containedObject.CustomRenderer != null)
                        {
                            containedObject.CustomRenderer.Draw(spriteBatch, gameTime);
                        }
                        else
                        {
                            if (containedObject is LivingEntity)
                            {
                                LivingEntityRenderer.Draw(spriteBatch, gameTime, (LivingEntity)containedObject);
                            }
                            else if (containedObject is AmbientHitableObject)
                            {
                                AmbientHitableObjectRenderer.Draw(spriteBatch, gameTime, (AmbientHitableObject)containedObject);
                            }
                        }
                    }
                }
            }

            if (interior.ContainedEffects != null)
            {
                foreach (var effectItem in interior.ContainedEffects)
                {
                    EffectRenderer.Draw(spriteBatch, gameTime, effectItem.Value);
                }
            }

            if (SimulationGame.IsDebug && interior.WorldLinks != null)
            {
                foreach (var worldLinkItem in interior.WorldLinks)
                {
                    if (SimulationGame.VisibleArea.Contains(new Point(worldLinkItem.Value.FromBlock.X * WorldGrid.BlockSize.X, worldLinkItem.Value.FromBlock.Y * WorldGrid.BlockSize.Y)))
                    {
                        SimulationGame.PrimitiveDrawer.Rectangle(new Rectangle(worldLinkItem.Value.FromBlock.X * WorldGrid.BlockSize.X, worldLinkItem.Value.FromBlock.Y * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y), Color.DarkBlue);
                    }
                }
            }
        }