Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java Assistance

Name: Student !HXEkJ/9fP6 2010-05-20 19:44

I am in need of assistance and I'm not sure if /prog/ does this sort of thing, but I'm asking anyway.
I'm currently writing my Final Project for my Java course and it is a game, a relatively simple game. The issue I'm having is collision. The point of the game is to keep your square from being hit by circles, and in the early stages of writing it, I had a detection system based on the coordinates of the start of the rectangle, and the start of the circle, plus the width and height of each, using the g2d.fillRect(x,y,w,h) and the g2d.fillOval(x,y,w,h)m however, during the course of editing, this stopped working for whatever reason.
My question basically boils down to this:
Is there a way to using the pixel colors to detect collision, something like,
if(bluePixel touches greenPixel)
collision = true;
If this is not possible, then shit.
If so, please assist me.

Name: Anonymous 2010-05-20 19:54

BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO SEGFAULT

Name: Student !HXEkJ/9fP6 2010-05-20 20:10

Why thank you, Kind sir.

Name: Anonymous 2010-05-20 20:20

SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT SEGFAULT BUFFALO

Name: Student !HXEkJ/9fP6 2010-05-20 20:26

That also seems to be of much assistance.

Name: Anonymous 2010-05-20 20:29

if(bluePixel touches greenPixel)

dumb idea, rethink what you're doing, and abstract things properly next time

Name: Student !HXEkJ/9fP6 2010-05-20 20:34

>>6
Why would this be such a dumb idea?

Name: Anonymous 2010-05-20 20:46

>>1
Just a reminder, bro - you're talking about programming, everything is possible. Now the question is whether you actually should do it the way you described (answer: no, it's a stupid idea).

There's a lot of literature around the Internet about collision detection, I suggest that you look around and read some. Just a hint: comparing stuff per-pixel is generally a bad idea. You're testing whether two simple geometrical shapes intersect or not - you most definitely don't need to render them first, and if you can't think of a different way to do it then maybe programming isn't for you.

Name: Student !HXEkJ/9fP6 2010-05-20 20:56

>>8
I figured it out, I merely rewrote the original collision detection system I had, and it worked.

Name: Am I on /prog/ or /sci/? 2010-05-20 20:57

>>1
Start by making sure the objects are within each others's bounding regions.

Proving that, construct the equation of the ellipse and then get the vector between the center of the ellipse to the rectangle.
Turn that vector into a y = x line equation.  Also, render the equation for the ellipse into y = x form.
Make the two equations equal to each other - y = y - and solve for an x.  There can be one or more x values depending on how much the shapes can embed themselves in each other before being collision checked.

From x, get (all) y values.  If you have more than one set of x,y pairs, and you need or want one, average them out or re-use the vector between the two shapes's centers.

Name: Student !HXEkJ/9fP6 2010-05-20 21:04

>>10
I'm not quite sure what that means, but this is what I did, it seems to work:
if(
(circle[i].x <= character.x +character.w) &&
(circle[i].x + circle[i].w >= character.x)&&
(circle[i].y <= character.y +character.h) &&
(circle[i].y + circle[i].h >= character.y)
)
gameEnd();

Name: Anonymous 2010-05-20 21:16

>>11
You wrote the step one >>10 is talking about.  The rest of >>10 is about the specifics of the collision and making sure (where) the shapes definitely touch, something you don't have to worry about since, apparently, the game ends.

Name: Anonymous 2010-05-20 21:31

>>11
Have you noticed that you actually made your circle a square?

Name: Anonymous 2010-05-20 21:37

>>13
Don't be silly. Von Lindemann proved that it's impossible to square a circle in 1882!

Name: Anonymous 2010-05-21 0:39

>>14
It's possible if the square's segment length is a transcendent number, such as pi

Name: Anonymous 2010-05-21 6:14

>>15
Care to explain how? I don't think that is correct.

Name: Anonymous 2010-05-21 6:46

>>16
It's wrong.

Name: Anonymous 2010-05-21 8:29

>>15
HAX MAH PEENUS

Name: Anonymous 2011-02-04 14:10

Name: Anonymous 2011-02-04 18:47

Name: Anonymous 2011-02-17 19:57

check my doubles

Name: Anonymous 2013-01-19 23:36

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Don't change these.
Name: Email:
Entire Thread Thread List