Results 1 to 1 of 1
- 10-15-2011, 10:56 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 13
- Rep Power
- 0
Detect collision between two objects(rect and oval)?
So, i'm trying to get into java, and i'm trying to make a simple pong game, so i have made the ball and paddle object, but i need to make it so, that the ball will bounce off the paddle like if it was hitting the border, but i can't seem to get the math right here.
This is was i made (It makes the applet freeze by and error though):
Those are the position methods from the paddle class:Java Code:public boolean toPaddle(){ if(x_pos > paddle.getX() || x_pos < paddle.getWidth() || y_pos > paddle.getY() || y_pos < paddle.getHeight()){ speedx = (rand.nextInt(2)+1)-4; // Changes the direction on the X-axis return true; } return false; }
I think i made the calculation on the paddle wrong, but this is what i could think off, after seaching a bit.Java Code:public int getX(){ return x_pos; } public int getY(){ return y_pos; } public int getWidth(){ int w = x_pos + p_width; return w; } public int getHeight(){ int h = y_pos + p_height; return h; }
Regards Naxix
Similar Threads
-
2D collision handling between two different moving objects
By Silversurfer20 in forum Java 2DReplies: 10Last Post: 04-05-2012, 09:32 AM -
OVal 1.80
By java software in forum Java SoftwareReplies: 0Last Post: 10-06-2011, 06:54 PM -
MouseEntered to rect
By g6pd in forum New To JavaReplies: 3Last Post: 03-10-2011, 01:52 PM -
Problem in collision between objects
By Chetans in forum Java GamingReplies: 3Last Post: 03-15-2010, 11:24 PM -
OVal 1.10
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11-03-2007, 06:00 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks