public BallsRepository(AimingArrow arrow, Bounds bounds, HangingBalls hangingBalls) { Arrow = arrow; FieldBounds = bounds; HangingBalls = hangingBalls; SetCurrentBall(new Ball(CURRENT_BALL_POSITION, HangingBalls.GetRandomColor())); SetNextBall(new Ball(NEXT_BALL_POSITION, HangingBalls.GetRandomColor())); ThrowBallTimer = new Timer(); ThrowBallTimer.AutoReset = false; ThrowBallTimer.Interval = 10000; ThrowBallTimerRemainingTime = (float)ThrowBallTimer.Interval; ResetTimer(); }
public BallsRepository(AimingArrow arrow, Bounds bounds, HangingBalls hangingBalls) { Arrow = arrow; FieldBounds = bounds; HangingBalls = hangingBalls; SetCurrentBall(new Ball(CURRENT_BALL_POSITION, HangingBalls.GetRandomColor())); SetNextBall(new Ball(NEXT_BALL_POSITION, HangingBalls.GetRandomColor())); ThrowBallTimer = new Timer(); ThrowBallTimer.AutoReset = false; ThrowBallTimer.Interval = 10000; ThrowBallTimerRemainingTime = (float)ThrowBallTimer.Interval; ResetTimer(); }
public void Update(GameTime gameTime, Game1 game) { ThrowBallTimerRemainingTime = MathHelper.Clamp(ThrowBallTimerRemainingTime - (float)gameTime.ElapsedGameTime.TotalMilliseconds, 0, (float)ThrowBallTimer.Interval); KeyboardState state = Keyboard.GetState(); if ((state.IsKeyDown(Keys.Space) && !PreviousKeyState.IsKeyDown(Keys.Space) || state.IsKeyDown(Keys.Up) && !PreviousKeyState.IsKeyDown(Keys.Up)) && !CurrentBall.IsMoving()) { ThrowCurrentBall(); } PreviousKeyState = state; if (BallCollideWithSideBounds(CurrentBall)) { CurrentBall.Direction.X *= -1; } HangingBalls.BallSlot interSectingSlot = HangingBalls.BallsIntersectingWithBall(CurrentBall); if (CurrentBall.IsMoving() && (interSectingSlot != null || HangingBalls.BallIntersectsWithUpperBounds(CurrentBall))) { HangingBalls.SetBallToNearestSlot(CurrentBall, interSectingSlot); SetCurrentBall(NextBall); SetNextBall(new Ball(NEXT_BALL_POSITION, HangingBalls.GetRandomColor())); } CurrentBall.Update(gameTime, game); NextBall.Update(gameTime, game); HangingBalls.Update(gameTime, game); }