Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Game advice

Options
  • 22-11-2011 3:47am
    #1
    Closed Accounts Posts: 8,866 ✭✭✭


    So I'm studying CS right now, and we're covering Java right off the bat, none of which I've done before. I started watching these Stanford lectures on programming the last few days and one of the assignments they were given was to develop the game Breakout. I've attached my copy of it, as i'm curious to hear any pointers anyone might have on my overall take on the project.

    And more specifically, if you're looking at it, I'd love to know how I would go about affecting the balls angle based off of where it strikes the paddle i.e. outer edges sharpen the angle, middle lessens it. Cheers!


Comments

  • Registered Users Posts: 360 ✭✭witless1


    Without knowing too much about the course and what was provided, at first glance the coding looks good. Comments are there which is nice to see :)

    As for your question I think you have the tools available from just a quick scan of the code and a google for the API of the ball and the paddle. You can certainly detect where on the paddle the ball hit it as you have:

    - The paddle dimensions provided.
    - The GRect class has a getX and getY co-ordinate so you can find out exactly where it is.
    - You have a means to detect a paddle collision which means you have the balls X + Y co-ordinate.
    - The ball inherits from GObject which has a move method which involves a vector (giving you direction)

    So I would probably have an if collider == paddle line in there, try find out exactly where the Paddle is, find out where the ball met the paddle and from what direction the ball met the paddle. Use your paddle dimensions to work out whether it hit the center or side and then change the balls movement direction appropriately. You might define side + middle and just affect the vector off of that. I doubt they want you having precise angles for every pixel of the bat!


  • Registered Users Posts: 37 corman007


    Hi Adam are those the lectures with Mehran Sahami?


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    They are indeed!


  • Registered Users Posts: 37 corman007


    He's without doubt the best lecturer i've ever seen/ had, guess thats what you pay all the money for in Stanford


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    That's life in the city!


  • Advertisement
  • Closed Accounts Posts: 159 ✭✭yenoah


    I dunno, find him a little exhausting. He's constantly up there with the voice, shouting 1000wpm. Jesus a gap every now and then i'd be great.


  • Registered Users Posts: 37 corman007


    yeah true but the bag of sweets thing is a new one :D


  • Closed Accounts Posts: 5,482 ✭✭✭Kidchameleon


    OP this is a nice Java library if you plan to take this further...

    http://lwjgl.org/

    Minecraft was made with this...


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Cheers, I'll have a look at that later!

    And thanks again to witless, got my ball going all over the shop! :)


Advertisement