Ejemplo n.º 1
0
        public Ball()
            : base()
        {
            Sprite pl = new Sprite("paddle_left", new Point(-22, 0), Art.GetImage("spriteSheet"), new Rectangle(0, 0, 44, 22), SpriteEffects.None);
            Sprite pr = new Sprite("paddle_right", new Point(22, 0), Art.GetImage("spriteSheet"), new Rectangle(0, 0, 44, 22), SpriteEffects.FlipHorizontally);

            drawComponent = new DrawComponent(this);
            drawComponent.AddSprite(pl);
            drawComponent.AddSprite(pr);

            //animation
            //Rectangle[] rSeq = Inf.RectangleSequence(4, 0, 0, 44, 22, 0, 22);
            //Rectangle[] lSeq = Inf.RectangleSequence(4, 0, 0, 44, 22, 0, 22);
            //Rectangle[] rSeq = Inf.RectangleSequence(4, 0, 88, 44, 22, 0, 22);
            //Rectangle[] lSeq = Inf.RectangleSequence(4, 0, 88, 44, 22, 0, 22);
            Rectangle[] rSeq = Inf.RectangleSequence(8, 0, 848, 44, 22, 0, 22);
            Rectangle[] lSeq = Inf.RectangleSequence(8, 0, 848, 44, 22, 0, 22);
            //Rectangle[] rSeqReverse = Inf.RectangleSequence(4, 0, 154, 44, 22, 0, -22);
            //Rectangle[] lSeqReverse = Inf.RectangleSequence(4, 0, 154, 44, 22, 0, -22);
            //rSeq = rSeq.Concat(rSeqReverse).ToArray();
            //lSeq = lSeq.Concat(lSeqReverse).ToArray();
            AnimatedSprite[] ap = new AnimatedSprite[2];
            ap[0] = new AnimatedSprite(pl.Id, lSeq, 0);
            ap[1] = new AnimatedSprite(pr.Id, rSeq, 0);

            SimpleAnimationPlayer flashCornerAnimation = new SimpleAnimationPlayer(ap, false, 8, 0.05f);

            drawComponent.AddAnimation("flashCorner", flashCornerAnimation);
            drawComponent.PlayAnimation("flashCorner");
            //

            setComponent(drawComponent);
            physicsComponent           = new PhysicsComponent(this);
            physicsComponent.BodyType  = PhysicBodyType.Dynamic;
            physicsComponent.Direction = new Vector2((float)(GameRoot.Rnd.Next(-100, 100)), (float)(GameRoot.Rnd.Next(-100, 100)));
            physicsComponent.Velocity  = GameRoot.Rnd.Next(100);
            physicsComponent.Collider2D.ColliderType = Collider2DType.Box;
            this.TransformComponent.Position         = new Vector2(GameRoot.Rnd.Next(GameRoot.Screen.Width), GameRoot.Rnd.Next(GameRoot.Screen.Height));
            physicsComponent.Collider2D.Size         = drawComponent.BoundingBox.Size;
            physicsComponent.Collider2D.Offset       = drawComponent.BoundingBox.Center;
            setComponent(physicsComponent);
            setBehavior(new BallInput(this));
        }
Ejemplo n.º 2
0
        public Turret()
            : base()
        {
            Texture2D textureTurret = Art.GetImage("turret");
            Texture2D maskTurret    = Art.GetImage("turret-mask");

            Sprite spriteTurret = new Sprite("turretBase", new Point(0, 0), textureTurret, new Rectangle(0, 0, textureTurret.Width / 8, textureTurret.Height / 8), SpriteEffects.None);
            Sprite turretMask   = new Sprite("turretMask", new Point(0, -5), maskTurret, new Rectangle(0, 0, maskTurret.Width / 8, maskTurret.Height / 8), SpriteEffects.None);

            drawComponent = new DrawComponent(this);
            drawComponent.AddSprite(spriteTurret);
            drawComponent.AddSprite(turretMask);

            Rectangle[]      tSeq = Inf.RectangleSequence(8, 8, textureTurret.Width, textureTurret.Height);
            Rectangle[]      mSeq = Inf.RectangleSequence(8, 8, maskTurret.Width, maskTurret.Height);
            AnimatedSprite[] ap   = new AnimatedSprite[2];
            ap[0] = new AnimatedSprite(spriteTurret.Id, tSeq, 0);
            ap[1] = new AnimatedSprite(turretMask.Id, mSeq, 0);

            SimpleAnimationPlayer turretRotation = new SimpleAnimationPlayer(ap, true, 64, 0.03f);

            drawComponent.AddAnimation("turretRotation", turretRotation);
            drawComponent.PlayAnimation("turretRotation");
            //

            setComponent(drawComponent);
            physicsComponent           = new PhysicsComponent(this);
            physicsComponent.BodyType  = PhysicBodyType.Static;
            physicsComponent.Direction = new Vector2((float)(GameRoot.Rnd.Next(-100, 100)), (float)(GameRoot.Rnd.Next(-100, 100)));
            physicsComponent.Velocity  = GameRoot.Rnd.Next(100);
            physicsComponent.Collider2D.ColliderType = Collider2DType.Box;
            this.TransformComponent.Position         = new Vector2(GameRoot.Rnd.Next(GameRoot.Screen.Width), GameRoot.Rnd.Next(GameRoot.Screen.Height));
            physicsComponent.Collider2D.Size         = drawComponent.BoundingBox.Size;
            physicsComponent.Collider2D.Offset       = drawComponent.BoundingBox.Center;
            setComponent(physicsComponent);
            setBehavior(new BallInput(this));
        }