Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Newbie trying to create a game using Java  (Read 1530 times)
0 Members and 1 Guest are viewing this topic.
Offline NewbieRed004

Innocent Bystander





« Posted 2005-12-09 01:17:42 »

I am trying to create a basic breakout game for one of my classes...i am having some troubles however with the last parts of the game. I cannot figure out how to make the ball bounce off of the brick and then the paddle and have the brick disappear. Any help would be greatly appreciated!!!

Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #1 - Posted 2005-12-09 01:44:56 »

that kinda depence on the design of the rest of the program.

depending on which collision detection methode you use you should in the process of determing the collision get the 2 objects that collide (the ball and the brick) and where they collide, calculate in which direction the ball is suppose to go and then simply call the apporiate methodes on the 2 objects. (for example ball.setDirection(), and brick.destroy()Wink

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Jeff

JGO Coder




Got any cats?


« Reply #2 - Posted 2005-12-09 04:36:31 »

The bounce is very very basic physics... google "angle of reflection"

AS for removing the brick, as already said it depends on how you are doing screen updates to begin with.  If iy were my game Id likely be doing active rendering and just re-draw all the bricks each frame.  If you use an image for each color brick and just draw by BLT it will all egt cached on the graphcis card and shoudl be very very fast.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #3 - Posted 2005-12-09 06:53:15 »

u.v = |U|*|V| * cos(theta)

But yeh, vector math is key.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline OverKill

Junior Devvie




Java games rock!


« Reply #4 - Posted 2005-12-09 08:33:23 »

@Jeff:
Although angle of reflection will work, it might not be applicable.
In the old pong game the reflection was based on what part of the paddle the ball landed on.
If it landed near the centre the ball bounced of normally. The farther out the greater the angle.
So it was shaped more like a lens then a paddle.
Otherwise the ball would allways fly at the same angles, or would it not?

Or am I getting something wrong?
Offline cylab

JGO Ninja


Medals: 55



« Reply #5 - Posted 2005-12-09 09:39:21 »

@OverKill
you are right. Also some versions use the current movement of the paddle to bias the reflection vector.

Mathias - I Know What [you] Did Last Summer!
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #6 - Posted 2005-12-09 09:52:02 »

Seriously guys. I use normal vector math on it and it works fine.
You can take into account the forces.

Acceleration of paddle and ball and gravity and so forth.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #7 - Posted 2005-12-09 15:10:02 »

Seriously guys. I use normal vector math on it and it works fine.
You can take into account the forces.

Acceleration of paddle and ball and gravity and so forth.

Don't add gravity unless you want a very different game. In fact, for Arkanoid/Breakout, you don't want to change the ball speed at all. "Simple" physics of reflecting the ball is sufficient for Arkanoid. Pong needed a more complicated physics arrangement (which wasn't very realistic, BTW) because it needed a way to actually control the ball. Once a developer has basic physics down in his game, it's quite easy to add the ability to deflect the ball by moving the paddle while it hits.

Java Game Console Project
Last Journal Entry: 12/17/04
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!