Example #1
0
        public MapChunk(uint x, uint y)
        {
            ChunkX = x;
            ChunkY = y;

            Tiles = new MapTile[64];
            for (int i = 0; i < 64; i++)
                Tiles[i] = new MapTile();
        }
Example #2
0
        public MapBlock(uint x, uint y)
        {
            BlockX = x;
            BlockY = y;

            Tiles = new MapTile[64];
            for (int i = 0; i < 64; i++)
                Tiles[i] = new MapTile();
        }
Example #3
0
 private void OnTileChanged(int x, int y)
 {
     if (Map != null)
     {
         if (IsClientEntity && Map.Index >= 0)
             Map.CenterPosition = new Point(x, y);
         Tile = Map.GetMapTile(x, y);
     }
     else
     {
         if (!IsClientEntity)
             Dispose();
     }
 }
Example #4
0
 internal void InternalDrawOverheads(MapTile tile, Position3D position)
 {
     // base entities do not draw, but they can have overheads, so we draw those.
     foreach (Overhead overhead in m_Overheads)
     {
         if (!overhead.IsDisposed)
             overhead.Draw(tile, position);
     }
 }
Example #5
0
 internal virtual void Draw(MapTile tile, Position3D position)
 {
 }
Example #6
0
 public virtual void Dispose()
 {
     IsDisposed = true;
     Tile = null;
 }
Example #7
0
        private void DrawEntities(Map map, Position3D center, MousePicking mousePicking, out Vector2 renderOffset)
        {
            if (center == null)
            {
                renderOffset = new Vector2();
                return;
            }

            // reset the spritebatch Z
            m_SpriteBatch.Reset();
            // set the lighting variables.
            m_SpriteBatch.SetLightIntensity(Lighting.IsometricLightLevel);
            m_SpriteBatch.SetLightDirection(Lighting.IsometricLightDirection);

            // get variables that describe the tiles drawn in the viewport: the first tile to draw,
            // the offset to that tile, and the number of tiles drawn in the x and y dimensions.

            CalculateViewport(center, overDrawTilesOnSides, overDrawTilesAtTopAndBottom, out firstTile, out renderOffset, out renderDimensions);

            CountEntitiesRendered = 0; // Count of objects rendered for statistics and debug

            overList = new MouseOverList(mousePicking); // List of entities mouse is over.

            for (y = 0; y < renderDimensions.Y * 2 + 1 + overDrawAdditionalTilesOnBottom; ++y)
            {
                drawPosition.X = (firstTile.X - firstTile.Y + (y % 2)) * TILE_SIZE_FLOAT_HALF + renderOffset.X;
                drawPosition.Y = (firstTile.X + firstTile.Y + y) * TILE_SIZE_FLOAT_HALF + renderOffset.Y;

                firstTileInRow.X = firstTile.X + ((y + 1) / 2);
                firstTileInRow.Y = firstTile.Y + (y / 2);
                for (x = 0; x < renderDimensions.X + 1; ++x)
                {
                    tile = map.GetMapTile(firstTileInRow.X - x, firstTileInRow.Y + x);
                    if (tile == null)
                    {
                        drawPosition.X -= TILE_SIZE_FLOAT;
                        continue;
                    }

                    entities = tile.Entities;
                    bool draw = true;
                    for (int i = 0; i < entities.Count; i++)
                    {
                        if (entities[i] is DeferredEntity)
                            deferredToRemove.Add(entities[i]);

                        if (!m_DrawTerrain)
                        {
                            if ((entities[i] is Ground) || (entities[i].Z > tile.Ground.Z))
                                draw = false;
                        }

                        if ((entities[i].Z >= m_DrawMaxItemAltitude || (m_DrawMaxItemAltitude != 255 && entities[i] is Item && (entities[i] as Item).ItemData.IsRoof)) && !(entities[i] is Ground))
                        {
                            continue;
                        }

                        if (draw)
                        {
                            AEntityView view = entities[i].GetView();
                            if (view != null)
                            {
                                if (view.Draw(m_SpriteBatch, drawPosition, overList, map, !m_UnderSurface))
                                    CountEntitiesRendered++;
                            }
                        }
                    }

                    foreach (AEntity deferred in deferredToRemove)
                        tile.OnExit(deferred);
                    deferredToRemove.Clear();

                    drawPosition.X -= TILE_SIZE_FLOAT;
                }
            }

            OverheadsView.Render(m_SpriteBatch, overList, map, m_UnderSurface);

            // Update the MouseOver objects
            mousePicking.UpdateOverEntities(overList, mousePicking.Position);

            // Draw the objects we just send to the spritebatch.
            m_SpriteBatch.GraphicsDevice.SetRenderTarget(m_RenderTargetSprites);
            m_SpriteBatch.GraphicsDevice.Clear(Color.Black);
            m_SpriteBatch.FlushSprites(true);
            m_SpriteBatch.GraphicsDevice.SetRenderTarget(null);
        }
Example #8
0
        private void DetermineIfClientIsUnderEntity(Map map, Position3D center)
        {
            // Are we inside (under a roof)? Do not draw tiles above our head.
            m_DrawMaxItemAltitude = 255;
            m_DrawTerrain = true;
            m_UnderSurface = false;

            MapTile tile;
            AEntity underObject, underTerrain;
            if ((tile = map.GetMapTile(center.X, center.Y)) != null)
            {
                if (tile.IsZUnderEntityOrGround(center.Z, out underObject, out underTerrain))
                {
                    // if we are under terrain, then do not draw any terrain at all.
                    m_DrawTerrain = (underTerrain == null);

                    if (!(underObject == null))
                    {
                        // Roofing and new floors ALWAYS begin at intervals of 20.
                        // if we are under a ROOF, then get rid of everything above me.Z + 20
                        // (this accounts for A-frame roofs). Otherwise, get rid of everything
                        // at the object above us.Z.
                        if (underObject is Item)
                        {
                            Item item = (Item)underObject;
                            if (item.ItemData.IsRoof)
                                m_DrawMaxItemAltitude = center.Z - (center.Z % 20) + 20;
                            else if (item.ItemData.IsSurface || (item.ItemData.IsWall && !item.ItemData.IsDoor))
                                m_DrawMaxItemAltitude = item.Z;
                            else
                            {
                                int z = center.Z + ((item.ItemData.Height > 20) ? item.ItemData.Height : 20);
                                m_DrawMaxItemAltitude = z;
                            }
                        }

                        // If we are under a roof tile, do not make roofs transparent if we are on an edge.
                        if (underObject is Item && ((Item)underObject).ItemData.IsRoof)
                        {
                            bool isRoofSouthEast = true;
                            if ((tile = map.GetMapTile(center.X + 1, center.Y)) != null)
                            {
                                tile.IsZUnderEntityOrGround(center.Z, out underObject, out underTerrain);
                                isRoofSouthEast = !(underObject == null);
                            }

                            if (!isRoofSouthEast)
                                m_DrawMaxItemAltitude = 255;
                        }

                        m_UnderSurface = (m_DrawMaxItemAltitude != 255);
                    }
                }
            }
        }
Example #9
0
 public virtual void Dispose()
 {
     m_OnDisposed?.Invoke(this);
     m_OnDisposed = null;
     m_OnUpdated = null;
     IsDisposed = true;
     Tile = null;
 }