public override void Update(Seconds time) { if (Location.X <= Horizontal.LowerBound || Location.X >= Horizontal.UpperBound) { Horizontal.Speed *= -1; } Location.X += Horizontal.Speed * time; }
public void Update(Seconds deltaSeconds) { if (this is MovableEntity movableEntity) { Meters horizontalDelta = deltaSeconds * movableEntity.Horizontal.Speed; Meters newXlocation = movableEntity.Location.X + horizontalDelta; //if you are leaving the screen if (newXlocation >= movableEntity.Horizontal.UpperBound) { //change direction movableEntity.Horizontal.Speed *= (-1); //move as far as you can movableEntity.Location.X = movableEntity.Horizontal.UpperBound; } else if (newXlocation <= movableEntity.Horizontal.LowerBound) { //change direction movableEntity.Horizontal.Speed *= (-1); //move as far as you can movableEntity.Location.X = movableEntity.Horizontal.LowerBound; } else { //just move movableEntity.Location.X += horizontalDelta; } } if (this is MovableJumpingEntity movableJumpingEntity) { Meters verticalDelta = deltaSeconds * movableJumpingEntity.Vertical.Speed; Meters newYlocation = movableJumpingEntity.Location.Y + verticalDelta; //if you are tryint to fly away from the screen if (newYlocation >= movableJumpingEntity.Vertical.UpperBound) { //change direction movableJumpingEntity.Vertical.Speed *= (-1); //move as far as you can movableJumpingEntity.Location.Y = movableJumpingEntity.Vertical.UpperBound; } //if you reach the ground else if (newYlocation <= movableJumpingEntity.Vertical.LowerBound) { //just stop falling movableJumpingEntity.Location.Y = movableJumpingEntity.Vertical.LowerBound; } else { //just move movableJumpingEntity.Location.Y += verticalDelta; } } }
public override void Update(Seconds seconds) { base.Update(seconds); var newLocation = this.Location.Y + (this.Vertical.Speed * seconds); if (newLocation.Value > this.Vertical.UpperBound.Value) { newLocation = this.Vertical.UpperBound; this.Vertical.ReverseDirection(); } if (newLocation.Value < this.Vertical.LowerBound.Value) { newLocation = this.Vertical.LowerBound; } this.Location.Y = newLocation; }
public override void Update(Seconds seconds) { var newLocation = this.Location.X + this.Horizontal.Speed * seconds; if (newLocation.Value > this.Horizontal.UpperBound.Value) { newLocation = this.Horizontal.UpperBound; this.Horizontal.ReverseDirection(); } if (newLocation.Value < this.Horizontal.LowerBound.Value) { newLocation = this.Horizontal.LowerBound; this.Horizontal.ReverseDirection(); } this.Location.X = newLocation; }
public override void Update(Seconds time) { if (Location.X <= Horizontal.LowerBound || Location.X >= Horizontal.UpperBound) { Horizontal.Speed *= -1; } Location.X += Horizontal.Speed * time; if (Location.Y >= Vertical.UpperBound) { Vertical.Speed *= -1; } else if (Location.Y == Vertical.LowerBound && Vertical.Speed < 0) { return; } else if (Location.Y < Vertical.LowerBound && Vertical.Speed < 0) { Location.Y = Vertical.LowerBound; return; } Location.Y += Vertical.Speed * time; }
public void Update(Seconds s) { time += s; }
public virtual void Update(Seconds time) { }
public virtual void Update(Seconds seconds) { }
public static Seconds Seconds(this double value) { Seconds sec = new Seconds(value); return(sec); }