Example #1
0
 // Draw the tile image at the passed X/Y location.
 private void DrawTile(Graphics g, int x, int y, Map.LAYER layer)
 {
     g.DrawImage(map.GetTileImage(x, y, layer),
                 (x * map.GetTileSize()) + map.GetMapRootX(),
                 (y * map.GetTileSize()) + map.GetMapRootY(),
                 map.GetTileSize(),
                 map.GetTileSize());
 }
Example #2
0
        /**********************************************************************PAINT*/
        /**********************************************************************PAINT*/
        /**********************************************************************PAINT*/

        private void drawSurface_Paint(object sender, PaintEventArgs e)
        {
            // Good ol' graphics object.
            Graphics g = e.Graphics;

            /******************************************** DRAW TILES*/

            /* This is a work around for not being able to iterate through elements in an Enum. We have to create a string
             *  array that contains the names of each element in the enum, then cycle through each element in the string array instead. */
            String[] LAYERS = Enum.GetNames(typeof(Map.LAYER));

            // Draw each layer of the map separately, starting with the floor.
            foreach (String currentElement in LAYERS)
            {
                // Convert the current element string to our Enum type "Layer"
                Map.LAYER THIS_LAYER = (Map.LAYER)Enum.Parse(typeof(Map.LAYER), currentElement);

                // Iterate through every tile and draw its appropriate layer image.
                for (int i = 0; i < map.GetColumns(); i++)
                {
                    for (int j = 0; j < map.GetRows(); j++)
                    {
                        // Check if this layer is not the floor. If it is, just draw it and don't worry about anything else.
                        if (THIS_LAYER != Map.LAYER.FLOOR)
                        {
                            // If this layer isn't the floor, make sure it isn't empty before you draw it.
                            if (!map.GetTiles()[i, j].IsTileLayerEmpty(THIS_LAYER))
                            {
                                DrawTile(g, i, j, THIS_LAYER);
                            }
                        }
                        else
                        {
                            DrawTile(g, i, j, THIS_LAYER);
                        }
                    }
                }
            }

            // Draw the grid if it is turned on.
            if (map.IsGridOn())
            {
                for (int i = 0; i < map.GetColumns(); i++)
                {
                    for (int j = 0; j < map.GetRows(); j++)
                    {
                        g.DrawRectangle(rectPen,
                                        (i * map.GetTileSize()) + map.GetMapRootX(),
                                        (j * map.GetTileSize()) + map.GetMapRootY(),
                                        map.GetTileSize(),
                                        map.GetTileSize());
                    }
                }
            }
        }
Example #3
0
 // Checks if this tile image layer is emtpy.
 public Boolean IsTileLayerEmpty(Map.LAYER layer)
 {
     if (GetImageKeys()[(int)layer] == null || GetImageKeys()[(int)layer] == Tile.NO_IMAGE)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #4
0
 // Returns the tile image key based on the layer passed. Returns the default "no image" marker if none is specified.
 public String GetTileImageKey(Map.LAYER layer)
 {
     if (GetImageKeys()[(int)layer] != null || GetImageKeys()[(int)layer] != Tile.NO_IMAGE)
     {
         return(GetImageKeys()[(int)layer]);
     }
     else
     {
         return(Tile.NO_IMAGE);
     }
 }
Example #5
0
 // Sets the tile image key based on the passed layer.
 public void SetTileImage(Map.LAYER layer, String key)
 {
     GetImageKeys()[(int)layer] = key;
 }
Example #6
0
 // Retreives the image for the tile at the specified index, on the specified layer.
 public Bitmap GetTileImage(int x, int y, Map.LAYER layer)
 {
     return(imagePalette.GetImage(TILES[x, y].GetTileImageKey(layer)));
 }