Exemple #1
0
        Rectangle GetRectanglePerDirection(ISpriteConst spriteConst, Direction direction)
        {
            Rectangle rectangle = default(Rectangle);

            if (direction == Direction.Up)
            {
                rectangle = spriteConst.upRect;
            }
            if (direction == Direction.Down)
            {
                rectangle = spriteConst.downRect;
            }
            if (direction == Direction.Left)
            {
                rectangle = spriteConst.leftRect;
            }
            if (direction == Direction.Right)
            {
                rectangle = spriteConst.rightRect;
            }
            if (direction == Direction.Stay)
            {
                rectangle = spriteConst.leftRect;
            }
            return(rectangle);
        }
Exemple #2
0
        public void SetSprite()
        {
            ///Пока не придумал как хранить точки для начала анимаций
            ///Поэтому только наброски
            ISpriteConst spriteConst = null;
            Bitmap       img         = null;
            string       path        = null;
            Rectangle    rectangle;
            Direction    direction = Command.direction;
            var          offset    = 1;

            if (Creature == null)
            {
                return;
            }
            if (Creature is ShortSkeleton)
            {
                path        = GetPath("SmallSkeleton.png");
                spriteConst = new SmallSkeletonConst();
            }
            else if (Creature is GreenMonster)
            {
                path        = GetPath("HighSkeletonAndGreenMonster.png");
                spriteConst = new GreenMonsterConst();
            }
            else if (Creature is Bullet)
            {
                path        = GetPath("SmallSkeleton.png");
                spriteConst = new BulletConst();
            }
            else if (Creature is HighSkeleton)
            {
                path        = GetPath("HighSkeletonAndGreenMonster.png");
                spriteConst = new HighSkeletonConst();
            }
            else if (Creature is Turret)
            {
                path = GetPath("TurretSprite.png");
                var newCreature = Creature as Turret;
                direction   = newCreature.DirectionType;
                spriteConst = new TurretConst();
            }
            else if (Creature is Castle)
            {
                path        = GetPath("CastleSprite.png");
                spriteConst = new CastleConst();
                offset      = 0;
            }
            else
            {
                throw new Exception("Не описанная сущность");
            }
            img              = new Bitmap(path);
            rectangle        = GetRectanglePerDirection(spriteConst, direction);
            Sprite           = new Sprite(img, rectangle);
            this.spriteConst = spriteConst;
            SetHitBox(LocationOnField);
            LocationOnControl = new Point(LocationOnField.X * ElementSize,
                                          LocationOnField.Y * ElementSize - (Sprite.SpriteSize.Height / 2) * offset);
            //....
        }