Exemplo n.º 1
0
        public StaticObjectViewModel(Game game, IStaticObject staticObject, SpriteBatch spriteBatch)
        {
            _game        = game;
            StaticObject = staticObject;
            _spriteBatch = spriteBatch;

            var graphics = new StaticObjectGraphics(game, staticObject);

            var worldCoords = HexHelper.ConvertToWorld(((HexNode)StaticObject.Node).OffsetCoords);

            var hexSize = MapMetrics.UnitSize / 2;
            var staticObjectPosition = new Vector2(
                (int)Math.Round(worldCoords[0] * hexSize * Math.Sqrt(3), MidpointRounding.ToEven),
                (int)Math.Round(worldCoords[1] * hexSize * 2 / 2, MidpointRounding.ToEven)
                );

            _rootSprite = new SpriteContainer
            {
                Position = staticObjectPosition
            };

            var shadowTexture = _game.Content.Load <Texture2D>("Sprites/game-objects/simple-object-shadow");

            _rootSprite.AddChild(new Sprite(shadowTexture)
            {
                Position = new Vector2(0, 0),
                Origin   = new Vector2(0.5f, 0.5f),
                Color    = new Color(Color.White, 0.5f)
            });

            _rootSprite.AddChild(graphics);
        }
        public StaticObjectViewModel(Game game, IStaticObject staticObject, SpriteBatch spriteBatch,
                                     bool createHighlighted = false)
        {
            _game        = game;
            StaticObject = staticObject;
            _spriteBatch = spriteBatch;

            var graphics = new StaticObjectGraphics(game, staticObject);

            var worldCoords = HexHelper.ConvertToWorld(((HexNode)StaticObject.Node).OffsetCoords);

            var hexSize = MapMetrics.UnitSize / 2;
            var staticObjectPosition = new Vector2(
                (int)Math.Round(worldCoords[0] * hexSize * Math.Sqrt(HIGHLIGHT_DURATION_SECONDS),
                                MidpointRounding.ToEven),
                (int)Math.Round(worldCoords[1] * hexSize * 2 / 2, MidpointRounding.ToEven)
                );

            _rootSprite = new SpriteContainer
            {
                Position = staticObjectPosition
            };

            var hasNoShadow = StaticObject.Purpose == PropContainerPurpose.Puddle ||
                              StaticObject.Purpose == PropContainerPurpose.Pit;

            if (!hasNoShadow)
            {
                var shadowTexture = _game.Content.Load <Texture2D>("Sprites/game-objects/simple-object-shadow");
                _rootSprite.AddChild(new Sprite(shadowTexture)
                {
                    Position = new Vector2(0, 0),
                    Origin   = new Vector2(0.5f, 0.5f),
                    Color    = new Color(Color.White, 0.5f)
                });
            }

            _rootSprite.AddChild(graphics);

            if (createHighlighted)
            {
                _highlightCounter = HIGHLIGHT_DURATION_SECONDS;
            }
        }