Evening all,
Having a few issues finishing my brickbreaker university project. As it stands the game will start and run, all of the bricks are happy to be hit by the ball, killed by the ball and have the ball bounce off. However, I've tried to use the same code (if (ballRectangle.Intersects(batRectangle)) to get the ball to bounce off the paddle but it's not having any of it.
I've attached the source code, there is also currently a save method in there that I can't get to work (see my other thread - http://www.c-sharpcorner.com/Forums/Thread/120430/saving-an-int-to-a-txt-file.aspx) but it's commented out so it shouldn't cause any compilation issues.
Any help you could offer would be great.
Cheers,
J.
EDIT : Slight update on this, it seems if the ball hits the area that the paddle starts off (dead centre) the ball will bounce as if the paddle is there, regardless of it's actual position.
Does this mean I'm moving the texture but not the rectangle? Is that possible?
Loading

FroglegRank #1,020 · 1.9K reputationPosted Apr 29, 2011, 8:05 PM EDT
if (keyState.IsKeyDown(Keys.Left) && 0 < bat.getPosition().X)
{
bat.moveLeft();
batRectangle.X = (int)bat.getPosition().X;
}
//Move right control
if (keyState.IsKeyDown(Keys.Right) && backgroundRectangle.Width > bat.getPosition().X + (bat.getWidth()))
{
bat.moveRight();
batRectangle.X = (int)bat.getPosition().X;
}
FroglegRank #1,020 · 1.9K reputationPosted Apr 29, 2011, 8:08 PM EDT
Also next time look at bounding boxes
Also in Breakout class in update put
quitGame();
and the method
public void quitGame()
{
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.Escape))
{
this.Exit();
}
}
so you can quit with escape key
Jamie Wyatt14 reputationPosted Apr 30, 2011, 6:20 AM EDT
As it stands once all of the bricks are destroyed the game will just bounce the ball around the screen, ideally I'd like it to redraw the bricks once all of them have been destroyed but I can't figure out how to get it to do that.
Latest source code is attached.
Cheers,
J.
FroglegRank #1,020 · 1.9K reputationPosted Apr 30, 2011, 9:18 AM EDT
1:score
2: level
3:lives
4: and maybe player name
Jamie Wyatt14 reputationPosted Apr 30, 2011, 6:10 PM EDT
Just wondered if you had any advice on redrawing all of the bricks after they've all been destroyed?
Again, thanks so much for your help.
J.
FroglegRank #1,020 · 1.9K reputationPosted May 1, 2011, 1:56 PM EDT
To load it before that screen loads I modified this in Breakout.cs
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
playScreen = new PlayScreen(this.Content, new EventHandler(PlayScreenAction), graphics);
homeScreen = new HomeScreen(this.Content, new EventHandler(HomeScreenAction), graphics);
playScreen.Load("highScore.txt");
screen = homeScreen;
}
Jamie Wyatt14 reputationPosted May 1, 2011, 4:38 PM EDT
FroglegRank #1,020 · 1.9K reputationPosted May 1, 2011, 5:04 PM EDT