Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (552)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Pixel perfect collision detection? on: 2012-12-14 07:38:09
One method that would work would be to simply convert both of your images to byte[][] arrays, where 1 represents an opaque pixel and 0 represents a transparent pixel. That may not be the best method, though.
2  Game Development / Newbie & Debugging Questions / Re: Pixel perfect collision detection? on: 2012-12-13 22:42:19
The first link has a post (by yours truly) at the bottom of the thread detailing how one goes about implementing pixel-perfect collision. The second link contains a simple method for basic collision detection in games. The basics behind 2D pixel-perfect collision detection methods don't exactly change from engine to engine.
3  Game Development / Newbie & Debugging Questions / Re: Pixel perfect collision detection? on: 2012-12-13 21:46:14
2 topics alone on the first page of the Game Mechanics board.

http://www.java-gaming.org/topics/perfect-colision-system-in-lwjgl/27836/view.html
http://www.java-gaming.org/topics/2d-collision-detection-best-approach/28040/view.html
4  Game Development / Game Mechanics / Re: Perfect collision system (in LWJGL) on: 2012-12-13 08:28:14
Ok, here we are.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static boolean intersectsByte(byte[][] a1, byte[][] a2, int x, int y) {
    for (int i = 0; i < a1.length; i++) {
        for (int j = 0; j < a1[0].length; j++) {
            if (a1[i][j] == 1) {
                for (int k = 0; k < a1.length; k++) {
                    for (int l = 0; l < a1[0].length; l++) {
                        if (((k - x) >= 0) && ((k - x) < a2.length) && ((l - y) >= 0) && ((l - y) < a2[0].length)) {
                            if (a2[k - x][l - y] == 1) {
                                return true; } } } } } } }
    return false; }

EDIT: It looks like the Rectangle's intersection() method could be useful for only checking the areas in which two locations intersect.
5  Game Development / Game Mechanics / Re: Perfect collision system (in LWJGL) on: 2012-12-13 08:14:38
UnconventionalT, you should rather make the appropriate checks and remove the try/catch clause.

You mean something like checking if (k - x) is greater/smaller than a2.length and if (l - y) is greater/smaller than a2[0].length? That wouldn't be necessary if I check only the areas that are overlapping.

Also, why? Is this just a bad programming practice?
6  Game Development / Game Mechanics / Re: Perfect collision system (in LWJGL) on: 2012-12-13 07:13:11
The method I'm currently thinking using is to check for basic bounding box collisions (using the Rectangle class and the intersects() method). If it detects a collision, I plan on having it check for pixel-perfect collision. Sometimes I render more than a thousand different bullets, so there won't be a need for pixel-perfect collision detection every update.

The basic idea behind my perfect-pixel collision detection method is to iterate though every pixel in one sprite and check it for every pixel in another sprite. The code then checks the contents to see if both locations contain one opaque pixel. One way to simplify this loop is to return true as soon as a collision is detected. Another method to speed it up would be to only consider the area that the two sprites overlap each other (but I haven't had time to figure that out yet). Another point is that you also have to factor in the offset between the two sprites. Handle any ArrayIndexOutOfBoundsExceptions and throw them away, that just means that the pixels you're checking against don't exist.

Example code using 2 byte[][] arrays. 1 means opaque pixel, 0 means transparent pixel.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static boolean intersectsByte(byte[][] a1, byte[][] a2, int x, int y) {
    for (int i = 0; i < a1.length; i++) {
        for (int j = 0; j < a1[0].length; j++) {
            if (a1[i][j] == 1) {
                for (int k = 0; k < a1.length; k++) {
                    for (int l = 0; l < a1[0].length; l++) {
                        try {
                            if (a2[k - x][l - y] == 1) { return true; }
                        } catch (Exception ex) { } } } } } }
    return false; }

(Ignore the terrible formatting, I'm just trying to keep my post length sane.)
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (23 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (41 views)
2014-08-06 19:49:38
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!