Exemplo n.º 1
0
        public UtilsDemo(Layer layer) : base(layer)
        {
            _grayscale  = ResourceHub.GetResource <Effect>("Effects", "Grayscale");
            _fireSprite = ResourceHub.GetResource <Sprite>("DefaultSprites", "Fire");


            // Animation.

            // Animation class is more sophisticated way of implementing animations.
            // It can be used for anything from sprite animation to UI element position.
            _fireAnimation       = new Animation();
            _fireAnimation.Speed = _animationSpeed;

            // You can set an easing to make animation non-linear.
            // If it's not set, animation will be linear.
            _fireAnimation.Easing = Easing.EaseInCirc;

            // You can trigger a method at the end of an animation.
            _fireAnimation.AnimationEndEvent += FireAnimationEnd;
            _fireAnimation.Start(true);
            // Animation.


            // Alarms.
            _slowTimeKeeper = new TimeKeeper();
            // Slowing down time for this time keeper.
            _slowTimeKeeper.TimeMultiplier = 0.5f;

            _autoAlarm = new AutoAlarm(_alarmPeriod);
            _slowAlarm = new Alarm();
            // This alarm will now use custom TimeKeeper, which is 2 times
            // slower than global TimeKeeper.
            _slowAlarm.TimeKeeper = _slowTimeKeeper;
            _slowAlarm.Set(_alarmPeriod);
            _slowAlarm.TriggerEvent += AlarmTrigger;
            // Alarms.


            // Camera.
            _camera = new Camera2D(400, 600);
            _camera.PortPosition    = new Vector2(400, 0);
            _camera.BackgroundColor = Color.Black;
            _camera.PostprocessorEffects.Add(_grayscale);
            _camera.PostprocessingMode = PostprocessingMode.Camera;
            // Camera.


            _random = new RandomExt();


            // State machine.
            // State machines are very useful for animation and complex logic.
            _stateMachine = new StateMachine <TestStates>(TestStates.Green, this);

            // Filling up the state machine with events.
            _stateMachine.AddState(TestStates.Green, Green, GreenEnter, GreenExit);
            _stateMachine.AddState(TestStates.Blue, Blue);
            _stateMachine.AddState(TestStates.Red, Red);
            // State machine.
        }
Exemplo n.º 2
0
        public Cannon(Vector2 position, ShootingMode mode, float rotation, float baseRotation, double firePeriod, double initialDelay, Layer layer) : base(layer)
        {
            AddComponent(new PositionComponent(position));

            _mode = mode;

            var solid = new SolidComponent();

            var collider = new RectangleCollider();

            collider.Size     = Vector2.One * Size;
            collider.Position = position;

            solid.Collider = collider;

            AddComponent(solid);

            _rotation     = rotation;
            _baseRotation = baseRotation;

            var rotationRad = MathHelper.ToRadians(rotation);

            _direction = new Vector2(
                Math.Sign((int)(Math.Cos(rotationRad) * 100)),                 // Double will be a tiny value instead of zero, so we need this.
                Math.Sign((int)(Math.Sin(rotationRad) * 100))
                );

            _fireAlarm         = new AutoAlarm(firePeriod);
            _initialDelayAlarm = new Alarm();
            _initialDelayAlarm.Set(initialDelay);
        }
Exemplo n.º 3
0
 public LevelRestartEffect(Layer layer, bool nextLevel = false) : base(layer)
 {
     _nextLevel  = nextLevel;
     _alarm      = new AutoAlarm(_fadeTime);
     _delayAlarm = new Alarm();
     _delayAlarm.Set(_fadeDelay);
 }