Results 1 to 7 of 7
  1. #1
    Ceasar is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default 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.
    Attached Thumbnails Attached Thumbnails Breakout Game code help.-clip_image002.jpg  
    Attached Files Attached Files

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    What exactly is your question? Or do you expect someone to do the whole assignment for you? :P
    My Hobby Project: LegacyClone

  3. #3
    Ceasar is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default

    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.

  4. #4
    Ceasar is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default

    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.

  5. #5
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    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.

  6. #6
    Ceasar is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default

    ok i multiplied j and i by the brick height and width. and it worked.

    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 );
    }
    }
    now off to create the blue, green and yellow bricks.

  7. #7
    Ceasar is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default

    Ok i got the bricks working now...thanks to all who helped

Similar Threads

  1. Replies: 2
    Last Post: 02-19-2014, 05:36 PM
  2. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  3. Need help with Breakout game
    By tfitz666 in forum New To Java
    Replies: 9
    Last Post: 03-22-2010, 05:26 AM
  4. Another Breakout question
    By jumpstart in forum New To Java
    Replies: 3
    Last Post: 07-29-2009, 04:48 AM
  5. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •