public override void Update(GameTime gameTime) { if (!IsActive) { return; } base.Update(gameTime); ObjectManager objMan = ObjectManager.GetInstance(); // Missed it if (GetPosition().Y > objMan.WindowBounds.Height) { IsVisible = false; SetVelocity(Vector2.Zero); } Paddle p1 = objMan.GetPaddle(); if (GetCollisionBox().Intersects(p1.GetCollisionBox())) { IsVisible = false; SetVelocity(Vector2.Zero); switch (_type) { case (int)POWERUPS.AKU: List <Brick> inactiveBricks = objMan.GetInactiveBricks(); int index = objMan.rand.Next(1, inactiveBricks.Count) - 1; Brick addBrick = inactiveBricks[index]; if (!addBrick.IsCurrentlyModified) { objMan.AddObjectByType(OBJTYPES.ADDBRICK, addBrick.GetPosition()); IsActive = false; IsVisible = false; addBrick.IsCurrentlyModified = true; break; } break; case (int)POWERUPS.JACK: List <Brick> bricks = objMan.GetBricks(); foreach (Brick subBrick in bricks) { if (subBrick.IsVisable) { if (!subBrick.IsCurrentlyModified) { objMan.AddObjectByType(OBJTYPES.SUBBRICK, subBrick.GetPosition()); IsActive = false; IsVisible = false; subBrick.IsCurrentlyModified = true; break; } } } break; case (int)POWERUPS.PSIZE: break; case (int)POWERUPS.SPEEDBALL: break; case (int)POWERUPS.SPEEDP: break; } } }
public override void Update(GameTime gameTime) { ObjectManager obj = ObjectManager.GetInstance(); Paddle p1 = obj.GetPaddle(); KeyboardState kb = Keyboard.GetState(); if (!_isInPlay) { SetVelocity(p1.GetVelocity()); if (kb.IsKeyDown(Keys.Space)) { SetVelocity(_movementSpeed, -_movementSpeed); _isInPlay = true; } } else { //Pause the ball // TODO: make a cheat if (kb.IsKeyDown(Keys.P)) { if (GetVelocity() == Vector2.Zero) { SetVelocity(_oldVelocity); } else { _oldVelocity = GetVelocity(); SetVelocity(Vector2.Zero); } } // Wall Collision // Right wall if ((GetPosition().X + GetBoundingBox().Width) >= obj.WindowBounds.Width) { SetVelocity(GetVelocity().X * -1, GetVelocity().Y); } // Left wall if (GetPosition().X <= 0) { SetVelocity(GetVelocity().X * -1, GetVelocity().Y); } // Top wall if (GetPosition().Y <= 0) { SetVelocity(GetVelocity().X, GetVelocity().Y * -1); } // Bottom wall if ((GetPosition().Y + GetBoundingBox().Height) >= obj.WindowBounds.Height || kb.IsKeyDown(Keys.R)) { // reset ball _isInPlay = false; SetVelocity(Vector2.Zero); SetPosition(GetStartPosition()); _fRotation = 1.0f; _fSpinSpeed = 0.1f; // reset paddle p1.SetPosition(p1.GetStartPosition()); } // Paddle Collision Rectangle currentRect = GetCollisionBox(); Rectangle paddleRect = p1.GetCollisionBox(); if (currentRect.Intersects(paddleRect)) //TODO seriously ??? sad... just sad... { if (GetOldPosition().X < GetPosition().X) { SetVelocity(GetVelocity().X, GetVelocity().Y * -1); } else if (GetOldPosition().X > GetPosition().X) { SetVelocity(GetVelocity().X, GetVelocity().Y * -1); } else { SetVelocity(GetVelocity() * -1); } } // Brick Collision foreach (Brick brick in obj.GetBricks()) { if (brick.GetCollisionBox().Intersects(GetCollisionBox())) // TODO this is terrible collision detection { SetVelocity(GetVelocity() * -1); brick.IsVisable = false; brick.IsActive = false; break; } } } // Update the position base.Update(gameTime); // Update the rotation _fRotation += _fSpinSpeed; }