Пример #1
0
        public override void DrawImage(GridCoord point, string image, short width, short height)
        {
            // Convert the width and height into window coords.
            width = (short)(width * (m_windowSizeX / m_camera.ZoomLevelX));
            height = (short)(height * (m_windowSizeY / m_camera.ZoomLevelY));

            // Cache the texture for future use.
            if (!m_textures.ContainsKey(image))
            {
                CacheTexture(image, width, height);
            }

            IntPtr imagePtr = m_textures[image];
            Sdl.SDL_Surface imageSurface = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(imagePtr, typeof(Sdl.SDL_Surface));

            // Also resize the texture if necessary
            if ((imageSurface.w != width)
                ||
                (imageSurface.h != height))
            {
                CacheTexture(image, width, height);
            }
            Sdl.SDL_Rect imageRect = new Sdl.SDL_Rect(0, 0, (short)imageSurface.w, (short)imageSurface.h);
            WindowCoord wpoint = GridToWindowCoords(point);
            Sdl.SDL_Rect dstRect = new Sdl.SDL_Rect((short)wpoint.X,(short)wpoint.Y,(short)imageSurface.w,(short)imageSurface.h);
            Sdl.SDL_BlitSurface(imagePtr, ref imageRect, m_surface, ref dstRect);
        }
Пример #2
0
 public void SetGridPosition(GridCoord coord)
 {
     m_gridPosX = coord.X;
     m_gridPosY = coord.Y;
 }
Пример #3
0
        public Grid(int initialX, int initialY)
        {
            m_sizeX = initialX;
            m_sizeY = initialY;
            m_tiles = new Tile[m_sizeX*m_sizeY];
            Random random = new Random(1);

            GridCoord gridcoord = new GridCoord(0,0);

            // Enumerate the tile type array.
            Tile.TileType[] typearray = (Tile.TileType[])Enum.GetValues(typeof(Tile.TileType));
            List<Tile.TileType> typelist = new List<Tile.TileType>(typearray);
            typelist.Remove(Tile.TileType.Max);
            typelist.Remove(Tile.TileType.OctopusGarden);

            for (int i = 0; i<(m_sizeX*m_sizeY);i++)
            {
                gridcoord.X = i%m_sizeY;
                gridcoord.Y = (float)Math.Floor((float)i / (float)m_sizeY);
                Tile.TileType type = Tile.TileType.Bedrock;

                // Edge tiles are always bedrock.
                if (this.IsEdgeTile(gridcoord))
                {
                    type = Tile.TileType.Bedrock;
                }
                else
                {
                    // Pick a random tile for now. Later define some simple rules for tile growth
                    int rand = random.Next(typelist.Count);
                    type = typelist[rand];
                }

                // Actually create the tile.
                Tile tile;
                switch(type)
                {
                    case Tile.TileType.Bedrock:
                        tile = new TileBedrock();
                        break;

                    case Tile.TileType.Rock:
                        tile = new TileRock();
                        break;

                    case Tile.TileType.Seaweed:
                        tile = new TileSeaweed();
                        break;

                    case Tile.TileType.Sand:
                    default:
                        tile = new TileSand();
                        break;

                }

                // Set the tile in the grid.
                tile.SetGridPosition(gridcoord);
                m_tiles[i] = tile;
            }
        }
Пример #4
0
 public bool IsEdgeTile(GridCoord coord)
 {
     if ((coord.X == 0)
         ||
         (coord.Y == 0)
         ||
         (coord.X == this.SizeX - 1)
         ||
         (coord.Y == this.SizeY - 1))
         return true;
     else
         return false;
 }
Пример #5
0
        public void DrawBorder()
        {
            Renderer renderer = Renderer.GetRenderer();

            GridCoord topLeft = new GridCoord(m_gridPosX, m_gridPosY);
            GridCoord bottomLeft = new GridCoord(m_gridPosX, m_gridPosY+1);
            GridCoord bottomRight = new GridCoord(m_gridPosX+1, m_gridPosY+1);
            GridCoord topRight = new GridCoord(m_gridPosX, m_gridPosY+1);
            renderer.DrawLine(topLeft, topRight, Color.White);
            renderer.DrawLine(topRight, bottomRight, Color.White);
            renderer.DrawLine(bottomRight, bottomLeft, Color.White);
            renderer.DrawLine(bottomLeft, topLeft, Color.White);
        }
Пример #6
0
 public void SetGridPosition(GridCoord coord)
 {
     m_gridPosX = (int)Math.Floor(coord.X);
     m_gridPosY = (int)Math.Floor(coord.Y);
 }
Пример #7
0
 public WindowCoord GridToWindowCoords(GridCoord gridCoord)
 {
     GridCoord camerapos = m_camera.GetGridPosition();
     float cameraTopLeftX = camerapos.X - m_camera.ZoomLevelX/2;
     float cameraTopLeftY = camerapos.Y - m_camera.ZoomLevelY/2;
     float windowCoordX = (gridCoord.X-cameraTopLeftX) * (m_windowSizeX / m_camera.ZoomLevelX);
     float windowCoordY = (gridCoord.Y-cameraTopLeftY) * (m_windowSizeY / m_camera.ZoomLevelY);
     return new WindowCoord(windowCoordX, windowCoordY);
 }
Пример #8
0
 public abstract void DrawText(GridCoord point, int size, string text, System.Drawing.Color colour);
Пример #9
0
 public abstract void DrawLine(GridCoord pointStart, GridCoord pointEnd, System.Drawing.Color colour);
Пример #10
0
 public abstract void DrawImage(GridCoord point, string image, short width, short height);
Пример #11
0
 public bool IsVisible(GridCoord pointTopLeft, GridCoord pointTopRight, GridCoord pointBottomRight, GridCoord pointBottomLeft)
 {
     return true;
 }
Пример #12
0
 public bool IsVisible(GridCoord pointStart, GridCoord pointEnd)
 {
     return true;
 }
Пример #13
0
        /*public bool IsVisible(GridCoord coord)
        {
            GridCoord cameraCoord = m_camera.GetGridPosition();
            // Easy - check the bounds of the camera box.
            if ((coord.X < cameraCoord.X - m_camera.ZoomLevel/2)
                ||
                (coord.X > cameraCoord.X + m_camera.ZoomLevel/2)
                ||
                (coord.Y < cameraCoord.Y - m_camera.ZoomLevel/2)
                ||
                (coord.Y > cameraCoord.Y + m_camera.ZoomLevel/2))
                return false;
            else
                return true;
        }

        public bool IsVisible(GridCoord pointStart, GridCoord pointEnd)
        {
            GridCoord cameraCoord = m_camera.GetGridPosition();
            if (IsVisible(pointStart)
                ||
                IsVisible(pointEnd)
                ||
                // Check for the case where the points lie either side of the camera box.
                ((cameraCoord.X - m_camera.ZoomLevel/2 > pointStart.X) && (cameraCoord.X + m_camera.ZoomLevel/2 < pointEnd.X)
                 &&
                 (cameraCoord.Y - m_camera.ZoomLevel/2 > pointStart.Y) && (cameraCoord.Y + m_camera.ZoomLevel/2 < pointEnd.Y)))
                return true;
            else
                return false;
        }

        public bool IsVisible(GridCoord pointTopLeft, GridCoord pointTopRight, GridCoord pointBottomRight, GridCoord pointBottomLeft)
        {
            if (IsVisible(pointTopLeft, pointTopRight)
                ||
                IsVisible(pointTopRight, pointBottomRight)
                ||
                IsVisible(pointBottomRight, pointBottomLeft)
                ||
                IsVisible(pointBottomLeft, pointTopLeft))
                return true;
            else
                return false;
        }*/
        public bool IsVisible(GridCoord point)
        {
            return true;
        }
Пример #14
0
        public override void DrawText(GridCoord point, int size, string text, System.Drawing.Color colour)
        {
            // Convert the colour
            Sdl.SDL_Color sdlcolour = new Sdl.SDL_Color(colour.R, colour.G, colour.B, colour.A);

            // Render the text to a surface
            IntPtr renderPtr = SdlTtf.TTF_RenderText_Solid(m_mainfont, text, sdlcolour);
            Sdl.SDL_Surface fontSurface = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(renderPtr, typeof(Sdl.SDL_Surface));

            // Calculate visibility
            WindowCoord wpoint = GridToWindowCoords(point);
            GridCoord toprightpoint = WindowToGridCoords(new WindowCoord(wpoint.X + fontSurface.w, wpoint.Y));
            GridCoord bottomrightpoint = WindowToGridCoords(new WindowCoord(wpoint.X + fontSurface.w, wpoint.Y + fontSurface.h));
            GridCoord bottomleftpoint = WindowToGridCoords(new WindowCoord(wpoint.X, wpoint.Y + fontSurface.h));

            if (IsVisible(point,toprightpoint,bottomrightpoint,bottomleftpoint))
            {
                // Then blit this to the main window
                Sdl.SDL_Rect fontRect = new Sdl.SDL_Rect(0, 0, (short)fontSurface.w, (short)fontSurface.h);
                Sdl.SDL_Rect dstRect = new Sdl.SDL_Rect((short)wpoint.X,(short)wpoint.Y,(short)fontSurface.w,(short)fontSurface.h);
                Sdl.SDL_BlitSurface(renderPtr, ref fontRect, m_surface, ref dstRect);
            }

            // Clean up the mess
            Sdl.SDL_FreeSurface(renderPtr);
        }
Пример #15
0
 public override void DrawLine(GridCoord pointStart, GridCoord pointEnd, System.Drawing.Color colour)
 {
     if (IsVisible(pointStart, pointEnd))
     {
         WindowCoord wpointStart = GridToWindowCoords(pointStart);
         WindowCoord wpointEnd = GridToWindowCoords(pointEnd);
         int result = SdlGfx.aalineRGBA(m_surface, (short)wpointStart.X, (short)wpointStart.Y, (short)wpointEnd.X, (short)wpointEnd.Y, colour.R, colour.G, colour.B, colour.A);
         if (result == -1)
         {
             throw new RenderException("Could not draw the line");
         }
     }
 }