Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Java for Game Design - Highly Terrible Idea...
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Wed Sep 01, 2010 4:53 pm    Post subject: Java for Game Design - Highly Terrible Idea... Reply with quote

Please don't move this thread, the Game Design section is dead.


I've started using Java for creating a game, but you usually need 20+ lines of code just to do a simple thing you can do in C# with less than 5. Because of this, I had to put so much effort just to get the engine of the game work. Also Java hasn't updated their Sound API to support mp3 yet???

Also how am I going to load an image and get good collision testing?

Example: I load an image that looks like this into java.


How do I make it so the collision bounds touches the blue and not the entire image the collision? Should I use getPixel before I get collision to make sure its not white? And before drawing it to the screen I should replace it to white(The Background Color?)


edit: Idea!

Code:
public void RegisterPoint(int x, int y){ //Once Registered, the only way to edit a point is to reset all of them.
    sprite_collision_points[pnt_num] = new Point(x,y);
    pnt_num+=1;
}

public void ResetAllPointData(){
    for (int i = 0;i< Integer.MAX_VALUE;i++)
    {
    if (sprite_collision_points[i] != null){sprite_collision_points[i] = null;}
    if (sprite_collision_points[i] == null){i=Integer.MAX_VALUE;}
    }
}

public Boolean CheckCollision(int x1, int x2){
    for (int i = 0;i< Integer.MAX_VALUE;i++)
    {
    if (sprite_collision_points[i].equals(new Point(x1,x2))){i=Integer.MAX_VALUE;return true;}
    if (sprite_collision_points[i] == null){i=Integer.MAX_VALUE;return false;}
    }
    return false;
}


I bet my Collision system is the most accurate out of all java games.

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
XaLeX
Expert Cheater
Reputation: 0

Joined: 19 Aug 2008
Posts: 226

PostPosted: Wed Sep 01, 2010 7:47 pm    Post subject: Reply with quote

Don't be offended, but it looks physical memory AND cpu intensive.
Also, those "i = Integer.MAX_VALUE" are horrible... why don't you use break? (btw the ones before a return are useless because you return from the function anyway.
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Wed Sep 01, 2010 8:58 pm    Post subject: Reply with quote

yeye I just made something in a couple of secs. i'll post later
_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Thu Sep 02, 2010 11:53 am    Post subject: Reply with quote

Fixed:

Code:
public void RegisterPoint(int x, int y){ //Once Registered, the only way to edit a point is to reset all of them.
    sprite_collision_points[x][y] = true;
    pnt_num+=1;
}

public void ResetAllPointData(){
    for (int i = 0, z = 0;i< 5000;i++, z++)
    {
    if (sprite_collision_points[i][z] == true){sprite_collision_points[i][z] = false;}
    if (sprite_collision_points[i][z] == null){i=Integer.MAX_VALUE;}
    }
}

public Boolean CheckCollision(int x1, int y1){
    if (sprite_collision_points[x1][y1] == true){return true;}
    if (sprite_collision_points[x1][y1] == false){return false;}
    if (sprite_collision_points[x1][y1] == null){return false;}
    return false;
}

public Boolean CheckCollisionBox(int x1, int y1,int x2, int y2){
    for (int i = x1;i < x2; i++)
    {
    for (int z = y1;i < y2; z++)
    {
    if (sprite_collision_points[i][z] == true){return true;}
    if (sprite_collision_points[i][z] == null){return false;}
    }
    }
    return false;
}

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Sep 02, 2010 4:23 pm    Post subject: Reply with quote

i haven't worked with collision but a bitwise and sounds like a good idea.


you can generate your collision mask from an image and use 1 bit for each pixel. if it's 1, it has collision, if it's 0, it doesn't.

then just do a bitwise and on a chunk of data and if any bits in the return at 1, then you have a collision and can stop the test. if you use SSE, you can effectively check 128 pixels in a single shot.
Back to top
View user's profile Send private message
XaLeX
Expert Cheater
Reputation: 0

Joined: 19 Aug 2008
Posts: 226

PostPosted: Thu Sep 02, 2010 5:28 pm    Post subject: Reply with quote

i'm not a java expert but i hope you'll accept these suggestions:



Quote:
Code:
public void ResetAllPointData(){
    for (int i = 0, z = 0;i< 5000;i++, z++)
    {
    if (sprite_collision_points[i][z] == true){sprite_collision_points[i][z] = false;}
    if (sprite_collision_points[i][z] == null){i=Integer.MAX_VALUE;}
    }
}
- The for will not cycle through the whole array, but only in the NorthWest - SouthEast diagonal.
- Some minor fixes can be made, and maybe you could consider deleting the whole array and allocating a new one if it's faster. Resetting a 1280x800 array takes a little more than one million cycles.
- It's better to avoid using numbers like that 5000. Define constants instead.
- If the array is of Boolean values, how can a value be null? Uninitialized?
Code:
public void ResetAllPointData() {
    for(int i = 0; i < SCREEN_WIDTH; i++) {
        for(int j = 0; j < SCREEN_HEIGHT; j++) {
            sprite_collision_points[i][j] = false;
        }
    }
}

-----
Quote:
Code:
public Boolean CheckCollision(int x1, int y1){
    if (sprite_collision_points[x1][y1] == true){return true;}
    if (sprite_collision_points[x1][y1] == false){return false;}
    if (sprite_collision_points[x1][y1] == null){return false;}
    return false;
}
Too many if's!
Code:
public Boolean CheckCollision(int x, int y) {
    return sprite_collision_points[x][y];
}

-----
Quote:
Code:
public Boolean CheckCollisionBox(int x1, int y1,int x2, int y2){
    for (int i = x1;i < x2; i++)
    {
    for (int z = y1;i < y2; z++)
    {
    if (sprite_collision_points[i][z] == true){return true;}
    if (sprite_collision_points[i][z] == null){return false;}
    }
    }
    return false;
}
My suggestion:
Code:
public Boolean CheckCollisionBox(int x1, int y1,int x2, int y2){
    for (int i = x1;i < x2; i++) {//depending on implementation, you may want "i <= x2" instead of "i < x2". Same goes for the other for.
        for (int z = y1; z < y2; z++) {//here it's "z < y2", not "i < y2"
            if (sprite_collision_points[i][z]){return true;}
        }
    }
    return false;
}
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Sep 02, 2010 7:18 pm    Post subject: Reply with quote

you should be avoiding doing work on the entire screen anyway if speed is a problem.

look at quad trees
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Thu Sep 02, 2010 7:32 pm    Post subject: Reply with quote

Wow XaLeX, you really fixed my entire program. But I still need to find how this java thing works.

@slovach - I created my own function already to do this.
I'm using simple graphics so it will work nicely.

Code:
public Boolean[][] getPoints(String imgloc, int maxX, int MaxY, Color SpecificColor, String name) throws IOException{
   BufferedImage image = new BufferedImage(555,555, BufferedImage.TYPE_INT_RGB);
   Image imagex = new ImageIcon(imgloc).getImage();
   image.getGraphics().drawImage(imagex, 0, 0, null);

   for (int i = 0;i<image.getWidth();i++)
   {
   for (int z = 0;z<image.getHeight();z++)
   {
   int color = image.getRGB(i,z);
   if (color == SpecificColor.getRGB() && i <= maxX && z <= MaxY){
   sprite_collision_points[i][z] = true;

   //System.out.print(i + "," + z);
   } else {sprite_collision_points[i][z] = false;}
   }
   }
   return writeData(sprite_collision_points,image.getWidth(),image.getHeight(), name);
}

public Boolean[][] writeData(Boolean[][] data, int width, int height, String name){ //Compacts data to about .3% of its actual size
    try {
     FileWriter outFile = new FileWriter("C:/Users/Christina/Desktop/" + name + ".txt");
     PrintWriter out = new PrintWriter(outFile);
     int start = -1;
     int start_false = -1;
        for (int i = 0;i< width;i++){
        for (int z = 0;z< height;z++){
            if (sprite_collision_points[i][z] == true && start == -1)
            {
              start = z;
              //out.println("[" + i + "," + z + "]=true");
            }
            if (sprite_collision_points[i][z] == false && start_false == -1)
            {
              start_false = z;
              //out.println("[" + i + "," + z + "]=true");
            }

            if (sprite_collision_points[i][z] == false && start != -1) {out.println("[" + i + "," + (start-1) + " to " + (z-1) + "]=true");start=-1;start_false=-1;}
            if (sprite_collision_points[i][z] == true && start_false != -1) {out.println("[" + i + "," + start_false + " to " + (z-1) + "]=false");start=-1;start_false=-1;}}

        start=-1;start_false=-1;
        }

              out.close();
              return sprite_collision_points;
          } catch (Exception e){
              System.out.println("ERROR");
              e.printStackTrace();
          }

             return null;
}



Example on an image Output:
Code:
[24,0 to 14]=false
[24,15 to 289]=true
[24,291 to 310]=false
[25,0 to 14]=false
[25,15 to 289]=true
[25,291 to 310]=false
[26,0 to 14]=false
[26,15 to 289]=true
[26,291 to 310]=false
[27,0 to 14]=false
[27,15 to 289]=true
[27,291 to 310]=false
[28,0 to 14]=false
[28,15 to 289]=true
[28,291 to 310]=false
[29,0 to 14]=false
[29,15 to 289]=true
[29,291 to 310]=false
[30,0 to 14]=false
[30,15 to 289]=true
[30,291 to 310]=false
[31,0 to 14]=false
[31,15 to 289]=true
[31,291 to 310]=false
[32,0 to 14]=false
[32,15 to 289]=true
[32,291 to 310]=false
[33,0 to 14]=false
[33,15 to 289]=true
[33,291 to 310]=false
[34,0 to 14]=false
[34,15 to 289]=true
[34,291 to 310]=false
[35,0 to 14]=false
[35,15 to 289]=true
.............................

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Fri Sep 03, 2010 4:17 pm    Post subject: Reply with quote

That above method was only used to store the data for the sprite collision because Java Can't write bits and I don't want to waste time using a library.

So I made a new idea.

1.Store the collision data in a BitSet[]
2.Whenever the players bounds collide with an objects bounds it will perform the collision test to see if it is an actual collision.

Code:
public BitSet[] getPoints(String imgloc, int maxX, int MaxY, Color SpecificColor, String name) {
   BufferedImage image = new BufferedImage(555,555, BufferedImage.TYPE_INT_RGB);
   Image imagex = new ImageIcon(imgloc).getImage();
   image.getGraphics().drawImage(imagex, 0, 0, null);
   BitSet[] bits1 = new BitSet[image.getWidth()]; //Creates the new collision array
   
   for (int i = 0;i<image.getWidth();i++)
   {
   bits1[i] = new BitSet(image.getHeight());
   for (int z = 0;z<image.getHeight();z++)
   {
   int color = image.getRGB(i,z);
   if (color == SpecificColor.getRGB() && i <= maxX && z <= MaxY){
   bits1[i].set(z);
   }
   }
   }
   return bits1;
}


Seems nice? Very Happy

Edit:
Implementation I used.

Gets the points as a BitSet
Code:
    Sprite x3 = new Sprite();
    x3.LoadPoints(new creator_getspritepoints().getPoints("C:/Users/Christina/Desktop/TestingImage.gif", 5555, 5555, Color.black,"test1"));
    System.out.print(x3.CheckCollision(0, 0));

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Fri Sep 03, 2010 10:28 pm    Post subject: Reply with quote

Well C# would only run on Windows/Xbox, Java can pretty much run on any OS whereas C# can't. Also, you can always make an online game too, if you don't want a downloadable one. RuneScape seems to be doing fine.
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Sat Sep 04, 2010 9:35 am    Post subject: Reply with quote

Its just that Java librarys have just too little capability...
_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
goat69
Master Cheater
Reputation: 2

Joined: 20 Jul 2010
Posts: 284

PostPosted: Sat Sep 04, 2010 10:04 am    Post subject: Re: Java for Game Design - Highly Terrible Idea... Reply with quote

Jorghi wrote:
Please don't move this thread, the Game Design section is dead.


I've started using Java for creating a game, but you usually need 20+ lines of code just to do a simple thing you can do in C# with less than 5. Because of this, I had to put so much effort just to get the engine of the game work. Also Java hasn't updated their Sound API to support mp3 yet???

Also how am I going to load an image and get good collision testing?

Example: I load an image that looks like this into java.


How do I make it so the collision bounds touches the blue and not the entire image the collision? Should I use getPixel before I get collision to make sure its not white? And before drawing it to the screen I should replace it to white(The Background Color?)


edit: Idea!

Code:
public void RegisterPoint(int x, int y){ //Once Registered, the only way to edit a point is to reset all of them.
    sprite_collision_points[pnt_num] = new Point(x,y);
    pnt_num+=1;
}

public void ResetAllPointData(){
    for (int i = 0;i< Integer.MAX_VALUE;i++)
    {
    if (sprite_collision_points[i] != null){sprite_collision_points[i] = null;}
    if (sprite_collision_points[i] == null){i=Integer.MAX_VALUE;}
    }
}

public Boolean CheckCollision(int x1, int x2){
    for (int i = 0;i< Integer.MAX_VALUE;i++)
    {
    if (sprite_collision_points[i].equals(new Point(x1,x2))){i=Integer.MAX_VALUE;return true;}
    if (sprite_collision_points[i] == null){i=Integer.MAX_VALUE;return false;}
    }
    return false;
}


I bet my Collision system is the most accurate out of all java games.




Runescape Private Server.
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Sat Sep 04, 2010 11:30 am    Post subject: Reply with quote

^ Your post is really useless..

And I'm done.

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
XaLeX
Expert Cheater
Reputation: 0

Joined: 19 Aug 2008
Posts: 226

PostPosted: Sat Sep 04, 2010 12:15 pm    Post subject: Reply with quote

Jorghi wrote:
Its just that Java librarys have just too little capability...
it's what you have to give up for portability Razz
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Sep 04, 2010 5:05 pm    Post subject: Reply with quote

CometJack wrote:
Well C# would only run on Windows/Xbox, Java can pretty much run on any OS whereas C# can't. Also, you can always make an online game too, if you don't want a downloadable one. RuneScape seems to be doing fine.


mono
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites