public MapContent(string filePath, Renderer renderer, string contentRoot)
        {
            XmlDocument document = new XmlDocument();
            document.Load(filePath);

            XmlNode mapNode = document[AttributeNames.MapAttributes.Map];

            Version = mapNode.Attributes[AttributeNames.MapAttributes.Version].Value;
            Orientation = (Orientation)Enum.Parse(typeof(Orientation), mapNode.Attributes[AttributeNames.MapAttributes.Orientation].Value, true);
            Width = Utilities.TryToParseInt(mapNode.Attributes[AttributeNames.MapAttributes.Width].Value);
            Height = Utilities.TryToParseInt(mapNode.Attributes[AttributeNames.MapAttributes.Height].Value);
            TileWidth = Utilities.TryToParseInt(mapNode.Attributes[AttributeNames.MapAttributes.TileWidth].Value);
            TileHeight = Utilities.TryToParseInt(mapNode.Attributes[AttributeNames.MapAttributes.TileHeight].Value);

            XmlNode propertiesNode = document.SelectSingleNode(AttributeNames.MapAttributes.MapProperties);
            if (propertiesNode != null)
                properties = new PropertyCollection(propertiesNode);

            BuildTileSets(document);

            BuildLayers(document);

            BuildTileSetTextures(renderer, contentRoot);

            GenerateTileSourceRectangles();
        }
Beispiel #2
0
        public static void DrawLine(Renderer renderer, int x1, int y1, int x2, int y2)
        {
            int result = SDL2.SDL.SDL_RenderDrawLine(renderer.Handle, x1, y1, x2, y2);

            if (result < 0)
                throw new Exception(String.Format("SDL_RenderDrawLine: {0}", SDL2.SDL.SDL_GetError()));
        }
 public static TrueTypeText CreateTrueTypeText(Renderer renderer, string fontPath, int fontSize, Color color, string text, int wrapLength)
 {
     Font font = new Font(fontPath, fontSize);
     Surface surface = new Surface(font, text, color, wrapLength);
     TrueTypeText trueTypeText = new TrueTypeText(renderer, surface, text, font, color, wrapLength);
     return trueTypeText;
 }
Beispiel #4
0
        public Texture(Renderer renderer, Surface surface)
        {
            Assert.IsNotNull(renderer, Errors.E_RENDERER_NULL);
            Assert.IsNotNull(surface, Errors.E_SURFACE_NULL);

            this.renderer = renderer;
            FilePath = surface.FilePath;
            AccessMode = TextureAccessMode.Static;
            Surface = surface;

            CreateTextureAndCleanup(surface.Width, surface.Height);
        }
        public RenderTarget(Renderer renderer, int width, int height)
        {
            Assert.IsNotNull(renderer, Errors.E_RENDERER_NULL);

            this.renderer = renderer;
            Width = width;
            Height = height;
            AccessMode = TextureAccessMode.Target;

            Handle = SDL.SDL_CreateTexture(renderer.Handle, SDL.SDL_PIXELFORMAT_RGBA8888, (int)AccessMode, Width, Height);
            if (Handle == IntPtr.Zero)
                throw new InvalidOperationException(Utilities.GetErrorMessage("RenderTarget"));
        }
        public override void Activate(SharpDL.Graphics.Renderer renderer)
        {
            base.Activate(renderer);

            textureBackgroundStripeTile = ContentManager.GetTexture("BackgroundStripeTileFaded");

            string fontPath            = ContentManager.GetContentPath(Styles.Fonts.DroidSansBold);
            Color  fontColorTitle      = Styles.Colors.PaleYellow;
            Color  fontColorLabelValue = Styles.Colors.White;
            int    fontSizeTitle       = Styles.FontSizes.MainMenuTitle;
            int    fontSizeContent     = Styles.FontSizes.Content;

            iconFrame          = ControlFactory.CreateIcon(ContentManager, "MenuPauseFrame");
            iconFrame.Position = new Vector(MainGame.SCREEN_WIDTH_LOGICAL / 2 - iconFrame.Width / 2, MainGame.SCREEN_HEIGHT_LOGICAL / 2 - iconFrame.Height / 2);

            buttonResumeGame            = ControlFactory.CreateButton(ContentManager, "ButtonLongRectangle", "ButtonLongRectangleHover", "ButtonLongRectangleSelected");
            buttonResumeGame.Label      = ControlFactory.CreateLabel(ContentManager, fontPath, fontSizeContent, fontColorLabelValue, "Resume");
            buttonResumeGame.ButtonType = ButtonType.TextOnly;
            buttonResumeGame.Position   = iconFrame.Position + new Vector(iconFrame.Width / 2 - buttonResumeGame.Width / 2, 16);
            buttonResumeGame.Released  += (sender, e) => ExitScreen();
            buttonResumeGame.EnableLabelShadow(ContentManager, 2, 2);

            buttonNewGame            = ControlFactory.CreateButton(ContentManager, "ButtonLongRectangle", "ButtonLongRectangleHover", "ButtonLongRectangleSelected");
            buttonNewGame.Label      = ControlFactory.CreateLabel(ContentManager, fontPath, fontSizeContent, fontColorLabelValue, "New Game");
            buttonNewGame.ButtonType = ButtonType.TextOnly;
            buttonNewGame.Position   = iconFrame.Position + new Vector(iconFrame.Width / 2 - buttonNewGame.Width / 2, 50);
            buttonNewGame.Released  += buttonNewGame_Clicked;
            buttonNewGame.EnableLabelShadow(ContentManager, 2, 2);

            buttonLoadGame            = ControlFactory.CreateButton(ContentManager, "ButtonLongRectangle", "ButtonLongRectangleHover", "ButtonLongRectangleSelected");
            buttonLoadGame.Label      = ControlFactory.CreateLabel(ContentManager, fontPath, fontSizeContent, fontColorLabelValue, "Load Game");
            buttonLoadGame.ButtonType = ButtonType.TextOnly;
            buttonLoadGame.Position   = iconFrame.Position + new Vector(iconFrame.Width / 2 - buttonLoadGame.Width / 2, 84);
            buttonLoadGame.Released  += buttonLoadGame_Clicked;
            buttonLoadGame.EnableLabelShadow(ContentManager, 2, 2);

            buttonOptions            = ControlFactory.CreateButton(ContentManager, "ButtonLongRectangle", "ButtonLongRectangleHover", "ButtonLongRectangleSelected");
            buttonOptions.Label      = ControlFactory.CreateLabel(ContentManager, fontPath, fontSizeContent, fontColorLabelValue, "Options");
            buttonOptions.ButtonType = ButtonType.TextOnly;
            buttonOptions.Position   = iconFrame.Position + new Vector(iconFrame.Width / 2 - buttonOptions.Width / 2, 118);
            buttonOptions.Released  += buttonOptions_Clicked;
            buttonOptions.EnableLabelShadow(ContentManager, 2, 2);

            buttonQuit            = ControlFactory.CreateButton(ContentManager, "ButtonLongRectangle", "ButtonLongRectangleHover", "ButtonLongRectangleSelected");
            buttonQuit.Label      = ControlFactory.CreateLabel(ContentManager, fontPath, fontSizeContent, fontColorLabelValue, "Quit");
            buttonQuit.ButtonType = ButtonType.TextOnly;
            buttonQuit.Position   = iconFrame.Position + new Vector(iconFrame.Width / 2 - buttonQuit.Width / 2, 152);
            buttonQuit.Released  += buttonQuit_Clicked;
            buttonQuit.EnableLabelShadow(ContentManager, 2, 2);
        }
        /// <summary
        /// >Default constructor creates a map from a .tmx file and creates any associated tileset textures by using the passed renderer.
        /// </summary>
        /// <param name="filePath">Path to the .tmx file to load</param>
        /// <param name="renderer">Renderer object used to load tileset textures</param>
        public TiledMap(string filePath, Renderer renderer, string contentRoot = "")
        {
            MapContent mapContent = new MapContent(filePath, renderer, contentRoot);

            TileWidth = mapContent.TileWidth;
            TileHeight = mapContent.TileHeight;

            PixelWidth = mapContent.Width * TileWidth;
            PixelHeight = mapContent.Height * TileHeight;

            HorizontalTileCount = mapContent.Width;
            VerticalTileCount = mapContent.Height;

            CreateLayers(mapContent);
            CalculateTilePositions(mapContent.Orientation);
        }
        public TrueTypeText(Renderer renderer, Surface surface, string text, Font textFont, Color color, int wrapLength)
        {
            Assert.IsNotNull(renderer, Errors.E_RENDERER_NULL);
            Assert.IsNotNull(surface, Errors.E_SURFACE_NULL);
            Assert.IsNotNull(textFont, Errors.E_FONT_NULL);

            Text = text;
            Font = textFont;
            Color = color;
            WrapLength = wrapLength;
            if (wrapLength > 0)
                IsWrapped = true;
            else
                IsWrapped = false;
            Texture = new Texture(renderer, surface);
        }
        public override void Draw(SharpDL.GameTime gameTime, SharpDL.Graphics.Renderer renderer)
        {
            base.Draw(gameTime, renderer);

            for (int x = 0; x <= MainGame.SCREEN_WIDTH_LOGICAL / textureBackgroundStripeTile.Width; x++)
            {
                for (int y = 0; y <= MainGame.SCREEN_HEIGHT_LOGICAL / textureBackgroundStripeTile.Height; y++)
                {
                    textureBackgroundStripeTile.Draw(x * textureBackgroundStripeTile.Width, y * textureBackgroundStripeTile.Height);
                }
            }

            iconFrame.Draw(gameTime, renderer);
            buttonResumeGame.Draw(gameTime, renderer);
            buttonNewGame.Draw(gameTime, renderer);
            buttonLoadGame.Draw(gameTime, renderer);
            buttonOptions.Draw(gameTime, renderer);
            buttonQuit.Draw(gameTime, renderer);
        }
Beispiel #10
0
        public Image(Renderer renderer, Surface surface, ImageFormat imageFormat)
        {
            Assert.IsNotNull(renderer, Errors.E_RENDERER_NULL);
            Assert.IsNotNull(surface, Errors.E_SURFACE_NULL);

            if (surface.Type == SurfaceType.Text)
                throw new Exception("Cannot create images from text surfaces.");

            Format = imageFormat;

            if (surface.Type == SurfaceType.BMP)
                Format = ImageFormat.BMP;
            else if (surface.Type == SurfaceType.PNG)
                Format = ImageFormat.PNG;
            else if (surface.Type == SurfaceType.JPG)
                Format = ImageFormat.JPG;

            Texture = new Texture(renderer, surface);
        }
 /// <summary>
 /// Draws the tile to the passed renderer if the tile is not empty. The draw will occur at the center of the tile's texture.
 /// </summary>
 /// <param name="gameTime"></param>
 /// <param name="renderer"></param>
 public void Draw(GameTime gameTime, Renderer renderer)
 {
     foreach (var tileLayer in TileLayers)
     {
         foreach (var tile in tileLayer.Tiles)
         {
             tile.Draw(gameTime, renderer);
         }
     }
 }
        private void BuildTileSetTextures(Renderer renderer, string contentRoot)
        {
            // build textures
            foreach (TileSetContent tileSet in tileSets)
            {
                string path = Path.Combine(contentRoot, tileSet.ImageSource);

                // need to use colorkey

                Surface surface = new Surface(path, SurfaceType.PNG);
                tileSet.Texture = new Texture(renderer, surface);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Draws the tile to the passed renderer if the tile is not empty. The draw will occur at the center of the tile's texture.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="renderer"></param>
        public void Draw(GameTime gameTime, Renderer renderer)
        {
            if (IsEmpty) return;

            Texture.Draw(
                GridPosition.X * Width,
                GridPosition.Y * Height,
                SourceTextureBounds);
        }