Image Collision / Detection help please.
Author |
Message |
.hack
|
Posted: Sun Jun 18, 2006 1:16 pm Post subject: Image Collision / Detection help please. |
|
|
I'm finishing up my Java Programming final and I am down to collision detection. I've searched the forums to not much avail.
I need a fast, and preferably easy to get hit detection. The program I am making has one playing field, 2 "bike" who leave a trail behind them. The goal is to have one bike collide with the others trail. Think Lightcycles and you have it exactly.
I am using images for pretty much everything, as I don't see much of a better way. Is there a method of collision that includes one image entering the bounds of another.
I know array detection is an option, but for this to work, the array would have to remember EVERY past coordinate of both players, and then compare the current position with the entire array -- I fear this can get very sluggish.
So, I found a few options.
1) Image COllision, is this possible?
2) Whatdotcolor - Completely frowned upon by everyone, and I'd rather avoid it.
3) MVC - I have no idea how to use, and the first I heard of it was today, not even sure if my teacher knows what it is. ALso I fear I'd have to recode my entire game around it.
Number 1 seems like the best bet. Any resources / opinions / tutorials / help?
THanks alot guys and gals |
|
|
|
|
|
Sponsor Sponsor
|
|
|
HellblazerX
|
Posted: Sun Jun 18, 2006 4:17 pm Post subject: (No subject) |
|
|
Trust me, Java handles calculations much better than Images. Trust me. And I don't think I've ever heard of "Image Collision". The Graphics2D class has a hit () method, which checks if a Shape object is intersecting with a Rectangle object. I suppose you could work with this. Also, if you're thinking of using whatdotcolor, BufferedImage class has a getRGB () method, which is probably as close to whatdotcolor as you'll get. And MVC? What's that? Do you mean Model-view-controller? I don't see how that would fit in with your collision detection. Wikipedia has a nice article on it, if you want to read about it.
Btw, my friend made a similar game for his FP, except he used a grid system for it. If all your options fail, then you could try that. |
|
|
|
|
|
.hack
|
Posted: Sun Jun 18, 2006 4:28 pm Post subject: (No subject) |
|
|
How did his grid system work, if you remember at all? In this, there has to be a trail of light behind the bike. so did he just make an array of kind of "blocks" on the playing field. Each block being a certain amount of coords?
This way u could flag which blocks have been occupied by an object, so if player ones position == a flagged block it counts as a collision?
If thats how it would be super sweet. I just don't know what the code would be if u could make "blocks" like that in an array.
Otherwise, I'm not really sure."
The trails are like this::
http://upload.wikimedia.org/wikipedia/en/2/28/Tron_Lightcycles.jpg
in that image. Of course this isn't 3d, its just a 2d overhead type angle, but I'd need the trail to be remembered, and the trail length is infinite, there is no end it keeps going until the player dies. |
|
|
|
|
|
HellblazerX
|
Posted: Sun Jun 18, 2006 4:38 pm Post subject: (No subject) |
|
|
.hack wrote: How did his grid system work, if you remember at all? In this, there has to be a trail of light behind the bike. so did he just make an array of kind of "blocks" on the playing field. Each block being a certain amount of coords?
That's basically it. He made a 2D array of Color instances, which hold the color of that grid. Collision detection was simple, if the player moved into a spot that wasn't black, or whatever color you're making the background, then it counts as a collision, and the player loses. And you don't need coordinates for this one. Just have all your movement in the grid block. Instead of moving your bike 5 pixels to the left, you can move him 1 grid space to the left, and when you go to draw it, you can multiple the grid coordinates by whatever size you want your blocks to be. So if you want 5x5 blocks, you mulitple your grid coordinate by 5, and that's where you draw the image. In your case, you could have a 2D array of int, where the numbers are indices to your images. |
|
|
|
|
|
.hack
|
Posted: Tue Jun 20, 2006 1:03 am Post subject: (No subject) |
|
|
Right on. Thanks for the help man, I'll see if I can work this in. The background field is just 1 image, so perhaps I can overlay the collision grid over that.
The images and menu is broken again for some reason I'm not sure of, when I fix that I'll let you know how it goes.
Thanks again! |
|
|
|
|
|
|
|