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
FroglegPosted May 1, 2011, 9:04 PM
Jamie WyattPosted May 1, 2011, 8:38 PM
FroglegPosted May 1, 2011, 5:56 PM
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 WyattPosted Apr 30, 2011, 10:10 PM
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.
FroglegPosted Apr 30, 2011, 1:18 PM
1:score
2: level
3:lives
4: and maybe player name
Jamie WyattPosted Apr 30, 2011, 10:20 AM
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.
FroglegPosted Apr 30, 2011, 12:08 AM
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
FroglegPosted Apr 30, 2011, 12:05 AM
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;
}