Exemplo n.º 1
0
        public override void Move(Unit unit, IGame game)
        {
            BaseMove(unit, game);

            if (bounceBottom(unit))
            {
                if (unit.VY >= GetTimeBased(DVY, game))
                {
                    unit.VY = 0;
                }
                else
                {
                    unit.VY = unit.VY * Bouncyness;
                }
            }

            if (screenEntered(unit))
            {
                bounceLeft(unit);
                bounceRight(unit);
                bounceTop(unit);
            }
            else
            {
                MoveIntoScreen(unit);
            }
        }
Exemplo n.º 2
0
 public override void FixedTimePassed(Unit unit, IGame game)
 {
     if (OnGround)
     {
         unit.VX = 0.90 * unit.VX;
     }
 }
        public override void Move(Unit unit, IGame game)
        {
            base.Move(unit, game);

            // Unit moet op de grond lopen voor een sprong
            if (unit.PosYBottom == CONSTANTS.CANVAS_HEIGHT &&
                unit.VY == 0)
            {
                // Tijd die het duurt om aan de top van de sprong te komen
                double timeUntilTop = JumpPower / DVY;

                // Hoogte van de sprong
                double jumpHeight = (JumpPower * 0.5) * timeUntilTop;

                // X-afstand afgelegt in deze tijd
                double expectedPosX = unit.PosXMiddle + (timeUntilTop * unit.VX); // Uitgaande van een constante VX

                Point mousePosition = game.InputContainer.MousePosition;

                if ((CONSTANTS.CANVAS_HEIGHT - mousePosition.Y) < jumpHeight && // Halen we de sprong over de muis?
                    Math.Abs(mousePosition.X - expectedPosX) < 25) // Zitten we ongeveer boven de muis aan de top?
                {
                    Jump(unit);
                }

            }
        }
Exemplo n.º 4
0
 public override void FixedTimePassed(Unit unit, IGame game)
 {
     if (unit.PosYBottom == CONSTANTS.CANVAS_HEIGHT &&
         unit.VY == 0 &&
         game.Random.Next(0, JumpChance) == 0)
         Jump(unit);
 }
        public void Animate(Unit unit, IGame game)
        {
            if (_loop || !_animationCompleted)
            {
                _timePassed += game.DT;

                if (_timePassed > _frameTime)
                {
                    int frames = (int)Math.Floor(_timePassed / _frameTime);
                    _timePassed -= (frames * _frameTime);
                    _currentFrame += frames;

                    while (_loop && _currentFrame >= _frameCount)
                    {
                        _currentFrame -= _frameCount;
                    }

                    if (!_loop && _currentFrame >= _frameCount)
                    {
                        _currentFrame = _frameCount - 1;
                        _animationCompleted = true;
                    }
                }
            }
        }
Exemplo n.º 6
0
        public virtual void Draw(Unit unit, IGame game)
        {
            if (DrawBehavior == null)
                CreateDrawBehavior(unit.Name, game);

            DrawBehavior.Draw(unit, game);
        }
Exemplo n.º 7
0
 public void AddUnit(Unit unit)
 {
     // Aanpassing in de list, lock nodig.
     lock (unitListLock)
     {
         Units.Add(unit);
     }
 }
Exemplo n.º 8
0
        public override void Move(Unit unit, IGame game)
        {
            if ((unit.VX < 0 &&
                DVX > 0) ||
                    (unit.VX > 0 &&
                    DVX < 0))
                DVX = -DVX;

            BaseMove(unit, game);
        }
Exemplo n.º 9
0
        public override void Move(Unit unit, IGame game)
        {
            BaseMove(unit, game);

            if (!isInScreenBottom(unit))
            {
                unit.PosYBottom = CONSTANTS.CANVAS_HEIGHT;

                OnGround = true;
            }
        }
Exemplo n.º 10
0
        public override void Move(Unit unit, IGame game)
        {
            BaseMove(unit, game);

            if (screenEntered(unit))
            {
                bounceLeft(unit);
                bounceRight(unit);
                bounceTop(unit);
                bounceBottom(unit);
            }
            else
            {
                MoveIntoScreen(unit);
            }
        }
Exemplo n.º 11
0
 protected virtual void FlipYSpeed(Unit unit)
 {
     FlipYAcceleration(unit);
     unit.VY = -unit.VY;
 }
Exemplo n.º 12
0
 protected virtual bool bounceRight(Unit unit)
 {
     if (!isInScreenRight(unit))
     {
         unit.PosXRight = CONSTANTS.CANVAS_WIDTH;
         FlipXSpeed(unit);
         return true;
     }
     return false;
 }
Exemplo n.º 13
0
 protected virtual bool bounceLeft(Unit unit)
 {
     if (!isInScreenLeft(unit))
     {
         unit.PosX = 0;
         FlipXSpeed(unit);
         return true;
     }
     return false;
 }
Exemplo n.º 14
0
 /// <summary>
 /// De beweeg logica, deze moet uniek zijn voor elke moveBehavior
 /// </summary>
 public abstract void Move(Unit unit, IGame game);
Exemplo n.º 15
0
 /// <summary>
 /// Basis beweging over de X en Y-as
 /// </summary>
 protected virtual void BaseMove(Unit unit, IGame game)
 {
     BaseMoveX(unit, game);
     BaseMoveY(unit, game);
 }
Exemplo n.º 16
0
 protected bool screenEntered(Unit unit)
 {
     if (!ScreenEntered)
     {
         ScreenEntered = (isInScreenBottom(unit) &&
                          isInScreenTop(unit) &&
                          isInScreenLeft(unit) &&
                          isInScreenRight(unit));
     }
     return ScreenEntered;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Wordt een vast aantal keren per seconde aangeroepen. 
 /// Alle random zonder condities (zoals een random kans om te springen) horen hier in te staan. 
 /// </summary>
 public virtual void FixedTimePassed(Unit unit, IGame game)
 {
 }
Exemplo n.º 18
0
 protected bool isInScreenTop(Unit unit)
 {
     return unit.PosY >= 0;
 }
Exemplo n.º 19
0
        protected virtual void MoveIntoScreen(Unit unit)
        {
            if ((unit.PosX < 0 && unit.VX < 0) ||
                (unit.PosXRight > CONSTANTS.CANVAS_WIDTH && unit.VX > 0))
                FlipXSpeed(unit);

            if ((unit.PosY < 0 && unit.VY < 0) ||
                (unit.PosYBottom > CONSTANTS.CANVAS_HEIGHT && unit.VY > 0))
                FlipYSpeed(unit);
        }
Exemplo n.º 20
0
 protected virtual bool bounceTop(Unit unit)
 {
     if (!isInScreenTop(unit))
     {
         unit.PosY = 0;
         FlipYSpeed(unit);
         return true;
     }
     return false;
 }
Exemplo n.º 21
0
 protected bool isInScreenRight(Unit unit)
 {
     return unit.PosXRight <= CONSTANTS.CANVAS_WIDTH;
 }
Exemplo n.º 22
0
 protected override bool bounceTop(Unit unit)
 {
     return false;
 }
Exemplo n.º 23
0
 public override void Move(Unit unit, IGame game)
 {
     base.Move(unit, game);
 }
Exemplo n.º 24
0
 protected virtual void FlipYAcceleration(Unit unit)
 {
     DVY = -DVY;
 }
Exemplo n.º 25
0
 protected virtual void FlipXSpeed(Unit unit)
 {
     FlipXAcceleration(unit);
     unit.VX = -unit.VX;
 }
Exemplo n.º 26
0
 protected virtual void FlipXAcceleration(Unit unit)
 {
     DVX = -DVX;
 }
Exemplo n.º 27
0
 protected override bool bounceRight(Unit unit)
 {
     return false;
 }
Exemplo n.º 28
0
 protected bool isInScreenBottom(Unit unit)
 {
     return unit.PosYBottom <= CONSTANTS.CANVAS_HEIGHT;
 }
Exemplo n.º 29
0
 protected override void MoveIntoScreen(Unit unit)
 {
     // Doe niks (unit probeert juist uit het scherm te komen)
 }
Exemplo n.º 30
0
 protected bool isInScreenLeft(Unit unit)
 {
     return unit.PosX >= 0;
 }