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); } }
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); } } }
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; } } } }
public virtual void Draw(Unit unit, IGame game) { if (DrawBehavior == null) CreateDrawBehavior(unit.Name, game); DrawBehavior.Draw(unit, game); }
public void AddUnit(Unit unit) { // Aanpassing in de list, lock nodig. lock (unitListLock) { Units.Add(unit); } }
public override void Move(Unit unit, IGame game) { if ((unit.VX < 0 && DVX > 0) || (unit.VX > 0 && DVX < 0)) DVX = -DVX; BaseMove(unit, game); }
public override void Move(Unit unit, IGame game) { BaseMove(unit, game); if (!isInScreenBottom(unit)) { unit.PosYBottom = CONSTANTS.CANVAS_HEIGHT; OnGround = true; } }
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); } }
protected virtual void FlipYSpeed(Unit unit) { FlipYAcceleration(unit); unit.VY = -unit.VY; }
protected virtual bool bounceRight(Unit unit) { if (!isInScreenRight(unit)) { unit.PosXRight = CONSTANTS.CANVAS_WIDTH; FlipXSpeed(unit); return true; } return false; }
protected virtual bool bounceLeft(Unit unit) { if (!isInScreenLeft(unit)) { unit.PosX = 0; FlipXSpeed(unit); return true; } return false; }
/// <summary> /// De beweeg logica, deze moet uniek zijn voor elke moveBehavior /// </summary> public abstract void Move(Unit unit, IGame game);
/// <summary> /// Basis beweging over de X en Y-as /// </summary> protected virtual void BaseMove(Unit unit, IGame game) { BaseMoveX(unit, game); BaseMoveY(unit, game); }
protected bool screenEntered(Unit unit) { if (!ScreenEntered) { ScreenEntered = (isInScreenBottom(unit) && isInScreenTop(unit) && isInScreenLeft(unit) && isInScreenRight(unit)); } return ScreenEntered; }
/// <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) { }
protected bool isInScreenTop(Unit unit) { return unit.PosY >= 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); }
protected virtual bool bounceTop(Unit unit) { if (!isInScreenTop(unit)) { unit.PosY = 0; FlipYSpeed(unit); return true; } return false; }
protected bool isInScreenRight(Unit unit) { return unit.PosXRight <= CONSTANTS.CANVAS_WIDTH; }
protected override bool bounceTop(Unit unit) { return false; }
public override void Move(Unit unit, IGame game) { base.Move(unit, game); }
protected virtual void FlipYAcceleration(Unit unit) { DVY = -DVY; }
protected virtual void FlipXSpeed(Unit unit) { FlipXAcceleration(unit); unit.VX = -unit.VX; }
protected virtual void FlipXAcceleration(Unit unit) { DVX = -DVX; }
protected override bool bounceRight(Unit unit) { return false; }
protected bool isInScreenBottom(Unit unit) { return unit.PosYBottom <= CONSTANTS.CANVAS_HEIGHT; }
protected override void MoveIntoScreen(Unit unit) { // Doe niks (unit probeert juist uit het scherm te komen) }
protected bool isInScreenLeft(Unit unit) { return unit.PosX >= 0; }