Пример #1
0
 public Player(Game game, AnimatedSprite sprite)
 {
     gameRef = (Game1)game;
     camera = new Camera(gameRef.ScreenRectangle);
     this.sprite = sprite;
     camera.LockToSprite(sprite);
 }
Пример #2
0
 public Player(Game game, AnimatedSprite sprite)
 {
     gameRef = (Game1)game;
     camera = new Camera(gameRef.ScreenRectangle);
     this.sprite = sprite;
     camera.LockToSprite(sprite);
     playerrect = new Rectangle(
             (int)sprite.Position.X,
             (int)sprite.Position.Y,
             sprite.Width,
             sprite.Height);
 }
Пример #3
0
 public void DrawLevel(GameTime gameTime, SpriteBatch spriteBatch, Camera camera)
 {
     levels[currentLevel].Draw(gameTime, spriteBatch,camera);
 }
Пример #4
0
 public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Camera camera)
 {
     map.Draw(spriteBatch, camera);
     foreach (Character character in characters)
         character.Draw(gameTime, spriteBatch);
     foreach (ItemSprite sprite in levelItem)
         sprite.Draw(gameTime, spriteBatch);
     foreach (ItemSprite door in doors)
         door.Draw(gameTime, spriteBatch);
 }
Пример #5
0
        public void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            Point cameraPoint = Engine.VectorToCell(camera.Position);
            Point viewPoint = Engine.VectorToCell(
            new Vector2(
             (camera.Position.X + camera.ViewportRectangle.Width),
             (camera.Position.Y + camera.ViewportRectangle.Height)));

            Rectangle destination = new Rectangle(0, 0, Engine.TileWidth, Engine.TileHeight);
            Tile tile;

            Point min = new Point();
            Point max = new Point();
            min.X = Math.Max(0, cameraPoint.X - 1);
            min.Y = Math.Max(0, cameraPoint.Y - 1);
            max.X = Math.Min(viewPoint.X + 1, mapWidth);
            max.Y = Math.Min(viewPoint.Y + 1, mapHeight);

            foreach (MapLayer layer in mapLayers)
            {
                for (int y = min.Y; y < max.Y; y++)
                {
                    destination.Y = y * Engine.TileHeight;
                    for (int x = min.X; x < max.X; x++)
                    {
                        tile = layer.GetTile(x, y);

                        if (tile.TileIndex == -1 || tile.Tileset == -1)
                            continue;

                        destination.X = x * Engine.TileWidth;

                        spriteBatch.Draw(
                            tilesets[tile.Tileset].Texture,
                            destination,
                            tilesets[tile.Tileset].SourceRectangles[tile.TileIndex],
                            Color.White);
                    }
                }
            }
        }