コード例 #1
0
        public override void Initialize()
        {
            Context.RemoveAllComponents();

            var center = Context.Bounds.GetCenter();

            hourLine = new LineComponent(center, center, Context)
            {
                Pixel = '#'.White()
            };
            secondLine = new LineComponent(center, center, Context)
            {
                Pixel = 'o'.White()
            };
            minuteLine = new LineComponent(center, center, Context)
            {
                Pixel = '.'.White()
            };

            circle = new CircleComponent(center, Context.Bounds.Height / 2f, Context)
            {
                Filled = false
            };
            circle.Transform.CentralizePivot();
        }
コード例 #2
0
        public void Draw_Context_CircleDrawn()
        {
            var ctx     = Substitute.For <IWorldContext>();
            var drawCtx = Substitute.For <IDrawContext>();
            var canvas  = Substitute.For <ICanvas>();

            drawCtx.Canvas.Returns(canvas);

            var target = new CircleComponent(new Point(10, 20), 4, ctx);
            var circle = target as ICircle;

            Assert.AreEqual(10, circle.Left);
            Assert.AreEqual(20, circle.Top);
            Assert.AreEqual(18, circle.Right);
            Assert.AreEqual(28, circle.Bottom);
            target.Draw(drawCtx);

            canvas.Received().Draw(target, true, '#'.White());
        }
コード例 #3
0
        public Laser(Game game)
            : base(game)
        {
            // Create a sprite component
            var sprite = new SpriteComponent(this);

            sprite.SetTexture(Game.Renderer.GetTexture("Assets/Laser.png"));

            // Create a move component, and set a forward speed
            var move = new MoveComponent(this)
            {
                ForwardSpeed = 800.0f,
            };

            // Create a circle component (for collision)
            _circle = new CircleComponent(this)
            {
                Radius = 11.0f,
            };
        }
コード例 #4
0
 protected override void UpdateActor(float deltaTime)
 {
     // If we run out of time, laser is dead
     _deathTimer -= deltaTime;
     if (_deathTimer <= 0.0f)
     {
         State = ActorState.Dead;
     }
     else
     {
         // Do we intersect with an asteroid?
         foreach (var asteroid in Game.Asteroids)
         {
             // The first asteroid we intersect with,
             // set ourselves and the asteroid to dead
             if (CircleComponent.Intersect(_circle, asteroid.Circle))
             {
                 State          = ActorState.Dead;
                 asteroid.State = ActorState.Dead;
                 break;
             }
         }
     }
 }
コード例 #5
0
        public override void Initialize()
        {
            Context.RemoveAllComponents();
            var bounds = Context.Bounds;

            var moveToFood1 = new RectangleComponent(Point.Zero, Context);

            moveToFood1.Transform.Position = moveToSampleArea.LeftTopPoint();
            moveToFood1.Transform
            .MoveTo(moveToSampleArea.RightBottomPoint(), 2, Easing.InBack)
            .Delay(1)
            .MoveTo(moveToSampleArea.RightTopPoint(), 2, Easing.Linear)
            .PingPong();

            var moveToFood2 = new RectangleComponent(Point.Zero, Context);

            moveToFood2.Transform.Position = moveToSampleArea.RightBottomPoint();
            moveToFood2.Transform
            .MoveTo(moveToSampleArea.LeftTopPoint(), 2, Easing.InBack)
            .Delay(1)
            .MoveTo(moveToSampleArea.LeftBottomPoint(), 2, Easing.Linear)
            .PingPong();

            var blinkFood = new RectangleComponent(Point.Zero, Context);

            blinkFood.Transform.Position = new Point(30, 11);
            blinkFood
            .Enable(1f)
            .Loop();

            controller1 = blinkFood
                          .To(0, 100, 19, Easing.Linear, v => numberSample1 = v)
                          .Loop();


            controller2 = blinkFood
                          .To(0, 10, 10, Easing.Linear, v => numberSample2 = v)
                          .Delay(5)
                          .To(10, 30, 10, Easing.Linear, v => numberSample2 = v)
                          .Delay(5)
                          .To(30, 100, 10, Easing.Linear, v => numberSample2 = v)
                          .Delay(5)
                          .PingPong();


            // Once blink
            for (var i = 0; i < 100; i++)
            {
                var b = new RectangleComponent(Point.Zero, Context);
                b.Transform.Position = new Point(31 + i, 11);
                b
                .Delay(i * 0.05f)
                .Enable(1f)
                .Enable(0.5f)
                .Enable(0.5f)
                .Once();
            }

            // Ping-pong move
            var length  = 100;
            var speed   = 0.1f;
            var maxTime = (length - 1) * speed;

            for (var i = 0; i < length; i++)
            {
                var b = new RectangleComponent(Point.Zero, Context);
                b.Transform.Position = new Point(31 + i, 13);
                b
                .Disable(i * speed).OnlyForward()
                .Delay(maxTime - (i * speed)).OnlyForward()

                .Delay(maxTime - ((length - 1 - i) * speed)).OnlyBackward()
                .Enable(((length - 1) - i) * speed).OnlyBackward()

                .PingPong();
            }

            // ScaleTo, MoveTo and PingPong
            new RectangleComponent(140, 1, Context)
            {
                Filled = true
            }.Transform
            .ScaleTo(new Point(20, 10), 1, Easing.InExpo)
            .MoveTo(new Point(140, bounds.Bottom - 10), 2, Easing.InBounce)
            .PingPong();

            // Circle and rectangle
            var circle = new CircleComponent(new Point(12, 20), 1, Context)
            {
                Filled = false
            };

            circle.Transform
            .Do(() => circle.Filled = false).OnlyForward()
            .ScaleTo(30, 3, Easing.InOutQuint)
            .Do(() => circle.Filled = true).OnlyBackward()
            .PingPong();

            var rect = new RectangleComponent(circle.Transform.Position, Context)
            {
                Filled = false
            };

            rect.Transform
            .ScaleTo(30, 3, Easing.InOutQuint)
            .Delay(3)
            .PingPong();


            // Circle and rectangle with pivot centralized.
            var circleCentralized = new CircleComponent(bounds.GetCenter(), 1, Context)
            {
                Filled = false
            };

            circleCentralized.Transform.CentralizePivot()
            .Do(() => circleCentralized.Filled = false).OnlyForward()
            .ScaleTo(30, 3, Easing.InOutQuint)
            .Do(() => circleCentralized.Filled = true).OnlyBackward()
            .PingPong();


            var rectCentralized = new RectangleComponent(circleCentralized.Transform.Position, Context)
            {
                Filled = false
            };

            rectCentralized.Transform.CentralizePivot()
            .ScaleTo(30, 3, Easing.InOutQuint)
            .Delay(3)
            .PingPong();
        }