Exemple #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            Position2 screenTileCount = screenSize.Map(i => i / tileSize);

            for (int x = Math.Max(0, (int)Math.Floor(player.Position.X - screenTileCount.X / 2)); x < Math.Min(map.Size.X, (int)Math.Ceiling(player.Position.X + screenTileCount.X / 2) + 1); x++)
            {
                for (int y = Math.Max(0, (int)Math.Floor(player.Position.Y - screenTileCount.Y / 2)); y < Math.Min(map.Size.Y, (int)Math.Ceiling(player.Position.Y + screenTileCount.Y / 2) + 1); y++)
                {
                    Tiles.Tile tile = map.TileMap[x, y];
                    if (tile != null)
                    {
                        spriteBatch.Draw(
                            nullTexture,
                            new Rectangle((int)((x - player.Position.X - 0.5f) * tileSize) + screenSize.X / 2, (int)((y - player.Position.Y - 0.5f) * tileSize) + screenSize.Y / 2, tileSize, tileSize),
                            tile.Color
                            );
                    }
                }
            }

            spriteBatch.Draw(nullTexture, new Rectangle((screenSize.X - (int)(player.Size.X * tileSize)) / 2, (screenSize.Y - (int)(player.Size.X * tileSize)) / 2, (int)(player.Size.X * tileSize), (int)(player.Size.Y * tileSize)), Color.GreenYellow);
            //Console.WriteLine(player.Position);

            //DEBUG
            spriteBatch.Draw(nullTexture, new Rectangle(screenSize.X / 2, screenSize.Y / 2, 2, 2), Color.LimeGreen);

            spriteBatch.End();

            base.Draw(gameTime);
        }
Exemple #2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj.GetType() != GetType())
            {
                return(false);
            }

            Position2 v = (Position2)obj;

            return(v.X == X && v.Y == Y);
        }
Exemple #3
0
 public void SetTile(Position2 postion, Tiles.Tile tile)
 {
     SetTile(postion.X, postion.Y, tile);
 }
Exemple #4
0
 public bool TryGetTile(Position2 postion, out Tiles.Tile tile)
 {
     return(TryGetTile(postion.X, postion.Y, out tile));
 }
Exemple #5
0
 public Tiles.Tile GetTile(Position2 postion)
 {
     return(GetTile(postion.X, postion.Y));
 }
Exemple #6
0
 public Map(Position2 size)
 {
     TileMap  = new Tiles.Tile[size.X, size.Y];
     Entities = new List <Entities.Entity>();
 }