Results 1 to 7 of 7
Thread: Breakout Game code help.
- 10-09-2009, 04:39 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 10
- Rep Power
- 0
Breakout Game code help.
Breakout – more details
(NOTE: for co-ordinates in Greenfoot the position (x=0, y=0) is the top left corner)
· The game has a grid of bricks 11 wide and 8 deep. The colour of the rows of
bricks varies – two rows each of yellow, green, blue and red (from front to back).
The value of the bricks is also different for each row: see
BreakoutWorld.POINTS, which gives the points value for each row (from the
back to the front).
· The ball starts in the position given by
(BALL_INITIAL_X, BALL_INITIAL_Y).
· The ball initially moves at 45 degrees, towards the top right corner. Each time the
ball hits something it will bounce through 90 degrees. This is achieved by simply
reversing the appropriate (x or y) direction. For example, the initial direction will
be x = +1, y = h–1. On striking the right hand wall the direction will change to x =
–1, y = –1 (i.e. x direction swaps from +1 to –1).
· When the ball hits a brick, the brick disappears and its point value is added to the
score
· When the ball misses the bat and drops off the screen the player loses one of their
3 “lives” and, if the player still has 1 or more lives, the ball returns to its initial
position and play continues
· The bat must get its instructions from the Controller class. This has a mode
variable that can be set to “EXPERT” or any other value. If this variable is set to
“EXPERT”, the controller passes back the required instructions (“left” or “right”)
to ensure the bat always hits the ball. For any other value it simply returns either
“left” (left arrow), “right” (right arrow) or “” (nothing) depending on what key is
currently pressed. You must include logic to prevent the bat leaving the screen.
· Play ends when there are no bricks left (a win) or no more lives (a loss).
here is the zip file.
should look like the image.
- 10-09-2009, 06:35 AM #2
What exactly is your question? Or do you expect someone to do the whole assignment for you? :P
My Hobby Project: LegacyClone
- 10-09-2009, 06:51 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 10
- Rep Power
- 0
no no i dont expect people to do it for me, i will be doin it bit by bit and asking questions.
like this one.
i need help making a loop to create bricks
here is the code to make one brick:
//creates a brick in breakoutWourld.
brick = new Brick(1,"red");
addToGame(brick, 20, 10);
any ideas on how i can loop it to make 2 rows that have 11 bricks.
- 10-09-2009, 06:53 AM #4
Member
- Join Date
- Oct 2009
- Posts
- 10
- Rep Power
- 0
a friend of mine came up with this one
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 11; j++)
{
brick = new Brick(1,"red");
addToGame(brick,20+j,10+i);
}
}
but it stacks the bricks on each other. so was thinking maybe we could use the brick height and width in the code that way they can be spaced.
- 10-09-2009, 03:01 PM #5
you're working with coordinates so you need to think on an x,y scale. look at how your bricks are being created in the current code. they go from (20,10)(21,11)(22,12)....and these are your coords so unless your bricks have a length and width < 1 they're going to overlap. Try incrementing by the size of the brick instead.
Liberty has never come from the government.
Liberty has always come from the subjects of government.
The history of liberty is the history of resistance.
The history of liberty is a history of the limitation of governmental power, not the increase of it.
- 10-10-2009, 12:08 AM #6
Member
- Join Date
- Oct 2009
- Posts
- 10
- Rep Power
- 0
ok i multiplied j and i by the brick height and width. and it worked.
now off to create the blue, green and yellow bricks.Java Code:for (int i = 0; i < 2; i++) { for (int j = 0; j < 11; j++) { brick = new Brick(1,"red"); addToGame(brick,20+j*BRICK_WIDTH,10+i*BRICK_HEIGHT ); } }
- 10-10-2009, 01:30 AM #7
Member
- Join Date
- Oct 2009
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
By JFlash in forum New To JavaReplies: 2Last Post: 08-05-2010, 04:49 AM -
Need help with Breakout game
By tfitz666 in forum New To JavaReplies: 9Last Post: 03-22-2010, 05:26 AM -
Another Breakout question
By jumpstart in forum New To JavaReplies: 3Last Post: 07-29-2009, 04:48 AM -
2D strategy game or 2D war game
By led1433 in forum Java 2DReplies: 5Last Post: 02-10-2009, 06:00 AM -
I have c++ code for LUDO Game, Can anyone change it to Java file - Please help me
By Bhanu Sagar in forum AWT / SwingReplies: 0Last Post: 03-12-2008, 06:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks