Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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 / Performance Tuning / Re: Pixel Collision Detection (not what u think at first) on: 2012-11-24 21:24:15
Well thanks deepthought, did that before with the addition of generating it each cycle completely new.
But sadly no feelable performace gain, but thanks anyways ^^

QuadTree looks intresting and might be what im looking for, thanks, will look into it c:
2  Game Development / Performance Tuning / Re: Pixel Collision Detection (not what u think at first) on: 2012-11-24 21:01:49
Sure ill try, here an image:

Dont know if u can see clearly...
But you controll that pixels(red thingys) with your mouse, they follow it...
well thats it atm ^^ later on there would be diffrent colered player who can "capture" my pixels, vice versa, with a algorithm like game of life...
But that shouldnt be too hard.

Dont look at the big rectangle, doesnt do anything.
and the errors in the backfground, well i have problems with overlapping pixels too...
3  Game Development / Performance Tuning / Pixel Collision Detection (not what u think at first) on: 2012-11-24 20:38:12
Hello guys,
first post here on the forum ^^

Story:
Well i have an very old game in mind, but i forgot the name.
It looked simple and easy to recode, but well...
Its some sort of "PixelEater", i will post if someone solves my problem Tongue

There is a simple "Pixel" class which just has coordinates and a color.
This "pixels" draw method just draws a 3x3 square on a 2D surface.
Now that the pixels dont overlap i have to do a collision detection.
Well since this "Pixels" are small and there shall be a ton (maybe 1000-2000, if i remember correctly from the old game),
they need to collide.

Well, atm the best solution i got is to do at every beginning of a workcycle, generate a 2 dimensional boolean Array with true = blocked and false = not blocked(no pixel here).
and then each pixel checks if he can moves in the direction he want to.
It goes good the first 10 pixels with no prob, but if u get above ~ 1500 it gets laggy as hell and 1 cpu core i dying...

Is there any way to get it faster, when all pixels should be moved, and with a reasonable speed ?

well heres the code...


"Pixel's" collsion, called by Slick2D engine:
(pixelMap = booleanArray)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
private void checkCollision(GamePlayState game, GameContainer container) {

        int xc, yc;   //x/yCoordiantes one the grid in real pixels :S like point(1/1) would be grid (0/0)
       xc = xr / 3; // calculation based on realCoordinates
       yc = yr / 3;
        try {
            if ((game.pixelMap[xc + 1][yc + 1] == true && xSpeed > 0 && ySpeed > 0)
                    || (game.pixelMap[xc - 1][yc - 1] == true && xSpeed < 0 && ySpeed < 0)
                    || (game.pixelMap[xc + 1][yc - 1] == true && xSpeed > 0 && ySpeed < 0)
                    || (game.pixelMap[xc - 1][yc + 1] == true && xSpeed < 0 && ySpeed > 0)) {
                xSpeed = 0;
                ySpeed = 0;
            } else {
                if ((game.pixelMap[xc + 1][yc] == true && xSpeed > 0)
                        || (game.pixelMap[xc - 1][yc] == true && xSpeed < 0)) {
                    xSpeed = 0;
                }

                if ((game.pixelMap[xc][yc + 1] == true && ySpeed > 0)
                        || (game.pixelMap[xc][yc - 1] == true && ySpeed < 0)) {
                    ySpeed = 0;
                }
            }

        } catch (Exception e) {
            Log.warn("CheckCollision error");
        }
    }


hope u understand me, if u have questions just ask ^^

~Markus
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.

Riven (4 views)
2014-07-29 12:53:52

Dwinin (7 views)
2014-07-29 10:59:34

E.R. Fleming (21 views)
2014-07-29 03:07:13

E.R. Fleming (8 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (51 views)
2014-07-17 23:47:54
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!