Exemplo n.º 1
0
        public int CompareTo(object e)
        {
            if (e == null)
            {
                return(1);
            }

            BackgroundObject other = e as BackgroundObject;

            if (other != this)
            {
                return(this.depth > other.depth ? 1 : this.depth < other.depth ? -1 : 0);
            }
            else
            {
                throw new ArgumentException("Object is not BackgroundObject");
            }
        }
Exemplo n.º 2
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            //draw tiles
            if (parent != null)
            {
                if (parent.Player != null)
                {
                    position = parent.Player.Position;
                }

                for (int i = 0; i < parent.BackList.Count; i++)  //draw background
                {
                    BackgroundObject o = parent.BackList[i];

                    if (o.Image != null)
                    {
                        spriteBatch.Draw(o.Image,
                                         new Rectangle(
                                             (int)(((o.Position.X - o.Size.X / 2) - position.X) * zoomScale * o.Depth + PointOnScreen.X),
                                             (int)(-((o.Position.Y + o.Size.Y / 2) - position.Y) * zoomScale * o.Depth + PointOnScreen.Y),
                                             (int)(o.Size.X * zoomScale), (int)(o.Size.Y * zoomScale)),
                                         o.SrcRect, o.Col);
                    }
                }

                for (int y = 0; y < parent.Tiles.GetLength(0); y++)
                {
                    for (int x = 0; x < parent.Tiles.GetLength(1); x++)
                    {
                        Tile til = parent.Tiles[y, x];
                        if (til != null)
                        {
                            spriteBatch.Draw(Game1.tileSheets[til.TileSheetName],
                                             new Rectangle(
                                                 (int)((x * Tile.TILE_WIDTH - position.X) * zoomScale + PointOnScreen.X),
                                                 (int)(-((y + 1) * Tile.TILE_WIDTH - position.Y) * zoomScale + PointOnScreen.Y),
                                                 (int)(Tile.TILE_WIDTH * zoomScale), (int)(Tile.TILE_WIDTH * zoomScale)),
                                             new Rectangle(
                                                 (til.TileSheetIndex % Tile.VARS) * Tile.TILE_TEX_WIDTH,
                                                 (til.TileSheetIndex / Tile.VARS) * Tile.TILE_TEX_WIDTH,
                                                 Tile.TILE_TEX_WIDTH, Tile.TILE_TEX_WIDTH),
                                             Color.White);
                        }
                    }
                }

                foreach (Entity ent in Parent.Entities)//draw entities
                {
                    if (ent.Texture != null)
                    {
                        spriteBatch.Draw(ent.Texture, new Rectangle(
                                             (int)((ent.Position.X - ent.Size.X / 2 - position.X) * zoomScale + PointOnScreen.X),
                                             (int)(-(ent.Position.Y + ent.Size.Y / 2 - position.Y) * zoomScale + PointOnScreen.Y),
                                             (int)(ent.Size.X * zoomScale), (int)(ent.Size.Y * zoomScale)),
                                         ent.SourceRect, ent.Color);
                    }
                }

                foreach (Particle p in Parent.Particles) //draw particles
                {
                    if (p.Texture != null)
                    {
                        spriteBatch.Draw(p.Texture, new Rectangle(
                                             (int)((p.Position.X - p.Size.X / 2 - position.X) * zoomScale + PointOnScreen.X),
                                             (int)(-(p.Position.Y + p.Size.Y / 2 - position.Y) * zoomScale + PointOnScreen.Y),
                                             (int)(p.Size.X * zoomScale), (int)(p.Size.Y * zoomScale)), p.SourceRect, p.Color);
                    }
                }
            }
        }