コード例 #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);
            }
        }
コード例 #2
0
 public override void FixedTimePassed(Unit unit, IGame game)
 {
     if (OnGround)
     {
         unit.VX = 0.90 * unit.VX;
     }
 }
コード例 #3
0
        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);
                }

            }
        }
コード例 #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);
 }
コード例 #5
0
        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;
                    }
                }
            }
        }
コード例 #6
0
ファイル: BaseUnitState.cs プロジェクト: Chirimorin/DuckHunt
        public virtual void Draw(Unit unit, IGame game)
        {
            if (DrawBehavior == null)
                CreateDrawBehavior(unit.Name, game);

            DrawBehavior.Draw(unit, game);
        }
コード例 #7
0
ファイル: UnitContainer.cs プロジェクト: Chirimorin/DuckHunt
 public void AddUnit(Unit unit)
 {
     // Aanpassing in de list, lock nodig.
     lock (unitListLock)
     {
         Units.Add(unit);
     }
 }
コード例 #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);
        }
コード例 #9
0
        public override void Move(Unit unit, IGame game)
        {
            BaseMove(unit, game);

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

                OnGround = true;
            }
        }
コード例 #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);
            }
        }
コード例 #11
0
 protected virtual void FlipYSpeed(Unit unit)
 {
     FlipYAcceleration(unit);
     unit.VY = -unit.VY;
 }
コード例 #12
0
 protected virtual bool bounceRight(Unit unit)
 {
     if (!isInScreenRight(unit))
     {
         unit.PosXRight = CONSTANTS.CANVAS_WIDTH;
         FlipXSpeed(unit);
         return true;
     }
     return false;
 }
コード例 #13
0
 protected virtual bool bounceLeft(Unit unit)
 {
     if (!isInScreenLeft(unit))
     {
         unit.PosX = 0;
         FlipXSpeed(unit);
         return true;
     }
     return false;
 }
コード例 #14
0
 /// <summary>
 /// De beweeg logica, deze moet uniek zijn voor elke moveBehavior
 /// </summary>
 public abstract void Move(Unit unit, IGame game);
コード例 #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);
 }
コード例 #16
0
 protected bool screenEntered(Unit unit)
 {
     if (!ScreenEntered)
     {
         ScreenEntered = (isInScreenBottom(unit) &&
                          isInScreenTop(unit) &&
                          isInScreenLeft(unit) &&
                          isInScreenRight(unit));
     }
     return ScreenEntered;
 }
コード例 #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)
 {
 }
コード例 #18
0
 protected bool isInScreenTop(Unit unit)
 {
     return unit.PosY >= 0;
 }
コード例 #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);
        }
コード例 #20
0
 protected virtual bool bounceTop(Unit unit)
 {
     if (!isInScreenTop(unit))
     {
         unit.PosY = 0;
         FlipYSpeed(unit);
         return true;
     }
     return false;
 }
コード例 #21
0
 protected bool isInScreenRight(Unit unit)
 {
     return unit.PosXRight <= CONSTANTS.CANVAS_WIDTH;
 }
コード例 #22
0
 protected override bool bounceTop(Unit unit)
 {
     return false;
 }
コード例 #23
0
 public override void Move(Unit unit, IGame game)
 {
     base.Move(unit, game);
 }
コード例 #24
0
 protected virtual void FlipYAcceleration(Unit unit)
 {
     DVY = -DVY;
 }
コード例 #25
0
 protected virtual void FlipXSpeed(Unit unit)
 {
     FlipXAcceleration(unit);
     unit.VX = -unit.VX;
 }
コード例 #26
0
 protected virtual void FlipXAcceleration(Unit unit)
 {
     DVX = -DVX;
 }
コード例 #27
0
 protected override bool bounceRight(Unit unit)
 {
     return false;
 }
コード例 #28
0
 protected bool isInScreenBottom(Unit unit)
 {
     return unit.PosYBottom <= CONSTANTS.CANVAS_HEIGHT;
 }
コード例 #29
0
 protected override void MoveIntoScreen(Unit unit)
 {
     // Doe niks (unit probeert juist uit het scherm te komen)
 }
コード例 #30
0
 protected bool isInScreenLeft(Unit unit)
 {
     return unit.PosX >= 0;
 }